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; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 548 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 549 | |
| 550 | private class PolicyHandler extends Handler { |
| 551 | @Override |
| 552 | public void handleMessage(Message msg) { |
| 553 | switch (msg.what) { |
| 554 | case MSG_ENABLE_POINTER_LOCATION: |
| 555 | enablePointerLocation(); |
| 556 | break; |
| 557 | case MSG_DISABLE_POINTER_LOCATION: |
| 558 | disablePointerLocation(); |
| 559 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 560 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 561 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 562 | break; |
| 563 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 564 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 565 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 566 | case MSG_DISPATCH_SHOW_RECENTS: |
| 567 | showRecentApps(false); |
| 568 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 569 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 570 | showGlobalActionsInternal(); |
| 571 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 572 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 573 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
| 574 | mKeyguardDrawComplete = true; |
| 575 | finishScreenTurningOn(); |
| 576 | break; |
| 577 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 578 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
| 579 | mKeyguardDrawComplete = true; |
| 580 | finishScreenTurningOn(); |
| 581 | break; |
| 582 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 583 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
| 584 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 585 | mWindowManagerDrawComplete = true; |
| 586 | finishScreenTurningOn(); |
| 587 | break; |
| 588 | case MSG_WAKING_UP: |
| 589 | handleWakingUp((ScreenOnListener) msg.obj); |
| 590 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 591 | case MSG_HIDE_BOOT_MESSAGE: |
| 592 | handleHideBootMessage(); |
| 593 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 594 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 595 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 596 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 601 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 602 | @Override |
| 603 | public void onUEvent(UEventObserver.UEvent event) { |
| 604 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 605 | } |
| 606 | }; |
| 607 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 608 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 609 | SettingsObserver(Handler handler) { |
| 610 | super(handler); |
| 611 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 612 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 613 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 614 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 615 | ContentResolver resolver = mContext.getContentResolver(); |
| 616 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 617 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 618 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 619 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 620 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 621 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 622 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 623 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 624 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 625 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 626 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 627 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 628 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 629 | Settings.System.USER_ROTATION), false, this, |
| 630 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 631 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 632 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 633 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 634 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 635 | Settings.System.POINTER_LOCATION), false, this, |
| 636 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 637 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 638 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 639 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 640 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 641 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 642 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 643 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 644 | Settings.Global.POLICY_CONTROL), false, this, |
| 645 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 646 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 650 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 651 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 652 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 653 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 654 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 655 | class MyWakeGestureListener extends WakeGestureListener { |
| 656 | MyWakeGestureListener(Context context, Handler handler) { |
| 657 | super(context, handler); |
| 658 | } |
| 659 | |
| 660 | @Override |
| 661 | public void onWakeUp() { |
| 662 | synchronized (mLock) { |
| 663 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 664 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 665 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 671 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 672 | MyOrientationListener(Context context, Handler handler) { |
| 673 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 674 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 675 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 676 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 677 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 678 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 679 | updateRotation(false); |
| 680 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 681 | } |
| 682 | MyOrientationListener mOrientationListener; |
| 683 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 684 | private final BarController mStatusBarController = new BarController("StatusBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 685 | View.STATUS_BAR_TRANSIENT, |
| 686 | View.STATUS_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 687 | View.STATUS_BAR_TRANSLUCENT, |
| 688 | StatusBarManager.WINDOW_STATUS_BAR, |
| 689 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 690 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 691 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 692 | View.NAVIGATION_BAR_TRANSIENT, |
| 693 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 694 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 695 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 696 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 697 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 698 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 699 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 700 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 701 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 702 | IStatusBarService getStatusBarService() { |
| 703 | synchronized (mServiceAquireLock) { |
| 704 | if (mStatusBarService == null) { |
| 705 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 706 | ServiceManager.getService("statusbar")); |
| 707 | } |
| 708 | return mStatusBarService; |
| 709 | } |
| 710 | } |
| 711 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 712 | /* |
| 713 | * We always let the sensor be switched on by default except when |
| 714 | * the user has explicitly disabled sensor based rotation or when the |
| 715 | * screen is switched off. |
| 716 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 717 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 718 | if (mSupportAutoRotation) { |
| 719 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 720 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 721 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 722 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 723 | // If the application has explicitly requested to follow the |
| 724 | // orientation, then we need to turn the sensor on. |
| 725 | return true; |
| 726 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 727 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 728 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 729 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 730 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 731 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 732 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 733 | // orientation management, |
| 734 | return true; |
| 735 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 736 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 737 | // If the setting for using the sensor by default is enabled, then |
| 738 | // we will always leave it on. Note that the user could go to |
| 739 | // a window that forces an orientation that does not use the |
| 740 | // sensor and in theory we could turn it off... however, when next |
| 741 | // turning it on we won't have a good value for the current |
| 742 | // orientation for a little bit, which can cause orientation |
| 743 | // changes to lag, so we'd like to keep it always on. (It will |
| 744 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 745 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 746 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 747 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 748 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 749 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 750 | /* |
| 751 | * Various use cases for invoking this function |
| 752 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 753 | * 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] | 754 | * if not already enabled |
| 755 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 756 | * already enabled |
| 757 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 758 | * screen turning on and current app has nosensor based orientation, do nothing |
| 759 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 760 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 761 | if (!mOrientationListener.canDetectOrientation()) { |
| 762 | // If sensor is turned off or nonexistent for some reason |
| 763 | return; |
| 764 | } |
| 765 | //Could have been invoked due to screen turning on or off or |
| 766 | //change of the currently visible window's orientation |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 767 | if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 768 | ", current orientation="+mCurrentAppOrientation+ |
| 769 | ", SensorEnabled="+mOrientationSensorEnabled); |
| 770 | boolean disable = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 771 | if (mScreenOnEarly) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 772 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 773 | disable = false; |
| 774 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 775 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 776 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 777 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 778 | mOrientationSensorEnabled = true; |
| 779 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 780 | } |
| 781 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 782 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 783 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 784 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 785 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 786 | mOrientationSensorEnabled = false; |
| 787 | } |
| 788 | } |
| 789 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 790 | private void interceptPowerKeyDown(boolean handled) { |
| 791 | mPowerKeyHandled = handled; |
| 792 | if (!handled) { |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 793 | mHandler.postDelayed(mPowerLongPress, |
| 794 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
| 798 | private boolean interceptPowerKeyUp(boolean canceled) { |
| 799 | if (!mPowerKeyHandled) { |
| 800 | mHandler.removeCallbacks(mPowerLongPress); |
| 801 | return !canceled; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 802 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 803 | return false; |
| 804 | } |
| 805 | |
| 806 | private void cancelPendingPowerKeyAction() { |
| 807 | if (!mPowerKeyHandled) { |
| 808 | mHandler.removeCallbacks(mPowerLongPress); |
| 809 | } |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 810 | if (mPowerKeyTriggered) { |
| 811 | mPendingPowerKeyUpCanceled = true; |
| 812 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 816 | if (mScreenshotChordEnabled |
| 817 | && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 818 | final long now = SystemClock.uptimeMillis(); |
| 819 | if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 820 | && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 821 | mVolumeDownKeyConsumedByScreenshotChord = true; |
| 822 | cancelPendingPowerKeyAction(); |
| 823 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 824 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | } |
| 828 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 829 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 830 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 831 | // Double the time it takes to take a screenshot from the keyguard |
| 832 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 833 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 834 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 835 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 838 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 839 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 842 | private void powerShortPress(long eventTime) { |
| 843 | if (mShortPressOnPowerBehavior < 0) { |
| 844 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 845 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 846 | } |
| 847 | |
| 848 | switch (mShortPressOnPowerBehavior) { |
| 849 | case SHORT_PRESS_POWER_NOTHING: |
| 850 | break; |
| 851 | case SHORT_PRESS_POWER_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, 0); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 854 | break; |
| 855 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 856 | mPowerManager.goToSleep(eventTime, |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 857 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 858 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 859 | break; |
| 860 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 861 | mPowerManager.goToSleep(eventTime, |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 862 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 863 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 864 | launchHomeFromHotKey(); |
| 865 | break; |
| 866 | } |
| 867 | } |
| 868 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 869 | private final Runnable mPowerLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 870 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 871 | public void run() { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 872 | // The context isn't read |
| 873 | if (mLongPressOnPowerBehavior < 0) { |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 874 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 875 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 876 | } |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 877 | int resolvedBehavior = mLongPressOnPowerBehavior; |
| 878 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 879 | resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 880 | } |
| 881 | |
| 882 | switch (resolvedBehavior) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 883 | case LONG_PRESS_POWER_NOTHING: |
| 884 | break; |
| 885 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 886 | mPowerKeyHandled = true; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 887 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 888 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 889 | } |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 890 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 891 | break; |
| 892 | case LONG_PRESS_POWER_SHUT_OFF: |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 893 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 894 | mPowerKeyHandled = true; |
| 895 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 896 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 897 | mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 898 | break; |
| 899 | } |
| 900 | } |
| 901 | }; |
| 902 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 903 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 904 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 905 | public void run() { |
| 906 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 907 | } |
| 908 | }; |
| 909 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 910 | @Override |
| 911 | public void showGlobalActions() { |
| 912 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 913 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 914 | } |
| 915 | |
| 916 | void showGlobalActionsInternal() { |
| 917 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 918 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 919 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 920 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 921 | final boolean keyguardShowing = keyguardIsShowingTq(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 922 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 923 | if (keyguardShowing) { |
| 924 | // since it took two seconds of long press to bring this up, |
| 925 | // 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] | 926 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
| 930 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 931 | return Settings.Global.getInt( |
| 932 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 933 | } |
| 934 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 935 | boolean isUserSetupComplete() { |
| 936 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 937 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 938 | } |
| 939 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 940 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 941 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 942 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 943 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 944 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 945 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 946 | toggleRecentApps(); |
| 947 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 948 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 949 | } |
| 950 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 951 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 952 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 953 | private void handleDoubleTapOnHome() { |
| 954 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 955 | mHomeConsumed = true; |
| 956 | toggleRecentApps(); |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 961 | @Override |
| 962 | public void run() { |
| 963 | if (mHomeDoubleTapPending) { |
| 964 | mHomeDoubleTapPending = false; |
| 965 | launchHomeFromHotKey(); |
| 966 | } |
| 967 | } |
| 968 | }; |
| 969 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 970 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 971 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 972 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 973 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 974 | mContext = context; |
| 975 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 976 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 977 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 978 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 979 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 980 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 981 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 982 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 983 | try { |
| 984 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 985 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 986 | mSettingsObserver = new SettingsObserver(mHandler); |
| 987 | mSettingsObserver.observe(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 988 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 989 | mShortcutManager.observe(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 990 | mUiMode = context.getResources().getInteger( |
| 991 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 992 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 993 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 994 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 995 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 996 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 997 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 998 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 999 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1000 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1001 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1002 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1003 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1004 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1005 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1006 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1007 | "PhoneWindowManager.mBroadcastWakeLock"); |
| 1008 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1009 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1010 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1011 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1012 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1013 | mCarDockRotation = readRotation( |
| 1014 | com.android.internal.R.integer.config_carDockRotation); |
| 1015 | mDeskDockRotation = readRotation( |
| 1016 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1017 | mUndockedHdmiRotation = readRotation( |
| 1018 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1019 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1020 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1021 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1022 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1023 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1024 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1025 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1026 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1027 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1028 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1029 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1030 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1031 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1032 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1033 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1034 | Context.ACCESSIBILITY_SERVICE); |
| 1035 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1036 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1037 | IntentFilter filter = new IntentFilter(); |
| 1038 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1039 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1040 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1041 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1042 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1043 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1044 | if (intent != null) { |
| 1045 | // Retrieve current sticky dock event broadcast. |
| 1046 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1047 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1048 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1049 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1050 | // register for dream-related broadcasts |
| 1051 | filter = new IntentFilter(); |
| 1052 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1053 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1054 | context.registerReceiver(mDreamReceiver, filter); |
| 1055 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1056 | // register for multiuser-relevant broadcasts |
| 1057 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1058 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1059 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1060 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1061 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1062 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1063 | @Override |
| 1064 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1065 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1066 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1067 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1068 | } |
| 1069 | @Override |
| 1070 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1071 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1072 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | @Override |
| 1076 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1077 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1078 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1079 | } |
| 1080 | } |
| 1081 | @Override |
| 1082 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1083 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1084 | } |
| 1085 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1086 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1087 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1088 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1089 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1090 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1091 | com.android.internal.R.array.config_longPressVibePattern); |
| 1092 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1093 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1094 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1095 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1096 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1097 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1098 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1099 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1100 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1101 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1102 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1103 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1104 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1105 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1106 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1107 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1108 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1109 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1110 | // Controls rotation and the like. |
| 1111 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1112 | |
| 1113 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1114 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 1115 | goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1116 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1119 | /** |
| 1120 | * Read values from config.xml that may be overridden depending on |
| 1121 | * the configuration of the device. |
| 1122 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1123 | */ |
| 1124 | private void readConfigurationDependentBehaviors() { |
| 1125 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1126 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1127 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1128 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1129 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1130 | } |
| 1131 | |
| 1132 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1133 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1134 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1135 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1136 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1137 | } |
| 1138 | } |
| 1139 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1140 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1141 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1142 | // This method might be called before the policy has been fully initialized |
| 1143 | // or for other displays we don't care about. |
| 1144 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1145 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1146 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1147 | mDisplay = display; |
| 1148 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1149 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1150 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1151 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1152 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1153 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1154 | mLandscapeRotation = Surface.ROTATION_0; |
| 1155 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1156 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1157 | mPortraitRotation = Surface.ROTATION_90; |
| 1158 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1159 | } else { |
| 1160 | mPortraitRotation = Surface.ROTATION_270; |
| 1161 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1162 | } |
| 1163 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1164 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1165 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1166 | mPortraitRotation = Surface.ROTATION_0; |
| 1167 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1168 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1169 | mLandscapeRotation = Surface.ROTATION_270; |
| 1170 | mSeascapeRotation = Surface.ROTATION_90; |
| 1171 | } else { |
| 1172 | mLandscapeRotation = Surface.ROTATION_90; |
| 1173 | mSeascapeRotation = Surface.ROTATION_270; |
| 1174 | } |
| 1175 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1176 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1177 | mStatusBarHeight = |
| 1178 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1179 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1180 | // Height of the navigation bar when presented horizontally at bottom |
| 1181 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1182 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1183 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1184 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1185 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1186 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1187 | |
| 1188 | // Width of the navigation bar when presented vertically along one side |
| 1189 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1190 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1191 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1192 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1193 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1194 | |
| 1195 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1196 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1197 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1198 | |
Craig Mautner | d4ec3324 | 2013-07-22 10:37:43 -0700 | [diff] [blame] | 1199 | // Allow the navigation bar to move on small devices (phones). |
| 1200 | mNavigationBarCanMove = shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1201 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1202 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1203 | // Allow a system property to override this. Used by the emulator. |
| 1204 | // See also hasNavigationBar(). |
| 1205 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1206 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1207 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1208 | } else if ("0".equals(navBarOverride)) { |
| 1209 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1212 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1213 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1214 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1215 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1216 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1217 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1218 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1219 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1220 | |
| 1221 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1222 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1223 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1224 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1225 | // For debug purposes the next line turns this feature off with: |
| 1226 | // $ adb shell setprop config.override_forced_orient true |
| 1227 | // $ adb shell wm size reset |
| 1228 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1229 | } |
| 1230 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1231 | /** |
| 1232 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1233 | * navigation bar and touch exploration is not enabled |
| 1234 | */ |
| 1235 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1236 | return mHasNavigationBar |
| 1237 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1240 | @Override |
| 1241 | public boolean isDefaultOrientationForced() { |
| 1242 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1245 | @Override |
| 1246 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1247 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1248 | mOverscanLeft = left; |
| 1249 | mOverscanTop = top; |
| 1250 | mOverscanRight = right; |
| 1251 | mOverscanBottom = bottom; |
| 1252 | } |
| 1253 | } |
| 1254 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1255 | public void updateSettings() { |
| 1256 | ContentResolver resolver = mContext.getContentResolver(); |
| 1257 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1258 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1259 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1260 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1261 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1262 | UserHandle.USER_CURRENT); |
| 1263 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1264 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1265 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1266 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1267 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1268 | // Configure wake gesture. |
| 1269 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1270 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1271 | UserHandle.USER_CURRENT) != 0; |
| 1272 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1273 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1274 | updateWakeGestureListenerLp(); |
| 1275 | } |
| 1276 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1277 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1278 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1279 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1280 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1281 | if (mUserRotation != userRotation) { |
| 1282 | mUserRotation = userRotation; |
| 1283 | updateRotation = true; |
| 1284 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1285 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1286 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1287 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1288 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1289 | if (mUserRotationMode != userRotationMode) { |
| 1290 | mUserRotationMode = userRotationMode; |
| 1291 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1292 | updateOrientationListenerLp(); |
| 1293 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1294 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1295 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1296 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1297 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1298 | if (mPointerLocationMode != pointerLocation) { |
| 1299 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1300 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1301 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1305 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1306 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1307 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1308 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1309 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1310 | if (mHasSoftInput != hasSoftInput) { |
| 1311 | mHasSoftInput = hasSoftInput; |
| 1312 | updateRotation = true; |
| 1313 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1314 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1315 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1316 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1317 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1318 | } |
| 1319 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1320 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1321 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1324 | private void updateWakeGestureListenerLp() { |
| 1325 | if (shouldEnableWakeGestureLp()) { |
| 1326 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1327 | } else { |
| 1328 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | private boolean shouldEnableWakeGestureLp() { |
| 1333 | return mWakeGestureEnabledSetting && !mScreenOnEarly |
| 1334 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1335 | && mWakeGestureListener.isSupported(); |
| 1336 | } |
| 1337 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1338 | private void enablePointerLocation() { |
| 1339 | if (mPointerLocationView == null) { |
| 1340 | mPointerLocationView = new PointerLocationView(mContext); |
| 1341 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1342 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1343 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1344 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1345 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1346 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1347 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1348 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1349 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1350 | if (ActivityManager.isHighEndGfx()) { |
| 1351 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1352 | lp.privateFlags |= |
| 1353 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1354 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1355 | lp.format = PixelFormat.TRANSLUCENT; |
| 1356 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1357 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1358 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1359 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1360 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1361 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1362 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1363 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1364 | |
| 1365 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1366 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1367 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1368 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1369 | wm.removeView(mPointerLocationView); |
| 1370 | mPointerLocationView = null; |
| 1371 | } |
| 1372 | } |
| 1373 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1374 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1375 | try { |
| 1376 | int rotation = mContext.getResources().getInteger(resID); |
| 1377 | switch (rotation) { |
| 1378 | case 0: |
| 1379 | return Surface.ROTATION_0; |
| 1380 | case 90: |
| 1381 | return Surface.ROTATION_90; |
| 1382 | case 180: |
| 1383 | return Surface.ROTATION_180; |
| 1384 | case 270: |
| 1385 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1386 | } |
| 1387 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1388 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1389 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1390 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1394 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1395 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1396 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1397 | |
| 1398 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1399 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1400 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 1401 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1402 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1403 | } |
| 1404 | String permission = null; |
| 1405 | switch (type) { |
| 1406 | case TYPE_TOAST: |
| 1407 | // XXX right now the app process has complete control over |
| 1408 | // this... should introduce a token to let the system |
| 1409 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1410 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1411 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1412 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1413 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1414 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1415 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1416 | case TYPE_VOICE_INTERACTION: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1417 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1418 | break; |
| 1419 | case TYPE_PHONE: |
| 1420 | case TYPE_PRIORITY_PHONE: |
| 1421 | case TYPE_SYSTEM_ALERT: |
| 1422 | case TYPE_SYSTEM_ERROR: |
| 1423 | case TYPE_SYSTEM_OVERLAY: |
| 1424 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1425 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1426 | break; |
| 1427 | default: |
| 1428 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1429 | } |
| 1430 | if (permission != null) { |
| 1431 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1432 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1433 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1434 | } |
| 1435 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1436 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1437 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1438 | |
| 1439 | @Override |
| 1440 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1441 | |
| 1442 | // If this switch statement is modified, modify the comment in the declarations of |
| 1443 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1444 | switch (attrs.type) { |
| 1445 | default: |
| 1446 | // These are the windows that by default are shown only to the user that created |
| 1447 | // them. If this needs to be overridden, set |
| 1448 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1449 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1450 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1451 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1452 | return true; |
| 1453 | } |
| 1454 | break; |
| 1455 | |
| 1456 | // These are the windows that by default are shown to all users. However, to |
| 1457 | // protect against spoofing, check permissions below. |
| 1458 | case TYPE_APPLICATION_STARTING: |
| 1459 | case TYPE_BOOT_PROGRESS: |
| 1460 | case TYPE_DISPLAY_OVERLAY: |
| 1461 | case TYPE_HIDDEN_NAV_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1462 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1463 | case TYPE_KEYGUARD_DIALOG: |
| 1464 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1465 | case TYPE_NAVIGATION_BAR: |
| 1466 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1467 | case TYPE_PHONE: |
| 1468 | case TYPE_POINTER: |
| 1469 | case TYPE_PRIORITY_PHONE: |
| 1470 | case TYPE_RECENTS_OVERLAY: |
| 1471 | case TYPE_SEARCH_BAR: |
| 1472 | case TYPE_STATUS_BAR: |
| 1473 | case TYPE_STATUS_BAR_PANEL: |
| 1474 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1475 | case TYPE_SYSTEM_DIALOG: |
| 1476 | case TYPE_UNIVERSE_BACKGROUND: |
| 1477 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1478 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1479 | break; |
| 1480 | } |
| 1481 | |
| 1482 | // Check if third party app has set window to system window type. |
| 1483 | return mContext.checkCallingOrSelfPermission( |
| 1484 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1485 | != PackageManager.PERMISSION_GRANTED; |
| 1486 | } |
| 1487 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1488 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1489 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1490 | switch (attrs.type) { |
| 1491 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1492 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1493 | // These types of windows can't receive input events. |
| 1494 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1495 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1496 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1497 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1498 | case TYPE_STATUS_BAR: |
| 1499 | |
| 1500 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 1501 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 1502 | // the keyguard as occluded wouldn't set these flags again. |
| 1503 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 1504 | if (mKeyguardHidden) { |
| 1505 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 1506 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1507 | } |
| 1508 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1509 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 1510 | |
| 1511 | if (attrs.type != TYPE_STATUS_BAR) { |
| 1512 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 1513 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1514 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1515 | |
| 1516 | if (ActivityManager.isHighEndGfx() |
| 1517 | && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
| 1518 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1519 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1520 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1521 | } |
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 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1524 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1525 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1526 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1527 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1528 | private boolean isHidden(int accessibilityMode) { |
| 1529 | switch (accessibilityMode) { |
| 1530 | case 1: |
| 1531 | return mLidState == LID_CLOSED; |
| 1532 | case 2: |
| 1533 | return mLidState == LID_OPEN; |
| 1534 | default: |
| 1535 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1536 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1537 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1538 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1539 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1540 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1541 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1542 | int navigationPresence) { |
| 1543 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1544 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1545 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1546 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1547 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1548 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1549 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1550 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1551 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1552 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1553 | if (!mHasSoftInput) { |
| 1554 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1555 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1556 | } |
| 1557 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1558 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1559 | || (navigationPresence == PRESENCE_INTERNAL |
| 1560 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1561 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1562 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1563 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1564 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1565 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1566 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1567 | public int windowTypeToLayerLw(int type) { |
| 1568 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1569 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1570 | } |
| 1571 | switch (type) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1572 | case TYPE_UNIVERSE_BACKGROUND: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1573 | return 1; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1574 | case TYPE_PRIVATE_PRESENTATION: |
| 1575 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1576 | case TYPE_WALLPAPER: |
| 1577 | // wallpaper is at the bottom, though the window manager may move it. |
| 1578 | return 2; |
| 1579 | case TYPE_PHONE: |
| 1580 | return 3; |
| 1581 | case TYPE_SEARCH_BAR: |
| 1582 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1583 | case TYPE_VOICE_INTERACTION: |
| 1584 | // voice interaction layer is almost immediately above apps. |
| 1585 | return 5; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1586 | case TYPE_RECENTS_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1587 | case TYPE_SYSTEM_DIALOG: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1588 | return 6; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1589 | case TYPE_TOAST: |
| 1590 | // toasts and the plugged-in battery thing |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1591 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1592 | case TYPE_PRIORITY_PHONE: |
| 1593 | // 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] | 1594 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1595 | case TYPE_DREAM: |
| 1596 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1597 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1598 | case TYPE_SYSTEM_ALERT: |
| 1599 | // like the ANR / app crashed dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1600 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1601 | case TYPE_INPUT_METHOD: |
| 1602 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1603 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1604 | case TYPE_INPUT_METHOD_DIALOG: |
| 1605 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1606 | return 12; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1607 | case TYPE_KEYGUARD_SCRIM: |
| 1608 | // the safety window that shows behind keyguard while keyguard is starting |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1609 | return 13; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1610 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1611 | return 14; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1612 | case TYPE_STATUS_BAR: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1613 | return 15; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1614 | case TYPE_STATUS_BAR_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1615 | return 16; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1616 | case TYPE_KEYGUARD_DIALOG: |
| 1617 | return 17; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1618 | case TYPE_VOLUME_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 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1622 | case TYPE_SYSTEM_OVERLAY: |
| 1623 | // the on-screen volume indicator and controller shown when the user |
| 1624 | // changes the device volume |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1625 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1626 | case TYPE_NAVIGATION_BAR: |
| 1627 | // the navigation bar, if available, shows atop most things |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1628 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1629 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1630 | // 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] | 1631 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1632 | case TYPE_SYSTEM_ERROR: |
| 1633 | // system-level error dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1634 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1635 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1636 | // used to highlight the magnified portion of a display |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1637 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1638 | case TYPE_DISPLAY_OVERLAY: |
| 1639 | // used to simulate secondary display devices |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1640 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1641 | case TYPE_DRAG: |
| 1642 | // the drag layer: input for drag-and-drop is associated with this window, |
| 1643 | // which sits above all other focusable windows |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1644 | return 25; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1645 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1646 | return 26; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1647 | case TYPE_BOOT_PROGRESS: |
| 1648 | return 27; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1649 | case TYPE_POINTER: |
| 1650 | // the (mouse) pointer layer |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1651 | return 28; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1652 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1653 | return 29; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1654 | } |
| 1655 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1656 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1660 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1661 | public int subWindowTypeToLayerLw(int type) { |
| 1662 | switch (type) { |
| 1663 | case TYPE_APPLICATION_PANEL: |
| 1664 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 1665 | return APPLICATION_PANEL_SUBLAYER; |
| 1666 | case TYPE_APPLICATION_MEDIA: |
| 1667 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 1668 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 1669 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1670 | case TYPE_APPLICATION_SUB_PANEL: |
| 1671 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 1672 | } |
| 1673 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 1674 | return 0; |
| 1675 | } |
| 1676 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1677 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1678 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1679 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1682 | @Override |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1683 | public int getAboveUniverseLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1684 | return windowTypeToLayerLw(TYPE_SYSTEM_ERROR); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1687 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1688 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1689 | if (mHasNavigationBar) { |
| 1690 | // For a basic navigation bar, when we are in landscape mode we place |
| 1691 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1692 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 1693 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1694 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1695 | } |
| 1696 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1697 | } |
| 1698 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1699 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1700 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1701 | if (mHasNavigationBar) { |
| 1702 | // For a basic navigation bar, when we are in portrait mode we place |
| 1703 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1704 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 1705 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1706 | } |
| 1707 | } |
| 1708 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1711 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1712 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 1713 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1716 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1717 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1718 | // There is a separate status bar at the top of the display. We don't count that as part |
| 1719 | // 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] | 1720 | // we do want to exclude it since applications can't generally use that part |
| 1721 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1722 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1723 | } |
| 1724 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1725 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 1726 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 1727 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 1728 | (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) || |
| 1729 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1730 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1731 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1732 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 1733 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 1734 | return attrs.type == TYPE_STATUS_BAR; |
| 1735 | } |
| 1736 | |
| 1737 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1738 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1739 | switch (attrs.type) { |
| 1740 | case TYPE_STATUS_BAR: |
| 1741 | case TYPE_NAVIGATION_BAR: |
| 1742 | case TYPE_WALLPAPER: |
| 1743 | case TYPE_DREAM: |
| 1744 | case TYPE_UNIVERSE_BACKGROUND: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1745 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1746 | return false; |
| 1747 | default: |
| 1748 | return true; |
| 1749 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1750 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1751 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1752 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1753 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1754 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 1755 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1756 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1757 | if (!SHOW_STARTING_ANIMATIONS) { |
| 1758 | return null; |
| 1759 | } |
| 1760 | if (packageName == null) { |
| 1761 | return null; |
| 1762 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1763 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1764 | WindowManager wm = null; |
| 1765 | View view = null; |
| 1766 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1767 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1768 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1769 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 1770 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 1771 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1772 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1773 | try { |
| 1774 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1775 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1776 | } catch (PackageManager.NameNotFoundException e) { |
| 1777 | // Ignore |
| 1778 | } |
| 1779 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1780 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1781 | Window win = PolicyManager.makeNewWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1782 | final TypedArray ta = win.getWindowStyle(); |
| 1783 | if (ta.getBoolean( |
| 1784 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 1785 | || ta.getBoolean( |
| 1786 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1787 | return null; |
| 1788 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1789 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1790 | Resources r = context.getResources(); |
| 1791 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1792 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1793 | win.setType( |
| 1794 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 1795 | // Force the window flags: this is a fake window, so it is not really |
| 1796 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 1797 | // flag because we do know that the next window will take input |
| 1798 | // focus, so we want to get the IME window up on top of us right away. |
| 1799 | win.setFlags( |
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, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1804 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1805 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1806 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1807 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1808 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1809 | win.setDefaultIcon(icon); |
| 1810 | win.setDefaultLogo(logo); |
| 1811 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1812 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1813 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1814 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1815 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 1816 | params.token = appToken; |
| 1817 | params.packageName = packageName; |
| 1818 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 1819 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1820 | params.privateFlags |= |
| 1821 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1822 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1823 | |
| 1824 | if (!compatInfo.supportsScreen()) { |
| 1825 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 1826 | } |
| 1827 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1828 | params.setTitle("Starting " + packageName); |
| 1829 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1830 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 1831 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1832 | |
| 1833 | if (win.isFloating()) { |
| 1834 | // Whoops, there is no way to display an animation/preview |
| 1835 | // of such a thing! After all that work... let's skip it. |
| 1836 | // (Note that we must do this here because it is in |
| 1837 | // getDecorView() where the theme is evaluated... maybe |
| 1838 | // we should peek the floating attribute from the theme |
| 1839 | // earlier.) |
| 1840 | return null; |
| 1841 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1842 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1843 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1844 | TAG, "Adding starting window for " + packageName |
| 1845 | + " / " + appToken + ": " |
| 1846 | + (view.getParent() != null ? view : null)); |
| 1847 | |
| 1848 | wm.addView(view, params); |
| 1849 | |
| 1850 | // Only return the view if it was successfully added to the |
| 1851 | // window manager... which we can tell by it having a parent. |
| 1852 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1853 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1854 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 1855 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 1856 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1857 | } catch (RuntimeException e) { |
| 1858 | // don't crash if something else bad happens, for example a |
| 1859 | // failure loading resources because we are loading from an app |
| 1860 | // on external storage that has been unmounted. |
| 1861 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1862 | } finally { |
| 1863 | if (view != null && view.getParent() == null) { |
| 1864 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 1865 | wm.removeViewImmediate(view); |
| 1866 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | return null; |
| 1870 | } |
| 1871 | |
| 1872 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1873 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1874 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1875 | if (DEBUG_STARTING_WINDOW) { |
| 1876 | RuntimeException e = new RuntimeException("here"); |
| 1877 | e.fillInStackTrace(); |
| 1878 | Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e); |
| 1879 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1880 | |
| 1881 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1882 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1883 | wm.removeView(window); |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | /** |
| 1888 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1889 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1890 | * Currently enforces that three window types are singletons: |
| 1891 | * <ul> |
| 1892 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1893 | * <li>KEYGUARD_TYPE</li> |
| 1894 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1895 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1896 | * @param win The window to be added |
| 1897 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1898 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1899 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 1900 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1901 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1902 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1903 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 1904 | switch (attrs.type) { |
| 1905 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1906 | mContext.enforceCallingOrSelfPermission( |
| 1907 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1908 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1909 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1910 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1911 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1912 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1913 | } |
| 1914 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1915 | mStatusBarController.setWindow(win); |
John Spurlock | 8fdfe62 | 2014-05-21 17:10:10 -0400 | [diff] [blame] | 1916 | mKeyguardDelegate.hideScrim(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1917 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1918 | case TYPE_NAVIGATION_BAR: |
| 1919 | mContext.enforceCallingOrSelfPermission( |
| 1920 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1921 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1922 | if (mNavigationBar != null) { |
| 1923 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1924 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1925 | } |
| 1926 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1927 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1928 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1929 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1930 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1931 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1932 | mContext.enforceCallingOrSelfPermission( |
| 1933 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1934 | "PhoneWindowManager"); |
| 1935 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1936 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1937 | mContext.enforceCallingOrSelfPermission( |
| 1938 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1939 | "PhoneWindowManager"); |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1940 | break; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1941 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1942 | mContext.enforceCallingOrSelfPermission( |
| 1943 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1944 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1945 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1946 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1947 | if (mKeyguardScrim != null) { |
| 1948 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 1949 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1950 | mKeyguardScrim = win; |
| 1951 | break; |
| 1952 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1953 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1954 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1958 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1959 | public void removeWindowLw(WindowState win) { |
| 1960 | if (mStatusBar == win) { |
| 1961 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1962 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 1963 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1964 | } else if (mKeyguardScrim == win) { |
| 1965 | Log.v(TAG, "Removing keyguard scrim"); |
| 1966 | mKeyguardScrim = null; |
| 1967 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1968 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1969 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1974 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1975 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1976 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1977 | public int selectAnimationLw(WindowState win, int transit) { |
| 1978 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 1979 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1980 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1981 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1982 | if (transit == TRANSIT_EXIT |
| 1983 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1984 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1985 | } else if (transit == TRANSIT_ENTER |
| 1986 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1987 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1988 | } |
| 1989 | } else if (win == mNavigationBar) { |
| 1990 | // This can be on either the bottom or the right. |
| 1991 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1992 | if (transit == TRANSIT_EXIT |
| 1993 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1994 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1995 | } else if (transit == TRANSIT_ENTER |
| 1996 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1997 | return R.anim.dock_bottom_enter; |
| 1998 | } |
| 1999 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2000 | if (transit == TRANSIT_EXIT |
| 2001 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2002 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2003 | } else if (transit == TRANSIT_ENTER |
| 2004 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2005 | return R.anim.dock_right_enter; |
| 2006 | } |
| 2007 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2011 | if (win.hasAppShownWindows()) { |
| 2012 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2013 | return com.android.internal.R.anim.app_starting_exit; |
| 2014 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2015 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2016 | && transit == TRANSIT_ENTER) { |
| 2017 | // Special case: we are animating in a dream, while the keyguard |
| 2018 | // is shown. We don't want an animation on the dream, because |
| 2019 | // we need it shown immediately with the keyguard animating away |
| 2020 | // to reveal it. |
| 2021 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | return 0; |
| 2025 | } |
| 2026 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2027 | @Override |
| 2028 | public void selectRotationAnimationLw(int anim[]) { |
| 2029 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2030 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2031 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2032 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2033 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2034 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2035 | case ROTATION_ANIMATION_CROSSFADE: |
| 2036 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2037 | anim[1] = R.anim.rotation_animation_enter; |
| 2038 | break; |
| 2039 | case ROTATION_ANIMATION_JUMPCUT: |
| 2040 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2041 | anim[1] = R.anim.rotation_animation_enter; |
| 2042 | break; |
| 2043 | case ROTATION_ANIMATION_ROTATE: |
| 2044 | default: |
| 2045 | anim[0] = anim[1] = 0; |
| 2046 | break; |
| 2047 | } |
| 2048 | } else { |
| 2049 | anim[0] = anim[1] = 0; |
| 2050 | } |
| 2051 | } |
| 2052 | |
| 2053 | @Override |
| 2054 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2055 | boolean forceDefault) { |
| 2056 | switch (exitAnimId) { |
| 2057 | case R.anim.rotation_animation_xfade_exit: |
| 2058 | case R.anim.rotation_animation_jump_exit: |
| 2059 | // These are the only cases that matter. |
| 2060 | if (forceDefault) { |
| 2061 | return false; |
| 2062 | } |
| 2063 | int anim[] = new int[2]; |
| 2064 | selectRotationAnimationLw(anim); |
| 2065 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2066 | default: |
| 2067 | return true; |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2072 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2073 | boolean goingToNotificationShade) { |
| 2074 | if (goingToNotificationShade) { |
| 2075 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
| 2076 | } else if (onWallpaper) { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2077 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 2078 | R.anim.lock_screen_behind_enter_wallpaper); |
| 2079 | AnimationSet set = (AnimationSet) a; |
| 2080 | |
| 2081 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2082 | set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator); |
| 2083 | set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2084 | return set; |
| 2085 | } else { |
| 2086 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 2087 | R.anim.lock_screen_behind_enter); |
| 2088 | AnimationSet set = (AnimationSet) a; |
| 2089 | |
| 2090 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2091 | set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator); |
| 2092 | return set; |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | |
| 2097 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2098 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2099 | if (goingToNotificationShade) { |
| 2100 | return null; |
| 2101 | } else { |
| 2102 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2103 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2104 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2105 | |
| 2106 | private static void awakenDreams() { |
| 2107 | IDreamManager dreamManager = getDreamManager(); |
| 2108 | if (dreamManager != null) { |
| 2109 | try { |
| 2110 | dreamManager.awaken(); |
| 2111 | } catch (RemoteException e) { |
| 2112 | // fine, stay asleep then |
| 2113 | } |
| 2114 | } |
| 2115 | } |
| 2116 | |
| 2117 | static IDreamManager getDreamManager() { |
| 2118 | return IDreamManager.Stub.asInterface( |
| 2119 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2120 | } |
| 2121 | |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 2122 | TelecommManager getTelecommService() { |
| 2123 | return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2124 | } |
| 2125 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2126 | static IAudioService getAudioService() { |
| 2127 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2128 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2129 | if (audioService == null) { |
| 2130 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2131 | } |
| 2132 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | boolean keyguardOn() { |
| 2136 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 2137 | } |
| 2138 | |
| 2139 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2140 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2141 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2142 | }; |
| 2143 | |
| 2144 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2145 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2146 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2147 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2148 | final int keyCode = event.getKeyCode(); |
| 2149 | final int repeatCount = event.getRepeatCount(); |
| 2150 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2151 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2152 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2153 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2154 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2155 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2156 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2157 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2158 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2159 | } |
| 2160 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2161 | // If we think we might have a volume down & power key chord on the way |
| 2162 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2163 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2164 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2165 | if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) { |
| 2166 | final long now = SystemClock.uptimeMillis(); |
| 2167 | final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 2168 | if (now < timeoutTime) { |
| 2169 | return timeoutTime - now; |
| 2170 | } |
| 2171 | } |
| 2172 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 2173 | && mVolumeDownKeyConsumedByScreenshotChord) { |
| 2174 | if (!down) { |
| 2175 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 2176 | } |
| 2177 | return -1; |
| 2178 | } |
| 2179 | } |
| 2180 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2181 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2182 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2183 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2184 | mPendingMetaAction = false; |
| 2185 | } |
| 2186 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2187 | // First we always handle the home key here, so applications |
| 2188 | // can never break it, although if keyguard is on, we do let |
| 2189 | // it handle it, because that gives us the correct 5 second |
| 2190 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2191 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2192 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2193 | // If we have released the home key, and didn't do anything else |
| 2194 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2195 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2196 | cancelPreloadRecentApps(); |
| 2197 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2198 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2199 | if (mHomeConsumed) { |
| 2200 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2201 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2202 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2203 | |
| 2204 | if (canceled) { |
| 2205 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2206 | return -1; |
| 2207 | } |
| 2208 | |
| 2209 | // If an incoming call is ringing, HOME is totally disabled. |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 2210 | // (The user is already on the InCallUI at this point, |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2211 | // and his ONLY options are to answer or reject the call.) |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 2212 | TelecommManager telecommManager = getTelecommService(); |
| 2213 | if (telecommManager != null && telecommManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 2214 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2215 | return -1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | // Delay handling home if a double-tap is possible. |
| 2219 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2220 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2221 | mHomeDoubleTapPending = true; |
| 2222 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2223 | ViewConfiguration.getDoubleTapTimeout()); |
| 2224 | return -1; |
| 2225 | } |
| 2226 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2227 | // If there's a dream running then use home to escape the dream |
| 2228 | // but don't actually go home. |
| 2229 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 2230 | mDreamManagerInternal.stopDream(false /*immediate*/); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2231 | return -1; |
| 2232 | } |
| 2233 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2234 | // Go home! |
| 2235 | launchHomeFromHotKey(); |
| 2236 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2237 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2238 | |
| 2239 | // If a system window has focus, then it doesn't make sense |
| 2240 | // right now to interact with applications. |
| 2241 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2242 | if (attrs != null) { |
| 2243 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2244 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2245 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2246 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2247 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2248 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2249 | } |
| 2250 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2251 | for (int i=0; i<typeCount; i++) { |
| 2252 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2253 | // 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] | 2254 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2255 | } |
| 2256 | } |
| 2257 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2258 | |
| 2259 | // Remember that home is pressed and handle special actions. |
| 2260 | if (repeatCount == 0) { |
| 2261 | mHomePressed = true; |
| 2262 | if (mHomeDoubleTapPending) { |
| 2263 | mHomeDoubleTapPending = false; |
| 2264 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2265 | handleDoubleTapOnHome(); |
| 2266 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2267 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2268 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2269 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2270 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2271 | if (!keyguardOn) { |
| 2272 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2273 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2274 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2275 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2276 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2277 | // Hijack modified menu keys for debugging features |
| 2278 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2279 | |
| 2280 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2281 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2282 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2283 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2284 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2285 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2286 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2287 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2288 | Intent service = new Intent(); |
| 2289 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2290 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2291 | boolean shown = Settings.Global.getInt( |
| 2292 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2293 | if (!shown) { |
| 2294 | mContext.startService(service); |
| 2295 | } else { |
| 2296 | mContext.stopService(service); |
| 2297 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2298 | Settings.Global.putInt( |
| 2299 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2300 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2301 | } |
| 2302 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2303 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2304 | if (down) { |
| 2305 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2306 | mSearchKeyShortcutPending = true; |
| 2307 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2308 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2309 | } else { |
| 2310 | mSearchKeyShortcutPending = false; |
| 2311 | if (mConsumeSearchKeyUp) { |
| 2312 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2313 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2314 | } |
| 2315 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2316 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2317 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2318 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2319 | if (down && repeatCount == 0) { |
| 2320 | preloadRecentApps(); |
| 2321 | } else if (!down) { |
| 2322 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2323 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2324 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2325 | return -1; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2326 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2327 | if (down) { |
| 2328 | if (repeatCount == 0) { |
| 2329 | mAssistKeyLongPressed = false; |
| 2330 | } else if (repeatCount == 1) { |
| 2331 | mAssistKeyLongPressed = true; |
| 2332 | if (!keyguardOn) { |
| 2333 | launchAssistLongPressAction(); |
| 2334 | } |
| 2335 | } |
| 2336 | } else { |
| 2337 | if (mAssistKeyLongPressed) { |
| 2338 | mAssistKeyLongPressed = false; |
| 2339 | } else { |
| 2340 | if (!keyguardOn) { |
| 2341 | launchAssistAction(); |
| 2342 | } |
| 2343 | } |
| 2344 | } |
| 2345 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2346 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2347 | if (!down) { |
| 2348 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2349 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2350 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2351 | } else { |
| 2352 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2353 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2354 | } |
| 2355 | mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
| 2356 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2357 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2358 | if (down && repeatCount == 0) { |
| 2359 | mHandler.post(mScreenshotRunnable); |
| 2360 | } |
| 2361 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2362 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2363 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2364 | if (down) { |
| 2365 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2366 | |
| 2367 | // Disable autobrightness if it's on |
| 2368 | int auto = Settings.System.getIntForUser( |
| 2369 | mContext.getContentResolver(), |
| 2370 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2371 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2372 | UserHandle.USER_CURRENT_OR_SELF); |
| 2373 | if (auto != 0) { |
| 2374 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2375 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2376 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2377 | UserHandle.USER_CURRENT_OR_SELF); |
| 2378 | } |
| 2379 | |
| 2380 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2381 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2382 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2383 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2384 | Settings.System.SCREEN_BRIGHTNESS, |
| 2385 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2386 | UserHandle.USER_CURRENT_OR_SELF); |
| 2387 | brightness += step; |
| 2388 | // Make sure we don't go beyond the limits. |
| 2389 | brightness = Math.min(max, brightness); |
| 2390 | brightness = Math.max(min, brightness); |
| 2391 | |
| 2392 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2393 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2394 | UserHandle.USER_CURRENT_OR_SELF); |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 2395 | mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
| 2396 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2397 | } |
| 2398 | return -1; |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2399 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2400 | if (down) { |
| 2401 | mPendingMetaAction = true; |
| 2402 | } else if (mPendingMetaAction) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2403 | launchAssistAction(); |
| 2404 | } |
| 2405 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2406 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2407 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2408 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2409 | // Any printing key that is chorded with Search should be consumed |
| 2410 | // even if no shortcut was invoked. This prevents text from being |
| 2411 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2412 | // 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] | 2413 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2414 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2415 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2416 | mConsumeSearchKeyUp = true; |
| 2417 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2418 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2419 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2420 | if (shortcutIntent != null) { |
| 2421 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2422 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2423 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2424 | } catch (ActivityNotFoundException ex) { |
| 2425 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2426 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2427 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2428 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2429 | } else { |
| 2430 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2431 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2432 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2433 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2434 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2438 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2439 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2440 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2441 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2442 | if (kcm.isPrintingKey(keyCode)) { |
| 2443 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2444 | metaState & ~(KeyEvent.META_META_ON |
| 2445 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2446 | if (shortcutIntent != null) { |
| 2447 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2448 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2449 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2450 | } catch (ActivityNotFoundException ex) { |
| 2451 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2452 | + "the activity to which it is registered was not found: " |
| 2453 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2454 | } |
| 2455 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2456 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2457 | } |
| 2458 | } |
| 2459 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2460 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2461 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2462 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2463 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2464 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2465 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2466 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2467 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2468 | } catch (ActivityNotFoundException ex) { |
| 2469 | Slog.w(TAG, "Dropping application launch key because " |
| 2470 | + "the activity to which it is registered was not found: " |
| 2471 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2472 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2473 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2474 | } |
| 2475 | } |
| 2476 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2477 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2478 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2479 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2480 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2481 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2482 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 2483 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2484 | return -1; |
| 2485 | } |
| 2486 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2487 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 2488 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 2489 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2490 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2491 | } |
| 2492 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2493 | // Handle keyboard language switching. |
| 2494 | if (down && repeatCount == 0 |
| 2495 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2496 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2497 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2498 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2499 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2500 | return -1; |
| 2501 | } |
| 2502 | if (mLanguageSwitchKeyPressed && !down |
| 2503 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2504 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2505 | mLanguageSwitchKeyPressed = false; |
| 2506 | return -1; |
| 2507 | } |
| 2508 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2509 | if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
| 2510 | return -1; |
| 2511 | } |
| 2512 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2513 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2514 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2515 | return -1; |
| 2516 | } |
| 2517 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2518 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2519 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2520 | } |
| 2521 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2522 | /** {@inheritDoc} */ |
| 2523 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2524 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2525 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2526 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2527 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2528 | + ", flags=" + event.getFlags() |
| 2529 | + ", keyCode=" + event.getKeyCode() |
| 2530 | + ", scanCode=" + event.getScanCode() |
| 2531 | + ", metaState=" + event.getMetaState() |
| 2532 | + ", repeatCount=" + event.getRepeatCount() |
| 2533 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2534 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2535 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2536 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2537 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2538 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2539 | final int keyCode = event.getKeyCode(); |
| 2540 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2541 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2542 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2543 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2544 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2545 | final FallbackAction fallbackAction; |
| 2546 | if (initialDown) { |
| 2547 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2548 | } else { |
| 2549 | fallbackAction = mFallbackActions.get(keyCode); |
| 2550 | } |
| 2551 | |
| 2552 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2553 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2554 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2555 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2556 | } |
| 2557 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2558 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2559 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2560 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2561 | event.getAction(), fallbackAction.keyCode, |
| 2562 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2563 | event.getDeviceId(), event.getScanCode(), |
| 2564 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2565 | |
| 2566 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2567 | fallbackEvent.recycle(); |
| 2568 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2569 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2570 | |
| 2571 | if (initialDown) { |
| 2572 | mFallbackActions.put(keyCode, fallbackAction); |
| 2573 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2574 | mFallbackActions.remove(keyCode); |
| 2575 | fallbackAction.recycle(); |
| 2576 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2577 | } |
| 2578 | } |
| 2579 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2580 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2581 | if (fallbackEvent == null) { |
| 2582 | Slog.d(TAG, "No fallback."); |
| 2583 | } else { |
| 2584 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2585 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2586 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2587 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2590 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2591 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2592 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2593 | long delayMillis = interceptKeyBeforeDispatching( |
| 2594 | win, fallbackEvent, policyFlags); |
| 2595 | if (delayMillis == 0) { |
| 2596 | return true; |
| 2597 | } |
| 2598 | } |
| 2599 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2600 | } |
| 2601 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2602 | private void launchAssistLongPressAction() { |
| 2603 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2604 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2605 | |
| 2606 | // launch the search activity |
| 2607 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2608 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2609 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2610 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2611 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2612 | SearchManager searchManager = getSearchManager(); |
| 2613 | if (searchManager != null) { |
| 2614 | searchManager.stopSearch(); |
| 2615 | } |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2616 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2617 | } catch (ActivityNotFoundException e) { |
| 2618 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | private void launchAssistAction() { |
| 2623 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2624 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2625 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2626 | if (intent != null) { |
| 2627 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2628 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2629 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2630 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2631 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2632 | } catch (ActivityNotFoundException e) { |
| 2633 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | private SearchManager getSearchManager() { |
| 2639 | if (mSearchManager == null) { |
| 2640 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2641 | } |
| 2642 | return mSearchManager; |
| 2643 | } |
| 2644 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2645 | private void preloadRecentApps() { |
| 2646 | mPreloadedRecentApps = true; |
| 2647 | try { |
| 2648 | IStatusBarService statusbar = getStatusBarService(); |
| 2649 | if (statusbar != null) { |
| 2650 | statusbar.preloadRecentApps(); |
| 2651 | } |
| 2652 | } catch (RemoteException e) { |
| 2653 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 2654 | // re-acquire status bar service next time it is needed. |
| 2655 | mStatusBarService = null; |
| 2656 | } |
| 2657 | } |
| 2658 | |
| 2659 | private void cancelPreloadRecentApps() { |
| 2660 | if (mPreloadedRecentApps) { |
| 2661 | mPreloadedRecentApps = false; |
| 2662 | try { |
| 2663 | IStatusBarService statusbar = getStatusBarService(); |
| 2664 | if (statusbar != null) { |
| 2665 | statusbar.cancelPreloadRecentApps(); |
| 2666 | } |
| 2667 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2668 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2669 | // re-acquire status bar service next time it is needed. |
| 2670 | mStatusBarService = null; |
| 2671 | } |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | private void toggleRecentApps() { |
| 2676 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2677 | try { |
| 2678 | IStatusBarService statusbar = getStatusBarService(); |
| 2679 | if (statusbar != null) { |
| 2680 | statusbar.toggleRecentApps(); |
| 2681 | } |
| 2682 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2683 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 2684 | // re-acquire status bar service next time it is needed. |
| 2685 | mStatusBarService = null; |
| 2686 | } |
| 2687 | } |
| 2688 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2689 | @Override |
| 2690 | public void showRecentApps() { |
| 2691 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 2692 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 2693 | } |
| 2694 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2695 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 2696 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2697 | try { |
| 2698 | IStatusBarService statusbar = getStatusBarService(); |
| 2699 | if (statusbar != null) { |
| 2700 | statusbar.showRecentApps(triggeredFromAltTab); |
| 2701 | } |
| 2702 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2703 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2704 | // re-acquire status bar service next time it is needed. |
| 2705 | mStatusBarService = null; |
| 2706 | } |
| 2707 | } |
| 2708 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2709 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2710 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2711 | try { |
| 2712 | IStatusBarService statusbar = getStatusBarService(); |
| 2713 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2714 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2715 | } |
| 2716 | } catch (RemoteException e) { |
| 2717 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 2718 | // re-acquire status bar service next time it is needed. |
| 2719 | mStatusBarService = null; |
| 2720 | } |
| 2721 | } |
| 2722 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2723 | /** |
| 2724 | * A home key -> launch home action was detected. Take the appropriate action |
| 2725 | * given the situation with the keyguard. |
| 2726 | */ |
| 2727 | void launchHomeFromHotKey() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 2728 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2729 | // don't launch home if keyguard showing |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2730 | } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2731 | // when in keyguard restricted mode, must first verify unlock |
| 2732 | // before launching home |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2733 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2734 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2735 | public void onKeyguardExitResult(boolean success) { |
| 2736 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2737 | try { |
| 2738 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2739 | } catch (RemoteException e) { |
| 2740 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2741 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2742 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2743 | } |
| 2744 | } |
| 2745 | }); |
| 2746 | } else { |
| 2747 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2748 | try { |
| 2749 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2750 | } catch (RemoteException e) { |
| 2751 | } |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 2752 | if (mRecentsVisible) { |
| 2753 | // Hide Recents and notify it to launch Home |
| 2754 | awakenDreams(); |
| 2755 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2756 | hideRecentApps(false, true); |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 2757 | } else { |
| 2758 | // Otherwise, just launch Home |
| 2759 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 2760 | startDockOrHome(); |
| 2761 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2762 | } |
| 2763 | } |
| 2764 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2765 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 2766 | @Override |
| 2767 | public void run() { |
| 2768 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2769 | // Clear flags. |
| 2770 | mForceClearedSystemUiFlags &= |
| 2771 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 2772 | } |
| 2773 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2774 | } |
| 2775 | }; |
| 2776 | |
| 2777 | /** |
| 2778 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 2779 | * to determine when the nav bar should be shown and prevent applications from |
| 2780 | * receiving those touches. |
| 2781 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2782 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 2783 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 2784 | super(inputChannel, looper); |
| 2785 | } |
| 2786 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2787 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2788 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2789 | boolean handled = false; |
| 2790 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 2791 | if (event instanceof MotionEvent |
| 2792 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 2793 | final MotionEvent motionEvent = (MotionEvent)event; |
| 2794 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2795 | // When the user taps down, we re-show the nav bar. |
| 2796 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2797 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2798 | // Any user activity always causes us to show the |
| 2799 | // navigation controls, if they had been hidden. |
| 2800 | // We also clear the low profile and only content |
| 2801 | // flags so that tapping on the screen will atomically |
| 2802 | // restore all currently hidden screen decorations. |
| 2803 | int newVal = mResettingSystemUiFlags | |
| 2804 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 2805 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 2806 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2807 | if (mResettingSystemUiFlags != newVal) { |
| 2808 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2809 | changed = true; |
| 2810 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2811 | // We don't allow the system's nav bar to be hidden |
| 2812 | // again for 1 second, to prevent applications from |
| 2813 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2814 | newVal = mForceClearedSystemUiFlags | |
| 2815 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2816 | if (mForceClearedSystemUiFlags != newVal) { |
| 2817 | mForceClearedSystemUiFlags = newVal; |
| 2818 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2819 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2820 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2821 | } |
| 2822 | if (changed) { |
| 2823 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 2824 | } |
| 2825 | } |
| 2826 | } |
| 2827 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2828 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2829 | } |
| 2830 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2831 | } |
| 2832 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 2833 | new InputEventReceiver.Factory() { |
| 2834 | @Override |
| 2835 | public InputEventReceiver createInputEventReceiver( |
| 2836 | InputChannel inputChannel, Looper looper) { |
| 2837 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 2838 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2839 | }; |
| 2840 | |
| 2841 | @Override |
| 2842 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 2843 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 2844 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 2845 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2846 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2847 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 2848 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2849 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2850 | // Clear any bits in the new visibility that are currently being |
| 2851 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2852 | return visibility & ~mResettingSystemUiFlags |
| 2853 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2854 | } |
| 2855 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2856 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2857 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2858 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 2859 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 2860 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2861 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2862 | 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] | 2863 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2864 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2865 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2866 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2867 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2868 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 2869 | } else { |
| 2870 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 2871 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 2872 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2873 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2874 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2875 | contentInset.set(mStableFullscreenLeft, mStableFullscreenTop, |
| 2876 | availRight - mStableFullscreenRight, |
| 2877 | availBottom - mStableFullscreenBottom); |
| 2878 | } else { |
| 2879 | contentInset.set(mStableLeft, mStableTop, |
| 2880 | availRight - mStableRight, availBottom - mStableBottom); |
| 2881 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2882 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2883 | contentInset.setEmpty(); |
| 2884 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2885 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
| 2886 | contentInset.set(mCurLeft, mCurTop, |
| 2887 | availRight - mCurRight, availBottom - mCurBottom); |
| 2888 | } else { |
| 2889 | contentInset.set(mCurLeft, mCurTop, |
| 2890 | availRight - mCurRight, availBottom - mCurBottom); |
| 2891 | } |
| 2892 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2893 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2894 | contentInset.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2895 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2896 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2897 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2898 | @Override |
| 2899 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 2900 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2901 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 2902 | if (isDefaultDisplay) { |
| 2903 | switch (displayRotation) { |
| 2904 | case Surface.ROTATION_90: |
| 2905 | overscanLeft = mOverscanTop; |
| 2906 | overscanTop = mOverscanRight; |
| 2907 | overscanRight = mOverscanBottom; |
| 2908 | overscanBottom = mOverscanLeft; |
| 2909 | break; |
| 2910 | case Surface.ROTATION_180: |
| 2911 | overscanLeft = mOverscanRight; |
| 2912 | overscanTop = mOverscanBottom; |
| 2913 | overscanRight = mOverscanLeft; |
| 2914 | overscanBottom = mOverscanTop; |
| 2915 | break; |
| 2916 | case Surface.ROTATION_270: |
| 2917 | overscanLeft = mOverscanBottom; |
| 2918 | overscanTop = mOverscanLeft; |
| 2919 | overscanRight = mOverscanTop; |
| 2920 | overscanBottom = mOverscanRight; |
| 2921 | break; |
| 2922 | default: |
| 2923 | overscanLeft = mOverscanLeft; |
| 2924 | overscanTop = mOverscanTop; |
| 2925 | overscanRight = mOverscanRight; |
| 2926 | overscanBottom = mOverscanBottom; |
| 2927 | break; |
| 2928 | } |
| 2929 | } else { |
| 2930 | overscanLeft = 0; |
| 2931 | overscanTop = 0; |
| 2932 | overscanRight = 0; |
| 2933 | overscanBottom = 0; |
| 2934 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2935 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 2936 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 2937 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 2938 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2939 | mSystemLeft = 0; |
| 2940 | mSystemTop = 0; |
| 2941 | mSystemRight = displayWidth; |
| 2942 | mSystemBottom = displayHeight; |
| 2943 | mUnrestrictedScreenLeft = overscanLeft; |
| 2944 | mUnrestrictedScreenTop = overscanTop; |
| 2945 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 2946 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 2947 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 2948 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2949 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 2950 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2951 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2952 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2953 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2954 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2955 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2956 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2957 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2958 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2959 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2960 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2961 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2962 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 2963 | final Rect pf = mTmpParentFrame; |
| 2964 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2965 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2966 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2967 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2968 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 2969 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 2970 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 2971 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2972 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2973 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2974 | if (isDefaultDisplay) { |
| 2975 | // For purposes of putting out fake window up to steal focus, we will |
| 2976 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2977 | final int sysui = mLastSystemUiFlags; |
| 2978 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2979 | boolean navTranslucent = (sysui |
| 2980 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2981 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 2982 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 2983 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 2984 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 2985 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 2986 | if (!isKeyguardShowing) { |
| 2987 | navTranslucent &= areTranslucentBarsAllowed(); |
| 2988 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2989 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2990 | // When the navigation bar isn't visible, we put up a fake |
| 2991 | // input window to catch all touch events. This way we can |
| 2992 | // detect when the user presses anywhere to bring back the nav |
| 2993 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2994 | if (navVisible || navAllowedHidden) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2995 | if (mHideNavFakeWindow != null) { |
| 2996 | mHideNavFakeWindow.dismiss(); |
| 2997 | mHideNavFakeWindow = null; |
| 2998 | } |
| 2999 | } else if (mHideNavFakeWindow == null) { |
| 3000 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 3001 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 3002 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3003 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3004 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3005 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3006 | // For purposes of positioning and showing the nav bar, if we have |
| 3007 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3008 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3009 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3010 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3011 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3012 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3013 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3014 | // Force the navigation bar to its appropriate place and |
| 3015 | // size. We need to do this directly, instead of relying on |
| 3016 | // it to bubble up from the nav bar, because this needs to |
| 3017 | // change atomically with screen rotations. |
| 3018 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 3019 | if (mNavigationBarOnBottom) { |
| 3020 | // 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] | 3021 | int top = displayHeight - overscanBottom |
| 3022 | - mNavigationBarHeightForRotation[displayRotation]; |
| 3023 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3024 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3025 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3026 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3027 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3028 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3029 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3030 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3031 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3032 | } else { |
| 3033 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3034 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3035 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3036 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3037 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3038 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3039 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3040 | // and not in the process of animating on or off, then |
| 3041 | // we can tell the app that it is covered by it. |
| 3042 | mSystemBottom = mTmpNavigationFrame.top; |
| 3043 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3044 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3045 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3046 | int left = displayWidth - overscanRight |
| 3047 | - mNavigationBarWidthForRotation[displayRotation]; |
| 3048 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3049 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3050 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3051 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3052 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3053 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3054 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3055 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3056 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3057 | } else { |
| 3058 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3059 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3060 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3061 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 3062 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3063 | // If the nav bar is currently requested to be visible, |
| 3064 | // and not in the process of animating on or off, then |
| 3065 | // we can tell the app that it is covered by it. |
| 3066 | mSystemRight = mTmpNavigationFrame.left; |
| 3067 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3068 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3069 | // Make sure the content and current rectangles are updated to |
| 3070 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3071 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3072 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3073 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3074 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3075 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3076 | // And compute the final frame. |
| 3077 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3078 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 3079 | mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3080 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3081 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3082 | updateSysUiVisibility = true; |
| 3083 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3084 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3085 | 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] | 3086 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 3087 | |
| 3088 | // decide where the status bar goes ahead of time |
| 3089 | if (mStatusBar != null) { |
| 3090 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3091 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3092 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3093 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3094 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3095 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3096 | vf.left = mStableLeft; |
| 3097 | vf.top = mStableTop; |
| 3098 | vf.right = mStableRight; |
| 3099 | vf.bottom = mStableBottom; |
| 3100 | |
| 3101 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3102 | |
| 3103 | // Let the status bar determine its size. |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3104 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3105 | |
| 3106 | // For layout, the status bar is always at the top with our fixed height. |
| 3107 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3108 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3109 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3110 | boolean statusBarTranslucent = (sysui |
| 3111 | & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3112 | if (!isKeyguardShowing) { |
| 3113 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3114 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3115 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3116 | // If the status bar is hidden, we don't want to cause |
| 3117 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 3118 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3119 | // Status bar may go away, so the screen area it occupies |
| 3120 | // is available to apps but just covering them when the |
| 3121 | // status bar is visible. |
| 3122 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3123 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3124 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3125 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3126 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3127 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3128 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3129 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3130 | String.format( |
| 3131 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3132 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3133 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3134 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3135 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3136 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3137 | && !statusBarTransient && !statusBarTranslucent |
| 3138 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3139 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3140 | // and not in the process of animating on or off, then |
| 3141 | // we can tell the app that it is covered by it. |
| 3142 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3143 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3144 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3145 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3146 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3147 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3148 | if (updateSysUiVisibility) { |
| 3149 | updateSystemUiVisibilityLw(); |
| 3150 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3151 | } |
| 3152 | } |
| 3153 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3154 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3155 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3156 | public int getSystemDecorLayerLw() { |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3157 | if (mStatusBar != null) return mStatusBar.getSurfaceLayer(); |
| 3158 | if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer(); |
| 3159 | return 0; |
| 3160 | } |
| 3161 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3162 | @Override |
| 3163 | public void getContentRectLw(Rect r) { |
| 3164 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3165 | } |
| 3166 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3167 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3168 | 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] | 3169 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3170 | // Here's a special case: if this attached window is a panel that is |
| 3171 | // above the dock window, and the window it is attached to is below |
| 3172 | // the dock window, then the frames we computed for the window it is |
| 3173 | // attached to can not be used because the dock is effectively part |
| 3174 | // of the underlying window and the attached window is floating on top |
| 3175 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3176 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3177 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3178 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3179 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3180 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3181 | } else { |
| 3182 | // The effective display frame of the attached window depends on |
| 3183 | // whether it is taking care of insetting its content. If not, |
| 3184 | // we need to use the parent's content frame so that the entire |
| 3185 | // window is positioned within that content. Otherwise we can use |
| 3186 | // the display frame and let the attached window take care of |
| 3187 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3188 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3189 | cf.set(attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3190 | } else { |
| 3191 | // If the window is resizing, then we want to base the content |
| 3192 | // frame on our attached content frame to resize... however, |
| 3193 | // things can be tricky if the attached window is NOT in resize |
| 3194 | // mode, in which case its content frame will be larger. |
| 3195 | // Ungh. So to deal with that, make sure the content frame |
| 3196 | // we end up using is not covering the IM dock. |
| 3197 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3198 | if (attached.isVoiceInteraction()) { |
| 3199 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3200 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3201 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3202 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3203 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3204 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3205 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3206 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3207 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3208 | } |
| 3209 | } |
| 3210 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3211 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3212 | vf.set(attached.getVisibleFrameLw()); |
| 3213 | } |
| 3214 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3215 | // window should be positioned relative to its parent or the entire |
| 3216 | // screen. |
| 3217 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3218 | ? attached.getFrameLw() : df); |
| 3219 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3220 | |
| 3221 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3222 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3223 | // If app is requesting a stable layout, don't let the |
| 3224 | // content insets go below the stable values. |
| 3225 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3226 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3227 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3228 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3229 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3230 | } else { |
| 3231 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3232 | if (r.top < mStableTop) r.top = mStableTop; |
| 3233 | if (r.right > mStableRight) r.right = mStableRight; |
| 3234 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3235 | } |
| 3236 | } |
| 3237 | } |
| 3238 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3239 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3240 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3241 | public void layoutWindowLw(WindowState win, WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3242 | // we've already done the status bar |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3243 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 3244 | if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) || |
| 3245 | win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3246 | return; |
| 3247 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3248 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 3249 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3250 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 3251 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3252 | 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] | 3253 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 3254 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3255 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3256 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3257 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3258 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3259 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3260 | final Rect pf = mTmpParentFrame; |
| 3261 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3262 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3263 | final Rect cf = mTmpContentFrame; |
| 3264 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3265 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3266 | final Rect sf = mTmpStableFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3267 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3268 | |
| 3269 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3270 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3271 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 3272 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 3273 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3274 | if (isDefaultDisplay) { |
| 3275 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 3276 | } else { |
| 3277 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 3278 | } |
| 3279 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3280 | if (!isDefaultDisplay) { |
| 3281 | if (attached != null) { |
| 3282 | // If this window is attached to another, our display |
| 3283 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3284 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3285 | } else { |
| 3286 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3287 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3288 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3289 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3290 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3291 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3292 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3293 | } |
| 3294 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3295 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3296 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3297 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3298 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3299 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3300 | // ...with content insets above the nav bar |
| 3301 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3302 | // IM dock windows always go to the bottom of the screen. |
| 3303 | attrs.gravity = Gravity.BOTTOM; |
| 3304 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 3305 | } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 3306 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3307 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3308 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3309 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 3310 | cf.left = vf.left = mStableLeft; |
| 3311 | cf.top = vf.top = mStableTop; |
| 3312 | cf.right = vf.right = mStableRight; |
| 3313 | vf.bottom = mStableBottom; |
| 3314 | cf.bottom = mContentBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3315 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3316 | |
| 3317 | // Default policy decor for the default display |
| 3318 | dcf.left = mSystemLeft; |
| 3319 | dcf.top = mSystemTop; |
| 3320 | dcf.right = mSystemRight; |
| 3321 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3322 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3323 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3324 | final boolean isAppWindow = |
| 3325 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3326 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3327 | final boolean topAtRest = |
| 3328 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3329 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3330 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3331 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3332 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 3333 | && (fl & WindowManager.LayoutParams. |
| 3334 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3335 | // Ensure policy decor includes status bar |
| 3336 | dcf.top = mStableTop; |
| 3337 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3338 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3339 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 3340 | && (fl & WindowManager.LayoutParams. |
| 3341 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3342 | // Ensure policy decor includes navigation bar |
| 3343 | dcf.bottom = mStableBottom; |
| 3344 | dcf.right = mStableRight; |
| 3345 | } |
| 3346 | } |
| 3347 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3348 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3349 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3350 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3351 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3352 | // This is the case for a normal activity window: we want it |
| 3353 | // to cover all of the screen space, and it can take care of |
| 3354 | // moving its contents to account for screen decorations that |
| 3355 | // intrude into that space. |
| 3356 | if (attached != null) { |
| 3357 | // If this window is attached to another, our display |
| 3358 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3359 | 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] | 3360 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3361 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3362 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3363 | // Status bar panels are the only windows who can go on top of |
| 3364 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3365 | // permission, so they have the same privileges as the status |
| 3366 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3367 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3368 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3369 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3370 | pf.left = df.left = of.left = hasNavBar |
| 3371 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3372 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3373 | pf.right = df.right = of.right = hasNavBar |
| 3374 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3375 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3376 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3377 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3378 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3379 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3380 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3381 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3382 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3383 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3384 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3385 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3386 | // Asking to layout into the overscan region, so give it that pure |
| 3387 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3388 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3389 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3390 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3391 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3392 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3393 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3394 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3395 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3396 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3397 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3398 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3399 | // only do this for application windows to ensure no window that |
| 3400 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3401 | pf.left = df.left = mOverscanScreenLeft; |
| 3402 | pf.top = df.top = mOverscanScreenTop; |
| 3403 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3404 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3405 | // We need to tell the app about where the frame inside the overscan |
| 3406 | // is, so it can inset its content by that amount -- it didn't ask |
| 3407 | // to actually extend itself into the overscan region. |
| 3408 | of.left = mUnrestrictedScreenLeft; |
| 3409 | of.top = mUnrestrictedScreenTop; |
| 3410 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3411 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3412 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3413 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3414 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3415 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3416 | + mRestrictedOverscanScreenWidth; |
| 3417 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3418 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3419 | // We need to tell the app about where the frame inside the overscan |
| 3420 | // is, so it can inset its content by that amount -- it didn't ask |
| 3421 | // to actually extend itself into the overscan region. |
| 3422 | of.left = mUnrestrictedScreenLeft; |
| 3423 | of.top = mUnrestrictedScreenTop; |
| 3424 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3425 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3426 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3427 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3428 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3429 | if (win.isVoiceInteraction()) { |
| 3430 | cf.left = mVoiceContentLeft; |
| 3431 | cf.top = mVoiceContentTop; |
| 3432 | cf.right = mVoiceContentRight; |
| 3433 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3434 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3435 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3436 | cf.left = mDockLeft; |
| 3437 | cf.top = mDockTop; |
| 3438 | cf.right = mDockRight; |
| 3439 | cf.bottom = mDockBottom; |
| 3440 | } else { |
| 3441 | cf.left = mContentLeft; |
| 3442 | cf.top = mContentTop; |
| 3443 | cf.right = mContentRight; |
| 3444 | cf.bottom = mContentBottom; |
| 3445 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3446 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3447 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3448 | // Full screen windows are always given a layout that is as if the |
| 3449 | // status bar and other transient decors are gone. This is to avoid |
| 3450 | // bad states when moving from a window that is not hding the |
| 3451 | // status bar to one that is. |
| 3452 | cf.left = mRestrictedScreenLeft; |
| 3453 | cf.top = mRestrictedScreenTop; |
| 3454 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3455 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3456 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3457 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3458 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3459 | vf.left = mCurLeft; |
| 3460 | vf.top = mCurTop; |
| 3461 | vf.right = mCurRight; |
| 3462 | vf.bottom = mCurBottom; |
| 3463 | } else { |
| 3464 | vf.set(cf); |
| 3465 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3466 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3467 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3468 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3469 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3470 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3471 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3472 | // A window that has requested to fill the entire screen just |
| 3473 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3474 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3475 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3476 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3477 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3478 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3479 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3480 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3481 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3482 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3483 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3484 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3485 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3486 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3487 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3488 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3489 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3490 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3491 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3492 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3493 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3494 | + mUnrestrictedScreenWidth; |
| 3495 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3496 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3497 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3498 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3499 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3500 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3501 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3502 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3503 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3504 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3505 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3506 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3507 | + mOverscanScreenWidth; |
| 3508 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3509 | + mOverscanScreenHeight; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3510 | } else if (attrs.type == TYPE_BOOT_PROGRESS |
| 3511 | || attrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3512 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3513 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3514 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3515 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3516 | + mOverscanScreenWidth; |
| 3517 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3518 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3519 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 3520 | // The wallpaper also has Real Ultimate Power. |
| 3521 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3522 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3523 | pf.right = df.right = of.right = cf.right |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3524 | = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3525 | pf.bottom = df.bottom = of.bottom = cf.bottom |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3526 | = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3527 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3528 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3529 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3530 | // Asking to layout into the overscan region, so give it that pure |
| 3531 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3532 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3533 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3534 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3535 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3536 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3537 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3538 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3539 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 3540 | && (attrs.type == TYPE_STATUS_BAR |
| 3541 | || attrs.type == TYPE_TOAST |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3542 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3543 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3544 | // Asking for layout as if the nav bar is hidden, lets the |
| 3545 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3546 | // 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] | 3547 | // can be above the nav bar can do this. |
| 3548 | // XXX This assumes that an app asking for this will also |
| 3549 | // ask for layout in only content. We can't currently figure out |
| 3550 | // 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] | 3551 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3552 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3553 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3554 | + mUnrestrictedScreenWidth; |
| 3555 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3556 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3557 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3558 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3559 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3560 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3561 | + mRestrictedScreenWidth; |
| 3562 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3563 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3564 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3565 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3566 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3567 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3568 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3569 | vf.left = mCurLeft; |
| 3570 | vf.top = mCurTop; |
| 3571 | vf.right = mCurRight; |
| 3572 | vf.bottom = mCurBottom; |
| 3573 | } else { |
| 3574 | vf.set(cf); |
| 3575 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3576 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3577 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3578 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3579 | // A child window should be placed inside of the same visible |
| 3580 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3581 | 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] | 3582 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3583 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3584 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3585 | // Otherwise, a normal window must be placed inside the content |
| 3586 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3587 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 3588 | // Status bar panels are the only windows who can go on top of |
| 3589 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3590 | // permission, so they have the same privileges as the status |
| 3591 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3592 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3593 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3594 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3595 | + mRestrictedScreenWidth; |
| 3596 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3597 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3598 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 3599 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 3600 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3601 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 3602 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 3603 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 3604 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3605 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3606 | pf.left = mContentLeft; |
| 3607 | pf.top = mContentTop; |
| 3608 | pf.right = mContentRight; |
| 3609 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 3610 | if (win.isVoiceInteraction()) { |
| 3611 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 3612 | df.top = of.top = cf.top = mVoiceContentTop; |
| 3613 | df.right = of.right = cf.right = mVoiceContentRight; |
| 3614 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 3615 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3616 | df.left = of.left = cf.left = mDockLeft; |
| 3617 | df.top = of.top = cf.top = mDockTop; |
| 3618 | df.right = of.right = cf.right = mDockRight; |
| 3619 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3620 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3621 | df.left = of.left = cf.left = mContentLeft; |
| 3622 | df.top = of.top = cf.top = mContentTop; |
| 3623 | df.right = of.right = cf.right = mContentRight; |
| 3624 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3625 | } |
| 3626 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3627 | vf.left = mCurLeft; |
| 3628 | vf.top = mCurTop; |
| 3629 | vf.right = mCurRight; |
| 3630 | vf.bottom = mCurBottom; |
| 3631 | } else { |
| 3632 | vf.set(cf); |
| 3633 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3634 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3635 | } |
| 3636 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3637 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 3638 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 3639 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3640 | df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 3641 | df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom |
| 3642 | = vf.right = vf.bottom = 10000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3643 | } |
| 3644 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3645 | 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] | 3646 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3647 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3648 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3649 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3650 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3651 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3652 | + " dcf=" + dcf.toShortString() |
| 3653 | + " sf=" + sf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3654 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3655 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3656 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3657 | // Dock windows carve out the bottom of the screen, so normal windows |
| 3658 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 3659 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 3660 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3661 | setLastInputMethodWindowLw(null, null); |
| 3662 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3663 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3664 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 3665 | && !win.getGivenInsetsPendingLw()) { |
| 3666 | offsetVoiceInputWindowLw(win); |
| 3667 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3668 | } |
| 3669 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3670 | private void offsetInputMethodWindowLw(WindowState win) { |
| 3671 | int top = win.getContentFrameLw().top; |
| 3672 | top += win.getGivenContentInsetsLw().top; |
| 3673 | if (mContentBottom > top) { |
| 3674 | mContentBottom = top; |
| 3675 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3676 | if (mVoiceContentBottom > top) { |
| 3677 | mVoiceContentBottom = top; |
| 3678 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3679 | top = win.getVisibleFrameLw().top; |
| 3680 | top += win.getGivenVisibleInsetsLw().top; |
| 3681 | if (mCurBottom > top) { |
| 3682 | mCurBottom = top; |
| 3683 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3684 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3685 | + mDockBottom + " mContentBottom=" |
| 3686 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 3687 | } |
| 3688 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3689 | private void offsetVoiceInputWindowLw(WindowState win) { |
| 3690 | final int gravity = win.getAttrs().gravity; |
| 3691 | switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER) |
| 3692 | << Gravity.AXIS_X_SHIFT)) { |
| 3693 | case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: { |
| 3694 | int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right; |
| 3695 | if (mVoiceContentLeft < right) { |
| 3696 | mVoiceContentLeft = right; |
| 3697 | } |
| 3698 | } break; |
| 3699 | case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: { |
| 3700 | int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left; |
| 3701 | if (mVoiceContentRight < left) { |
| 3702 | mVoiceContentRight = left; |
| 3703 | } |
| 3704 | } break; |
| 3705 | } |
| 3706 | switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER) |
| 3707 | << Gravity.AXIS_Y_SHIFT)) { |
| 3708 | case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: { |
| 3709 | int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom; |
| 3710 | if (mVoiceContentTop < bottom) { |
| 3711 | mVoiceContentTop = bottom; |
| 3712 | } |
| 3713 | } break; |
| 3714 | case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: { |
| 3715 | int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top; |
| 3716 | if (mVoiceContentBottom < top) { |
| 3717 | mVoiceContentBottom = top; |
| 3718 | } |
| 3719 | } break; |
| 3720 | } |
| 3721 | } |
| 3722 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3723 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 3724 | @Override |
| 3725 | public void finishLayoutLw() { |
| 3726 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3730 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3731 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3732 | mTopFullscreenOpaqueWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3733 | mAppsToBeHidden.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3734 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3735 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3736 | mForcingShowNavBar = false; |
| 3737 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3738 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3739 | mHideLockScreen = false; |
| 3740 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3741 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3742 | mShowingLockscreen = false; |
| 3743 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3744 | mWinShowWhenLocked = null; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3748 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3749 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3750 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 3751 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3752 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3753 | if (mTopFullscreenOpaqueWindowState == null |
| 3754 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 3755 | mForcingShowNavBar = true; |
| 3756 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3757 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 3758 | if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 3759 | mForceStatusBarFromKeyguard = true; |
| 3760 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3761 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 3762 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3763 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3764 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3765 | mForceStatusBarFromKeyguard = true; |
| 3766 | } else { |
| 3767 | mForceStatusBar = true; |
| 3768 | } |
| 3769 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3770 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3771 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3772 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3773 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3774 | && attrs.type <= LAST_APPLICATION_WINDOW; |
| 3775 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3776 | // If the lockscreen was showing when the dream started then wait |
| 3777 | // for the dream to draw before hiding the lockscreen. |
| 3778 | if (!mDreamingLockscreen |
| 3779 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 3780 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3781 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3782 | } |
| 3783 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3784 | |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 3785 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
Craig Mautner | 74ee938 | 2014-04-01 15:20:16 -0700 | [diff] [blame] | 3786 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3787 | final boolean secureKeyguard = isKeyguardSecure(); |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3788 | if (appWindow) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3789 | if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) { |
| 3790 | // Remove any previous windows with the same appToken. |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3791 | mAppsToBeHidden.remove(win.getAppToken()); |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3792 | if (mAppsToBeHidden.isEmpty() && showWhenLocked && |
| 3793 | isKeyguardSecureIncludingHidden()) { |
| 3794 | mWinShowWhenLocked = win; |
| 3795 | mHideLockScreen = true; |
| 3796 | mForceStatusBarFromKeyguard = false; |
| 3797 | } |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3798 | } else { |
| 3799 | mAppsToBeHidden.add(win.getAppToken()); |
| 3800 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3801 | if (attrs.x == 0 && attrs.y == 0 |
| 3802 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 3803 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 3804 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 3805 | mTopFullscreenOpaqueWindowState = win; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3806 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | da09ae3 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3807 | if (showWhenLocked) { |
| 3808 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 3809 | "Setting mHideLockScreen to true by win " + win); |
| 3810 | mHideLockScreen = true; |
| 3811 | mForceStatusBarFromKeyguard = false; |
| 3812 | } |
Craig Mautner | 4bdab6b | 2014-04-01 12:05:11 -0700 | [diff] [blame] | 3813 | if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
Craig Mautner | da09ae3 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3814 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 3815 | "Setting mDismissKeyguard true by win " + win); |
| 3816 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 3817 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 3818 | mWinDismissingKeyguard = win; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3819 | mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard; |
Craig Mautner | da09ae3 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3820 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3821 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 3822 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3823 | mAllowLockscreenWhenOn = true; |
| 3824 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3825 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3826 | |
| 3827 | if (mWinShowWhenLocked != null && |
| 3828 | mWinShowWhenLocked.getAppToken() != win.getAppToken()) { |
| 3829 | win.hideLw(false); |
| 3830 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3831 | } |
| 3832 | } |
| 3833 | } |
| 3834 | |
| 3835 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3836 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3837 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3838 | if (mWinShowWhenLocked != null && |
| 3839 | mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) { |
| 3840 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 3841 | // fullscreen window. |
| 3842 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 3843 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 3844 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 3845 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 3846 | } |
| 3847 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3848 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3849 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3850 | |
| 3851 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 3852 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 3853 | : null; |
| 3854 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3855 | // If we are not currently showing a dream then remember the current |
| 3856 | // lockscreen state. We will use this to determine whether the dream |
| 3857 | // started while the lockscreen was showing and remember this state |
| 3858 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3859 | if (!mShowingDream) { |
| 3860 | mDreamingLockscreen = mShowingLockscreen; |
| 3861 | } |
| 3862 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3863 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3864 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3865 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 3866 | + " top=" + mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3867 | if (mForceStatusBar || mForceStatusBarFromKeyguard) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3868 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3869 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3870 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3871 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 3872 | // Maintain fullscreen layout until incoming animation is complete. |
| 3873 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 3874 | // Transient status bar on the lockscreen is not allowed |
| 3875 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 3876 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 3877 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 3878 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3879 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3880 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3881 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3882 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3883 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3884 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3885 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3886 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3887 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3888 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3889 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 3890 | // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window |
| 3891 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 3892 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3893 | if (mStatusBarController.isTransientShowing()) { |
| 3894 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3895 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3896 | } |
| 3897 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3898 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3899 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3900 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3901 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3902 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 3903 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3904 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3905 | 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] | 3906 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3907 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3908 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3909 | } |
| 3910 | } |
| 3911 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3912 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 3913 | if (mTopIsFullscreen != topIsFullscreen) { |
| 3914 | if (!topIsFullscreen) { |
| 3915 | // Force another layout when status bar becomes fully shown. |
| 3916 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3917 | } |
| 3918 | mTopIsFullscreen = topIsFullscreen; |
| 3919 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3920 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3921 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 3922 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3923 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 3924 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 3925 | + mHideLockScreen); |
| 3926 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) { |
| 3927 | mKeyguardHidden = true; |
| 3928 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3929 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3930 | | FINISH_LAYOUT_REDO_CONFIG |
| 3931 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3932 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3933 | if (mKeyguardDelegate.isShowing()) { |
| 3934 | mHandler.post(new Runnable() { |
| 3935 | @Override |
| 3936 | public void run() { |
| 3937 | mKeyguardDelegate.keyguardDone(false, false); |
| 3938 | } |
| 3939 | }); |
| 3940 | } |
| 3941 | } else if (mHideLockScreen) { |
| 3942 | mKeyguardHidden = true; |
| 3943 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) { |
| 3944 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3945 | | FINISH_LAYOUT_REDO_CONFIG |
| 3946 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3947 | } |
| 3948 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 3949 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 3950 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 3951 | // Only launch the next keyguard unlock window once per window. |
| 3952 | mKeyguardHidden = false; |
| 3953 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) { |
| 3954 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3955 | | FINISH_LAYOUT_REDO_CONFIG |
| 3956 | | FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3957 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3958 | mHandler.post(new Runnable() { |
| 3959 | @Override |
| 3960 | public void run() { |
| 3961 | mKeyguardDelegate.dismiss(); |
| 3962 | } |
| 3963 | }); |
| 3964 | } |
| 3965 | } else { |
| 3966 | mWinDismissingKeyguard = null; |
| 3967 | mKeyguardHidden = false; |
| 3968 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) { |
| 3969 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3970 | | FINISH_LAYOUT_REDO_CONFIG |
| 3971 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3972 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3973 | } |
| 3974 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3975 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3976 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3977 | // If the navigation bar has been hidden or shown, we need to do another |
| 3978 | // layout pass to update that window. |
| 3979 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3980 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3981 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 3982 | // update since mAllowLockscreenWhenOn might have changed |
| 3983 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3984 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3985 | } |
| 3986 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3987 | /** |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3988 | * 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] | 3989 | * immediately need to put the wallpaper directly behind the Keyguard when a window with flag |
| 3990 | * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we |
| 3991 | * would wait for Keyguard to change the flags, that would be running asynchronously and thus be |
| 3992 | * too late so the user might see the window behind. |
| 3993 | * |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3994 | * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3995 | * @return Whether the flags have changed and we have to redo the layout. |
| 3996 | */ |
| 3997 | private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3998 | if (setHiddenResult |
| 3999 | == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4000 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4001 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4002 | return true; |
| 4003 | } else if (setHiddenResult |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4004 | == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4005 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4006 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4007 | return true; |
| 4008 | } else { |
| 4009 | return false; |
| 4010 | } |
| 4011 | } |
| 4012 | |
| 4013 | private boolean isStatusBarKeyguard() { |
| 4014 | return mStatusBar != null |
| 4015 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4016 | } |
| 4017 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4018 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4019 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4020 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4021 | // 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] | 4022 | return false; |
| 4023 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4024 | return true; |
| 4025 | } |
| 4026 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4027 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4028 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4029 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4030 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4031 | // If the navigation bar has been hidden or shown, we need to do another |
| 4032 | // layout pass to update that window. |
| 4033 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4034 | } |
| 4035 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4036 | } |
| 4037 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4038 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4039 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4040 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4041 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4042 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4043 | if (newLidState == mLidState) { |
| 4044 | return; |
| 4045 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4046 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4047 | mLidState = newLidState; |
| 4048 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4049 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4050 | |
| 4051 | if (lidOpen) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 4052 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4053 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4054 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4055 | } |
| 4056 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4057 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4058 | void setHdmiPlugged(boolean plugged) { |
| 4059 | if (mHdmiPlugged != plugged) { |
| 4060 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4061 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4062 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4063 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4064 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4065 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4066 | } |
| 4067 | } |
| 4068 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4069 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4070 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4071 | // watch for HDMI plug messages if the hdmi switch exists |
| 4072 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4073 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4074 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4075 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4076 | FileReader reader = null; |
| 4077 | try { |
| 4078 | reader = new FileReader(filename); |
| 4079 | char[] buf = new char[15]; |
| 4080 | int n = reader.read(buf); |
| 4081 | if (n > 1) { |
| 4082 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4083 | } |
| 4084 | } catch (IOException ex) { |
| 4085 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4086 | } catch (NumberFormatException ex) { |
| 4087 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4088 | } finally { |
| 4089 | if (reader != null) { |
| 4090 | try { |
| 4091 | reader.close(); |
| 4092 | } catch (IOException ex) { |
| 4093 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4094 | } |
| 4095 | } |
| 4096 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4097 | // This dance forces the code in setHdmiPlugged to run. |
| 4098 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4099 | mHdmiPlugged = !plugged; |
| 4100 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4101 | } |
| 4102 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4103 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4104 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4105 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4106 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4107 | @Override public void run() { |
| 4108 | synchronized (mScreenshotLock) { |
| 4109 | if (mScreenshotConnection != null) { |
| 4110 | mContext.unbindService(mScreenshotConnection); |
| 4111 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4112 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4113 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4114 | } |
| 4115 | }; |
| 4116 | |
| 4117 | // Assume this is called from the Handler thread. |
| 4118 | private void takeScreenshot() { |
| 4119 | synchronized (mScreenshotLock) { |
| 4120 | if (mScreenshotConnection != null) { |
| 4121 | return; |
| 4122 | } |
| 4123 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4124 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 4125 | Intent intent = new Intent(); |
| 4126 | intent.setComponent(cn); |
| 4127 | ServiceConnection conn = new ServiceConnection() { |
| 4128 | @Override |
| 4129 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 4130 | synchronized (mScreenshotLock) { |
| 4131 | if (mScreenshotConnection != this) { |
| 4132 | return; |
| 4133 | } |
| 4134 | Messenger messenger = new Messenger(service); |
| 4135 | Message msg = Message.obtain(null, 1); |
| 4136 | final ServiceConnection myConn = this; |
| 4137 | Handler h = new Handler(mHandler.getLooper()) { |
| 4138 | @Override |
| 4139 | public void handleMessage(Message msg) { |
| 4140 | synchronized (mScreenshotLock) { |
| 4141 | if (mScreenshotConnection == myConn) { |
| 4142 | mContext.unbindService(mScreenshotConnection); |
| 4143 | mScreenshotConnection = null; |
| 4144 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 4145 | } |
| 4146 | } |
| 4147 | } |
| 4148 | }; |
| 4149 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 4150 | msg.arg1 = msg.arg2 = 0; |
| 4151 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 4152 | msg.arg1 = 1; |
| 4153 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 4154 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4155 | try { |
| 4156 | messenger.send(msg); |
| 4157 | } catch (RemoteException e) { |
| 4158 | } |
| 4159 | } |
| 4160 | } |
| 4161 | @Override |
| 4162 | public void onServiceDisconnected(ComponentName name) {} |
| 4163 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 4164 | if (mContext.bindServiceAsUser( |
| 4165 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4166 | mScreenshotConnection = conn; |
| 4167 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 4168 | } |
| 4169 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4172 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4173 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4174 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4175 | if (!mSystemBooted) { |
| 4176 | // If we have not yet booted, don't let key events do anything. |
| 4177 | return 0; |
| 4178 | } |
| 4179 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4180 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4181 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 4182 | final boolean canceled = event.isCanceled(); |
| 4183 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 4184 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4185 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4186 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 4187 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 4188 | // the same as if it were open and in front. |
| 4189 | // This will prevent any keys other than the power button from waking the screen |
| 4190 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4191 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4192 | (interactive ? |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4193 | mKeyguardDelegate.isShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4194 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4195 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4196 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4197 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4198 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4199 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4200 | } |
| 4201 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4202 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4203 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 4204 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 4205 | || event.isWakeKey(); |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame^] | 4206 | if (interactive |
| 4207 | || (isInjected && !isWakeKey) |
| 4208 | || (!interactive && shouldDispatchInputWhenNonInteractive())) { |
| 4209 | // When the device is interactive, the key is injected, or we're currently dozing in a |
| 4210 | // non-interactive state with the screen on and the keyguard showing, pass the key to |
| 4211 | // the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4212 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4213 | isWakeKey = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4214 | } else { |
| 4215 | // When the screen is off and the key is not injected, determine whether |
| 4216 | // to wake the device but don't pass the key to the application. |
| 4217 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4218 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 4219 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4220 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4221 | } |
| 4222 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4223 | // If the key would be handled globally, just return the result, don't worry about special |
| 4224 | // key processing. |
| 4225 | if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4226 | if (isWakeKey) { |
| 4227 | mPowerManager.wakeUp(event.getEventTime()); |
| 4228 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4229 | return result; |
| 4230 | } |
| 4231 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4232 | boolean useHapticFeedback = down |
| 4233 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 4234 | && event.getRepeatCount() == 0; |
| 4235 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4236 | // Handle special keys. |
| 4237 | switch (keyCode) { |
| 4238 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 4239 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4240 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4241 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 4242 | if (down) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4243 | if (interactive && !mVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4244 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 4245 | mVolumeDownKeyTriggered = true; |
| 4246 | mVolumeDownKeyTime = event.getDownTime(); |
| 4247 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 4248 | cancelPendingPowerKeyAction(); |
| 4249 | interceptScreenshotChord(); |
| 4250 | } |
| 4251 | } else { |
| 4252 | mVolumeDownKeyTriggered = false; |
| 4253 | cancelPendingScreenshotChordAction(); |
| 4254 | } |
| 4255 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 4256 | if (down) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4257 | if (interactive && !mVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4258 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 4259 | mVolumeUpKeyTriggered = true; |
| 4260 | cancelPendingPowerKeyAction(); |
| 4261 | cancelPendingScreenshotChordAction(); |
| 4262 | } |
| 4263 | } else { |
| 4264 | mVolumeUpKeyTriggered = false; |
| 4265 | cancelPendingScreenshotChordAction(); |
| 4266 | } |
| 4267 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4268 | if (down) { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4269 | TelecommManager telecommManager = getTelecommService(); |
| 4270 | if (telecommManager != null) { |
| 4271 | if (telecommManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4272 | // If an incoming call is ringing, either VOLUME key means |
| 4273 | // "silence ringer". We handle these keys here, rather than |
| 4274 | // in the InCallScreen, to make sure we'll respond to them |
| 4275 | // even if the InCallScreen hasn't come to the foreground yet. |
| 4276 | // Look for the DOWN event here, to agree with the "fallback" |
| 4277 | // behavior in the InCallScreen. |
| 4278 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4279 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4280 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4281 | // Silence the ringer. (It's safe to call this |
| 4282 | // even if the ringer has already been silenced.) |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4283 | telecommManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4284 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4285 | // And *don't* pass this key thru to the current activity |
| 4286 | // (which is probably the InCallScreen.) |
| 4287 | result &= ~ACTION_PASS_TO_USER; |
| 4288 | break; |
| 4289 | } |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 4290 | if (telecommManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4291 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 4292 | // 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] | 4293 | // the application, just pass it to the session service. |
| 4294 | |
| 4295 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4296 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4297 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4298 | } |
| 4299 | } |
| 4300 | |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4301 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4302 | // If we aren't passing to the user and no one else |
| 4303 | // handled it send it to the session manager to figure |
| 4304 | // out. |
| 4305 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4306 | .sendVolumeKeyEvent(event, true); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4307 | break; |
| 4308 | } |
| 4309 | } |
| 4310 | break; |
| 4311 | } |
| 4312 | |
| 4313 | case KeyEvent.KEYCODE_ENDCALL: { |
| 4314 | result &= ~ACTION_PASS_TO_USER; |
| 4315 | if (down) { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4316 | TelecommManager telecommManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4317 | boolean hungUp = false; |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4318 | if (telecommManager != null) { |
| 4319 | hungUp = telecommManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4320 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4321 | interceptPowerKeyDown(!interactive || hungUp); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4322 | } else { |
| 4323 | if (interceptPowerKeyUp(canceled)) { |
| 4324 | if ((mEndcallBehavior |
| 4325 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 4326 | if (goHome()) { |
| 4327 | break; |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 4328 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4329 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4330 | if ((mEndcallBehavior |
| 4331 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 4332 | mPowerManager.goToSleep(event.getEventTime(), |
| 4333 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4334 | isWakeKey = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4335 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4336 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4337 | } |
| 4338 | break; |
| 4339 | } |
| 4340 | |
| 4341 | case KeyEvent.KEYCODE_POWER: { |
| 4342 | result &= ~ACTION_PASS_TO_USER; |
| 4343 | if (down) { |
Jeff Brown | 26c6a50 | 2014-04-11 02:15:54 -0700 | [diff] [blame] | 4344 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 4345 | event.getDownTime(), isImmersiveMode(mLastSystemUiFlags)); |
| 4346 | if (panic) { |
| 4347 | mHandler.post(mRequestTransientNav); |
| 4348 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4349 | if (interactive && !mPowerKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4350 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 4351 | mPowerKeyTriggered = true; |
| 4352 | mPowerKeyTime = event.getDownTime(); |
| 4353 | interceptScreenshotChord(); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4354 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4355 | |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4356 | TelecommManager telecommManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4357 | boolean hungUp = false; |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4358 | if (telecommManager != null) { |
| 4359 | if (telecommManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4360 | // Pressing Power while there's a ringing incoming |
| 4361 | // call should silence the ringer. |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4362 | telecommManager.silenceRinger(); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4363 | } else if ((mIncallPowerBehavior |
| 4364 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 4365 | && telecommManager.isInCall() && interactive) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4366 | // Otherwise, if "Power button ends call" is enabled, |
| 4367 | // the Power button will hang up any current active call. |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4368 | hungUp = telecommManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4369 | } |
| 4370 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4371 | interceptPowerKeyDown(!interactive || hungUp |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4372 | || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4373 | } else { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4374 | mPowerKeyTriggered = false; |
| 4375 | cancelPendingScreenshotChordAction(); |
| 4376 | if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 4377 | powerShortPress(event.getEventTime()); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4378 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4379 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4380 | mPendingPowerKeyUpCanceled = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4381 | } |
| 4382 | break; |
| 4383 | } |
| 4384 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4385 | case KeyEvent.KEYCODE_SLEEP: { |
| 4386 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4387 | if (!mPowerManager.isInteractive()) { |
| 4388 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 4389 | } |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 4390 | mPowerManager.goToSleep(event.getEventTime(), |
| 4391 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4392 | isWakeKey = false; |
| 4393 | break; |
| 4394 | } |
| 4395 | |
| 4396 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4397 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4398 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4399 | break; |
| 4400 | } |
| 4401 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4402 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4403 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4404 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4405 | if (down) { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4406 | TelecommManager telecommManager = getTelecommService(); |
| 4407 | if (telecommManager != null) { |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 4408 | if (telecommManager.isInCall()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4409 | // Suppress PLAY/PAUSE toggle when phone is ringing or in-call |
| 4410 | // to avoid music playback. |
| 4411 | break; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4412 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4413 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4414 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4415 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4416 | case KeyEvent.KEYCODE_MUTE: |
| 4417 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4418 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4419 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4420 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4421 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4422 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4423 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4424 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4425 | // Only do this if we would otherwise not pass it to the user. In that |
| 4426 | // case, the PhoneWindow class will do the same thing, except it will |
| 4427 | // 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] | 4428 | // Note that we need to make a copy of the key event here because the |
| 4429 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4430 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4431 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4432 | new KeyEvent(event)); |
| 4433 | msg.setAsynchronous(true); |
| 4434 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4435 | } |
| 4436 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4437 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4438 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4439 | case KeyEvent.KEYCODE_CALL: { |
| 4440 | if (down) { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4441 | TelecommManager telecommManager = getTelecommService(); |
| 4442 | if (telecommManager != null) { |
| 4443 | if (telecommManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4444 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4445 | + " CALL key-down while ringing: Answer the call!"); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4446 | telecommManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4447 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4448 | // And *don't* pass this key thru to the current activity |
| 4449 | // (which is presumably the InCallScreen.) |
| 4450 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4451 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4452 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4453 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4454 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4455 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 4456 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 4457 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 4458 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 4459 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 4460 | // key event here because the original key event will be recycled when we return. |
| 4461 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 4462 | mBroadcastWakeLock.acquire(); |
| 4463 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 4464 | keyguardActive ? 1 : 0, 0); |
| 4465 | msg.setAsynchronous(true); |
| 4466 | msg.sendToTarget(); |
| 4467 | } |
| 4468 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4469 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4470 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4471 | if (useHapticFeedback) { |
| 4472 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 4473 | } |
| 4474 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4475 | if (isWakeKey) { |
| 4476 | mPowerManager.wakeUp(event.getEventTime()); |
| 4477 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4478 | return result; |
| 4479 | } |
| 4480 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4481 | /** |
| 4482 | * When the screen is off we ignore some keys that might otherwise typically |
| 4483 | * be considered wake keys. We filter them out here. |
| 4484 | * |
| 4485 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 4486 | * is always considered a wake key. |
| 4487 | */ |
| 4488 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 4489 | switch (keyCode) { |
| 4490 | // ignore volume keys unless docked |
| 4491 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4492 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4493 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4494 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4495 | |
| 4496 | // ignore media and camera keys |
| 4497 | case KeyEvent.KEYCODE_MUTE: |
| 4498 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4499 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4500 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4501 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4502 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4503 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4504 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4505 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4506 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4507 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4508 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4509 | case KeyEvent.KEYCODE_CAMERA: |
| 4510 | return false; |
| 4511 | } |
| 4512 | return true; |
| 4513 | } |
| 4514 | |
| 4515 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4516 | /** {@inheritDoc} */ |
| 4517 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame^] | 4518 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 4519 | if ((policyFlags & FLAG_WAKE) != 0) { |
| 4520 | mPowerManager.wakeUp(whenNanos / 1000000); |
| 4521 | return 0; |
| 4522 | } |
| 4523 | if (shouldDispatchInputWhenNonInteractive()) { |
| 4524 | return ACTION_PASS_TO_USER; |
| 4525 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4526 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4527 | } |
| 4528 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame^] | 4529 | private boolean shouldDispatchInputWhenNonInteractive() { |
| 4530 | return keyguardIsShowingTq() && mDisplay != null && |
| 4531 | mDisplay.getState() != Display.STATE_OFF; |
| 4532 | } |
| 4533 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4534 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 4535 | if (DEBUG_INPUT) { |
| 4536 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4537 | } |
| 4538 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4539 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 4540 | if (DEBUG_INPUT) { |
| 4541 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 4542 | } |
| 4543 | |
| 4544 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 4545 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4546 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 4547 | } |
| 4548 | |
| 4549 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 4550 | |
| 4551 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4552 | && event.getRepeatCount() == 0) { |
| 4553 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 4554 | |
| 4555 | Message msg = mHandler.obtainMessage( |
| 4556 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 4557 | msg.setAsynchronous(true); |
| 4558 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 4559 | } else { |
| 4560 | mBroadcastWakeLock.release(); |
| 4561 | } |
| 4562 | } |
| 4563 | |
| 4564 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 4565 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4566 | |
| 4567 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 4568 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 4569 | if (DEBUG_INPUT) { |
| 4570 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 4571 | } |
| 4572 | |
| 4573 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 4574 | mBroadcastWakeLock.release(); |
| 4575 | } |
| 4576 | |
| 4577 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 4578 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4579 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4580 | } |
| 4581 | } |
| 4582 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 4583 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
| 4584 | Intent voiceIntent = |
| 4585 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 4586 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
| 4587 | mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
| 4588 | mBroadcastWakeLock.release(); |
| 4589 | } |
| 4590 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4591 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4592 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4593 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 4594 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 4595 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 4596 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4597 | } else { |
| 4598 | try { |
| 4599 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 4600 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 4601 | mUiMode = uiModeService.getCurrentModeType(); |
| 4602 | } catch (RemoteException e) { |
| 4603 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 4604 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4605 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4606 | synchronized (mLock) { |
| 4607 | updateOrientationListenerLp(); |
| 4608 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4609 | } |
| 4610 | }; |
| 4611 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4612 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 4613 | @Override |
| 4614 | public void onReceive(Context context, Intent intent) { |
| 4615 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4616 | if (mKeyguardDelegate != null) { |
| 4617 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4618 | } |
| 4619 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4620 | if (mKeyguardDelegate != null) { |
| 4621 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4622 | } |
| 4623 | } |
| 4624 | } |
| 4625 | }; |
| 4626 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4627 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 4628 | @Override |
| 4629 | public void onReceive(Context context, Intent intent) { |
| 4630 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 4631 | // tickle the settings observer: this first ensures that we're |
| 4632 | // observing the relevant settings for the newly-active user, |
| 4633 | // and then updates our own bookkeeping based on the now- |
| 4634 | // current user. |
| 4635 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4636 | |
| 4637 | // force a re-application of focused window sysui visibility. |
| 4638 | // the window may never have been shown for this user |
| 4639 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4640 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4641 | mLastSystemUiFlags = 0; |
| 4642 | updateSystemUiVisibilityLw(); |
| 4643 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4644 | } |
| 4645 | } |
| 4646 | }; |
| 4647 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 4648 | private final Runnable mRequestTransientNav = new Runnable() { |
| 4649 | @Override |
| 4650 | public void run() { |
| 4651 | requestTransientBars(mNavigationBar); |
| 4652 | } |
| 4653 | }; |
| 4654 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4655 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4656 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 4657 | if (!isUserSetupComplete()) { |
| 4658 | // Swipe-up for navigation bar is disabled during setup |
| 4659 | return; |
| 4660 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4661 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 4662 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4663 | if (sb || nb) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4664 | WindowState barTarget = sb ? mStatusBar : mNavigationBar; |
| 4665 | if (sb ^ nb && barTarget != swipeTarget) { |
| 4666 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4667 | return; |
| 4668 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4669 | if (sb) mStatusBarController.showTransient(); |
| 4670 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4671 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4672 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4673 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4674 | } |
| 4675 | } |
| 4676 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4677 | @Override |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 4678 | public void goingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4679 | EventLog.writeEvent(70000, 0); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4680 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4681 | mScreenOnEarly = false; |
| 4682 | mScreenOnFully = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4683 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4684 | if (mKeyguardDelegate != null) { |
| 4685 | mKeyguardDelegate.onScreenTurnedOff(why); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4686 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4687 | synchronized (mLock) { |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 4688 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4689 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4690 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4691 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4692 | } |
| 4693 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4694 | @Override |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 4695 | public void wakingUp(final ScreenOnListener screenOnListener) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4696 | EventLog.writeEvent(70000, 1); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4697 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...", |
| 4698 | new RuntimeException("here").fillInStackTrace()); |
| 4699 | mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget(); |
| 4700 | } |
| 4701 | |
| 4702 | // Called on the mHandler thread. |
| 4703 | private void handleWakingUp(final ScreenOnListener screenOnListener) { |
| 4704 | if (screenOnListener != null) { |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 4705 | mScreenOnListener = screenOnListener; |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 4706 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4707 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4708 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4709 | mScreenOnEarly = true; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 4710 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4711 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4712 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4713 | } |
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 | mKeyguardDrawComplete = false; |
| 4716 | mWindowManagerDrawComplete = false; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4717 | if (mKeyguardDelegate != null) { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4718 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 4719 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
| 4720 | mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4721 | } else { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4722 | if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 4723 | mKeyguardDrawComplete = true; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4724 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4725 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4726 | } |
| 4727 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4728 | // Called on the mHandler thread. |
| 4729 | private void finishScreenTurningOn() { |
| 4730 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 4731 | "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 4732 | + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 4733 | if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) { |
| 4734 | return; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 4737 | ScreenOnListener screenOnListener; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4738 | synchronized (mLock) { |
| 4739 | mScreenOnFully = true; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 4740 | screenOnListener = mScreenOnListener; |
| 4741 | mScreenOnListener = null; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4742 | } |
| 4743 | |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 4744 | try { |
| 4745 | mWindowManager.setEventDispatching(true); |
| 4746 | } catch (RemoteException unhandled) { |
| 4747 | } |
| 4748 | |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 4749 | if (screenOnListener != null) { |
| 4750 | screenOnListener.onScreenOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4751 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4752 | |
| 4753 | setKeyguardDrawn(); |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 4754 | |
| 4755 | if (mBootMessageNeedsHiding) { |
| 4756 | handleHideBootMessage(); |
| 4757 | mBootMessageNeedsHiding = false; |
| 4758 | } |
| 4759 | } |
| 4760 | |
| 4761 | private void handleHideBootMessage() { |
| 4762 | if (mBootMsgDialog == null) { |
| 4763 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up"); |
| 4764 | return; |
| 4765 | } |
| 4766 | if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) { |
| 4767 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready"); |
| 4768 | mBootMessageNeedsHiding = true; |
| 4769 | return; |
| 4770 | } |
| 4771 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 4772 | mBootMsgDialog.dismiss(); |
| 4773 | mBootMsgDialog = null; |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4777 | public boolean isScreenOnEarly() { |
| 4778 | return mScreenOnEarly; |
| 4779 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4780 | |
| 4781 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4782 | public boolean isScreenOnFully() { |
| 4783 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4784 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4785 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4786 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4787 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4788 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4789 | if (mKeyguardDelegate != null) { |
| 4790 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4791 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4795 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4796 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4797 | if (mKeyguardDelegate != null) { |
| 4798 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4799 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4800 | } |
| 4801 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 4802 | private boolean keyguardIsShowingTq() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4803 | if (mKeyguardDelegate == null) return false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4804 | return mKeyguardDelegate.isShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4805 | } |
| 4806 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4807 | |
| 4808 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4809 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4810 | public boolean isKeyguardLocked() { |
| 4811 | return keyguardOn(); |
| 4812 | } |
| 4813 | |
| 4814 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4815 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4816 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4817 | if (mKeyguardDelegate == null) return false; |
| 4818 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4819 | } |
| 4820 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4821 | // Returns true if keyguard is currently locked whether or not it is currently hidden. |
| 4822 | private boolean isKeyguardSecureIncludingHidden() { |
| 4823 | return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing(); |
| 4824 | } |
| 4825 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4826 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4827 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4828 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4829 | if (mKeyguardDelegate == null) return false; |
| 4830 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4831 | } |
| 4832 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4833 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4834 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4835 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4836 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4837 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4838 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 4839 | // ask the keyguard to prompt the user to authenticate if necessary |
| 4840 | mKeyguardDelegate.dismiss(); |
| 4841 | } |
| 4842 | }); |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | public void notifyActivityDrawnForKeyguardLw() { |
| 4847 | if (mKeyguardDelegate != null) { |
| 4848 | mHandler.post(new Runnable() { |
| 4849 | @Override |
| 4850 | public void run() { |
| 4851 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4852 | } |
| 4853 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 4857 | private void setKeyguardDrawn() { |
| 4858 | synchronized (mLock) { |
| 4859 | mKeyguardDrawn = true; |
| 4860 | } |
| 4861 | try { |
| 4862 | mWindowManager.enableScreenIfNeeded(); |
| 4863 | } catch (RemoteException unhandled) { |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | @Override |
| 4868 | public boolean isKeyguardDrawnLw() { |
| 4869 | synchronized (mLock) { |
| 4870 | return mKeyguardDrawn; |
| 4871 | } |
| 4872 | } |
| 4873 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 4874 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 4875 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 4876 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 4877 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 4878 | } |
| 4879 | } |
| 4880 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4881 | void sendCloseSystemWindows() { |
| 4882 | sendCloseSystemWindows(mContext, null); |
| 4883 | } |
| 4884 | |
| 4885 | void sendCloseSystemWindows(String reason) { |
| 4886 | sendCloseSystemWindows(mContext, reason); |
| 4887 | } |
| 4888 | |
| 4889 | static void sendCloseSystemWindows(Context context, String reason) { |
| 4890 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4891 | try { |
| 4892 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 4893 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4894 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4895 | } |
| 4896 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 4897 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4898 | @Override |
| 4899 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4900 | if (false) { |
| 4901 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 4902 | + orientation + ", last=" + lastRotation |
| 4903 | + "); user=" + mUserRotation + " " |
| 4904 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 4905 | ? "USER_ROTATION_LOCKED" : "") |
| 4906 | ); |
| 4907 | } |
| 4908 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 4909 | if (mForceDefaultOrientation) { |
| 4910 | return Surface.ROTATION_0; |
| 4911 | } |
| 4912 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4913 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4914 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 4915 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 4916 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4917 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4918 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4919 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 4920 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4921 | // Ignore sensor when lid switch is open and rotation is forced. |
| 4922 | preferredRotation = mLidOpenRotation; |
| 4923 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4924 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4925 | // Ignore sensor when in car dock unless explicitly enabled. |
| 4926 | // This case can override the behavior of NOSENSOR, and can also |
| 4927 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4928 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4929 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 4930 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 4931 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 4932 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4933 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4934 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 4935 | // This case can override the behavior of NOSENSOR, and can also |
| 4936 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4937 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4938 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4939 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 4940 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 4941 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4942 | preferredRotation = mDemoHdmiRotation; |
| 4943 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 4944 | && mUndockedHdmiRotation >= 0) { |
| 4945 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 4946 | // been specified in the configuration (only for legacy devices without |
| 4947 | // full multi-display support). |
| 4948 | // Note that the dock orientation overrides the HDMI orientation. |
| 4949 | preferredRotation = mUndockedHdmiRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4950 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 4951 | // Application just wants to remain locked in the last rotation. |
| 4952 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 4953 | } else if (!mSupportAutoRotation) { |
| 4954 | // If we don't support auto-rotation then bail out here and ignore |
| 4955 | // the sensor and any rotation lock settings. |
| 4956 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4957 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4958 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4959 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 4960 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 4961 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 4962 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4963 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 4964 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4965 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 4966 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 4967 | // Otherwise, use sensor only if requested by the application or enabled |
| 4968 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4969 | if (mAllowAllRotations < 0) { |
| 4970 | // Can't read this during init() because the context doesn't |
| 4971 | // have display metrics at that time so we cannot determine |
| 4972 | // tablet vs. phone then. |
| 4973 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 4974 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 4975 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4976 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4977 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4978 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4979 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4980 | preferredRotation = sensorRotation; |
| 4981 | } else { |
| 4982 | preferredRotation = lastRotation; |
| 4983 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4984 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 4985 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 4986 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 4987 | // The idea is that the user rotation expresses a weak preference for the direction |
| 4988 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 4989 | // 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] | 4990 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4991 | } else { |
| 4992 | // No overriding preference. |
| 4993 | // We will do exactly what the application asked us to do. |
| 4994 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4995 | } |
| 4996 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4997 | switch (orientation) { |
| 4998 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4999 | // Return portrait unless overridden. |
| 5000 | if (isAnyPortrait(preferredRotation)) { |
| 5001 | return preferredRotation; |
| 5002 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5003 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5004 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5005 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5006 | // Return landscape unless overridden. |
| 5007 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5008 | return preferredRotation; |
| 5009 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5010 | return mLandscapeRotation; |
| 5011 | |
| 5012 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5013 | // Return reverse portrait unless overridden. |
| 5014 | if (isAnyPortrait(preferredRotation)) { |
| 5015 | return preferredRotation; |
| 5016 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5017 | return mUpsideDownRotation; |
| 5018 | |
| 5019 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5020 | // Return seascape unless overridden. |
| 5021 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5022 | return preferredRotation; |
| 5023 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5024 | return mSeascapeRotation; |
| 5025 | |
| 5026 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5027 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5028 | // Return either landscape rotation. |
| 5029 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5030 | return preferredRotation; |
| 5031 | } |
| 5032 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 5033 | return lastRotation; |
| 5034 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5035 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5036 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5037 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5038 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5039 | // Return either portrait rotation. |
| 5040 | if (isAnyPortrait(preferredRotation)) { |
| 5041 | return preferredRotation; |
| 5042 | } |
| 5043 | if (isAnyPortrait(lastRotation)) { |
| 5044 | return lastRotation; |
| 5045 | } |
| 5046 | return mPortraitRotation; |
| 5047 | |
| 5048 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5049 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 5050 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5051 | if (preferredRotation >= 0) { |
| 5052 | return preferredRotation; |
| 5053 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5054 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 5055 | } |
| 5056 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5057 | } |
| 5058 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5059 | @Override |
| 5060 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 5061 | switch (orientation) { |
| 5062 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 5063 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 5064 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 5065 | return isAnyPortrait(rotation); |
| 5066 | |
| 5067 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 5068 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 5069 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 5070 | return isLandscapeOrSeascape(rotation); |
| 5071 | |
| 5072 | default: |
| 5073 | return true; |
| 5074 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5075 | } |
| 5076 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5077 | @Override |
| 5078 | public void setRotationLw(int rotation) { |
| 5079 | mOrientationListener.setCurrentRotation(rotation); |
| 5080 | } |
| 5081 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5082 | private boolean isLandscapeOrSeascape(int rotation) { |
| 5083 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5086 | private boolean isAnyPortrait(int rotation) { |
| 5087 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5090 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5091 | public int getUserRotationMode() { |
| 5092 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 5093 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 5094 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 5095 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5096 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5097 | |
| 5098 | // 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] | 5099 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5100 | public void setUserRotationMode(int mode, int rot) { |
| 5101 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5102 | |
| 5103 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5104 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5105 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5106 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5107 | rot, |
| 5108 | UserHandle.USER_CURRENT); |
| 5109 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5110 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5111 | 0, |
| 5112 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5113 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5114 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5115 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5116 | 1, |
| 5117 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5118 | } |
| 5119 | } |
| 5120 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5121 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5122 | public void setSafeMode(boolean safeMode) { |
| 5123 | mSafeMode = safeMode; |
| 5124 | performHapticFeedbackLw(null, safeMode |
| 5125 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 5126 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5127 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5128 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 5129 | static long[] getLongIntArray(Resources r, int resid) { |
| 5130 | int[] ar = r.getIntArray(resid); |
| 5131 | if (ar == null) { |
| 5132 | return null; |
| 5133 | } |
| 5134 | long[] out = new long[ar.length]; |
| 5135 | for (int i=0; i<ar.length; i++) { |
| 5136 | out[i] = ar[i]; |
| 5137 | } |
| 5138 | return out; |
| 5139 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5140 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5141 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5142 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5143 | public void systemReady() { |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 5144 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null); |
| 5145 | mKeyguardDelegate.onSystemReady(); |
| 5146 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5147 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5148 | synchronized (mLock) { |
| 5149 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5150 | mSystemReady = true; |
| 5151 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5152 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5153 | public void run() { |
| 5154 | updateSettings(); |
| 5155 | } |
| 5156 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5157 | } |
| 5158 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5159 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5160 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5161 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5162 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5163 | if (mKeyguardDelegate != null) { |
| 5164 | mKeyguardDelegate.onBootCompleted(); |
| 5165 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5166 | synchronized (mLock) { |
| 5167 | mSystemBooted = true; |
| 5168 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5169 | wakingUp(null); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5170 | } |
| 5171 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5172 | ProgressDialog mBootMsgDialog = null; |
| 5173 | |
| 5174 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5175 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5176 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5177 | mHandler.post(new Runnable() { |
| 5178 | @Override public void run() { |
| 5179 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 5180 | int theme; |
| 5181 | if (mContext.getPackageManager().hasSystemFeature( |
| 5182 | PackageManager.FEATURE_WATCH)) { |
| 5183 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 5184 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 5185 | PackageManager.FEATURE_TELEVISION)) { |
| 5186 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 5187 | } else { |
| 5188 | theme = 0; |
| 5189 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 5190 | |
| 5191 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 5192 | // This dialog will consume all events coming in to |
| 5193 | // it, to avoid it trying to do things too early in boot. |
| 5194 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 5195 | return true; |
| 5196 | } |
| 5197 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5198 | return true; |
| 5199 | } |
| 5200 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 5201 | return true; |
| 5202 | } |
| 5203 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 5204 | return true; |
| 5205 | } |
| 5206 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 5207 | return true; |
| 5208 | } |
| 5209 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 5210 | AccessibilityEvent event) { |
| 5211 | return true; |
| 5212 | } |
| 5213 | }; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5214 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 5215 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 5216 | mBootMsgDialog.setIndeterminate(true); |
| 5217 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5218 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5219 | mBootMsgDialog.getWindow().addFlags( |
| 5220 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 5221 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 5222 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 5223 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 5224 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 5225 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5226 | mBootMsgDialog.setCancelable(false); |
| 5227 | mBootMsgDialog.show(); |
| 5228 | } |
| 5229 | mBootMsgDialog.setMessage(msg); |
| 5230 | } |
| 5231 | }); |
| 5232 | } |
| 5233 | |
| 5234 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5235 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5236 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5237 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5238 | } |
| 5239 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5240 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5241 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5242 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5243 | // *************************************** |
| 5244 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 5245 | // *************************************** |
| 5246 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 5247 | // WITH ITS LOCKS HELD. |
| 5248 | // |
| 5249 | // This code must be VERY careful about the locks |
| 5250 | // it acquires. |
| 5251 | // In fact, the current code acquires way too many, |
| 5252 | // and probably has lurking deadlocks. |
| 5253 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5254 | synchronized (mScreenLockTimeout) { |
| 5255 | if (mLockScreenTimerActive) { |
| 5256 | // reset the timer |
| 5257 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5258 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5259 | } |
| 5260 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5261 | } |
| 5262 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5263 | class ScreenLockTimeout implements Runnable { |
| 5264 | Bundle options; |
| 5265 | |
| 5266 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5267 | public void run() { |
| 5268 | synchronized (this) { |
| 5269 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5270 | if (mKeyguardDelegate != null) { |
| 5271 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5272 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5273 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5274 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5275 | } |
| 5276 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5277 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5278 | public void setLockOptions(Bundle options) { |
| 5279 | this.options = options; |
| 5280 | } |
| 5281 | } |
| 5282 | |
| 5283 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 5284 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5285 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5286 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5287 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 5288 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5289 | if (options != null) { |
| 5290 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 5291 | // until the runnable actually executes. |
| 5292 | mScreenLockTimeout.setLockOptions(options); |
| 5293 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5294 | mHandler.post(mScreenLockTimeout); |
| 5295 | } |
| 5296 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5297 | private void updateLockScreenTimeout() { |
| 5298 | synchronized (mScreenLockTimeout) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5299 | boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5300 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5301 | if (mLockScreenTimerActive != enable) { |
| 5302 | if (enable) { |
| 5303 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 5304 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5305 | } else { |
| 5306 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 5307 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5308 | } |
| 5309 | mLockScreenTimerActive = enable; |
| 5310 | } |
| 5311 | } |
| 5312 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5313 | |
| 5314 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5315 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5316 | public void enableScreenAfterBoot() { |
| 5317 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5318 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5319 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5320 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 5321 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5322 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5323 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5324 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 5325 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5326 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5327 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5328 | |
| 5329 | synchronized (mLock) { |
| 5330 | updateWakeGestureListenerLp(); |
| 5331 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5332 | } |
| 5333 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5334 | void updateUiMode() { |
| 5335 | if (mUiModeManager == null) { |
| 5336 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 5337 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5338 | } |
| 5339 | try { |
| 5340 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 5341 | } catch (RemoteException e) { |
| 5342 | } |
| 5343 | } |
| 5344 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5345 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5346 | try { |
| 5347 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5348 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 5349 | } catch (RemoteException e) { |
| 5350 | // Ignore |
| 5351 | } |
| 5352 | } |
| 5353 | |
| 5354 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 5355 | try { |
| 5356 | //set orientation on WindowManager |
| 5357 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5358 | } catch (RemoteException e) { |
| 5359 | // Ignore |
| 5360 | } |
| 5361 | } |
| 5362 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5363 | /** |
| 5364 | * Return an Intent to launch the currently active dock app as home. Returns |
| 5365 | * null if the standard home should be launched, which is the case if any of the following is |
| 5366 | * true: |
| 5367 | * <ul> |
| 5368 | * <li>The device is not in either car mode or desk mode |
| 5369 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 5370 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 5371 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 5372 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 5373 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5374 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5375 | */ |
| 5376 | Intent createHomeDockIntent() { |
| 5377 | Intent intent = null; |
| 5378 | |
| 5379 | // What home does is based on the mode, not the dock state. That |
| 5380 | // is, when in car mode you should be taken to car home regardless |
| 5381 | // of whether we are actually in a car dock. |
| 5382 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 5383 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 5384 | intent = mCarDockIntent; |
| 5385 | } |
| 5386 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 5387 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 5388 | intent = mDeskDockIntent; |
| 5389 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5390 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 5391 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5392 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 5393 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 5394 | // Always launch dock home from home when watch is docked, if it exists. |
| 5395 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | if (intent == null) { |
| 5399 | return null; |
| 5400 | } |
| 5401 | |
| 5402 | ActivityInfo ai = null; |
| 5403 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 5404 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 5405 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 5406 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5407 | if (info != null) { |
| 5408 | ai = info.activityInfo; |
| 5409 | } |
| 5410 | if (ai != null |
| 5411 | && ai.metaData != null |
| 5412 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 5413 | intent = new Intent(intent); |
| 5414 | intent.setClassName(ai.packageName, ai.name); |
| 5415 | return intent; |
| 5416 | } |
| 5417 | |
| 5418 | return null; |
| 5419 | } |
| 5420 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5421 | void startDockOrHome() { |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 5422 | awakenDreams(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5423 | |
| 5424 | Intent dock = createHomeDockIntent(); |
| 5425 | if (dock != null) { |
| 5426 | try { |
| 5427 | mContext.startActivityAsUser(dock, UserHandle.CURRENT); |
| 5428 | return; |
| 5429 | } catch (ActivityNotFoundException e) { |
| 5430 | } |
| 5431 | } |
| 5432 | |
Dianne Hackborn | d888399 | 2012-09-07 15:58:52 -0700 | [diff] [blame] | 5433 | mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5434 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5435 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5436 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5437 | * goes to the home screen |
| 5438 | * @return whether it did anything |
| 5439 | */ |
| 5440 | boolean goHome() { |
| 5441 | if (false) { |
| 5442 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 5443 | try { |
| 5444 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 5445 | } catch (RemoteException e) { |
| 5446 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 5447 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5448 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5449 | } else { |
| 5450 | // This code brings home to the front or, if it is already |
| 5451 | // at the front, puts the device to sleep. |
| 5452 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 5453 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 5454 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 5455 | Log.d(TAG, "UTS-TEST-MODE"); |
| 5456 | } else { |
| 5457 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 5458 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5459 | Intent dock = createHomeDockIntent(); |
| 5460 | if (dock != null) { |
| 5461 | int result = ActivityManagerNative.getDefault() |
| 5462 | .startActivityAsUser(null, null, dock, |
| 5463 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 5464 | null, null, 0, |
| 5465 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5466 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5467 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 5468 | return false; |
| 5469 | } |
| 5470 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5471 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5472 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5473 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5474 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5475 | null, null, 0, |
| 5476 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5477 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5478 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5479 | return false; |
| 5480 | } |
| 5481 | } catch (RemoteException ex) { |
| 5482 | // bummer, the activity manager, which is in this process, is dead |
| 5483 | } |
| 5484 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5485 | return true; |
| 5486 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5487 | |
| 5488 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5489 | public void setCurrentOrientationLw(int newOrientation) { |
| 5490 | synchronized (mLock) { |
| 5491 | if (newOrientation != mCurrentAppOrientation) { |
| 5492 | mCurrentAppOrientation = newOrientation; |
| 5493 | updateOrientationListenerLp(); |
| 5494 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5495 | } |
| 5496 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5497 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5498 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 5499 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 5500 | return; |
| 5501 | } |
| 5502 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 5503 | Context.AUDIO_SERVICE); |
| 5504 | if (audioManager.isSilentMode()) { |
| 5505 | return; |
| 5506 | } |
| 5507 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 5508 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 5509 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 5510 | ringTone.play(); |
| 5511 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5512 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5513 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 5514 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 5515 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 5516 | } |
| 5517 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5518 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5519 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 5520 | if (!mVibrator.hasVibrator()) { |
| 5521 | return false; |
| 5522 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5523 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 5524 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 5525 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5526 | return false; |
| 5527 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5528 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5529 | switch (effectId) { |
| 5530 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5531 | pattern = mLongPressVibePattern; |
| 5532 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5533 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5534 | pattern = mVirtualKeyVibePattern; |
| 5535 | break; |
| 5536 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 5537 | pattern = mKeyboardTapVibePattern; |
| 5538 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 5539 | case HapticFeedbackConstants.CLOCK_TICK: |
| 5540 | pattern = mClockTickVibePattern; |
| 5541 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 5542 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 5543 | pattern = mCalendarDateVibePattern; |
| 5544 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5545 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5546 | pattern = mSafeModeDisabledVibePattern; |
| 5547 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5548 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5549 | pattern = mSafeModeEnabledVibePattern; |
| 5550 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5551 | default: |
| 5552 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5553 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5554 | int owningUid; |
| 5555 | String owningPackage; |
| 5556 | if (win != null) { |
| 5557 | owningUid = win.getOwningUid(); |
| 5558 | owningPackage = win.getOwningPackage(); |
| 5559 | } else { |
| 5560 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 5561 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5562 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5563 | if (pattern.length == 1) { |
| 5564 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 5565 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5566 | } else { |
| 5567 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 5568 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5569 | } |
| 5570 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5571 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5572 | |
| 5573 | @Override |
| 5574 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5575 | } |
| 5576 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5577 | @Override |
| 5578 | public void keepScreenOnStoppedLw() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5579 | if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 5580 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5581 | } |
| 5582 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 5583 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5584 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5585 | // If there is no window focused, there will be nobody to handle the events |
| 5586 | // 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] | 5587 | WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState; |
| 5588 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5589 | return 0; |
| 5590 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5591 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5592 | // We are updating at a point where the keyguard has gotten |
| 5593 | // focus, but we were last in a state where the top window is |
| 5594 | // hiding it. This is probably because the keyguard as been |
| 5595 | // shown while the top window was displayed, so we want to ignore |
| 5596 | // it here because this is just a very transient change and it |
| 5597 | // will quickly lose focus once it correctly gets hidden. |
| 5598 | return 0; |
| 5599 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5600 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 5601 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5602 | & ~mResettingSystemUiFlags |
| 5603 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5604 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5605 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5606 | } |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5607 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5608 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5609 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 5610 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5611 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5612 | return 0; |
| 5613 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5614 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5615 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5616 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5617 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5618 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5619 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5620 | try { |
| 5621 | IStatusBarService statusbar = getStatusBarService(); |
| 5622 | if (statusbar != null) { |
| 5623 | statusbar.setSystemUiVisibility(visibility, 0xffffffff); |
| 5624 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5625 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5626 | } catch (RemoteException e) { |
| 5627 | // re-acquire status bar service next time it is needed. |
| 5628 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5629 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5630 | } |
| 5631 | }); |
| 5632 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5633 | } |
| 5634 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5635 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5636 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5637 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 5638 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5639 | : mTopFullscreenOpaqueWindowState; |
| 5640 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5641 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5642 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5643 | // prevent status bar interaction from clearing certain flags |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5644 | boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 5645 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5646 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 5647 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 5648 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5649 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 5650 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5651 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 5652 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5653 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5654 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5655 | |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 5656 | if (!areTranslucentBarsAllowed() && transWin != mStatusBar) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 5657 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 5658 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5659 | } |
| 5660 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5661 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5662 | boolean immersiveSticky = |
| 5663 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5664 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5665 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5666 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5667 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 5668 | boolean hideStatusBarSysui = |
| 5669 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5670 | boolean hideNavBarSysui = |
| 5671 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5672 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5673 | boolean transientStatusBarAllowed = |
| 5674 | mStatusBar != null && ( |
| 5675 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5676 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5677 | || statusBarHasFocus); |
| 5678 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5679 | boolean transientNavBarAllowed = |
| 5680 | mNavigationBar != null && |
| 5681 | hideNavBarSysui && immersiveSticky; |
| 5682 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 5683 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5684 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 5685 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5686 | && !transientNavBarAllowed; |
| 5687 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5688 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5689 | clearClearableFlagsLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5690 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5691 | |
| 5692 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 5693 | |
| 5694 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5695 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 5696 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 5697 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5698 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5699 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 5700 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5701 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5702 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5703 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 5704 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5705 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5706 | } |
| 5707 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5708 | private void clearClearableFlagsLw() { |
| 5709 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5710 | if (newVal != mResettingSystemUiFlags) { |
| 5711 | mResettingSystemUiFlags = newVal; |
| 5712 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 5713 | } |
| 5714 | } |
| 5715 | |
| 5716 | private boolean isImmersiveMode(int vis) { |
| 5717 | 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] | 5718 | return mNavigationBar != null |
| 5719 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 5720 | && (vis & flags) != 0 |
| 5721 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5722 | } |
| 5723 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5724 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5725 | * @return whether the navigation or status bar can be made translucent |
| 5726 | * |
| 5727 | * This should return true unless touch exploration is not enabled or |
| 5728 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5729 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5730 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 5731 | return mTranslucentDecorEnabled |
| 5732 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5733 | } |
| 5734 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5735 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 5736 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5737 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5738 | public boolean hasNavigationBar() { |
| 5739 | return mHasNavigationBar; |
| 5740 | } |
| 5741 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5742 | @Override |
| 5743 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 5744 | mLastInputMethodWindow = ime; |
| 5745 | mLastInputMethodTargetWindow = target; |
| 5746 | } |
| 5747 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5748 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 5749 | public int getInputMethodWindowVisibleHeightLw() { |
| 5750 | return mDockBottom - mCurBottom; |
| 5751 | } |
| 5752 | |
| 5753 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5754 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 5755 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5756 | if (mKeyguardDelegate != null) { |
| 5757 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5758 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 5759 | if (mStatusBarService != null) { |
| 5760 | try { |
| 5761 | mStatusBarService.setCurrentUser(newUserId); |
| 5762 | } catch (RemoteException e) { |
| 5763 | // oh well |
| 5764 | } |
| 5765 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5766 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5767 | } |
| 5768 | |
| 5769 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 5770 | public boolean canMagnifyWindow(int windowType) { |
| 5771 | switch (windowType) { |
| 5772 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 5773 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 5774 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 5775 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 5776 | return false; |
| 5777 | } |
| 5778 | } |
| 5779 | return true; |
| 5780 | } |
| 5781 | |
| 5782 | @Override |
| 5783 | public boolean isTopLevelWindow(int windowType) { |
| 5784 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 5785 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 5786 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 5787 | } |
| 5788 | return true; |
| 5789 | } |
| 5790 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5791 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 5792 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5793 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5794 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 5795 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5796 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5797 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
| 5798 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5799 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 5800 | || mForceClearedSystemUiFlags != 0) { |
| 5801 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 5802 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 5803 | pw.print(" mResettingSystemUiFlags=0x"); |
| 5804 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 5805 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 5806 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5807 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5808 | if (mLastFocusNeedsMenu) { |
| 5809 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 5810 | pw.println(mLastFocusNeedsMenu); |
| 5811 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5812 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 5813 | pw.println(mWakeGestureEnabledSetting); |
| 5814 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5815 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5816 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 5817 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5818 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 5819 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 5820 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 5821 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5822 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5823 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5824 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 5825 | pw.print(mCarDockEnablesAccelerometer); |
| 5826 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 5827 | pw.println(mDeskDockEnablesAccelerometer); |
| 5828 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 5829 | pw.print(mLidKeyboardAccessibility); |
| 5830 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5831 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5832 | pw.print(prefix); |
| 5833 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 5834 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
| 5835 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 5836 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 5837 | pw.print(" mScreenOnFully="); pw.print(mScreenOnFully); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5838 | pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5839 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 5840 | pw.print(","); pw.print(mOverscanScreenTop); |
| 5841 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 5842 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 5843 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 5844 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 5845 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 5846 | pw.print(" top="); pw.print(mOverscanTop); |
| 5847 | pw.print(" right="); pw.print(mOverscanRight); |
| 5848 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 5849 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 5850 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 5851 | pw.print(mRestrictedOverscanScreenLeft); |
| 5852 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 5853 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 5854 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5855 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 5856 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 5857 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 5858 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 5859 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 5860 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 5861 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 5862 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5863 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 5864 | pw.print(","); pw.print(mStableFullscreenTop); |
| 5865 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 5866 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5867 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 5868 | pw.print(","); pw.print(mStableTop); |
| 5869 | pw.print(")-("); pw.print(mStableRight); |
| 5870 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5871 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 5872 | pw.print(","); pw.print(mSystemTop); |
| 5873 | pw.print(")-("); pw.print(mSystemRight); |
| 5874 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5875 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 5876 | pw.print(","); pw.print(mCurTop); |
| 5877 | pw.print(")-("); pw.print(mCurRight); |
| 5878 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 5879 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 5880 | pw.print(","); pw.print(mContentTop); |
| 5881 | pw.print(")-("); pw.print(mContentRight); |
| 5882 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 5883 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 5884 | pw.print(","); pw.print(mVoiceContentTop); |
| 5885 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 5886 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5887 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 5888 | pw.print(","); pw.print(mDockTop); |
| 5889 | pw.print(")-("); pw.print(mDockRight); |
| 5890 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5891 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 5892 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5893 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 5894 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
| 5895 | pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5896 | if (mLastInputMethodWindow != null) { |
| 5897 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 5898 | pw.println(mLastInputMethodWindow); |
| 5899 | } |
| 5900 | if (mLastInputMethodTargetWindow != null) { |
| 5901 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 5902 | pw.println(mLastInputMethodTargetWindow); |
| 5903 | } |
| 5904 | if (mStatusBar != null) { |
| 5905 | pw.print(prefix); pw.print("mStatusBar="); |
| 5906 | pw.println(mStatusBar); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5907 | pw.print(prefix); pw.print("isStatusBarKeyguard="); |
| 5908 | pw.print(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5909 | } |
| 5910 | if (mNavigationBar != null) { |
| 5911 | pw.print(prefix); pw.print("mNavigationBar="); |
| 5912 | pw.println(mNavigationBar); |
| 5913 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5914 | if (mFocusedWindow != null) { |
| 5915 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 5916 | pw.println(mFocusedWindow); |
| 5917 | } |
| 5918 | if (mFocusedApp != null) { |
| 5919 | pw.print(prefix); pw.print("mFocusedApp="); |
| 5920 | pw.println(mFocusedApp); |
| 5921 | } |
| 5922 | if (mWinDismissingKeyguard != null) { |
| 5923 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 5924 | pw.println(mWinDismissingKeyguard); |
| 5925 | } |
| 5926 | if (mTopFullscreenOpaqueWindowState != null) { |
| 5927 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 5928 | pw.println(mTopFullscreenOpaqueWindowState); |
| 5929 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5930 | if (mForcingShowNavBar) { |
| 5931 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 5932 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 5933 | pw.println(mForcingShowNavBarLayer); |
| 5934 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5935 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5936 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5937 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 5938 | pw.print(" mForceStatusBarFromKeyguard="); |
| 5939 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5940 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5941 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5942 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 5943 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 5944 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 5945 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 5946 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 5947 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 5948 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 5949 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 5950 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 5951 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 5952 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5953 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 5954 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 5955 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 5956 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 5957 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5958 | mStatusBarController.dump(pw, prefix); |
| 5959 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5960 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 5961 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5962 | if (mWakeGestureListener != null) { |
| 5963 | mWakeGestureListener.dump(pw, prefix); |
| 5964 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 5965 | if (mOrientationListener != null) { |
| 5966 | mOrientationListener.dump(pw, prefix); |
| 5967 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5968 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5969 | } |