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 | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 49 | import android.media.session.MediaSessionLegacyHelper; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 51 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 52 | import android.os.Handler; |
| 53 | import android.os.IBinder; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 54 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 55 | import android.os.Message; |
| 56 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 57 | import android.os.PowerManager; |
| 58 | import android.os.RemoteException; |
| 59 | import android.os.ServiceManager; |
| 60 | import android.os.SystemClock; |
| 61 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 62 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 63 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 64 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 65 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 66 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 67 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 68 | import android.service.dreams.DreamService; |
| 69 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 70 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 71 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 72 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 73 | import android.util.EventLog; |
| 74 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 75 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 76 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 77 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 78 | import android.view.Gravity; |
| 79 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 80 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 81 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 82 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 83 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 84 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 85 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 86 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 87 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 88 | import android.view.KeyEvent; |
| 89 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 90 | import android.view.Surface; |
| 91 | import android.view.View; |
| 92 | import android.view.ViewConfiguration; |
| 93 | import android.view.Window; |
| 94 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 95 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 96 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 97 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 98 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 99 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 100 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 101 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 102 | import android.view.animation.AnimationUtils; |
| 103 | |
| 104 | import com.android.internal.R; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 105 | import com.android.internal.policy.IKeyguardService; |
| 106 | import com.android.internal.policy.IKeyguardServiceConstants; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 107 | import com.android.internal.policy.PolicyManager; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 108 | import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 109 | import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 110 | import com.android.internal.statusbar.IStatusBarService; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 111 | import com.android.internal.widget.PointerLocationView; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 112 | import com.android.server.LocalServices; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 113 | |
| 114 | import java.io.File; |
| 115 | import java.io.FileReader; |
| 116 | import java.io.IOException; |
| 117 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 118 | import java.util.HashSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 119 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 120 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 121 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 122 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 123 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 124 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 125 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
| 126 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 127 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 128 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 129 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 130 | * introduces a new method suffix, Lp, for an internal lock of the |
| 131 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 132 | * 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] | 133 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 134 | */ |
| 135 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 136 | static final String TAG = "WindowManager"; |
| 137 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 138 | static final boolean localLOGV = false; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 139 | static final boolean DEBUG_LAYOUT = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 140 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 141 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 142 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 143 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 144 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 145 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 146 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 147 | // No longer recommended for desk docks; still useful in car docks. |
| 148 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 149 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 150 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 151 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 152 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 153 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 154 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3; |
| 155 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 156 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 157 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 158 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 159 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 160 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 161 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 162 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 163 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 164 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 165 | // These need to match the documentation/constant in |
| 166 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 167 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 168 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 169 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 170 | |
| 171 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 172 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 173 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 174 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 175 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 176 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 177 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 178 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 179 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 180 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 181 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 182 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 183 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 184 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 185 | /** |
| 186 | * These are the system UI flags that, when changing, can cause the layout |
| 187 | * of the screen to change. |
| 188 | */ |
| 189 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 190 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 191 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 192 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 193 | | View.NAVIGATION_BAR_TRANSLUCENT |
| 194 | | View.SYSTEM_UI_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 195 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 196 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 197 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 198 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 199 | .build(); |
| 200 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 201 | /** |
| 202 | * Keyguard stuff |
| 203 | */ |
| 204 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 205 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 206 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 207 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 208 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 209 | * |
| 210 | * These are special keys that are used to launch particular kinds of applications, |
| 211 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 212 | * usage page. We don't support quite that many yet... |
| 213 | */ |
| 214 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 215 | static { |
| 216 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 217 | sApplicationLaunchKeyCategories.append( |
| 218 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 219 | sApplicationLaunchKeyCategories.append( |
| 220 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 221 | sApplicationLaunchKeyCategories.append( |
| 222 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 223 | sApplicationLaunchKeyCategories.append( |
| 224 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 225 | sApplicationLaunchKeyCategories.append( |
| 226 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 227 | sApplicationLaunchKeyCategories.append( |
| 228 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 229 | } |
| 230 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 231 | /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ |
| 232 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
| 233 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 234 | /** |
| 235 | * Lock protecting internal state. Must not call out into window |
| 236 | * manager with lock held. (This lock will be acquired in places |
| 237 | * where the window manager is calling in with its own lock held.) |
| 238 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 239 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 240 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 241 | Context mContext; |
| 242 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 243 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 244 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 245 | PowerManager mPowerManager; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 246 | DreamManagerInternal mDreamManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 247 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 248 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 249 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 250 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 251 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 252 | AccessibilityManager mAccessibilityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 253 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 254 | // Vibrator pattern for haptic feedback of a long press. |
| 255 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 256 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 257 | // Vibrator pattern for haptic feedback of virtual key press. |
| 258 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 259 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 260 | // Vibrator pattern for a short vibration. |
| 261 | long[] mKeyboardTapVibePattern; |
| 262 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 263 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 264 | long[] mClockTickVibePattern; |
| 265 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 266 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 267 | long[] mCalendarDateVibePattern; |
| 268 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 269 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 270 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 271 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 272 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 273 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 274 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 275 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 276 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 277 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 278 | boolean mSafeMode; |
| 279 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 280 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 281 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 282 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 283 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 284 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 285 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 286 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 287 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 288 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 289 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 290 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 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; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 307 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 308 | WindowState mLastInputMethodWindow = null; |
| 309 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 310 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 311 | // FIXME This state is shared between the input reader and handler thread. |
| 312 | // Technically it's broken and buggy but it has been like this for many years |
| 313 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 314 | // so that only one thread is involved in handling input policy. Unfortunately |
| 315 | // it's on a critical path for power management so we can't just post the work to the |
| 316 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 317 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 318 | volatile boolean mPowerKeyHandled; |
| 319 | volatile int mPowerKeyPressCounter; |
| 320 | volatile boolean mEndCallKeyHandled; |
| 321 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 322 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 323 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 324 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 325 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 326 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 327 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 328 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 329 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 330 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 331 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 332 | boolean mHdmiPlugged; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 333 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 334 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 335 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 336 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 337 | int mCarDockRotation; |
| 338 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 339 | int mUndockedHdmiRotation; |
| 340 | int mDemoHdmiRotation; |
| 341 | boolean mDemoHdmiRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 342 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 343 | boolean mWakeGestureEnabledSetting; |
| 344 | MyWakeGestureListener mWakeGestureListener; |
| 345 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 346 | // Default display does not rotate, apps that require non-default orientation will have to |
| 347 | // have the orientation emulated. |
| 348 | private boolean mForceDefaultOrientation = false; |
| 349 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 350 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 351 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 352 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 353 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 354 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 355 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 356 | boolean mCarDockEnablesAccelerometer; |
| 357 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 358 | int mLidKeyboardAccessibility; |
| 359 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 360 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 361 | int mShortPressOnPowerBehavior; |
| 362 | int mLongPressOnPowerBehavior; |
| 363 | int mDoublePressOnPowerBehavior; |
| 364 | int mTriplePressOnPowerBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 365 | boolean mAwake; |
| 366 | boolean mScreenOnEarly; |
| 367 | boolean mScreenOnFully; |
| 368 | ScreenOnListener mScreenOnListener; |
| 369 | boolean mKeyguardDrawComplete; |
| 370 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 371 | boolean mOrientationSensorEnabled = false; |
| 372 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 373 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 374 | boolean mTranslucentDecorEnabled = true; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 375 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 376 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 377 | |
| 378 | // The last window we were told about in focusChanged. |
| 379 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 380 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 381 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 382 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 383 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 384 | // The current size of the screen; really; extends into the overscan area of |
| 385 | // the screen and doesn't account for any system elements like the status bar. |
| 386 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 387 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 388 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 389 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 390 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 391 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 392 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 393 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 394 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 395 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 396 | // if the status bar can't be hidden; in that case it effectively carves out |
| 397 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 398 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 399 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 400 | // During layout, the current screen borders accounting for any currently |
| 401 | // visible system UI elements. |
| 402 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 403 | // For applications requesting stable content insets, these are them. |
| 404 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 405 | // For applications requesting stable content insets but have also set the |
| 406 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 407 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 408 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 409 | // During layout, the current screen borders with all outer decoration |
| 410 | // (status bar, input method dock) accounted for. |
| 411 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 412 | // During layout, the frame in which content should be displayed |
| 413 | // to the user, accounting for all screen decoration except for any |
| 414 | // space they deem as available for other content. This is usually |
| 415 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 416 | // content insets. |
| 417 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 418 | // During layout, the frame in which voice content should be displayed |
| 419 | // to the user, accounting for all screen decoration except for any |
| 420 | // space they deem as available for other content. |
| 421 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 422 | // 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] | 423 | // windows are placed. |
| 424 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 425 | // During layout, the layer at which the doc window is placed. |
| 426 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 427 | // During layout, this is the layer of the status bar. |
| 428 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 429 | int mLastSystemUiFlags; |
| 430 | // Bits that we are in the process of clearing, so we want to prevent |
| 431 | // them from being set by applications until everything has been updated |
| 432 | // to have them clear. |
| 433 | int mResettingSystemUiFlags = 0; |
| 434 | // Bits that we are currently always keeping cleared. |
| 435 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 436 | // What we last reported to system UI about whether the compatibility |
| 437 | // menu needs to be displayed. |
| 438 | boolean mLastFocusNeedsMenu = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 439 | |
| 440 | FakeWindow mHideNavFakeWindow = null; |
| 441 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 442 | static final Rect mTmpParentFrame = new Rect(); |
| 443 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 444 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 445 | static final Rect mTmpContentFrame = new Rect(); |
| 446 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 447 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 448 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 449 | static final Rect mTmpNavigationFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 450 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 451 | WindowState mTopFullscreenOpaqueWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 452 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 453 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 454 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 455 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 456 | boolean mForceStatusBarFromKeyguard; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 457 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 458 | boolean mForcingShowNavBar; |
| 459 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 460 | |
| 461 | // States of keyguard dismiss. |
| 462 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 463 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 464 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 465 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 466 | |
| 467 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 468 | * be done once per window. */ |
| 469 | private WindowState mWinDismissingKeyguard; |
| 470 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 471 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 472 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 473 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 474 | * the wallpaper. */ |
| 475 | private WindowState mWinShowWhenLocked; |
| 476 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 477 | boolean mShowingLockscreen; |
| 478 | boolean mShowingDream; |
| 479 | boolean mDreamingLockscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 480 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 481 | boolean mHomeConsumed; |
| 482 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 483 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 484 | Intent mCarDockIntent; |
| 485 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 486 | boolean mSearchKeyShortcutPending; |
| 487 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 488 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 489 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 490 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 491 | // support for activating the lock screen while the screen is on |
| 492 | boolean mAllowLockscreenWhenOn; |
| 493 | int mLockScreenTimeout; |
| 494 | boolean mLockScreenTimerActive; |
| 495 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 496 | // 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] | 497 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 498 | |
| 499 | // Behavior of POWER button while in-call and screen on. |
| 500 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 501 | int mIncallPowerBehavior; |
| 502 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 503 | Display mDisplay; |
| 504 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 505 | int mLandscapeRotation = 0; // default landscape rotation |
| 506 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 507 | int mPortraitRotation = 0; // default portrait rotation |
| 508 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 509 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 510 | int mOverscanLeft = 0; |
| 511 | int mOverscanTop = 0; |
| 512 | int mOverscanRight = 0; |
| 513 | int mOverscanBottom = 0; |
| 514 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 515 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 516 | private int mLongPressOnHomeBehavior; |
| 517 | |
| 518 | // What we do when the user double-taps on home |
| 519 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 520 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 521 | // Allowed theater mode wake actions |
| 522 | private boolean mAllowTheaterModeWakeFromKey; |
| 523 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 524 | private boolean mAllowTheaterModeWakeFromMotion; |
| 525 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 526 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 527 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 528 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 529 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 530 | // Time to volume and power must be pressed within this interval of each other. |
| 531 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 532 | // Increase the chord delay when taking a screenshot from the keyguard |
| 533 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 534 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 535 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 536 | private long mScreenshotChordVolumeDownKeyTime; |
| 537 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 538 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 539 | private boolean mScreenshotChordPowerKeyTriggered; |
| 540 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 541 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 542 | /* The number of steps between min and max brightness */ |
| 543 | private static final int BRIGHTNESS_STEPS = 10; |
| 544 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 545 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 546 | ShortcutManager mShortcutManager; |
| 547 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 548 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 549 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 550 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 551 | private int mCurrentUserId; |
| 552 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 553 | // Maps global key codes to the components that will handle them. |
| 554 | private GlobalKeyManager mGlobalKeyManager; |
| 555 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 556 | // Fallback actions by key code. |
| 557 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 558 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 559 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 560 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 561 | = new LogDecelerateInterpolator(100, 0); |
| 562 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 563 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 564 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 565 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 566 | 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] | 567 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 568 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 569 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 570 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 571 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 572 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 573 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 574 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 575 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 576 | |
| 577 | private class PolicyHandler extends Handler { |
| 578 | @Override |
| 579 | public void handleMessage(Message msg) { |
| 580 | switch (msg.what) { |
| 581 | case MSG_ENABLE_POINTER_LOCATION: |
| 582 | enablePointerLocation(); |
| 583 | break; |
| 584 | case MSG_DISABLE_POINTER_LOCATION: |
| 585 | disablePointerLocation(); |
| 586 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 587 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 588 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 589 | break; |
| 590 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 591 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 592 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 593 | case MSG_DISPATCH_SHOW_RECENTS: |
| 594 | showRecentApps(false); |
| 595 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 596 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 597 | showGlobalActionsInternal(); |
| 598 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 599 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 600 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 601 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 602 | break; |
| 603 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 604 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 605 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 606 | break; |
| 607 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 608 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 609 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 610 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 611 | case MSG_HIDE_BOOT_MESSAGE: |
| 612 | handleHideBootMessage(); |
| 613 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 614 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 615 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 616 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 617 | case MSG_POWER_DELAYED_PRESS: |
| 618 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 619 | finishPowerKeyPress(); |
| 620 | break; |
| 621 | case MSG_POWER_LONG_PRESS: |
| 622 | powerLongPress(); |
| 623 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 628 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 629 | @Override |
| 630 | public void onUEvent(UEventObserver.UEvent event) { |
| 631 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 632 | } |
| 633 | }; |
| 634 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 635 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 636 | SettingsObserver(Handler handler) { |
| 637 | super(handler); |
| 638 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 639 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 640 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 641 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 642 | ContentResolver resolver = mContext.getContentResolver(); |
| 643 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 644 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 645 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 646 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 647 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 648 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 649 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 650 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 651 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 652 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 653 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 654 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 655 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 656 | Settings.System.USER_ROTATION), false, this, |
| 657 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 658 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 659 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 660 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 661 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 662 | Settings.System.POINTER_LOCATION), false, this, |
| 663 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 664 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 665 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 666 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 667 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 668 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 669 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 670 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 671 | Settings.Global.POLICY_CONTROL), false, this, |
| 672 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 673 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 677 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 678 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 679 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 680 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 681 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 682 | class MyWakeGestureListener extends WakeGestureListener { |
| 683 | MyWakeGestureListener(Context context, Handler handler) { |
| 684 | super(context, handler); |
| 685 | } |
| 686 | |
| 687 | @Override |
| 688 | public void onWakeUp() { |
| 689 | synchronized (mLock) { |
| 690 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 691 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 692 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 698 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 699 | MyOrientationListener(Context context, Handler handler) { |
| 700 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 701 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 702 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 703 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 704 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 705 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 706 | updateRotation(false); |
| 707 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 708 | } |
| 709 | MyOrientationListener mOrientationListener; |
| 710 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 711 | private final BarController mStatusBarController = new BarController("StatusBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 712 | View.STATUS_BAR_TRANSIENT, |
| 713 | View.STATUS_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 714 | View.STATUS_BAR_TRANSLUCENT, |
| 715 | StatusBarManager.WINDOW_STATUS_BAR, |
| 716 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 717 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 718 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 719 | View.NAVIGATION_BAR_TRANSIENT, |
| 720 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 721 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 722 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 723 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 724 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 725 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 726 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 727 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 728 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 729 | IStatusBarService getStatusBarService() { |
| 730 | synchronized (mServiceAquireLock) { |
| 731 | if (mStatusBarService == null) { |
| 732 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 733 | ServiceManager.getService("statusbar")); |
| 734 | } |
| 735 | return mStatusBarService; |
| 736 | } |
| 737 | } |
| 738 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 739 | /* |
| 740 | * We always let the sensor be switched on by default except when |
| 741 | * the user has explicitly disabled sensor based rotation or when the |
| 742 | * screen is switched off. |
| 743 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 744 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 745 | if (mSupportAutoRotation) { |
| 746 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 747 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 748 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 749 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 750 | // If the application has explicitly requested to follow the |
| 751 | // orientation, then we need to turn the sensor on. |
| 752 | return true; |
| 753 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 754 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 755 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 756 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 757 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 758 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 759 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 760 | // orientation management, |
| 761 | return true; |
| 762 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 763 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 764 | // If the setting for using the sensor by default is enabled, then |
| 765 | // we will always leave it on. Note that the user could go to |
| 766 | // a window that forces an orientation that does not use the |
| 767 | // sensor and in theory we could turn it off... however, when next |
| 768 | // turning it on we won't have a good value for the current |
| 769 | // orientation for a little bit, which can cause orientation |
| 770 | // changes to lag, so we'd like to keep it always on. (It will |
| 771 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 772 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 773 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 774 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 775 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 776 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 777 | /* |
| 778 | * Various use cases for invoking this function |
| 779 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 780 | * 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] | 781 | * if not already enabled |
| 782 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 783 | * already enabled |
| 784 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 785 | * screen turning on and current app has nosensor based orientation, do nothing |
| 786 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 787 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 788 | if (!mOrientationListener.canDetectOrientation()) { |
| 789 | // If sensor is turned off or nonexistent for some reason |
| 790 | return; |
| 791 | } |
| 792 | //Could have been invoked due to screen turning on or off or |
| 793 | //change of the currently visible window's orientation |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 794 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 795 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
| 796 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 797 | boolean disable = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 798 | if (mScreenOnEarly && mAwake) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 799 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 800 | disable = false; |
| 801 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 802 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 803 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 804 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 805 | mOrientationSensorEnabled = true; |
| 806 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 809 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 810 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 811 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 812 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 813 | mOrientationSensorEnabled = false; |
| 814 | } |
| 815 | } |
| 816 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 817 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 818 | // Hold a wake lock until the power key is released. |
| 819 | if (!mPowerKeyWakeLock.isHeld()) { |
| 820 | mPowerKeyWakeLock.acquire(); |
| 821 | } |
| 822 | |
| 823 | // Cancel multi-press detection timeout. |
| 824 | if (mPowerKeyPressCounter != 0) { |
| 825 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 826 | } |
| 827 | |
| 828 | // Detect user pressing the power button in panic when an application has |
| 829 | // taken over the whole screen. |
| 830 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
| 831 | event.getDownTime(), isImmersiveMode(mLastSystemUiFlags)); |
| 832 | if (panic) { |
| 833 | mHandler.post(mRequestTransientNav); |
| 834 | } |
| 835 | |
| 836 | // Latch power key state to detect screenshot chord. |
| 837 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 838 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 839 | mScreenshotChordPowerKeyTriggered = true; |
| 840 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 841 | interceptScreenshotChord(); |
| 842 | } |
| 843 | |
| 844 | // Stop ringing or end call if configured to do so when power is pressed. |
| 845 | TelecomManager telecomManager = getTelecommService(); |
| 846 | boolean hungUp = false; |
| 847 | if (telecomManager != null) { |
| 848 | if (telecomManager.isRinging()) { |
| 849 | // Pressing Power while there's a ringing incoming |
| 850 | // call should silence the ringer. |
| 851 | telecomManager.silenceRinger(); |
| 852 | } else if ((mIncallPowerBehavior |
| 853 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 854 | && telecomManager.isInCall() && interactive) { |
| 855 | // Otherwise, if "Power button ends call" is enabled, |
| 856 | // the Power button will hang up any current active call. |
| 857 | hungUp = telecomManager.endCall(); |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | // If the power key has still not yet been handled, then detect short |
| 862 | // press, long press, or multi press and decide what to do. |
| 863 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
| 864 | || mScreenshotChordVolumeUpKeyTriggered; |
| 865 | if (!mPowerKeyHandled) { |
| 866 | if (interactive) { |
| 867 | // When interactive, we're already awake. |
| 868 | // Wait for a long press or for the button to be released to decide what to do. |
| 869 | if (hasLongPressOnPowerBehavior()) { |
| 870 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 871 | msg.setAsynchronous(true); |
| 872 | mHandler.sendMessageDelayed(msg, |
| 873 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 874 | } |
| 875 | } else { |
| 876 | // When non-interactive, we ordinarily wake up immediately and |
| 877 | // consume the key. However on some devices we need to support multi-press |
| 878 | // without waking so we will delay handling for later in that case |
| 879 | // (at the cost of increased latency). |
| 880 | final int maxCount = getMaxMultiPressPowerCount(); |
| 881 | if (maxCount <= 1) { |
| 882 | // No other actions. We can wake immediately. |
| 883 | wakeUpFromPowerKey(event.getDownTime()); |
| 884 | mPowerKeyHandled = true; |
| 885 | } |
| 886 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 890 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 891 | final boolean handled = canceled || mPowerKeyHandled; |
| 892 | mScreenshotChordPowerKeyTriggered = false; |
| 893 | cancelPendingScreenshotChordAction(); |
| 894 | cancelPendingPowerKeyAction(); |
| 895 | |
| 896 | if (!handled) { |
| 897 | // Figure out how to handle the key now that it has been released. |
| 898 | mPowerKeyPressCounter += 1; |
| 899 | |
| 900 | final int maxCount = getMaxMultiPressPowerCount(); |
| 901 | final long eventTime = event.getDownTime(); |
| 902 | if (mPowerKeyPressCounter < maxCount) { |
| 903 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 904 | // Continue holding the wake lock. |
| 905 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 906 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 907 | msg.setAsynchronous(true); |
| 908 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 909 | return; |
| 910 | } |
| 911 | |
| 912 | // No other actions. Handle it immediately. |
| 913 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 914 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 915 | |
| 916 | // Done. Reset our state. |
| 917 | finishPowerKeyPress(); |
| 918 | } |
| 919 | |
| 920 | private void finishPowerKeyPress() { |
| 921 | mPowerKeyPressCounter = 0; |
| 922 | if (mPowerKeyWakeLock.isHeld()) { |
| 923 | mPowerKeyWakeLock.release(); |
| 924 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | private void cancelPendingPowerKeyAction() { |
| 928 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 929 | mPowerKeyHandled = true; |
| 930 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 931 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 935 | if (mScreenOnEarly && !mScreenOnFully) { |
| 936 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 937 | + "already in the process of turning the screen on."); |
| 938 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 939 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 940 | |
| 941 | if (count == 2) { |
| 942 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 943 | } else if (count == 3) { |
| 944 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
| 945 | } else if (!interactive) { |
| 946 | wakeUpFromPowerKey(eventTime); |
| 947 | } else { |
| 948 | switch (mShortPressOnPowerBehavior) { |
| 949 | case SHORT_PRESS_POWER_NOTHING: |
| 950 | break; |
| 951 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 952 | mPowerManager.goToSleep(eventTime, |
| 953 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 954 | break; |
| 955 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 956 | mPowerManager.goToSleep(eventTime, |
| 957 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 958 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 959 | break; |
| 960 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 961 | mPowerManager.goToSleep(eventTime, |
| 962 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 963 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 964 | launchHomeFromHotKey(); |
| 965 | break; |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 971 | switch (behavior) { |
| 972 | case MULTI_PRESS_POWER_NOTHING: |
| 973 | break; |
| 974 | case MULTI_PRESS_POWER_THEATER_MODE: |
| 975 | if (isTheaterModeEnabled()) { |
| 976 | Slog.i(TAG, "Toggling theater mode off."); |
| 977 | Settings.Global.putInt(mContext.getContentResolver(), |
| 978 | Settings.Global.THEATER_MODE_ON, 0); |
| 979 | if (!interactive) { |
| 980 | wakeUpFromPowerKey(eventTime); |
| 981 | } |
| 982 | } else { |
| 983 | Slog.i(TAG, "Toggling theater mode on."); |
| 984 | Settings.Global.putInt(mContext.getContentResolver(), |
| 985 | Settings.Global.THEATER_MODE_ON, 1); |
| 986 | if (interactive) { |
| 987 | mPowerManager.goToSleep(eventTime, |
| 988 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 989 | } |
| 990 | } |
| 991 | break; |
| 992 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
| 993 | mPowerManager.boostScreenBrightness(eventTime); |
| 994 | break; |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | private int getMaxMultiPressPowerCount() { |
| 999 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1000 | return 3; |
| 1001 | } |
| 1002 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1003 | return 2; |
| 1004 | } |
| 1005 | return 1; |
| 1006 | } |
| 1007 | |
| 1008 | private void powerLongPress() { |
| 1009 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1010 | switch (behavior) { |
| 1011 | case LONG_PRESS_POWER_NOTHING: |
| 1012 | break; |
| 1013 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1014 | mPowerKeyHandled = true; |
| 1015 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1016 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1017 | } |
| 1018 | showGlobalActionsInternal(); |
| 1019 | break; |
| 1020 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1021 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1022 | mPowerKeyHandled = true; |
| 1023 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1024 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1025 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1026 | break; |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | private int getResolvedLongPressOnPowerBehavior() { |
| 1031 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1032 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1033 | } |
| 1034 | return mLongPressOnPowerBehavior; |
| 1035 | } |
| 1036 | |
| 1037 | private boolean hasLongPressOnPowerBehavior() { |
| 1038 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1042 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1043 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1044 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1045 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1046 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1047 | && now <= mScreenshotChordPowerKeyTime |
| 1048 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1049 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1050 | cancelPendingPowerKeyAction(); |
| 1051 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1052 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1057 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1058 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1059 | // Double the time it takes to take a screenshot from the keyguard |
| 1060 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1061 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1062 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1063 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1066 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1067 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1070 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1071 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1072 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1073 | mEndCallKeyHandled = true; |
| 1074 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1075 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1076 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1077 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1078 | } |
| 1079 | }; |
| 1080 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1081 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1082 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1083 | public void run() { |
| 1084 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1085 | } |
| 1086 | }; |
| 1087 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1088 | @Override |
| 1089 | public void showGlobalActions() { |
| 1090 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1091 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1092 | } |
| 1093 | |
| 1094 | void showGlobalActionsInternal() { |
| 1095 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1096 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1097 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1098 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 1099 | final boolean keyguardShowing = keyguardIsShowingTq(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1100 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1101 | if (keyguardShowing) { |
| 1102 | // since it took two seconds of long press to bring this up, |
| 1103 | // 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] | 1104 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1109 | return Settings.Global.getInt( |
| 1110 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1113 | boolean isUserSetupComplete() { |
| 1114 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1115 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1116 | } |
| 1117 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1118 | private void handleShortPressOnHome() { |
| 1119 | // If there's a dream running then use home to escape the dream |
| 1120 | // but don't actually go home. |
| 1121 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1122 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1123 | return; |
| 1124 | } |
| 1125 | |
| 1126 | // Go home! |
| 1127 | launchHomeFromHotKey(); |
| 1128 | } |
| 1129 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1130 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1131 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1132 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1133 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1134 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1135 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 1136 | toggleRecentApps(); |
| 1137 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 1138 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1139 | } |
| 1140 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1141 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1142 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1143 | private void handleDoubleTapOnHome() { |
| 1144 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1145 | mHomeConsumed = true; |
| 1146 | toggleRecentApps(); |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1151 | @Override |
| 1152 | public void run() { |
| 1153 | if (mHomeDoubleTapPending) { |
| 1154 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1155 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1156 | } |
| 1157 | } |
| 1158 | }; |
| 1159 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1160 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1161 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1162 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1163 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1164 | mContext = context; |
| 1165 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1166 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1167 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1168 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1169 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1170 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1171 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1172 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1173 | try { |
| 1174 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1175 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1176 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1177 | mSettingsObserver.observe(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1178 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 1179 | mShortcutManager.observe(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1180 | mUiMode = context.getResources().getInteger( |
| 1181 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1182 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1183 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1184 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1185 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1186 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1187 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1188 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1189 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1190 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1191 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1192 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1193 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1194 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1195 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1196 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1197 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1198 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1199 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1200 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1201 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1202 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1203 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1204 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1205 | mCarDockRotation = readRotation( |
| 1206 | com.android.internal.R.integer.config_carDockRotation); |
| 1207 | mDeskDockRotation = readRotation( |
| 1208 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1209 | mUndockedHdmiRotation = readRotation( |
| 1210 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1211 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1212 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1213 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1214 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1215 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1216 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1217 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1218 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1219 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1220 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1221 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1222 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1223 | |
| 1224 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1225 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1226 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1227 | || mContext.getResources().getBoolean( |
| 1228 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1229 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1230 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
| 1231 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1232 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1233 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1234 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1235 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1236 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1237 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1238 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1239 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1240 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1241 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1242 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1243 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1244 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1245 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
| 1246 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1247 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1248 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1249 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1250 | Context.ACCESSIBILITY_SERVICE); |
| 1251 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1252 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1253 | IntentFilter filter = new IntentFilter(); |
| 1254 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1255 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1256 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1257 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1258 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1259 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1260 | if (intent != null) { |
| 1261 | // Retrieve current sticky dock event broadcast. |
| 1262 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1263 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1264 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1265 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1266 | // register for dream-related broadcasts |
| 1267 | filter = new IntentFilter(); |
| 1268 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1269 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1270 | context.registerReceiver(mDreamReceiver, filter); |
| 1271 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1272 | // register for multiuser-relevant broadcasts |
| 1273 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1274 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1275 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1276 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1277 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1278 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1279 | @Override |
| 1280 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1281 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1282 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1283 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1284 | } |
| 1285 | @Override |
| 1286 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1287 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1288 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | @Override |
| 1292 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1293 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1294 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | @Override |
| 1298 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1299 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1300 | } |
| 1301 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1302 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1303 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1304 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1305 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1306 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1307 | com.android.internal.R.array.config_longPressVibePattern); |
| 1308 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1309 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1310 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1311 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1312 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1313 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1314 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1315 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1316 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1317 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1318 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1319 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1320 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1321 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1322 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1323 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1324 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1325 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1326 | // Controls rotation and the like. |
| 1327 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1328 | |
| 1329 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1330 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 1331 | goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1332 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1335 | /** |
| 1336 | * Read values from config.xml that may be overridden depending on |
| 1337 | * the configuration of the device. |
| 1338 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1339 | */ |
| 1340 | private void readConfigurationDependentBehaviors() { |
| 1341 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1342 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1343 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1344 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1345 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1346 | } |
| 1347 | |
| 1348 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1349 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1350 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1351 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1352 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1353 | } |
| 1354 | } |
| 1355 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1356 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1357 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1358 | // This method might be called before the policy has been fully initialized |
| 1359 | // or for other displays we don't care about. |
| 1360 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1361 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1362 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1363 | mDisplay = display; |
| 1364 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1365 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1366 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1367 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1368 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1369 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1370 | mLandscapeRotation = Surface.ROTATION_0; |
| 1371 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1372 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1373 | mPortraitRotation = Surface.ROTATION_90; |
| 1374 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1375 | } else { |
| 1376 | mPortraitRotation = Surface.ROTATION_270; |
| 1377 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1378 | } |
| 1379 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1380 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1381 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1382 | mPortraitRotation = Surface.ROTATION_0; |
| 1383 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1384 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1385 | mLandscapeRotation = Surface.ROTATION_270; |
| 1386 | mSeascapeRotation = Surface.ROTATION_90; |
| 1387 | } else { |
| 1388 | mLandscapeRotation = Surface.ROTATION_90; |
| 1389 | mSeascapeRotation = Surface.ROTATION_270; |
| 1390 | } |
| 1391 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1392 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1393 | mStatusBarHeight = |
| 1394 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1395 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1396 | // Height of the navigation bar when presented horizontally at bottom |
| 1397 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1398 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1399 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1400 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1401 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1402 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1403 | |
| 1404 | // Width of the navigation bar when presented vertically along one side |
| 1405 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1406 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1407 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1408 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1409 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1410 | |
| 1411 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1412 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1413 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1414 | |
Craig Mautner | d4ec3324 | 2013-07-22 10:37:43 -0700 | [diff] [blame] | 1415 | // Allow the navigation bar to move on small devices (phones). |
| 1416 | mNavigationBarCanMove = shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1417 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1418 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1419 | // Allow a system property to override this. Used by the emulator. |
| 1420 | // See also hasNavigationBar(). |
| 1421 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1422 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1423 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1424 | } else if ("0".equals(navBarOverride)) { |
| 1425 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1426 | } |
| 1427 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1428 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1429 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1430 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1431 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1432 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1433 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1434 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1435 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1436 | |
| 1437 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1438 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1439 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1440 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1441 | // For debug purposes the next line turns this feature off with: |
| 1442 | // $ adb shell setprop config.override_forced_orient true |
| 1443 | // $ adb shell wm size reset |
| 1444 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1445 | } |
| 1446 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1447 | /** |
| 1448 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1449 | * navigation bar and touch exploration is not enabled |
| 1450 | */ |
| 1451 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1452 | return mHasNavigationBar |
| 1453 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1456 | @Override |
| 1457 | public boolean isDefaultOrientationForced() { |
| 1458 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1461 | @Override |
| 1462 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1463 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1464 | mOverscanLeft = left; |
| 1465 | mOverscanTop = top; |
| 1466 | mOverscanRight = right; |
| 1467 | mOverscanBottom = bottom; |
| 1468 | } |
| 1469 | } |
| 1470 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1471 | public void updateSettings() { |
| 1472 | ContentResolver resolver = mContext.getContentResolver(); |
| 1473 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1474 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1475 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1476 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1477 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1478 | UserHandle.USER_CURRENT); |
| 1479 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1480 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1481 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1482 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1483 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1484 | // Configure wake gesture. |
| 1485 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1486 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1487 | UserHandle.USER_CURRENT) != 0; |
| 1488 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1489 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1490 | updateWakeGestureListenerLp(); |
| 1491 | } |
| 1492 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1493 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1494 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1495 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1496 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1497 | if (mUserRotation != userRotation) { |
| 1498 | mUserRotation = userRotation; |
| 1499 | updateRotation = true; |
| 1500 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1501 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1502 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1503 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1504 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1505 | if (mUserRotationMode != userRotationMode) { |
| 1506 | mUserRotationMode = userRotationMode; |
| 1507 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1508 | updateOrientationListenerLp(); |
| 1509 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1510 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1511 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1512 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1513 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1514 | if (mPointerLocationMode != pointerLocation) { |
| 1515 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1516 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1517 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1518 | } |
| 1519 | } |
| 1520 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1521 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1522 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1523 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1524 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1525 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1526 | if (mHasSoftInput != hasSoftInput) { |
| 1527 | mHasSoftInput = hasSoftInput; |
| 1528 | updateRotation = true; |
| 1529 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1530 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1531 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1532 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1533 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1534 | } |
| 1535 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1536 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1537 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1540 | private void updateWakeGestureListenerLp() { |
| 1541 | if (shouldEnableWakeGestureLp()) { |
| 1542 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1543 | } else { |
| 1544 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1549 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1550 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1551 | && mWakeGestureListener.isSupported(); |
| 1552 | } |
| 1553 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1554 | private void enablePointerLocation() { |
| 1555 | if (mPointerLocationView == null) { |
| 1556 | mPointerLocationView = new PointerLocationView(mContext); |
| 1557 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1558 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1559 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1560 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1561 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1562 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1563 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1564 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1565 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1566 | if (ActivityManager.isHighEndGfx()) { |
| 1567 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1568 | lp.privateFlags |= |
| 1569 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1570 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1571 | lp.format = PixelFormat.TRANSLUCENT; |
| 1572 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1573 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1574 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1575 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1576 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1577 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1578 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1579 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1580 | |
| 1581 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1582 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1583 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1584 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1585 | wm.removeView(mPointerLocationView); |
| 1586 | mPointerLocationView = null; |
| 1587 | } |
| 1588 | } |
| 1589 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1590 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1591 | try { |
| 1592 | int rotation = mContext.getResources().getInteger(resID); |
| 1593 | switch (rotation) { |
| 1594 | case 0: |
| 1595 | return Surface.ROTATION_0; |
| 1596 | case 90: |
| 1597 | return Surface.ROTATION_90; |
| 1598 | case 180: |
| 1599 | return Surface.ROTATION_180; |
| 1600 | case 270: |
| 1601 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1602 | } |
| 1603 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1604 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1605 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1606 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1610 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1611 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1612 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1613 | |
| 1614 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1615 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1616 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 1617 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1618 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1619 | } |
| 1620 | String permission = null; |
| 1621 | switch (type) { |
| 1622 | case TYPE_TOAST: |
| 1623 | // XXX right now the app process has complete control over |
| 1624 | // this... should introduce a token to let the system |
| 1625 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1626 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1627 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1628 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1629 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1630 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1631 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1632 | case TYPE_VOICE_INTERACTION: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1633 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1634 | break; |
| 1635 | case TYPE_PHONE: |
| 1636 | case TYPE_PRIORITY_PHONE: |
| 1637 | case TYPE_SYSTEM_ALERT: |
| 1638 | case TYPE_SYSTEM_ERROR: |
| 1639 | case TYPE_SYSTEM_OVERLAY: |
| 1640 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1641 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1642 | break; |
| 1643 | default: |
| 1644 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1645 | } |
| 1646 | if (permission != null) { |
| 1647 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1648 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1649 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1650 | } |
| 1651 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1652 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1653 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1654 | |
| 1655 | @Override |
| 1656 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1657 | |
| 1658 | // If this switch statement is modified, modify the comment in the declarations of |
| 1659 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1660 | switch (attrs.type) { |
| 1661 | default: |
| 1662 | // These are the windows that by default are shown only to the user that created |
| 1663 | // them. If this needs to be overridden, set |
| 1664 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1665 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1666 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1667 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1668 | return true; |
| 1669 | } |
| 1670 | break; |
| 1671 | |
| 1672 | // These are the windows that by default are shown to all users. However, to |
| 1673 | // protect against spoofing, check permissions below. |
| 1674 | case TYPE_APPLICATION_STARTING: |
| 1675 | case TYPE_BOOT_PROGRESS: |
| 1676 | case TYPE_DISPLAY_OVERLAY: |
| 1677 | case TYPE_HIDDEN_NAV_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1678 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1679 | case TYPE_KEYGUARD_DIALOG: |
| 1680 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1681 | case TYPE_NAVIGATION_BAR: |
| 1682 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1683 | case TYPE_PHONE: |
| 1684 | case TYPE_POINTER: |
| 1685 | case TYPE_PRIORITY_PHONE: |
| 1686 | case TYPE_RECENTS_OVERLAY: |
| 1687 | case TYPE_SEARCH_BAR: |
| 1688 | case TYPE_STATUS_BAR: |
| 1689 | case TYPE_STATUS_BAR_PANEL: |
| 1690 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1691 | case TYPE_SYSTEM_DIALOG: |
| 1692 | case TYPE_UNIVERSE_BACKGROUND: |
| 1693 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1694 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1695 | break; |
| 1696 | } |
| 1697 | |
| 1698 | // Check if third party app has set window to system window type. |
| 1699 | return mContext.checkCallingOrSelfPermission( |
| 1700 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1701 | != PackageManager.PERMISSION_GRANTED; |
| 1702 | } |
| 1703 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1704 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1705 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1706 | switch (attrs.type) { |
| 1707 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1708 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1709 | // These types of windows can't receive input events. |
| 1710 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1711 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1712 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1713 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1714 | case TYPE_STATUS_BAR: |
| 1715 | |
| 1716 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 1717 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 1718 | // the keyguard as occluded wouldn't set these flags again. |
| 1719 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 1720 | if (mKeyguardHidden) { |
| 1721 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 1722 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1723 | } |
| 1724 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1725 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 1726 | |
| 1727 | if (attrs.type != TYPE_STATUS_BAR) { |
| 1728 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 1729 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1730 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1731 | |
| 1732 | if (ActivityManager.isHighEndGfx() |
| 1733 | && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
Adrian Roos | f5e9b5c | 2014-09-10 15:27:41 +0200 | [diff] [blame] | 1734 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1735 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1736 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1737 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1738 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1739 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1740 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1741 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1742 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 1743 | private void readCameraLensCoverState() { |
| 1744 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 1745 | } |
| 1746 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1747 | private boolean isHidden(int accessibilityMode) { |
| 1748 | switch (accessibilityMode) { |
| 1749 | case 1: |
| 1750 | return mLidState == LID_CLOSED; |
| 1751 | case 2: |
| 1752 | return mLidState == LID_OPEN; |
| 1753 | default: |
| 1754 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1755 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1756 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1757 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1758 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1759 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1760 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1761 | int navigationPresence) { |
| 1762 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1763 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1764 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1765 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1766 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1767 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1768 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1769 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1770 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1771 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1772 | if (!mHasSoftInput) { |
| 1773 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1774 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1775 | } |
| 1776 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1777 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1778 | || (navigationPresence == PRESENCE_INTERNAL |
| 1779 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1780 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1781 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1782 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1783 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1784 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1785 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1786 | public int windowTypeToLayerLw(int type) { |
| 1787 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1788 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1789 | } |
| 1790 | switch (type) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1791 | case TYPE_UNIVERSE_BACKGROUND: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1792 | return 1; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1793 | case TYPE_PRIVATE_PRESENTATION: |
| 1794 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1795 | case TYPE_WALLPAPER: |
| 1796 | // wallpaper is at the bottom, though the window manager may move it. |
| 1797 | return 2; |
| 1798 | case TYPE_PHONE: |
| 1799 | return 3; |
| 1800 | case TYPE_SEARCH_BAR: |
| 1801 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1802 | case TYPE_VOICE_INTERACTION: |
| 1803 | // voice interaction layer is almost immediately above apps. |
| 1804 | return 5; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1805 | case TYPE_RECENTS_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1806 | case TYPE_SYSTEM_DIALOG: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1807 | return 6; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1808 | case TYPE_TOAST: |
| 1809 | // toasts and the plugged-in battery thing |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1810 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1811 | case TYPE_PRIORITY_PHONE: |
| 1812 | // 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] | 1813 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1814 | case TYPE_DREAM: |
| 1815 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1816 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1817 | case TYPE_SYSTEM_ALERT: |
| 1818 | // like the ANR / app crashed dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1819 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1820 | case TYPE_INPUT_METHOD: |
| 1821 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1822 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1823 | case TYPE_INPUT_METHOD_DIALOG: |
| 1824 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1825 | return 12; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1826 | case TYPE_KEYGUARD_SCRIM: |
| 1827 | // the safety window that shows behind keyguard while keyguard is starting |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1828 | return 13; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1829 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1830 | return 14; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1831 | case TYPE_STATUS_BAR: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1832 | return 15; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1833 | case TYPE_STATUS_BAR_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1834 | return 16; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1835 | case TYPE_KEYGUARD_DIALOG: |
| 1836 | return 17; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1837 | case TYPE_VOLUME_OVERLAY: |
| 1838 | // the on-screen volume indicator and controller shown when the user |
| 1839 | // changes the device volume |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1840 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1841 | case TYPE_SYSTEM_OVERLAY: |
| 1842 | // the on-screen volume indicator and controller shown when the user |
| 1843 | // changes the device volume |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1844 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1845 | case TYPE_NAVIGATION_BAR: |
| 1846 | // the navigation bar, if available, shows atop most things |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1847 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1848 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1849 | // 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] | 1850 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1851 | case TYPE_SYSTEM_ERROR: |
| 1852 | // system-level error dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1853 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1854 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1855 | // used to highlight the magnified portion of a display |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1856 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1857 | case TYPE_DISPLAY_OVERLAY: |
| 1858 | // used to simulate secondary display devices |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1859 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1860 | case TYPE_DRAG: |
| 1861 | // the drag layer: input for drag-and-drop is associated with this window, |
| 1862 | // which sits above all other focusable windows |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1863 | return 25; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1864 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1865 | return 26; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1866 | case TYPE_BOOT_PROGRESS: |
| 1867 | return 27; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1868 | case TYPE_POINTER: |
| 1869 | // the (mouse) pointer layer |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1870 | return 28; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1871 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1872 | return 29; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1873 | } |
| 1874 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1875 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1879 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1880 | public int subWindowTypeToLayerLw(int type) { |
| 1881 | switch (type) { |
| 1882 | case TYPE_APPLICATION_PANEL: |
| 1883 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 1884 | return APPLICATION_PANEL_SUBLAYER; |
| 1885 | case TYPE_APPLICATION_MEDIA: |
| 1886 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 1887 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 1888 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1889 | case TYPE_APPLICATION_SUB_PANEL: |
| 1890 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 1891 | } |
| 1892 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 1893 | return 0; |
| 1894 | } |
| 1895 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1896 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1897 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1898 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1901 | @Override |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1902 | public int getAboveUniverseLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1903 | return windowTypeToLayerLw(TYPE_SYSTEM_ERROR); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1906 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1907 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1908 | if (mHasNavigationBar) { |
| 1909 | // For a basic navigation bar, when we are in landscape mode we place |
| 1910 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1911 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 1912 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1913 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1914 | } |
| 1915 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1916 | } |
| 1917 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1918 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1919 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1920 | if (mHasNavigationBar) { |
| 1921 | // For a basic navigation bar, when we are in portrait mode we place |
| 1922 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1923 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 1924 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1930 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1931 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 1932 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1935 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1936 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1937 | // There is a separate status bar at the top of the display. We don't count that as part |
| 1938 | // 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] | 1939 | // we do want to exclude it since applications can't generally use that part |
| 1940 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1941 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1942 | } |
| 1943 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1944 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 1945 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 1946 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 1947 | (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) || |
| 1948 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1949 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1950 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1951 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 1952 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 1953 | return attrs.type == TYPE_STATUS_BAR; |
| 1954 | } |
| 1955 | |
| 1956 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1957 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1958 | switch (attrs.type) { |
| 1959 | case TYPE_STATUS_BAR: |
| 1960 | case TYPE_NAVIGATION_BAR: |
| 1961 | case TYPE_WALLPAPER: |
| 1962 | case TYPE_DREAM: |
| 1963 | case TYPE_UNIVERSE_BACKGROUND: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1964 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1965 | return false; |
| 1966 | default: |
| 1967 | return true; |
| 1968 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1969 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1970 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 1971 | @Override |
| 1972 | public WindowState getWinShowWhenLockedLw() { |
| 1973 | return mWinShowWhenLocked; |
| 1974 | } |
| 1975 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1976 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1977 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1978 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 1979 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1980 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1981 | if (!SHOW_STARTING_ANIMATIONS) { |
| 1982 | return null; |
| 1983 | } |
| 1984 | if (packageName == null) { |
| 1985 | return null; |
| 1986 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1987 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1988 | WindowManager wm = null; |
| 1989 | View view = null; |
| 1990 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1991 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1992 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1993 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 1994 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 1995 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1996 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1997 | try { |
| 1998 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1999 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2000 | } catch (PackageManager.NameNotFoundException e) { |
| 2001 | // Ignore |
| 2002 | } |
| 2003 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2004 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2005 | Window win = PolicyManager.makeNewWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2006 | final TypedArray ta = win.getWindowStyle(); |
| 2007 | if (ta.getBoolean( |
| 2008 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 2009 | || ta.getBoolean( |
| 2010 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2011 | return null; |
| 2012 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2013 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2014 | Resources r = context.getResources(); |
| 2015 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2016 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2017 | win.setType( |
| 2018 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 2019 | // Force the window flags: this is a fake window, so it is not really |
| 2020 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2021 | // flag because we do know that the next window will take input |
| 2022 | // focus, so we want to get the IME window up on top of us right away. |
| 2023 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2024 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2025 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2026 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2027 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2028 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2029 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2030 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2031 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2032 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2033 | win.setDefaultIcon(icon); |
| 2034 | win.setDefaultLogo(logo); |
| 2035 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2036 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2037 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2038 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2039 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2040 | params.token = appToken; |
| 2041 | params.packageName = packageName; |
| 2042 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2043 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2044 | params.privateFlags |= |
| 2045 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2046 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2047 | |
| 2048 | if (!compatInfo.supportsScreen()) { |
| 2049 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2050 | } |
| 2051 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2052 | params.setTitle("Starting " + packageName); |
| 2053 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2054 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2055 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2056 | |
| 2057 | if (win.isFloating()) { |
| 2058 | // Whoops, there is no way to display an animation/preview |
| 2059 | // of such a thing! After all that work... let's skip it. |
| 2060 | // (Note that we must do this here because it is in |
| 2061 | // getDecorView() where the theme is evaluated... maybe |
| 2062 | // we should peek the floating attribute from the theme |
| 2063 | // earlier.) |
| 2064 | return null; |
| 2065 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2066 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2067 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2068 | TAG, "Adding starting window for " + packageName |
| 2069 | + " / " + appToken + ": " |
| 2070 | + (view.getParent() != null ? view : null)); |
| 2071 | |
| 2072 | wm.addView(view, params); |
| 2073 | |
| 2074 | // Only return the view if it was successfully added to the |
| 2075 | // window manager... which we can tell by it having a parent. |
| 2076 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2077 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2078 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2079 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2080 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2081 | } catch (RuntimeException e) { |
| 2082 | // don't crash if something else bad happens, for example a |
| 2083 | // failure loading resources because we are loading from an app |
| 2084 | // on external storage that has been unmounted. |
| 2085 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2086 | } finally { |
| 2087 | if (view != null && view.getParent() == null) { |
| 2088 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2089 | wm.removeViewImmediate(view); |
| 2090 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | return null; |
| 2094 | } |
| 2095 | |
| 2096 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2097 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2098 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2099 | if (DEBUG_STARTING_WINDOW) { |
| 2100 | RuntimeException e = new RuntimeException("here"); |
| 2101 | e.fillInStackTrace(); |
| 2102 | Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e); |
| 2103 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2104 | |
| 2105 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2106 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2107 | wm.removeView(window); |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | /** |
| 2112 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2113 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2114 | * Currently enforces that three window types are singletons: |
| 2115 | * <ul> |
| 2116 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2117 | * <li>KEYGUARD_TYPE</li> |
| 2118 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2119 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2120 | * @param win The window to be added |
| 2121 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2122 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2123 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2124 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2125 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2126 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2127 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2128 | switch (attrs.type) { |
| 2129 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2130 | mContext.enforceCallingOrSelfPermission( |
| 2131 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2132 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2133 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2134 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2135 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2136 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2137 | } |
| 2138 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2139 | mStatusBarController.setWindow(win); |
John Spurlock | 8fdfe62 | 2014-05-21 17:10:10 -0400 | [diff] [blame] | 2140 | mKeyguardDelegate.hideScrim(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2141 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2142 | case TYPE_NAVIGATION_BAR: |
| 2143 | mContext.enforceCallingOrSelfPermission( |
| 2144 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2145 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2146 | if (mNavigationBar != null) { |
| 2147 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2148 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2149 | } |
| 2150 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2151 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2152 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2153 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2154 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2155 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2156 | mContext.enforceCallingOrSelfPermission( |
| 2157 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2158 | "PhoneWindowManager"); |
| 2159 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2160 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2161 | mContext.enforceCallingOrSelfPermission( |
| 2162 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2163 | "PhoneWindowManager"); |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2164 | break; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2165 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 2166 | mContext.enforceCallingOrSelfPermission( |
| 2167 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2168 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2169 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2170 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2171 | if (mKeyguardScrim != null) { |
| 2172 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2173 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2174 | mKeyguardScrim = win; |
| 2175 | break; |
| 2176 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2177 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2178 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2182 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2183 | public void removeWindowLw(WindowState win) { |
| 2184 | if (mStatusBar == win) { |
| 2185 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2186 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2187 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2188 | } else if (mKeyguardScrim == win) { |
| 2189 | Log.v(TAG, "Removing keyguard scrim"); |
| 2190 | mKeyguardScrim = null; |
| 2191 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2192 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2193 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2198 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2199 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2200 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2201 | public int selectAnimationLw(WindowState win, int transit) { |
| 2202 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2203 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2204 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2205 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2206 | if (transit == TRANSIT_EXIT |
| 2207 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2208 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2209 | } else if (transit == TRANSIT_ENTER |
| 2210 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2211 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2212 | } |
| 2213 | } else if (win == mNavigationBar) { |
| 2214 | // This can be on either the bottom or the right. |
| 2215 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2216 | if (transit == TRANSIT_EXIT |
| 2217 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2218 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2219 | } else if (transit == TRANSIT_ENTER |
| 2220 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2221 | return R.anim.dock_bottom_enter; |
| 2222 | } |
| 2223 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2224 | if (transit == TRANSIT_EXIT |
| 2225 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2226 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2227 | } else if (transit == TRANSIT_ENTER |
| 2228 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2229 | return R.anim.dock_right_enter; |
| 2230 | } |
| 2231 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2235 | if (win.hasAppShownWindows()) { |
| 2236 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2237 | return com.android.internal.R.anim.app_starting_exit; |
| 2238 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2239 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2240 | && transit == TRANSIT_ENTER) { |
| 2241 | // Special case: we are animating in a dream, while the keyguard |
| 2242 | // is shown. We don't want an animation on the dream, because |
| 2243 | // we need it shown immediately with the keyguard animating away |
| 2244 | // to reveal it. |
| 2245 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | return 0; |
| 2249 | } |
| 2250 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2251 | @Override |
| 2252 | public void selectRotationAnimationLw(int anim[]) { |
| 2253 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2254 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2255 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2256 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2257 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2258 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2259 | case ROTATION_ANIMATION_CROSSFADE: |
| 2260 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2261 | anim[1] = R.anim.rotation_animation_enter; |
| 2262 | break; |
| 2263 | case ROTATION_ANIMATION_JUMPCUT: |
| 2264 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2265 | anim[1] = R.anim.rotation_animation_enter; |
| 2266 | break; |
| 2267 | case ROTATION_ANIMATION_ROTATE: |
| 2268 | default: |
| 2269 | anim[0] = anim[1] = 0; |
| 2270 | break; |
| 2271 | } |
| 2272 | } else { |
| 2273 | anim[0] = anim[1] = 0; |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | @Override |
| 2278 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2279 | boolean forceDefault) { |
| 2280 | switch (exitAnimId) { |
| 2281 | case R.anim.rotation_animation_xfade_exit: |
| 2282 | case R.anim.rotation_animation_jump_exit: |
| 2283 | // These are the only cases that matter. |
| 2284 | if (forceDefault) { |
| 2285 | return false; |
| 2286 | } |
| 2287 | int anim[] = new int[2]; |
| 2288 | selectRotationAnimationLw(anim); |
| 2289 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2290 | default: |
| 2291 | return true; |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2296 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2297 | boolean goingToNotificationShade) { |
| 2298 | if (goingToNotificationShade) { |
| 2299 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
| 2300 | } else if (onWallpaper) { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2301 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 2302 | R.anim.lock_screen_behind_enter_wallpaper); |
| 2303 | AnimationSet set = (AnimationSet) a; |
| 2304 | |
| 2305 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2306 | set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator); |
| 2307 | set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2308 | return set; |
| 2309 | } else { |
| 2310 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 2311 | R.anim.lock_screen_behind_enter); |
| 2312 | AnimationSet set = (AnimationSet) a; |
| 2313 | |
| 2314 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2315 | set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator); |
| 2316 | return set; |
| 2317 | } |
| 2318 | } |
| 2319 | |
| 2320 | |
| 2321 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2322 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2323 | if (goingToNotificationShade) { |
| 2324 | return null; |
| 2325 | } else { |
| 2326 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2327 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2328 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2329 | |
| 2330 | private static void awakenDreams() { |
| 2331 | IDreamManager dreamManager = getDreamManager(); |
| 2332 | if (dreamManager != null) { |
| 2333 | try { |
| 2334 | dreamManager.awaken(); |
| 2335 | } catch (RemoteException e) { |
| 2336 | // fine, stay asleep then |
| 2337 | } |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | static IDreamManager getDreamManager() { |
| 2342 | return IDreamManager.Stub.asInterface( |
| 2343 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2344 | } |
| 2345 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2346 | TelecomManager getTelecommService() { |
| 2347 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2348 | } |
| 2349 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2350 | static IAudioService getAudioService() { |
| 2351 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2352 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2353 | if (audioService == null) { |
| 2354 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2355 | } |
| 2356 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | boolean keyguardOn() { |
| 2360 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 2361 | } |
| 2362 | |
| 2363 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2364 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2365 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2366 | }; |
| 2367 | |
| 2368 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2369 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2370 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2371 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2372 | final int keyCode = event.getKeyCode(); |
| 2373 | final int repeatCount = event.getRepeatCount(); |
| 2374 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2375 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2376 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2377 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2378 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2379 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2380 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2381 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2382 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2383 | } |
| 2384 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2385 | // If we think we might have a volume down & power key chord on the way |
| 2386 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2387 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2388 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2389 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2390 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2391 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2392 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2393 | if (now < timeoutTime) { |
| 2394 | return timeoutTime - now; |
| 2395 | } |
| 2396 | } |
| 2397 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2398 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2399 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2400 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2401 | } |
| 2402 | return -1; |
| 2403 | } |
| 2404 | } |
| 2405 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2406 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2407 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2408 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2409 | mPendingMetaAction = false; |
| 2410 | } |
| 2411 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2412 | // First we always handle the home key here, so applications |
| 2413 | // can never break it, although if keyguard is on, we do let |
| 2414 | // it handle it, because that gives us the correct 5 second |
| 2415 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2416 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2417 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2418 | // If we have released the home key, and didn't do anything else |
| 2419 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2420 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2421 | cancelPreloadRecentApps(); |
| 2422 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2423 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2424 | if (mHomeConsumed) { |
| 2425 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2426 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2427 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2428 | |
| 2429 | if (canceled) { |
| 2430 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2431 | return -1; |
| 2432 | } |
| 2433 | |
| 2434 | // If an incoming call is ringing, HOME is totally disabled. |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 2435 | // (The user is already on the InCallUI at this point, |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2436 | // and his ONLY options are to answer or reject the call.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2437 | TelecomManager telecomManager = getTelecommService(); |
| 2438 | if (telecomManager != null && telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 2439 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2440 | return -1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | // Delay handling home if a double-tap is possible. |
| 2444 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2445 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2446 | mHomeDoubleTapPending = true; |
| 2447 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2448 | ViewConfiguration.getDoubleTapTimeout()); |
| 2449 | return -1; |
| 2450 | } |
| 2451 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2452 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2453 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2454 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2455 | |
| 2456 | // If a system window has focus, then it doesn't make sense |
| 2457 | // right now to interact with applications. |
| 2458 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2459 | if (attrs != null) { |
| 2460 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2461 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2462 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2463 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2464 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2465 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2466 | } |
| 2467 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2468 | for (int i=0; i<typeCount; i++) { |
| 2469 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2470 | // 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] | 2471 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2472 | } |
| 2473 | } |
| 2474 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2475 | |
| 2476 | // Remember that home is pressed and handle special actions. |
| 2477 | if (repeatCount == 0) { |
| 2478 | mHomePressed = true; |
| 2479 | if (mHomeDoubleTapPending) { |
| 2480 | mHomeDoubleTapPending = false; |
| 2481 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2482 | handleDoubleTapOnHome(); |
| 2483 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2484 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2485 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2486 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2487 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2488 | if (!keyguardOn) { |
| 2489 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2490 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2491 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2492 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2493 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2494 | // Hijack modified menu keys for debugging features |
| 2495 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2496 | |
| 2497 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2498 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2499 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2500 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2501 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2502 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2503 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2504 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2505 | Intent service = new Intent(); |
| 2506 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2507 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2508 | boolean shown = Settings.Global.getInt( |
| 2509 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2510 | if (!shown) { |
| 2511 | mContext.startService(service); |
| 2512 | } else { |
| 2513 | mContext.stopService(service); |
| 2514 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2515 | Settings.Global.putInt( |
| 2516 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2517 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2518 | } |
| 2519 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2520 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2521 | if (down) { |
| 2522 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2523 | mSearchKeyShortcutPending = true; |
| 2524 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2525 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2526 | } else { |
| 2527 | mSearchKeyShortcutPending = false; |
| 2528 | if (mConsumeSearchKeyUp) { |
| 2529 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2530 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2531 | } |
| 2532 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2533 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2534 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2535 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2536 | if (down && repeatCount == 0) { |
| 2537 | preloadRecentApps(); |
| 2538 | } else if (!down) { |
| 2539 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2540 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2541 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2542 | return -1; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2543 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2544 | if (down) { |
| 2545 | if (repeatCount == 0) { |
| 2546 | mAssistKeyLongPressed = false; |
| 2547 | } else if (repeatCount == 1) { |
| 2548 | mAssistKeyLongPressed = true; |
| 2549 | if (!keyguardOn) { |
| 2550 | launchAssistLongPressAction(); |
| 2551 | } |
| 2552 | } |
| 2553 | } else { |
| 2554 | if (mAssistKeyLongPressed) { |
| 2555 | mAssistKeyLongPressed = false; |
| 2556 | } else { |
| 2557 | if (!keyguardOn) { |
| 2558 | launchAssistAction(); |
| 2559 | } |
| 2560 | } |
| 2561 | } |
| 2562 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2563 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2564 | if (!down) { |
| 2565 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2566 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2567 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2568 | } else { |
| 2569 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2570 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2571 | } |
| 2572 | mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
| 2573 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2574 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2575 | if (down && repeatCount == 0) { |
| 2576 | mHandler.post(mScreenshotRunnable); |
| 2577 | } |
| 2578 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2579 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2580 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2581 | if (down) { |
| 2582 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2583 | |
| 2584 | // Disable autobrightness if it's on |
| 2585 | int auto = Settings.System.getIntForUser( |
| 2586 | mContext.getContentResolver(), |
| 2587 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2588 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2589 | UserHandle.USER_CURRENT_OR_SELF); |
| 2590 | if (auto != 0) { |
| 2591 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2592 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2593 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2594 | UserHandle.USER_CURRENT_OR_SELF); |
| 2595 | } |
| 2596 | |
| 2597 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2598 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2599 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2600 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2601 | Settings.System.SCREEN_BRIGHTNESS, |
| 2602 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2603 | UserHandle.USER_CURRENT_OR_SELF); |
| 2604 | brightness += step; |
| 2605 | // Make sure we don't go beyond the limits. |
| 2606 | brightness = Math.min(max, brightness); |
| 2607 | brightness = Math.max(min, brightness); |
| 2608 | |
| 2609 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2610 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2611 | UserHandle.USER_CURRENT_OR_SELF); |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 2612 | mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
| 2613 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2614 | } |
| 2615 | return -1; |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2616 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2617 | if (down) { |
| 2618 | mPendingMetaAction = true; |
| 2619 | } else if (mPendingMetaAction) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2620 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2621 | } |
| 2622 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2623 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2624 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2625 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2626 | // Any printing key that is chorded with Search should be consumed |
| 2627 | // even if no shortcut was invoked. This prevents text from being |
| 2628 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2629 | // 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] | 2630 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2631 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2632 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2633 | mConsumeSearchKeyUp = true; |
| 2634 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2635 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2636 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2637 | if (shortcutIntent != null) { |
| 2638 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2639 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2640 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2641 | } catch (ActivityNotFoundException ex) { |
| 2642 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2643 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2644 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2645 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2646 | } else { |
| 2647 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2648 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2649 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2650 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2651 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2652 | } |
| 2653 | } |
| 2654 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2655 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2656 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2657 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2658 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2659 | if (kcm.isPrintingKey(keyCode)) { |
| 2660 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2661 | metaState & ~(KeyEvent.META_META_ON |
| 2662 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2663 | if (shortcutIntent != null) { |
| 2664 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2665 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2666 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2667 | } catch (ActivityNotFoundException ex) { |
| 2668 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2669 | + "the activity to which it is registered was not found: " |
| 2670 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2671 | } |
| 2672 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2673 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2677 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2678 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2679 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2680 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2681 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2682 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2683 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2684 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2685 | } catch (ActivityNotFoundException ex) { |
| 2686 | Slog.w(TAG, "Dropping application launch key because " |
| 2687 | + "the activity to which it is registered was not found: " |
| 2688 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2689 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2690 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2691 | } |
| 2692 | } |
| 2693 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2694 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2695 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2696 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2697 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2698 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2699 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 2700 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2701 | return -1; |
| 2702 | } |
| 2703 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2704 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 2705 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 2706 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2707 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2708 | } |
| 2709 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2710 | // Handle keyboard language switching. |
| 2711 | if (down && repeatCount == 0 |
| 2712 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2713 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2714 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2715 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2716 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2717 | return -1; |
| 2718 | } |
| 2719 | if (mLanguageSwitchKeyPressed && !down |
| 2720 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2721 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2722 | mLanguageSwitchKeyPressed = false; |
| 2723 | return -1; |
| 2724 | } |
| 2725 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2726 | if (isValidGlobalKey(keyCode) |
| 2727 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2728 | return -1; |
| 2729 | } |
| 2730 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2731 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2732 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2733 | return -1; |
| 2734 | } |
| 2735 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2736 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2737 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2738 | } |
| 2739 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2740 | /** {@inheritDoc} */ |
| 2741 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2742 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2743 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2744 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2745 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2746 | + ", flags=" + event.getFlags() |
| 2747 | + ", keyCode=" + event.getKeyCode() |
| 2748 | + ", scanCode=" + event.getScanCode() |
| 2749 | + ", metaState=" + event.getMetaState() |
| 2750 | + ", repeatCount=" + event.getRepeatCount() |
| 2751 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2752 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2753 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2754 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2755 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2756 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2757 | final int keyCode = event.getKeyCode(); |
| 2758 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2759 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2760 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2761 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2762 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2763 | final FallbackAction fallbackAction; |
| 2764 | if (initialDown) { |
| 2765 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2766 | } else { |
| 2767 | fallbackAction = mFallbackActions.get(keyCode); |
| 2768 | } |
| 2769 | |
| 2770 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2771 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2772 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2773 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2774 | } |
| 2775 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2776 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2777 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2778 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2779 | event.getAction(), fallbackAction.keyCode, |
| 2780 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2781 | event.getDeviceId(), event.getScanCode(), |
| 2782 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2783 | |
| 2784 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2785 | fallbackEvent.recycle(); |
| 2786 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2787 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2788 | |
| 2789 | if (initialDown) { |
| 2790 | mFallbackActions.put(keyCode, fallbackAction); |
| 2791 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2792 | mFallbackActions.remove(keyCode); |
| 2793 | fallbackAction.recycle(); |
| 2794 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2795 | } |
| 2796 | } |
| 2797 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2798 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2799 | if (fallbackEvent == null) { |
| 2800 | Slog.d(TAG, "No fallback."); |
| 2801 | } else { |
| 2802 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2803 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2804 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2805 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2806 | } |
| 2807 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2808 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2809 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2810 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2811 | long delayMillis = interceptKeyBeforeDispatching( |
| 2812 | win, fallbackEvent, policyFlags); |
| 2813 | if (delayMillis == 0) { |
| 2814 | return true; |
| 2815 | } |
| 2816 | } |
| 2817 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2818 | } |
| 2819 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2820 | private void launchAssistLongPressAction() { |
| 2821 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2822 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2823 | |
| 2824 | // launch the search activity |
| 2825 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2826 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2827 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2828 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2829 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2830 | SearchManager searchManager = getSearchManager(); |
| 2831 | if (searchManager != null) { |
| 2832 | searchManager.stopSearch(); |
| 2833 | } |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2834 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2835 | } catch (ActivityNotFoundException e) { |
| 2836 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | private void launchAssistAction() { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2841 | launchAssistAction(null); |
| 2842 | } |
| 2843 | |
| 2844 | private void launchAssistAction(String hint) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2845 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2846 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2847 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2848 | if (intent != null) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2849 | if (hint != null) { |
| 2850 | intent.putExtra(hint, true); |
| 2851 | } |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2852 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2853 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2854 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2855 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2856 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2857 | } catch (ActivityNotFoundException e) { |
| 2858 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2859 | } |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | private SearchManager getSearchManager() { |
| 2864 | if (mSearchManager == null) { |
| 2865 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2866 | } |
| 2867 | return mSearchManager; |
| 2868 | } |
| 2869 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2870 | private void preloadRecentApps() { |
| 2871 | mPreloadedRecentApps = true; |
| 2872 | try { |
| 2873 | IStatusBarService statusbar = getStatusBarService(); |
| 2874 | if (statusbar != null) { |
| 2875 | statusbar.preloadRecentApps(); |
| 2876 | } |
| 2877 | } catch (RemoteException e) { |
| 2878 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 2879 | // re-acquire status bar service next time it is needed. |
| 2880 | mStatusBarService = null; |
| 2881 | } |
| 2882 | } |
| 2883 | |
| 2884 | private void cancelPreloadRecentApps() { |
| 2885 | if (mPreloadedRecentApps) { |
| 2886 | mPreloadedRecentApps = false; |
| 2887 | try { |
| 2888 | IStatusBarService statusbar = getStatusBarService(); |
| 2889 | if (statusbar != null) { |
| 2890 | statusbar.cancelPreloadRecentApps(); |
| 2891 | } |
| 2892 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2893 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2894 | // re-acquire status bar service next time it is needed. |
| 2895 | mStatusBarService = null; |
| 2896 | } |
| 2897 | } |
| 2898 | } |
| 2899 | |
| 2900 | private void toggleRecentApps() { |
| 2901 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2902 | try { |
| 2903 | IStatusBarService statusbar = getStatusBarService(); |
| 2904 | if (statusbar != null) { |
| 2905 | statusbar.toggleRecentApps(); |
| 2906 | } |
| 2907 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2908 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 2909 | // re-acquire status bar service next time it is needed. |
| 2910 | mStatusBarService = null; |
| 2911 | } |
| 2912 | } |
| 2913 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2914 | @Override |
| 2915 | public void showRecentApps() { |
| 2916 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 2917 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 2918 | } |
| 2919 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2920 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 2921 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2922 | try { |
| 2923 | IStatusBarService statusbar = getStatusBarService(); |
| 2924 | if (statusbar != null) { |
| 2925 | statusbar.showRecentApps(triggeredFromAltTab); |
| 2926 | } |
| 2927 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2928 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2929 | // re-acquire status bar service next time it is needed. |
| 2930 | mStatusBarService = null; |
| 2931 | } |
| 2932 | } |
| 2933 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2934 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2935 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2936 | try { |
| 2937 | IStatusBarService statusbar = getStatusBarService(); |
| 2938 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2939 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2940 | } |
| 2941 | } catch (RemoteException e) { |
| 2942 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 2943 | // re-acquire status bar service next time it is needed. |
| 2944 | mStatusBarService = null; |
| 2945 | } |
| 2946 | } |
| 2947 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2948 | /** |
| 2949 | * A home key -> launch home action was detected. Take the appropriate action |
| 2950 | * given the situation with the keyguard. |
| 2951 | */ |
| 2952 | void launchHomeFromHotKey() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 2953 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2954 | // don't launch home if keyguard showing |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2955 | } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2956 | // when in keyguard restricted mode, must first verify unlock |
| 2957 | // before launching home |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2958 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2959 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2960 | public void onKeyguardExitResult(boolean success) { |
| 2961 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2962 | try { |
| 2963 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2964 | } catch (RemoteException e) { |
| 2965 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2966 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2967 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2968 | } |
| 2969 | } |
| 2970 | }); |
| 2971 | } else { |
| 2972 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2973 | try { |
| 2974 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2975 | } catch (RemoteException e) { |
| 2976 | } |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 2977 | if (mRecentsVisible) { |
| 2978 | // Hide Recents and notify it to launch Home |
| 2979 | awakenDreams(); |
| 2980 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2981 | hideRecentApps(false, true); |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 2982 | } else { |
| 2983 | // Otherwise, just launch Home |
| 2984 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 2985 | startDockOrHome(); |
| 2986 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2987 | } |
| 2988 | } |
| 2989 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2990 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 2991 | @Override |
| 2992 | public void run() { |
| 2993 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2994 | // Clear flags. |
| 2995 | mForceClearedSystemUiFlags &= |
| 2996 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 2997 | } |
| 2998 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2999 | } |
| 3000 | }; |
| 3001 | |
| 3002 | /** |
| 3003 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3004 | * to determine when the nav bar should be shown and prevent applications from |
| 3005 | * receiving those touches. |
| 3006 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3007 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3008 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3009 | super(inputChannel, looper); |
| 3010 | } |
| 3011 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3012 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3013 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3014 | boolean handled = false; |
| 3015 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3016 | if (event instanceof MotionEvent |
| 3017 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3018 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3019 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3020 | // When the user taps down, we re-show the nav bar. |
| 3021 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3022 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3023 | // Any user activity always causes us to show the |
| 3024 | // navigation controls, if they had been hidden. |
| 3025 | // We also clear the low profile and only content |
| 3026 | // flags so that tapping on the screen will atomically |
| 3027 | // restore all currently hidden screen decorations. |
| 3028 | int newVal = mResettingSystemUiFlags | |
| 3029 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3030 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3031 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3032 | if (mResettingSystemUiFlags != newVal) { |
| 3033 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3034 | changed = true; |
| 3035 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3036 | // We don't allow the system's nav bar to be hidden |
| 3037 | // again for 1 second, to prevent applications from |
| 3038 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3039 | newVal = mForceClearedSystemUiFlags | |
| 3040 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3041 | if (mForceClearedSystemUiFlags != newVal) { |
| 3042 | mForceClearedSystemUiFlags = newVal; |
| 3043 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3044 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3045 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3046 | } |
| 3047 | if (changed) { |
| 3048 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3049 | } |
| 3050 | } |
| 3051 | } |
| 3052 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3053 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3054 | } |
| 3055 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3056 | } |
| 3057 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3058 | new InputEventReceiver.Factory() { |
| 3059 | @Override |
| 3060 | public InputEventReceiver createInputEventReceiver( |
| 3061 | InputChannel inputChannel, Looper looper) { |
| 3062 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3063 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3064 | }; |
| 3065 | |
| 3066 | @Override |
| 3067 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3068 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3069 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3070 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3071 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3072 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3073 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3074 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3075 | // Clear any bits in the new visibility that are currently being |
| 3076 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3077 | return visibility & ~mResettingSystemUiFlags |
| 3078 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3081 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3082 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3083 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3084 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3085 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3086 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3087 | 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] | 3088 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3089 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3090 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3091 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3092 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3093 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3094 | } else { |
| 3095 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3096 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3097 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3098 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3099 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3100 | contentInset.set(mStableFullscreenLeft, mStableFullscreenTop, |
| 3101 | availRight - mStableFullscreenRight, |
| 3102 | availBottom - mStableFullscreenBottom); |
| 3103 | } else { |
| 3104 | contentInset.set(mStableLeft, mStableTop, |
| 3105 | availRight - mStableRight, availBottom - mStableBottom); |
| 3106 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3107 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3108 | contentInset.setEmpty(); |
| 3109 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3110 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
| 3111 | contentInset.set(mCurLeft, mCurTop, |
| 3112 | availRight - mCurRight, availBottom - mCurBottom); |
| 3113 | } else { |
| 3114 | contentInset.set(mCurLeft, mCurTop, |
| 3115 | availRight - mCurRight, availBottom - mCurBottom); |
| 3116 | } |
| 3117 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3118 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3119 | contentInset.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3120 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3121 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3122 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3123 | @Override |
| 3124 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 3125 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3126 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3127 | if (isDefaultDisplay) { |
| 3128 | switch (displayRotation) { |
| 3129 | case Surface.ROTATION_90: |
| 3130 | overscanLeft = mOverscanTop; |
| 3131 | overscanTop = mOverscanRight; |
| 3132 | overscanRight = mOverscanBottom; |
| 3133 | overscanBottom = mOverscanLeft; |
| 3134 | break; |
| 3135 | case Surface.ROTATION_180: |
| 3136 | overscanLeft = mOverscanRight; |
| 3137 | overscanTop = mOverscanBottom; |
| 3138 | overscanRight = mOverscanLeft; |
| 3139 | overscanBottom = mOverscanTop; |
| 3140 | break; |
| 3141 | case Surface.ROTATION_270: |
| 3142 | overscanLeft = mOverscanBottom; |
| 3143 | overscanTop = mOverscanLeft; |
| 3144 | overscanRight = mOverscanTop; |
| 3145 | overscanBottom = mOverscanRight; |
| 3146 | break; |
| 3147 | default: |
| 3148 | overscanLeft = mOverscanLeft; |
| 3149 | overscanTop = mOverscanTop; |
| 3150 | overscanRight = mOverscanRight; |
| 3151 | overscanBottom = mOverscanBottom; |
| 3152 | break; |
| 3153 | } |
| 3154 | } else { |
| 3155 | overscanLeft = 0; |
| 3156 | overscanTop = 0; |
| 3157 | overscanRight = 0; |
| 3158 | overscanBottom = 0; |
| 3159 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3160 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3161 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3162 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3163 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3164 | mSystemLeft = 0; |
| 3165 | mSystemTop = 0; |
| 3166 | mSystemRight = displayWidth; |
| 3167 | mSystemBottom = displayHeight; |
| 3168 | mUnrestrictedScreenLeft = overscanLeft; |
| 3169 | mUnrestrictedScreenTop = overscanTop; |
| 3170 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3171 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3172 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3173 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3174 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3175 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3176 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3177 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3178 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3179 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3180 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3181 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3182 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3183 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3184 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3185 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3186 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3187 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3188 | final Rect pf = mTmpParentFrame; |
| 3189 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3190 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3191 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3192 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3193 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3194 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3195 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3196 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3197 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3198 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3199 | if (isDefaultDisplay) { |
| 3200 | // For purposes of putting out fake window up to steal focus, we will |
| 3201 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3202 | final int sysui = mLastSystemUiFlags; |
| 3203 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3204 | boolean navTranslucent = (sysui |
| 3205 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3206 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3207 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3208 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3209 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3210 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3211 | if (!isKeyguardShowing) { |
| 3212 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3213 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3214 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3215 | // When the navigation bar isn't visible, we put up a fake |
| 3216 | // input window to catch all touch events. This way we can |
| 3217 | // detect when the user presses anywhere to bring back the nav |
| 3218 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3219 | if (navVisible || navAllowedHidden) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3220 | if (mHideNavFakeWindow != null) { |
| 3221 | mHideNavFakeWindow.dismiss(); |
| 3222 | mHideNavFakeWindow = null; |
| 3223 | } |
| 3224 | } else if (mHideNavFakeWindow == null) { |
| 3225 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 3226 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 3227 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3228 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3229 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3230 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3231 | // For purposes of positioning and showing the nav bar, if we have |
| 3232 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3233 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3234 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3235 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3236 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3237 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3238 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3239 | // Force the navigation bar to its appropriate place and |
| 3240 | // size. We need to do this directly, instead of relying on |
| 3241 | // it to bubble up from the nav bar, because this needs to |
| 3242 | // change atomically with screen rotations. |
| 3243 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 3244 | if (mNavigationBarOnBottom) { |
| 3245 | // 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] | 3246 | int top = displayHeight - overscanBottom |
| 3247 | - mNavigationBarHeightForRotation[displayRotation]; |
| 3248 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3249 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3250 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3251 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3252 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3253 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3254 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3255 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3256 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3257 | } else { |
| 3258 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3259 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3260 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3261 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3262 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3263 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3264 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3265 | // and not in the process of animating on or off, then |
| 3266 | // we can tell the app that it is covered by it. |
| 3267 | mSystemBottom = mTmpNavigationFrame.top; |
| 3268 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3269 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3270 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3271 | int left = displayWidth - overscanRight |
| 3272 | - mNavigationBarWidthForRotation[displayRotation]; |
| 3273 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3274 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3275 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3276 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3277 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3278 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3279 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3280 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3281 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3282 | } else { |
| 3283 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3284 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3285 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3286 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 3287 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3288 | // If the nav bar is currently requested to be visible, |
| 3289 | // and not in the process of animating on or off, then |
| 3290 | // we can tell the app that it is covered by it. |
| 3291 | mSystemRight = mTmpNavigationFrame.left; |
| 3292 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3293 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3294 | // Make sure the content and current rectangles are updated to |
| 3295 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3296 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3297 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3298 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3299 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3300 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3301 | // And compute the final frame. |
| 3302 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3303 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 3304 | mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3305 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3306 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3307 | updateSysUiVisibility = true; |
| 3308 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3309 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3310 | 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] | 3311 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 3312 | |
| 3313 | // decide where the status bar goes ahead of time |
| 3314 | if (mStatusBar != null) { |
| 3315 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3316 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3317 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3318 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3319 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3320 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3321 | vf.left = mStableLeft; |
| 3322 | vf.top = mStableTop; |
| 3323 | vf.right = mStableRight; |
| 3324 | vf.bottom = mStableBottom; |
| 3325 | |
| 3326 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3327 | |
| 3328 | // Let the status bar determine its size. |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3329 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3330 | |
| 3331 | // For layout, the status bar is always at the top with our fixed height. |
| 3332 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3333 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3334 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3335 | boolean statusBarTranslucent = (sysui |
| 3336 | & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3337 | if (!isKeyguardShowing) { |
| 3338 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3339 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3340 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3341 | // If the status bar is hidden, we don't want to cause |
| 3342 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 3343 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3344 | // Status bar may go away, so the screen area it occupies |
| 3345 | // is available to apps but just covering them when the |
| 3346 | // status bar is visible. |
| 3347 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3348 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3349 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3350 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3351 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3352 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3353 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3354 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3355 | String.format( |
| 3356 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3357 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3358 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3359 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3360 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3361 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3362 | && !statusBarTransient && !statusBarTranslucent |
| 3363 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3364 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3365 | // and not in the process of animating on or off, then |
| 3366 | // we can tell the app that it is covered by it. |
| 3367 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3368 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3369 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3370 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3371 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3372 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3373 | if (updateSysUiVisibility) { |
| 3374 | updateSystemUiVisibilityLw(); |
| 3375 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3376 | } |
| 3377 | } |
| 3378 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3379 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3380 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3381 | public int getSystemDecorLayerLw() { |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3382 | if (mStatusBar != null) return mStatusBar.getSurfaceLayer(); |
| 3383 | if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer(); |
| 3384 | return 0; |
| 3385 | } |
| 3386 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3387 | @Override |
| 3388 | public void getContentRectLw(Rect r) { |
| 3389 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3390 | } |
| 3391 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3392 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3393 | 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] | 3394 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3395 | // Here's a special case: if this attached window is a panel that is |
| 3396 | // above the dock window, and the window it is attached to is below |
| 3397 | // the dock window, then the frames we computed for the window it is |
| 3398 | // attached to can not be used because the dock is effectively part |
| 3399 | // of the underlying window and the attached window is floating on top |
| 3400 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3401 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3402 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3403 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3404 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3405 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3406 | } else { |
| 3407 | // The effective display frame of the attached window depends on |
| 3408 | // whether it is taking care of insetting its content. If not, |
| 3409 | // we need to use the parent's content frame so that the entire |
| 3410 | // window is positioned within that content. Otherwise we can use |
| 3411 | // the display frame and let the attached window take care of |
| 3412 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3413 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3414 | cf.set(attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3415 | } else { |
| 3416 | // If the window is resizing, then we want to base the content |
| 3417 | // frame on our attached content frame to resize... however, |
| 3418 | // things can be tricky if the attached window is NOT in resize |
| 3419 | // mode, in which case its content frame will be larger. |
| 3420 | // Ungh. So to deal with that, make sure the content frame |
| 3421 | // we end up using is not covering the IM dock. |
| 3422 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3423 | if (attached.isVoiceInteraction()) { |
| 3424 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3425 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3426 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3427 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3428 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3429 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3430 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3431 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3432 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3433 | } |
| 3434 | } |
| 3435 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3436 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3437 | vf.set(attached.getVisibleFrameLw()); |
| 3438 | } |
| 3439 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3440 | // window should be positioned relative to its parent or the entire |
| 3441 | // screen. |
| 3442 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3443 | ? attached.getFrameLw() : df); |
| 3444 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3445 | |
| 3446 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3447 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3448 | // If app is requesting a stable layout, don't let the |
| 3449 | // content insets go below the stable values. |
| 3450 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3451 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3452 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3453 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3454 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3455 | } else { |
| 3456 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3457 | if (r.top < mStableTop) r.top = mStableTop; |
| 3458 | if (r.right > mStableRight) r.right = mStableRight; |
| 3459 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3460 | } |
| 3461 | } |
| 3462 | } |
| 3463 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3464 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3465 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3466 | public void layoutWindowLw(WindowState win, WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3467 | // we've already done the status bar |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3468 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 3469 | if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) || |
| 3470 | win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3471 | return; |
| 3472 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3473 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 3474 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3475 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 3476 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3477 | 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] | 3478 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 3479 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3480 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3481 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3482 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3483 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3484 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3485 | final Rect pf = mTmpParentFrame; |
| 3486 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3487 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3488 | final Rect cf = mTmpContentFrame; |
| 3489 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3490 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3491 | final Rect sf = mTmpStableFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3492 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3493 | |
| 3494 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3495 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3496 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 3497 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 3498 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3499 | if (isDefaultDisplay) { |
| 3500 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 3501 | } else { |
| 3502 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 3503 | } |
| 3504 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3505 | if (!isDefaultDisplay) { |
| 3506 | if (attached != null) { |
| 3507 | // If this window is attached to another, our display |
| 3508 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3509 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3510 | } else { |
| 3511 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3512 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3513 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3514 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3515 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3516 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3517 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3518 | } |
| 3519 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3520 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3521 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3522 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3523 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3524 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3525 | // ...with content insets above the nav bar |
| 3526 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3527 | // IM dock windows always go to the bottom of the screen. |
| 3528 | attrs.gravity = Gravity.BOTTOM; |
| 3529 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 3530 | } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 3531 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3532 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3533 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3534 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 3535 | cf.left = vf.left = mStableLeft; |
| 3536 | cf.top = vf.top = mStableTop; |
| 3537 | cf.right = vf.right = mStableRight; |
| 3538 | vf.bottom = mStableBottom; |
| 3539 | cf.bottom = mContentBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3540 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3541 | |
| 3542 | // Default policy decor for the default display |
| 3543 | dcf.left = mSystemLeft; |
| 3544 | dcf.top = mSystemTop; |
| 3545 | dcf.right = mSystemRight; |
| 3546 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3547 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3548 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3549 | final boolean isAppWindow = |
| 3550 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3551 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3552 | final boolean topAtRest = |
| 3553 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3554 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3555 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3556 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3557 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 3558 | && (fl & WindowManager.LayoutParams. |
| 3559 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3560 | // Ensure policy decor includes status bar |
| 3561 | dcf.top = mStableTop; |
| 3562 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3563 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3564 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 3565 | && (fl & WindowManager.LayoutParams. |
| 3566 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3567 | // Ensure policy decor includes navigation bar |
| 3568 | dcf.bottom = mStableBottom; |
| 3569 | dcf.right = mStableRight; |
| 3570 | } |
| 3571 | } |
| 3572 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3573 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3574 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3575 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3576 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3577 | // This is the case for a normal activity window: we want it |
| 3578 | // to cover all of the screen space, and it can take care of |
| 3579 | // moving its contents to account for screen decorations that |
| 3580 | // intrude into that space. |
| 3581 | if (attached != null) { |
| 3582 | // If this window is attached to another, our display |
| 3583 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3584 | 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] | 3585 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3586 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3587 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 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. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3592 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3593 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3594 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3595 | pf.left = df.left = of.left = hasNavBar |
| 3596 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3597 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3598 | pf.right = df.right = of.right = hasNavBar |
| 3599 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3600 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3601 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3602 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3603 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3604 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3605 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3606 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3607 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3608 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3609 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3610 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3611 | // Asking to layout into the overscan region, so give it that pure |
| 3612 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3613 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3614 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3615 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3616 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3617 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3618 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3619 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3620 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3621 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3622 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3623 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3624 | // only do this for application windows to ensure no window that |
| 3625 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3626 | pf.left = df.left = mOverscanScreenLeft; |
| 3627 | pf.top = df.top = mOverscanScreenTop; |
| 3628 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3629 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3630 | // We need to tell the app about where the frame inside the overscan |
| 3631 | // is, so it can inset its content by that amount -- it didn't ask |
| 3632 | // to actually extend itself into the overscan region. |
| 3633 | of.left = mUnrestrictedScreenLeft; |
| 3634 | of.top = mUnrestrictedScreenTop; |
| 3635 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3636 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3637 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3638 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3639 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3640 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3641 | + mRestrictedOverscanScreenWidth; |
| 3642 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3643 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3644 | // We need to tell the app about where the frame inside the overscan |
| 3645 | // is, so it can inset its content by that amount -- it didn't ask |
| 3646 | // to actually extend itself into the overscan region. |
| 3647 | of.left = mUnrestrictedScreenLeft; |
| 3648 | of.top = mUnrestrictedScreenTop; |
| 3649 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3650 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3651 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3652 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3653 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3654 | if (win.isVoiceInteraction()) { |
| 3655 | cf.left = mVoiceContentLeft; |
| 3656 | cf.top = mVoiceContentTop; |
| 3657 | cf.right = mVoiceContentRight; |
| 3658 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3659 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3660 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3661 | cf.left = mDockLeft; |
| 3662 | cf.top = mDockTop; |
| 3663 | cf.right = mDockRight; |
| 3664 | cf.bottom = mDockBottom; |
| 3665 | } else { |
| 3666 | cf.left = mContentLeft; |
| 3667 | cf.top = mContentTop; |
| 3668 | cf.right = mContentRight; |
| 3669 | cf.bottom = mContentBottom; |
| 3670 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3671 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3672 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3673 | // Full screen windows are always given a layout that is as if the |
| 3674 | // status bar and other transient decors are gone. This is to avoid |
| 3675 | // bad states when moving from a window that is not hding the |
| 3676 | // status bar to one that is. |
| 3677 | cf.left = mRestrictedScreenLeft; |
| 3678 | cf.top = mRestrictedScreenTop; |
| 3679 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3680 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3681 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3682 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3683 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3684 | vf.left = mCurLeft; |
| 3685 | vf.top = mCurTop; |
| 3686 | vf.right = mCurRight; |
| 3687 | vf.bottom = mCurBottom; |
| 3688 | } else { |
| 3689 | vf.set(cf); |
| 3690 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3691 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3692 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3693 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3694 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3695 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3696 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3697 | // A window that has requested to fill the entire screen just |
| 3698 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3699 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3700 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3701 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3702 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3703 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3704 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3705 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3706 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3707 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3708 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3709 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3710 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3711 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3712 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3713 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3714 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3715 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3716 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3717 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3718 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3719 | + mUnrestrictedScreenWidth; |
| 3720 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3721 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3722 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3723 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3724 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3725 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3726 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3727 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3728 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3729 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3730 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3731 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3732 | + mOverscanScreenWidth; |
| 3733 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3734 | + mOverscanScreenHeight; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3735 | } else if (attrs.type == TYPE_BOOT_PROGRESS |
| 3736 | || attrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3737 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3738 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3739 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3740 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3741 | + mOverscanScreenWidth; |
| 3742 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3743 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3744 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3745 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 3746 | // it about the overscan area. |
| 3747 | pf.left = df.left = mOverscanScreenLeft; |
| 3748 | pf.top = df.top = mOverscanScreenTop; |
| 3749 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3750 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 3751 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 3752 | of.top = cf.top = mUnrestrictedScreenTop; |
| 3753 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3754 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3755 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3756 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3757 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3758 | // Asking to layout into the overscan region, so give it that pure |
| 3759 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3760 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3761 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3762 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3763 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3764 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3765 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3766 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3767 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 3768 | && (attrs.type == TYPE_STATUS_BAR |
| 3769 | || attrs.type == TYPE_TOAST |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3770 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3771 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3772 | // Asking for layout as if the nav bar is hidden, lets the |
| 3773 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3774 | // 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] | 3775 | // can be above the nav bar can do this. |
| 3776 | // XXX This assumes that an app asking for this will also |
| 3777 | // ask for layout in only content. We can't currently figure out |
| 3778 | // 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] | 3779 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3780 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3781 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3782 | + mUnrestrictedScreenWidth; |
| 3783 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3784 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3785 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3786 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3787 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3788 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3789 | + mRestrictedScreenWidth; |
| 3790 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3791 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3792 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3793 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3794 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3795 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3796 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3797 | vf.left = mCurLeft; |
| 3798 | vf.top = mCurTop; |
| 3799 | vf.right = mCurRight; |
| 3800 | vf.bottom = mCurBottom; |
| 3801 | } else { |
| 3802 | vf.set(cf); |
| 3803 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3804 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3805 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3806 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3807 | // A child window should be placed inside of the same visible |
| 3808 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3809 | 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] | 3810 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3811 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3812 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3813 | // Otherwise, a normal window must be placed inside the content |
| 3814 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3815 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 3816 | // Status bar panels are the only windows who can go on top of |
| 3817 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3818 | // permission, so they have the same privileges as the status |
| 3819 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3820 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3821 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3822 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3823 | + mRestrictedScreenWidth; |
| 3824 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3825 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3826 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 3827 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 3828 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3829 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 3830 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 3831 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 3832 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3833 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3834 | pf.left = mContentLeft; |
| 3835 | pf.top = mContentTop; |
| 3836 | pf.right = mContentRight; |
| 3837 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 3838 | if (win.isVoiceInteraction()) { |
| 3839 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 3840 | df.top = of.top = cf.top = mVoiceContentTop; |
| 3841 | df.right = of.right = cf.right = mVoiceContentRight; |
| 3842 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 3843 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3844 | df.left = of.left = cf.left = mDockLeft; |
| 3845 | df.top = of.top = cf.top = mDockTop; |
| 3846 | df.right = of.right = cf.right = mDockRight; |
| 3847 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3848 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3849 | df.left = of.left = cf.left = mContentLeft; |
| 3850 | df.top = of.top = cf.top = mContentTop; |
| 3851 | df.right = of.right = cf.right = mContentRight; |
| 3852 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3853 | } |
| 3854 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3855 | vf.left = mCurLeft; |
| 3856 | vf.top = mCurTop; |
| 3857 | vf.right = mCurRight; |
| 3858 | vf.bottom = mCurBottom; |
| 3859 | } else { |
| 3860 | vf.set(cf); |
| 3861 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3862 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3863 | } |
| 3864 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3865 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 3866 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 3867 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3868 | df.left = df.top = -10000; |
| 3869 | df.right = df.bottom = 10000; |
| 3870 | if (attrs.type != TYPE_WALLPAPER) { |
| 3871 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 3872 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 3873 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3874 | } |
| 3875 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3876 | 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] | 3877 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3878 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3879 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3880 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3881 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3882 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3883 | + " dcf=" + dcf.toShortString() |
| 3884 | + " sf=" + sf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3885 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3886 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3887 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3888 | // Dock windows carve out the bottom of the screen, so normal windows |
| 3889 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 3890 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 3891 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3892 | setLastInputMethodWindowLw(null, null); |
| 3893 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3894 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3895 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 3896 | && !win.getGivenInsetsPendingLw()) { |
| 3897 | offsetVoiceInputWindowLw(win); |
| 3898 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3899 | } |
| 3900 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3901 | private void offsetInputMethodWindowLw(WindowState win) { |
| 3902 | int top = win.getContentFrameLw().top; |
| 3903 | top += win.getGivenContentInsetsLw().top; |
| 3904 | if (mContentBottom > top) { |
| 3905 | mContentBottom = top; |
| 3906 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3907 | if (mVoiceContentBottom > top) { |
| 3908 | mVoiceContentBottom = top; |
| 3909 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3910 | top = win.getVisibleFrameLw().top; |
| 3911 | top += win.getGivenVisibleInsetsLw().top; |
| 3912 | if (mCurBottom > top) { |
| 3913 | mCurBottom = top; |
| 3914 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3915 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3916 | + mDockBottom + " mContentBottom=" |
| 3917 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 3918 | } |
| 3919 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3920 | private void offsetVoiceInputWindowLw(WindowState win) { |
| 3921 | final int gravity = win.getAttrs().gravity; |
| 3922 | switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER) |
| 3923 | << Gravity.AXIS_X_SHIFT)) { |
| 3924 | case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: { |
| 3925 | int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right; |
| 3926 | if (mVoiceContentLeft < right) { |
| 3927 | mVoiceContentLeft = right; |
| 3928 | } |
| 3929 | } break; |
| 3930 | case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: { |
| 3931 | int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left; |
| 3932 | if (mVoiceContentRight < left) { |
| 3933 | mVoiceContentRight = left; |
| 3934 | } |
| 3935 | } break; |
| 3936 | } |
| 3937 | switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER) |
| 3938 | << Gravity.AXIS_Y_SHIFT)) { |
| 3939 | case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: { |
| 3940 | int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom; |
| 3941 | if (mVoiceContentTop < bottom) { |
| 3942 | mVoiceContentTop = bottom; |
| 3943 | } |
| 3944 | } break; |
| 3945 | case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: { |
| 3946 | int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top; |
| 3947 | if (mVoiceContentBottom < top) { |
| 3948 | mVoiceContentBottom = top; |
| 3949 | } |
| 3950 | } break; |
| 3951 | } |
| 3952 | } |
| 3953 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3954 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 3955 | @Override |
| 3956 | public void finishLayoutLw() { |
| 3957 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3958 | } |
| 3959 | |
| 3960 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3961 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3962 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3963 | mTopFullscreenOpaqueWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3964 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 3965 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3966 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3967 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3968 | mForcingShowNavBar = false; |
| 3969 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3970 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3971 | mHideLockScreen = false; |
| 3972 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3973 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3974 | mShowingLockscreen = false; |
| 3975 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3976 | mWinShowWhenLocked = null; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3980 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3981 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3982 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 3983 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3984 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3985 | if (mTopFullscreenOpaqueWindowState == null |
| 3986 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 3987 | mForcingShowNavBar = true; |
| 3988 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3989 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 3990 | if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 3991 | mForceStatusBarFromKeyguard = true; |
| 3992 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3993 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 3994 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3995 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3996 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3997 | mForceStatusBarFromKeyguard = true; |
| 3998 | } else { |
| 3999 | mForceStatusBar = true; |
| 4000 | } |
| 4001 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4002 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4003 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4004 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4005 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 4006 | && attrs.type < FIRST_SYSTEM_WINDOW; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4007 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4008 | // If the lockscreen was showing when the dream started then wait |
| 4009 | // for the dream to draw before hiding the lockscreen. |
| 4010 | if (!mDreamingLockscreen |
| 4011 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4012 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4013 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4014 | } |
| 4015 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4016 | |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4017 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
Craig Mautner | 74ee938 | 2014-04-01 15:20:16 -0700 | [diff] [blame] | 4018 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4019 | final boolean secureKeyguard = isKeyguardSecure(); |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4020 | if (appWindow) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4021 | final IApplicationToken appToken = win.getAppToken(); |
| 4022 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4023 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4024 | mAppsToBeHidden.remove(appToken); |
| 4025 | mAppsThatDismissKeyguard.remove(appToken); |
| 4026 | if (mAppsToBeHidden.isEmpty() && isKeyguardSecureIncludingHidden()) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4027 | mWinShowWhenLocked = win; |
| 4028 | mHideLockScreen = true; |
| 4029 | mForceStatusBarFromKeyguard = false; |
| 4030 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4031 | } else if (dismissKeyguard) { |
| 4032 | if (secureKeyguard) { |
| 4033 | mAppsToBeHidden.add(appToken); |
| 4034 | } else { |
| 4035 | mAppsToBeHidden.remove(appToken); |
| 4036 | } |
| 4037 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4038 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4039 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4040 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4041 | if (attrs.x == 0 && attrs.y == 0 |
| 4042 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4043 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 4044 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4045 | mTopFullscreenOpaqueWindowState = win; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4046 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4047 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4048 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4049 | "Setting mDismissKeyguard true by win " + win); |
| 4050 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 4051 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 4052 | mWinDismissingKeyguard = win; |
| 4053 | mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard; |
| 4054 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) { |
| 4055 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4056 | "Setting mHideLockScreen to true by win " + win); |
| 4057 | mHideLockScreen = true; |
| 4058 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4059 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4060 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4061 | mAllowLockscreenWhenOn = true; |
| 4062 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4063 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4064 | |
| 4065 | if (mWinShowWhenLocked != null && |
| 4066 | mWinShowWhenLocked.getAppToken() != win.getAppToken()) { |
| 4067 | win.hideLw(false); |
| 4068 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4069 | } |
| 4070 | } |
| 4071 | } |
| 4072 | |
| 4073 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4074 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4075 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4076 | if (mWinShowWhenLocked != null && |
| 4077 | mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) { |
| 4078 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4079 | // fullscreen window. |
| 4080 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4081 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4082 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4083 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4084 | } |
| 4085 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4086 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4087 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4088 | |
| 4089 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4090 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4091 | : null; |
| 4092 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4093 | // If we are not currently showing a dream then remember the current |
| 4094 | // lockscreen state. We will use this to determine whether the dream |
| 4095 | // started while the lockscreen was showing and remember this state |
| 4096 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4097 | if (!mShowingDream) { |
| 4098 | mDreamingLockscreen = mShowingLockscreen; |
| 4099 | } |
| 4100 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4101 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4102 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4103 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 4104 | + " top=" + mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4105 | if (mForceStatusBar || mForceStatusBarFromKeyguard) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4106 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4107 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4108 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4109 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4110 | // Maintain fullscreen layout until incoming animation is complete. |
| 4111 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 4112 | // Transient status bar on the lockscreen is not allowed |
| 4113 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 4114 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 4115 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 4116 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4117 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4118 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4119 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4120 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4121 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4122 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4123 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4124 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4125 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4126 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4127 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 4128 | // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window |
| 4129 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 4130 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4131 | if (mStatusBarController.isTransientShowing()) { |
| 4132 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4133 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4134 | } |
| 4135 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4136 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4137 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4138 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4139 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 4140 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 4141 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4142 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4143 | 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] | 4144 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4145 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4146 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4147 | } |
| 4148 | } |
| 4149 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4150 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4151 | if (mTopIsFullscreen != topIsFullscreen) { |
| 4152 | if (!topIsFullscreen) { |
| 4153 | // Force another layout when status bar becomes fully shown. |
| 4154 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4155 | } |
| 4156 | mTopIsFullscreen = topIsFullscreen; |
| 4157 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4158 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4159 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 4160 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4161 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 4162 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 4163 | + mHideLockScreen); |
| 4164 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) { |
| 4165 | mKeyguardHidden = true; |
| 4166 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4167 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4168 | | FINISH_LAYOUT_REDO_CONFIG |
| 4169 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4170 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4171 | if (mKeyguardDelegate.isShowing()) { |
| 4172 | mHandler.post(new Runnable() { |
| 4173 | @Override |
| 4174 | public void run() { |
| 4175 | mKeyguardDelegate.keyguardDone(false, false); |
| 4176 | } |
| 4177 | }); |
| 4178 | } |
| 4179 | } else if (mHideLockScreen) { |
| 4180 | mKeyguardHidden = true; |
| 4181 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) { |
| 4182 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4183 | | FINISH_LAYOUT_REDO_CONFIG |
| 4184 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4185 | } |
| 4186 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 4187 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 4188 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 4189 | // Only launch the next keyguard unlock window once per window. |
| 4190 | mKeyguardHidden = false; |
| 4191 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) { |
| 4192 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4193 | | FINISH_LAYOUT_REDO_CONFIG |
| 4194 | | FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4195 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4196 | mHandler.post(new Runnable() { |
| 4197 | @Override |
| 4198 | public void run() { |
| 4199 | mKeyguardDelegate.dismiss(); |
| 4200 | } |
| 4201 | }); |
| 4202 | } |
| 4203 | } else { |
| 4204 | mWinDismissingKeyguard = null; |
| 4205 | mKeyguardHidden = false; |
| 4206 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) { |
| 4207 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4208 | | FINISH_LAYOUT_REDO_CONFIG |
| 4209 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4210 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 4211 | } |
| 4212 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4213 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4214 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4215 | // If the navigation bar has been hidden or shown, we need to do another |
| 4216 | // layout pass to update that window. |
| 4217 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4218 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4219 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4220 | // update since mAllowLockscreenWhenOn might have changed |
| 4221 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4222 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4223 | } |
| 4224 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4225 | /** |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4226 | * 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] | 4227 | * immediately need to put the wallpaper directly behind the Keyguard when a window with flag |
| 4228 | * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we |
| 4229 | * would wait for Keyguard to change the flags, that would be running asynchronously and thus be |
| 4230 | * too late so the user might see the window behind. |
| 4231 | * |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4232 | * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4233 | * @return Whether the flags have changed and we have to redo the layout. |
| 4234 | */ |
| 4235 | private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4236 | if (setHiddenResult |
| 4237 | == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4238 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4239 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4240 | return true; |
| 4241 | } else if (setHiddenResult |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4242 | == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4243 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4244 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4245 | return true; |
| 4246 | } else { |
| 4247 | return false; |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | private boolean isStatusBarKeyguard() { |
| 4252 | return mStatusBar != null |
| 4253 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4254 | } |
| 4255 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4256 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4257 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4258 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4259 | // 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] | 4260 | return false; |
| 4261 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4262 | return true; |
| 4263 | } |
| 4264 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4265 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4266 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4267 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4268 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4269 | // If the navigation bar has been hidden or shown, we need to do another |
| 4270 | // layout pass to update that window. |
| 4271 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4272 | } |
| 4273 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4274 | } |
| 4275 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4276 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4277 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4278 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4279 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4280 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4281 | if (newLidState == mLidState) { |
| 4282 | return; |
| 4283 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4284 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4285 | mLidState = newLidState; |
| 4286 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4287 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4288 | |
| 4289 | if (lidOpen) { |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4290 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4291 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4292 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4293 | } |
| 4294 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4295 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4296 | @Override |
| 4297 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 4298 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 4299 | if (mCameraLensCoverState == lensCoverState) { |
| 4300 | return; |
| 4301 | } |
| 4302 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 4303 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 4304 | Intent intent; |
| 4305 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 4306 | mKeyguardDelegate.isShowing(); |
| 4307 | if (keyguardActive) { |
| 4308 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 4309 | } else { |
| 4310 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 4311 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4312 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4313 | mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 4314 | } |
| 4315 | mCameraLensCoverState = lensCoverState; |
| 4316 | } |
| 4317 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4318 | void setHdmiPlugged(boolean plugged) { |
| 4319 | if (mHdmiPlugged != plugged) { |
| 4320 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4321 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4322 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4323 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4324 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4325 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4326 | } |
| 4327 | } |
| 4328 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4329 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4330 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4331 | // watch for HDMI plug messages if the hdmi switch exists |
| 4332 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4333 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4334 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4335 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4336 | FileReader reader = null; |
| 4337 | try { |
| 4338 | reader = new FileReader(filename); |
| 4339 | char[] buf = new char[15]; |
| 4340 | int n = reader.read(buf); |
| 4341 | if (n > 1) { |
| 4342 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4343 | } |
| 4344 | } catch (IOException ex) { |
| 4345 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4346 | } catch (NumberFormatException ex) { |
| 4347 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4348 | } finally { |
| 4349 | if (reader != null) { |
| 4350 | try { |
| 4351 | reader.close(); |
| 4352 | } catch (IOException ex) { |
| 4353 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4354 | } |
| 4355 | } |
| 4356 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4357 | // This dance forces the code in setHdmiPlugged to run. |
| 4358 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4359 | mHdmiPlugged = !plugged; |
| 4360 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4361 | } |
| 4362 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4363 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4364 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4365 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4366 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4367 | @Override public void run() { |
| 4368 | synchronized (mScreenshotLock) { |
| 4369 | if (mScreenshotConnection != null) { |
| 4370 | mContext.unbindService(mScreenshotConnection); |
| 4371 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4372 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4373 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4374 | } |
| 4375 | }; |
| 4376 | |
| 4377 | // Assume this is called from the Handler thread. |
| 4378 | private void takeScreenshot() { |
| 4379 | synchronized (mScreenshotLock) { |
| 4380 | if (mScreenshotConnection != null) { |
| 4381 | return; |
| 4382 | } |
| 4383 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4384 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 4385 | Intent intent = new Intent(); |
| 4386 | intent.setComponent(cn); |
| 4387 | ServiceConnection conn = new ServiceConnection() { |
| 4388 | @Override |
| 4389 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 4390 | synchronized (mScreenshotLock) { |
| 4391 | if (mScreenshotConnection != this) { |
| 4392 | return; |
| 4393 | } |
| 4394 | Messenger messenger = new Messenger(service); |
| 4395 | Message msg = Message.obtain(null, 1); |
| 4396 | final ServiceConnection myConn = this; |
| 4397 | Handler h = new Handler(mHandler.getLooper()) { |
| 4398 | @Override |
| 4399 | public void handleMessage(Message msg) { |
| 4400 | synchronized (mScreenshotLock) { |
| 4401 | if (mScreenshotConnection == myConn) { |
| 4402 | mContext.unbindService(mScreenshotConnection); |
| 4403 | mScreenshotConnection = null; |
| 4404 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 4405 | } |
| 4406 | } |
| 4407 | } |
| 4408 | }; |
| 4409 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 4410 | msg.arg1 = msg.arg2 = 0; |
| 4411 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 4412 | msg.arg1 = 1; |
| 4413 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 4414 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4415 | try { |
| 4416 | messenger.send(msg); |
| 4417 | } catch (RemoteException e) { |
| 4418 | } |
| 4419 | } |
| 4420 | } |
| 4421 | @Override |
| 4422 | public void onServiceDisconnected(ComponentName name) {} |
| 4423 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 4424 | if (mContext.bindServiceAsUser( |
| 4425 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4426 | mScreenshotConnection = conn; |
| 4427 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 4428 | } |
| 4429 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4430 | } |
| 4431 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4432 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4433 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4434 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4435 | if (!mSystemBooted) { |
| 4436 | // If we have not yet booted, don't let key events do anything. |
| 4437 | return 0; |
| 4438 | } |
| 4439 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4440 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4441 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 4442 | final boolean canceled = event.isCanceled(); |
| 4443 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 4444 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4445 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4446 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 4447 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 4448 | // the same as if it were open and in front. |
| 4449 | // This will prevent any keys other than the power button from waking the screen |
| 4450 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4451 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4452 | (interactive ? |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4453 | mKeyguardDelegate.isShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4454 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4455 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4456 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4457 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4458 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4459 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4460 | } |
| 4461 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4462 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4463 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 4464 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 4465 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4466 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4467 | // When the device is interactive or the key is injected pass the |
| 4468 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4469 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4470 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4471 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 4472 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 4473 | // to the application but preserve its wake key status to make sure we still move |
| 4474 | // from dozing to fully interactive if we would normally go from off to fully |
| 4475 | // interactive. |
| 4476 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4477 | } else { |
| 4478 | // When the screen is off and the key is not injected, determine whether |
| 4479 | // to wake the device but don't pass the key to the application. |
| 4480 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4481 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 4482 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4483 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4484 | } |
| 4485 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4486 | // If the key would be handled globally, just return the result, don't worry about special |
| 4487 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4488 | if (isValidGlobalKey(keyCode) |
| 4489 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4490 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4491 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4492 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4493 | return result; |
| 4494 | } |
| 4495 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4496 | boolean useHapticFeedback = down |
| 4497 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 4498 | && event.getRepeatCount() == 0; |
| 4499 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4500 | // Handle special keys. |
| 4501 | switch (keyCode) { |
| 4502 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 4503 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4504 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4505 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 4506 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4507 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4508 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4509 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 4510 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 4511 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4512 | cancelPendingPowerKeyAction(); |
| 4513 | interceptScreenshotChord(); |
| 4514 | } |
| 4515 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4516 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4517 | cancelPendingScreenshotChordAction(); |
| 4518 | } |
| 4519 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 4520 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4521 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4522 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4523 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4524 | cancelPendingPowerKeyAction(); |
| 4525 | cancelPendingScreenshotChordAction(); |
| 4526 | } |
| 4527 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4528 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4529 | cancelPendingScreenshotChordAction(); |
| 4530 | } |
| 4531 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4532 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4533 | TelecomManager telecomManager = getTelecommService(); |
| 4534 | if (telecomManager != null) { |
| 4535 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4536 | // If an incoming call is ringing, either VOLUME key means |
| 4537 | // "silence ringer". We handle these keys here, rather than |
| 4538 | // in the InCallScreen, to make sure we'll respond to them |
| 4539 | // even if the InCallScreen hasn't come to the foreground yet. |
| 4540 | // Look for the DOWN event here, to agree with the "fallback" |
| 4541 | // behavior in the InCallScreen. |
| 4542 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4543 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4544 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4545 | // Silence the ringer. (It's safe to call this |
| 4546 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4547 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4548 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4549 | // And *don't* pass this key thru to the current activity |
| 4550 | // (which is probably the InCallScreen.) |
| 4551 | result &= ~ACTION_PASS_TO_USER; |
| 4552 | break; |
| 4553 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4554 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4555 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 4556 | // 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] | 4557 | // the application, just pass it to the session service. |
| 4558 | |
| 4559 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4560 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4561 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4562 | } |
| 4563 | } |
| 4564 | |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4565 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4566 | // If we aren't passing to the user and no one else |
| 4567 | // handled it send it to the session manager to figure |
| 4568 | // out. |
| 4569 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4570 | .sendVolumeKeyEvent(event, true); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4571 | break; |
| 4572 | } |
| 4573 | } |
| 4574 | break; |
| 4575 | } |
| 4576 | |
| 4577 | case KeyEvent.KEYCODE_ENDCALL: { |
| 4578 | result &= ~ACTION_PASS_TO_USER; |
| 4579 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4580 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4581 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4582 | if (telecomManager != null) { |
| 4583 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4584 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4585 | if (interactive && !hungUp) { |
| 4586 | mEndCallKeyHandled = false; |
| 4587 | mHandler.postDelayed(mEndCallLongPress, |
| 4588 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 4589 | } else { |
| 4590 | mEndCallKeyHandled = true; |
| 4591 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4592 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4593 | if (!mEndCallKeyHandled) { |
| 4594 | mHandler.removeCallbacks(mEndCallLongPress); |
| 4595 | if (!canceled) { |
| 4596 | if ((mEndcallBehavior |
| 4597 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 4598 | if (goHome()) { |
| 4599 | break; |
| 4600 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 4601 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4602 | if ((mEndcallBehavior |
| 4603 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 4604 | mPowerManager.goToSleep(event.getEventTime(), |
| 4605 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 4606 | isWakeKey = false; |
| 4607 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4608 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4609 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4610 | } |
| 4611 | break; |
| 4612 | } |
| 4613 | |
| 4614 | case KeyEvent.KEYCODE_POWER: { |
| 4615 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4616 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4617 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4618 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4619 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4620 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4621 | } |
| 4622 | break; |
| 4623 | } |
| 4624 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4625 | case KeyEvent.KEYCODE_SLEEP: { |
| 4626 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4627 | if (!mPowerManager.isInteractive()) { |
| 4628 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 4629 | } |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 4630 | mPowerManager.goToSleep(event.getEventTime(), |
| 4631 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4632 | isWakeKey = false; |
| 4633 | break; |
| 4634 | } |
| 4635 | |
| 4636 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4637 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4638 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4639 | break; |
| 4640 | } |
| 4641 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4642 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4643 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4644 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4645 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4646 | case KeyEvent.KEYCODE_MUTE: |
| 4647 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4648 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4649 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4650 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4651 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4652 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4653 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4654 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 4655 | // If the global session is active pass all media keys to it |
| 4656 | // instead of the active window. |
| 4657 | result &= ~ACTION_PASS_TO_USER; |
| 4658 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4659 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4660 | // Only do this if we would otherwise not pass it to the user. In that |
| 4661 | // case, the PhoneWindow class will do the same thing, except it will |
| 4662 | // 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] | 4663 | // Note that we need to make a copy of the key event here because the |
| 4664 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4665 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4666 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4667 | new KeyEvent(event)); |
| 4668 | msg.setAsynchronous(true); |
| 4669 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4670 | } |
| 4671 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4672 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4673 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4674 | case KeyEvent.KEYCODE_CALL: { |
| 4675 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4676 | TelecomManager telecomManager = getTelecommService(); |
| 4677 | if (telecomManager != null) { |
| 4678 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4679 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4680 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4681 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4682 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4683 | // And *don't* pass this key thru to the current activity |
| 4684 | // (which is presumably the InCallScreen.) |
| 4685 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4686 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4687 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4688 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4689 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4690 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 4691 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 4692 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 4693 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 4694 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 4695 | // key event here because the original key event will be recycled when we return. |
| 4696 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 4697 | mBroadcastWakeLock.acquire(); |
| 4698 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 4699 | keyguardActive ? 1 : 0, 0); |
| 4700 | msg.setAsynchronous(true); |
| 4701 | msg.sendToTarget(); |
| 4702 | } |
| 4703 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4704 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4705 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4706 | if (useHapticFeedback) { |
| 4707 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 4708 | } |
| 4709 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4710 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4711 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4712 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4713 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4714 | return result; |
| 4715 | } |
| 4716 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4717 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4718 | * Returns true if the key can have global actions attached to it. |
| 4719 | * We reserve all power management keys for the system since they require |
| 4720 | * very careful handling. |
| 4721 | */ |
| 4722 | private static boolean isValidGlobalKey(int keyCode) { |
| 4723 | switch (keyCode) { |
| 4724 | case KeyEvent.KEYCODE_POWER: |
| 4725 | case KeyEvent.KEYCODE_WAKEUP: |
| 4726 | case KeyEvent.KEYCODE_SLEEP: |
| 4727 | return false; |
| 4728 | default: |
| 4729 | return true; |
| 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4734 | * When the screen is off we ignore some keys that might otherwise typically |
| 4735 | * be considered wake keys. We filter them out here. |
| 4736 | * |
| 4737 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 4738 | * is always considered a wake key. |
| 4739 | */ |
| 4740 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 4741 | switch (keyCode) { |
| 4742 | // ignore volume keys unless docked |
| 4743 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4744 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4745 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4746 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4747 | |
| 4748 | // ignore media and camera keys |
| 4749 | case KeyEvent.KEYCODE_MUTE: |
| 4750 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4751 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4752 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4753 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4754 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4755 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4756 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4757 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4758 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4759 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4760 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4761 | case KeyEvent.KEYCODE_CAMERA: |
| 4762 | return false; |
| 4763 | } |
| 4764 | return true; |
| 4765 | } |
| 4766 | |
| 4767 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4768 | /** {@inheritDoc} */ |
| 4769 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4770 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 4771 | if ((policyFlags & FLAG_WAKE) != 0) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame^] | 4772 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) { |
| 4773 | return 0; |
| 4774 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4775 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame^] | 4776 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4777 | if (shouldDispatchInputWhenNonInteractive()) { |
| 4778 | return ACTION_PASS_TO_USER; |
| 4779 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame^] | 4780 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4781 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4782 | } |
| 4783 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4784 | private boolean shouldDispatchInputWhenNonInteractive() { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame^] | 4785 | // Send events to keyguard while the screen is on. |
| 4786 | if (keyguardIsShowingTq() && mDisplay != null && mDisplay.getState() != Display.STATE_OFF) { |
| 4787 | return true; |
| 4788 | } |
| 4789 | |
| 4790 | // Send events to a dozing dream even if the screen is off since the dream |
| 4791 | // is in control of the state of the screen. |
| 4792 | IDreamManager dreamManager = getDreamManager(); |
| 4793 | |
| 4794 | try { |
| 4795 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 4796 | return true; |
| 4797 | } |
| 4798 | } catch (RemoteException e) { |
| 4799 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 4800 | } |
| 4801 | |
| 4802 | // Otherwise, consume events since the user can't see what is being |
| 4803 | // interacted with. |
| 4804 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4807 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 4808 | if (DEBUG_INPUT) { |
| 4809 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4810 | } |
| 4811 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4812 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 4813 | if (DEBUG_INPUT) { |
| 4814 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 4815 | } |
| 4816 | |
| 4817 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 4818 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4819 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 4820 | } |
| 4821 | |
| 4822 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 4823 | |
| 4824 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4825 | && event.getRepeatCount() == 0) { |
| 4826 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 4827 | |
| 4828 | Message msg = mHandler.obtainMessage( |
| 4829 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 4830 | msg.setAsynchronous(true); |
| 4831 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 4832 | } else { |
| 4833 | mBroadcastWakeLock.release(); |
| 4834 | } |
| 4835 | } |
| 4836 | |
| 4837 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 4838 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4839 | |
| 4840 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 4841 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 4842 | if (DEBUG_INPUT) { |
| 4843 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 4844 | } |
| 4845 | |
| 4846 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 4847 | mBroadcastWakeLock.release(); |
| 4848 | } |
| 4849 | |
| 4850 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 4851 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4852 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4853 | } |
| 4854 | } |
| 4855 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 4856 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
| 4857 | Intent voiceIntent = |
| 4858 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 4859 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
| 4860 | mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
| 4861 | mBroadcastWakeLock.release(); |
| 4862 | } |
| 4863 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4864 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4865 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4866 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 4867 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 4868 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 4869 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4870 | } else { |
| 4871 | try { |
| 4872 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 4873 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 4874 | mUiMode = uiModeService.getCurrentModeType(); |
| 4875 | } catch (RemoteException e) { |
| 4876 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 4877 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4878 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4879 | synchronized (mLock) { |
| 4880 | updateOrientationListenerLp(); |
| 4881 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4882 | } |
| 4883 | }; |
| 4884 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4885 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 4886 | @Override |
| 4887 | public void onReceive(Context context, Intent intent) { |
| 4888 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4889 | if (mKeyguardDelegate != null) { |
| 4890 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4891 | } |
| 4892 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4893 | if (mKeyguardDelegate != null) { |
| 4894 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4895 | } |
| 4896 | } |
| 4897 | } |
| 4898 | }; |
| 4899 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4900 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 4901 | @Override |
| 4902 | public void onReceive(Context context, Intent intent) { |
| 4903 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 4904 | // tickle the settings observer: this first ensures that we're |
| 4905 | // observing the relevant settings for the newly-active user, |
| 4906 | // and then updates our own bookkeeping based on the now- |
| 4907 | // current user. |
| 4908 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4909 | |
| 4910 | // force a re-application of focused window sysui visibility. |
| 4911 | // the window may never have been shown for this user |
| 4912 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4913 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4914 | mLastSystemUiFlags = 0; |
| 4915 | updateSystemUiVisibilityLw(); |
| 4916 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4917 | } |
| 4918 | } |
| 4919 | }; |
| 4920 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 4921 | private final Runnable mRequestTransientNav = new Runnable() { |
| 4922 | @Override |
| 4923 | public void run() { |
| 4924 | requestTransientBars(mNavigationBar); |
| 4925 | } |
| 4926 | }; |
| 4927 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4928 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4929 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 4930 | if (!isUserSetupComplete()) { |
| 4931 | // Swipe-up for navigation bar is disabled during setup |
| 4932 | return; |
| 4933 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4934 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 4935 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4936 | if (sb || nb) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4937 | WindowState barTarget = sb ? mStatusBar : mNavigationBar; |
| 4938 | if (sb ^ nb && barTarget != swipeTarget) { |
| 4939 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4940 | return; |
| 4941 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4942 | if (sb) mStatusBarController.showTransient(); |
| 4943 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4944 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4945 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4946 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4947 | } |
| 4948 | } |
| 4949 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 4950 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4951 | @Override |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 4952 | public void goingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4953 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 4954 | if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep..."); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 4955 | |
| 4956 | // We must get this work done here because the power manager will drop |
| 4957 | // the wake lock and let the system suspend once this function returns. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4958 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 4959 | mAwake = false; |
| 4960 | mKeyguardDrawComplete = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 4961 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4962 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4963 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4964 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 4965 | |
| 4966 | if (mKeyguardDelegate != null) { |
| 4967 | mKeyguardDelegate.onScreenTurnedOff(why); |
| 4968 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4969 | } |
| 4970 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4971 | private void wakeUpFromPowerKey(long eventTime) { |
| 4972 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey); |
| 4973 | } |
| 4974 | |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame^] | 4975 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) { |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4976 | if (!wakeInTheaterMode && isTheaterModeEnabled()) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame^] | 4977 | return false; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | mPowerManager.wakeUp(wakeTime); |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame^] | 4981 | return true; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4982 | } |
| 4983 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 4984 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4985 | @Override |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 4986 | public void wakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4987 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 4988 | if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 4989 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 4990 | // Since goToSleep performs these functions synchronously, we must |
| 4991 | // do the same here. We cannot post this work to a handler because |
| 4992 | // that might cause it to become reordered with respect to what |
| 4993 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4994 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 4995 | mAwake = true; |
| 4996 | mKeyguardDrawComplete = false; |
| 4997 | if (mKeyguardDelegate != null) { |
| 4998 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 4999 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
| 5000 | } |
| 5001 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5002 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5003 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5004 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5005 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5006 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5007 | if (mKeyguardDelegate != null) { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5008 | mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5009 | // ... eventually calls finishKeyguardDrawn |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5010 | } else { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5011 | if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5012 | finishKeyguardDrawn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5013 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5014 | } |
| 5015 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5016 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5017 | synchronized (mLock) { |
| 5018 | if (!mAwake || mKeyguardDrawComplete) { |
| 5019 | return; // spurious |
| 5020 | } |
| 5021 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5022 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5023 | if (mKeyguardDelegate != null) { |
| 5024 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5025 | } |
| 5026 | } |
| 5027 | |
| 5028 | finishScreenTurningOn(); |
| 5029 | } |
| 5030 | |
| 5031 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5032 | @Override |
| 5033 | public void screenTurnedOff() { |
| 5034 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 5035 | |
| 5036 | synchronized (mLock) { |
| 5037 | mScreenOnEarly = false; |
| 5038 | mScreenOnFully = false; |
| 5039 | mWindowManagerDrawComplete = false; |
| 5040 | mScreenOnListener = null; |
| 5041 | updateOrientationListenerLp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5042 | } |
| 5043 | } |
| 5044 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5045 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5046 | @Override |
| 5047 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5048 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5049 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5050 | synchronized (mLock) { |
| 5051 | mScreenOnEarly = true; |
| 5052 | mScreenOnFully = false; |
| 5053 | mWindowManagerDrawComplete = false; |
| 5054 | mScreenOnListener = screenOnListener; |
| 5055 | updateOrientationListenerLp(); |
| 5056 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5057 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 5058 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 5059 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5060 | // ... eventually calls finishWindowsDrawn |
| 5061 | } |
| 5062 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5063 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5064 | synchronized (mLock) { |
| 5065 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
| 5066 | return; // spurious |
| 5067 | } |
| 5068 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5069 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5070 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5071 | |
| 5072 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5073 | } |
| 5074 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5075 | private void finishScreenTurningOn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5076 | final ScreenOnListener listener; |
| 5077 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5078 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5079 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5080 | "finishScreenTurningOn: mAwake=" + mAwake |
| 5081 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 5082 | + ", mScreenOnFully=" + mScreenOnFully |
| 5083 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 5084 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 5085 | |
| 5086 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 5087 | || (mAwake && !mKeyguardDrawComplete)) { |
| 5088 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5091 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 5092 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 5093 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5094 | mScreenOnFully = true; |
| 5095 | |
| 5096 | // Remember the first time we draw the keyguard so we know when we're done with |
| 5097 | // the main part of booting and can enable the screen and hide boot messages. |
| 5098 | if (!mKeyguardDrawnOnce && mAwake) { |
| 5099 | mKeyguardDrawnOnce = true; |
| 5100 | enableScreen = true; |
| 5101 | if (mBootMessageNeedsHiding) { |
| 5102 | mBootMessageNeedsHiding = false; |
| 5103 | hideBootMessages(); |
| 5104 | } |
| 5105 | } else { |
| 5106 | enableScreen = false; |
| 5107 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5108 | } |
| 5109 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5110 | if (listener != null) { |
| 5111 | listener.onScreenOn(); |
| 5112 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 5113 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5114 | if (enableScreen) { |
| 5115 | try { |
| 5116 | mWindowManager.enableScreenIfNeeded(); |
| 5117 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5118 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5119 | } |
| 5120 | } |
| 5121 | |
| 5122 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5123 | synchronized (mLock) { |
| 5124 | if (!mKeyguardDrawnOnce) { |
| 5125 | mBootMessageNeedsHiding = true; |
| 5126 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 5127 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5128 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5129 | |
| 5130 | if (mBootMsgDialog != null) { |
| 5131 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 5132 | mBootMsgDialog.dismiss(); |
| 5133 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5134 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5138 | public boolean isScreenOn() { |
| 5139 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5140 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5141 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5142 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5143 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5144 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5145 | if (mKeyguardDelegate != null) { |
| 5146 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5147 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5148 | } |
| 5149 | |
| 5150 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5151 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5152 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5153 | if (mKeyguardDelegate != null) { |
| 5154 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5155 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5156 | } |
| 5157 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 5158 | private boolean keyguardIsShowingTq() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5159 | if (mKeyguardDelegate == null) return false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5160 | return mKeyguardDelegate.isShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5161 | } |
| 5162 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5163 | |
| 5164 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5165 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5166 | public boolean isKeyguardLocked() { |
| 5167 | return keyguardOn(); |
| 5168 | } |
| 5169 | |
| 5170 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5171 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5172 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5173 | if (mKeyguardDelegate == null) return false; |
| 5174 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5175 | } |
| 5176 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 5177 | // Returns true if keyguard is currently locked whether or not it is currently hidden. |
| 5178 | private boolean isKeyguardSecureIncludingHidden() { |
| 5179 | return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing(); |
| 5180 | } |
| 5181 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5182 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5183 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5184 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5185 | if (mKeyguardDelegate == null) return false; |
| 5186 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5187 | } |
| 5188 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5189 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5190 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5191 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5192 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5193 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5194 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 5195 | // ask the keyguard to prompt the user to authenticate if necessary |
| 5196 | mKeyguardDelegate.dismiss(); |
| 5197 | } |
| 5198 | }); |
| 5199 | } |
| 5200 | } |
| 5201 | |
| 5202 | public void notifyActivityDrawnForKeyguardLw() { |
| 5203 | if (mKeyguardDelegate != null) { |
| 5204 | mHandler.post(new Runnable() { |
| 5205 | @Override |
| 5206 | public void run() { |
| 5207 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5208 | } |
| 5209 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5210 | } |
| 5211 | } |
| 5212 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5213 | @Override |
| 5214 | public boolean isKeyguardDrawnLw() { |
| 5215 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5216 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5217 | } |
| 5218 | } |
| 5219 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5220 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5221 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5222 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5223 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5224 | } |
| 5225 | } |
| 5226 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5227 | void sendCloseSystemWindows() { |
| 5228 | sendCloseSystemWindows(mContext, null); |
| 5229 | } |
| 5230 | |
| 5231 | void sendCloseSystemWindows(String reason) { |
| 5232 | sendCloseSystemWindows(mContext, reason); |
| 5233 | } |
| 5234 | |
| 5235 | static void sendCloseSystemWindows(Context context, String reason) { |
| 5236 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 5237 | try { |
| 5238 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 5239 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5240 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5241 | } |
| 5242 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 5243 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5244 | @Override |
| 5245 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5246 | if (false) { |
| 5247 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 5248 | + orientation + ", last=" + lastRotation |
| 5249 | + "); user=" + mUserRotation + " " |
| 5250 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 5251 | ? "USER_ROTATION_LOCKED" : "") |
| 5252 | ); |
| 5253 | } |
| 5254 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 5255 | if (mForceDefaultOrientation) { |
| 5256 | return Surface.ROTATION_0; |
| 5257 | } |
| 5258 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5259 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5260 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 5261 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 5262 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5263 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5264 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5265 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5266 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5267 | // Ignore sensor when lid switch is open and rotation is forced. |
| 5268 | preferredRotation = mLidOpenRotation; |
| 5269 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5270 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5271 | // Ignore sensor when in car dock unless explicitly enabled. |
| 5272 | // This case can override the behavior of NOSENSOR, and can also |
| 5273 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5274 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5275 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 5276 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5277 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 5278 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5279 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5280 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 5281 | // This case can override the behavior of NOSENSOR, and can also |
| 5282 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5283 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5284 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5285 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 5286 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 5287 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5288 | preferredRotation = mDemoHdmiRotation; |
| 5289 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 5290 | && mUndockedHdmiRotation >= 0) { |
| 5291 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 5292 | // been specified in the configuration (only for legacy devices without |
| 5293 | // full multi-display support). |
| 5294 | // Note that the dock orientation overrides the HDMI orientation. |
| 5295 | preferredRotation = mUndockedHdmiRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5296 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 5297 | // Application just wants to remain locked in the last rotation. |
| 5298 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5299 | } else if (!mSupportAutoRotation) { |
| 5300 | // If we don't support auto-rotation then bail out here and ignore |
| 5301 | // the sensor and any rotation lock settings. |
| 5302 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5303 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5304 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5305 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 5306 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 5307 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 5308 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5309 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 5310 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5311 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 5312 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 5313 | // Otherwise, use sensor only if requested by the application or enabled |
| 5314 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5315 | if (mAllowAllRotations < 0) { |
| 5316 | // Can't read this during init() because the context doesn't |
| 5317 | // have display metrics at that time so we cannot determine |
| 5318 | // tablet vs. phone then. |
| 5319 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 5320 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 5321 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5322 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5323 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5324 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5325 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5326 | preferredRotation = sensorRotation; |
| 5327 | } else { |
| 5328 | preferredRotation = lastRotation; |
| 5329 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5330 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 5331 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 5332 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 5333 | // The idea is that the user rotation expresses a weak preference for the direction |
| 5334 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 5335 | // 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] | 5336 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5337 | } else { |
| 5338 | // No overriding preference. |
| 5339 | // We will do exactly what the application asked us to do. |
| 5340 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5341 | } |
| 5342 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5343 | switch (orientation) { |
| 5344 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5345 | // Return portrait unless overridden. |
| 5346 | if (isAnyPortrait(preferredRotation)) { |
| 5347 | return preferredRotation; |
| 5348 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5349 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5350 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5351 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5352 | // Return landscape unless overridden. |
| 5353 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5354 | return preferredRotation; |
| 5355 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5356 | return mLandscapeRotation; |
| 5357 | |
| 5358 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5359 | // Return reverse portrait unless overridden. |
| 5360 | if (isAnyPortrait(preferredRotation)) { |
| 5361 | return preferredRotation; |
| 5362 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5363 | return mUpsideDownRotation; |
| 5364 | |
| 5365 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5366 | // Return seascape unless overridden. |
| 5367 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5368 | return preferredRotation; |
| 5369 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5370 | return mSeascapeRotation; |
| 5371 | |
| 5372 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5373 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5374 | // Return either landscape rotation. |
| 5375 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5376 | return preferredRotation; |
| 5377 | } |
| 5378 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 5379 | return lastRotation; |
| 5380 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5381 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5382 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5383 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5384 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5385 | // Return either portrait rotation. |
| 5386 | if (isAnyPortrait(preferredRotation)) { |
| 5387 | return preferredRotation; |
| 5388 | } |
| 5389 | if (isAnyPortrait(lastRotation)) { |
| 5390 | return lastRotation; |
| 5391 | } |
| 5392 | return mPortraitRotation; |
| 5393 | |
| 5394 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5395 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 5396 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5397 | if (preferredRotation >= 0) { |
| 5398 | return preferredRotation; |
| 5399 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5400 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 5401 | } |
| 5402 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5403 | } |
| 5404 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5405 | @Override |
| 5406 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 5407 | switch (orientation) { |
| 5408 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 5409 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 5410 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 5411 | return isAnyPortrait(rotation); |
| 5412 | |
| 5413 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 5414 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 5415 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 5416 | return isLandscapeOrSeascape(rotation); |
| 5417 | |
| 5418 | default: |
| 5419 | return true; |
| 5420 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5421 | } |
| 5422 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5423 | @Override |
| 5424 | public void setRotationLw(int rotation) { |
| 5425 | mOrientationListener.setCurrentRotation(rotation); |
| 5426 | } |
| 5427 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5428 | private boolean isLandscapeOrSeascape(int rotation) { |
| 5429 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5430 | } |
| 5431 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5432 | private boolean isAnyPortrait(int rotation) { |
| 5433 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5434 | } |
| 5435 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5436 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5437 | public int getUserRotationMode() { |
| 5438 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 5439 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 5440 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 5441 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5442 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5443 | |
| 5444 | // 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] | 5445 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5446 | public void setUserRotationMode(int mode, int rot) { |
| 5447 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5448 | |
| 5449 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5450 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5451 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5452 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5453 | rot, |
| 5454 | UserHandle.USER_CURRENT); |
| 5455 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5456 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5457 | 0, |
| 5458 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5459 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5460 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5461 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5462 | 1, |
| 5463 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5464 | } |
| 5465 | } |
| 5466 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5467 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5468 | public void setSafeMode(boolean safeMode) { |
| 5469 | mSafeMode = safeMode; |
| 5470 | performHapticFeedbackLw(null, safeMode |
| 5471 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 5472 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5473 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5474 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 5475 | static long[] getLongIntArray(Resources r, int resid) { |
| 5476 | int[] ar = r.getIntArray(resid); |
| 5477 | if (ar == null) { |
| 5478 | return null; |
| 5479 | } |
| 5480 | long[] out = new long[ar.length]; |
| 5481 | for (int i=0; i<ar.length; i++) { |
| 5482 | out[i] = ar[i]; |
| 5483 | } |
| 5484 | return out; |
| 5485 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5486 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5487 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5488 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5489 | public void systemReady() { |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 5490 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null); |
| 5491 | mKeyguardDelegate.onSystemReady(); |
| 5492 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5493 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5494 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5495 | synchronized (mLock) { |
| 5496 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5497 | mSystemReady = true; |
| 5498 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5499 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5500 | public void run() { |
| 5501 | updateSettings(); |
| 5502 | } |
| 5503 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5504 | } |
| 5505 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5506 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5507 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5508 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5509 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5510 | if (mKeyguardDelegate != null) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 5511 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5512 | mKeyguardDelegate.onBootCompleted(); |
| 5513 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5514 | synchronized (mLock) { |
| 5515 | mSystemBooted = true; |
| 5516 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5517 | wakingUp(); |
| 5518 | screenTurningOn(null); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5519 | } |
| 5520 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5521 | ProgressDialog mBootMsgDialog = null; |
| 5522 | |
| 5523 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5524 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5525 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5526 | mHandler.post(new Runnable() { |
| 5527 | @Override public void run() { |
| 5528 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 5529 | int theme; |
| 5530 | if (mContext.getPackageManager().hasSystemFeature( |
| 5531 | PackageManager.FEATURE_WATCH)) { |
| 5532 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 5533 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 5534 | PackageManager.FEATURE_TELEVISION)) { |
| 5535 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 5536 | } else { |
| 5537 | theme = 0; |
| 5538 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 5539 | |
| 5540 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 5541 | // This dialog will consume all events coming in to |
| 5542 | // it, to avoid it trying to do things too early in boot. |
| 5543 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 5544 | return true; |
| 5545 | } |
| 5546 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5547 | return true; |
| 5548 | } |
| 5549 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 5550 | return true; |
| 5551 | } |
| 5552 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 5553 | return true; |
| 5554 | } |
| 5555 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 5556 | return true; |
| 5557 | } |
| 5558 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 5559 | AccessibilityEvent event) { |
| 5560 | return true; |
| 5561 | } |
| 5562 | }; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5563 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 5564 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 5565 | mBootMsgDialog.setIndeterminate(true); |
| 5566 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5567 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5568 | mBootMsgDialog.getWindow().addFlags( |
| 5569 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 5570 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 5571 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 5572 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 5573 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 5574 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5575 | mBootMsgDialog.setCancelable(false); |
| 5576 | mBootMsgDialog.show(); |
| 5577 | } |
| 5578 | mBootMsgDialog.setMessage(msg); |
| 5579 | } |
| 5580 | }); |
| 5581 | } |
| 5582 | |
| 5583 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5584 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5585 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5586 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5587 | } |
| 5588 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5589 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5590 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5591 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5592 | // *************************************** |
| 5593 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 5594 | // *************************************** |
| 5595 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 5596 | // WITH ITS LOCKS HELD. |
| 5597 | // |
| 5598 | // This code must be VERY careful about the locks |
| 5599 | // it acquires. |
| 5600 | // In fact, the current code acquires way too many, |
| 5601 | // and probably has lurking deadlocks. |
| 5602 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5603 | synchronized (mScreenLockTimeout) { |
| 5604 | if (mLockScreenTimerActive) { |
| 5605 | // reset the timer |
| 5606 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5607 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5608 | } |
| 5609 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5610 | } |
| 5611 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5612 | class ScreenLockTimeout implements Runnable { |
| 5613 | Bundle options; |
| 5614 | |
| 5615 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5616 | public void run() { |
| 5617 | synchronized (this) { |
| 5618 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5619 | if (mKeyguardDelegate != null) { |
| 5620 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5621 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5622 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5623 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5624 | } |
| 5625 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5626 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5627 | public void setLockOptions(Bundle options) { |
| 5628 | this.options = options; |
| 5629 | } |
| 5630 | } |
| 5631 | |
| 5632 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 5633 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5634 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5635 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5636 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 5637 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5638 | if (options != null) { |
| 5639 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 5640 | // until the runnable actually executes. |
| 5641 | mScreenLockTimeout.setLockOptions(options); |
| 5642 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5643 | mHandler.post(mScreenLockTimeout); |
| 5644 | } |
| 5645 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5646 | private void updateLockScreenTimeout() { |
| 5647 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5648 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5649 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5650 | if (mLockScreenTimerActive != enable) { |
| 5651 | if (enable) { |
| 5652 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 5653 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5654 | } else { |
| 5655 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 5656 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5657 | } |
| 5658 | mLockScreenTimerActive = enable; |
| 5659 | } |
| 5660 | } |
| 5661 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5662 | |
| 5663 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5664 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5665 | public void enableScreenAfterBoot() { |
| 5666 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5667 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5668 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5669 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 5670 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5671 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5672 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5673 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 5674 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5675 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5676 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5677 | |
| 5678 | synchronized (mLock) { |
| 5679 | updateWakeGestureListenerLp(); |
| 5680 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5681 | } |
| 5682 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5683 | void updateUiMode() { |
| 5684 | if (mUiModeManager == null) { |
| 5685 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 5686 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5687 | } |
| 5688 | try { |
| 5689 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 5690 | } catch (RemoteException e) { |
| 5691 | } |
| 5692 | } |
| 5693 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5694 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5695 | try { |
| 5696 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5697 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 5698 | } catch (RemoteException e) { |
| 5699 | // Ignore |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 5704 | try { |
| 5705 | //set orientation on WindowManager |
| 5706 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5707 | } catch (RemoteException e) { |
| 5708 | // Ignore |
| 5709 | } |
| 5710 | } |
| 5711 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5712 | /** |
| 5713 | * Return an Intent to launch the currently active dock app as home. Returns |
| 5714 | * null if the standard home should be launched, which is the case if any of the following is |
| 5715 | * true: |
| 5716 | * <ul> |
| 5717 | * <li>The device is not in either car mode or desk mode |
| 5718 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 5719 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 5720 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 5721 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 5722 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5723 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5724 | */ |
| 5725 | Intent createHomeDockIntent() { |
| 5726 | Intent intent = null; |
| 5727 | |
| 5728 | // What home does is based on the mode, not the dock state. That |
| 5729 | // is, when in car mode you should be taken to car home regardless |
| 5730 | // of whether we are actually in a car dock. |
| 5731 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 5732 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 5733 | intent = mCarDockIntent; |
| 5734 | } |
| 5735 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 5736 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 5737 | intent = mDeskDockIntent; |
| 5738 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5739 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 5740 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5741 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 5742 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 5743 | // Always launch dock home from home when watch is docked, if it exists. |
| 5744 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5745 | } |
| 5746 | |
| 5747 | if (intent == null) { |
| 5748 | return null; |
| 5749 | } |
| 5750 | |
| 5751 | ActivityInfo ai = null; |
| 5752 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 5753 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 5754 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 5755 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5756 | if (info != null) { |
| 5757 | ai = info.activityInfo; |
| 5758 | } |
| 5759 | if (ai != null |
| 5760 | && ai.metaData != null |
| 5761 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 5762 | intent = new Intent(intent); |
| 5763 | intent.setClassName(ai.packageName, ai.name); |
| 5764 | return intent; |
| 5765 | } |
| 5766 | |
| 5767 | return null; |
| 5768 | } |
| 5769 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5770 | void startDockOrHome() { |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 5771 | awakenDreams(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5772 | |
| 5773 | Intent dock = createHomeDockIntent(); |
| 5774 | if (dock != null) { |
| 5775 | try { |
| 5776 | mContext.startActivityAsUser(dock, UserHandle.CURRENT); |
| 5777 | return; |
| 5778 | } catch (ActivityNotFoundException e) { |
| 5779 | } |
| 5780 | } |
| 5781 | |
Dianne Hackborn | d888399 | 2012-09-07 15:58:52 -0700 | [diff] [blame] | 5782 | mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5783 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5784 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5785 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5786 | * goes to the home screen |
| 5787 | * @return whether it did anything |
| 5788 | */ |
| 5789 | boolean goHome() { |
| 5790 | if (false) { |
| 5791 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 5792 | try { |
| 5793 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 5794 | } catch (RemoteException e) { |
| 5795 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 5796 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5797 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5798 | } else { |
| 5799 | // This code brings home to the front or, if it is already |
| 5800 | // at the front, puts the device to sleep. |
| 5801 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 5802 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 5803 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 5804 | Log.d(TAG, "UTS-TEST-MODE"); |
| 5805 | } else { |
| 5806 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 5807 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5808 | Intent dock = createHomeDockIntent(); |
| 5809 | if (dock != null) { |
| 5810 | int result = ActivityManagerNative.getDefault() |
| 5811 | .startActivityAsUser(null, null, dock, |
| 5812 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 5813 | null, null, 0, |
| 5814 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5815 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5816 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 5817 | return false; |
| 5818 | } |
| 5819 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5820 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5821 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5822 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5823 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5824 | null, null, 0, |
| 5825 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 5826 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5827 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5828 | return false; |
| 5829 | } |
| 5830 | } catch (RemoteException ex) { |
| 5831 | // bummer, the activity manager, which is in this process, is dead |
| 5832 | } |
| 5833 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5834 | return true; |
| 5835 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5836 | |
| 5837 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5838 | public void setCurrentOrientationLw(int newOrientation) { |
| 5839 | synchronized (mLock) { |
| 5840 | if (newOrientation != mCurrentAppOrientation) { |
| 5841 | mCurrentAppOrientation = newOrientation; |
| 5842 | updateOrientationListenerLp(); |
| 5843 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5844 | } |
| 5845 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5846 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5847 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 5848 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 5849 | return; |
| 5850 | } |
| 5851 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 5852 | Context.AUDIO_SERVICE); |
| 5853 | if (audioManager.isSilentMode()) { |
| 5854 | return; |
| 5855 | } |
| 5856 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 5857 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 5858 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 5859 | ringTone.play(); |
| 5860 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5861 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5862 | private boolean isTheaterModeEnabled() { |
| 5863 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 5864 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 5865 | } |
| 5866 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5867 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 5868 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 5869 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 5870 | } |
| 5871 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5872 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5873 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 5874 | if (!mVibrator.hasVibrator()) { |
| 5875 | return false; |
| 5876 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5877 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 5878 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 5879 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5880 | return false; |
| 5881 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5882 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5883 | switch (effectId) { |
| 5884 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5885 | pattern = mLongPressVibePattern; |
| 5886 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5887 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5888 | pattern = mVirtualKeyVibePattern; |
| 5889 | break; |
| 5890 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 5891 | pattern = mKeyboardTapVibePattern; |
| 5892 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 5893 | case HapticFeedbackConstants.CLOCK_TICK: |
| 5894 | pattern = mClockTickVibePattern; |
| 5895 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 5896 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 5897 | pattern = mCalendarDateVibePattern; |
| 5898 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5899 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5900 | pattern = mSafeModeDisabledVibePattern; |
| 5901 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5902 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5903 | pattern = mSafeModeEnabledVibePattern; |
| 5904 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5905 | default: |
| 5906 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5907 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5908 | int owningUid; |
| 5909 | String owningPackage; |
| 5910 | if (win != null) { |
| 5911 | owningUid = win.getOwningUid(); |
| 5912 | owningPackage = win.getOwningPackage(); |
| 5913 | } else { |
| 5914 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 5915 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5916 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5917 | if (pattern.length == 1) { |
| 5918 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 5919 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5920 | } else { |
| 5921 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 5922 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5923 | } |
| 5924 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5925 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5926 | |
| 5927 | @Override |
| 5928 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5929 | } |
| 5930 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5931 | @Override |
| 5932 | public void keepScreenOnStoppedLw() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5933 | if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 5934 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5935 | } |
| 5936 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 5937 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5938 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5939 | // If there is no window focused, there will be nobody to handle the events |
| 5940 | // 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] | 5941 | WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState; |
| 5942 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5943 | return 0; |
| 5944 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5945 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5946 | // We are updating at a point where the keyguard has gotten |
| 5947 | // focus, but we were last in a state where the top window is |
| 5948 | // hiding it. This is probably because the keyguard as been |
| 5949 | // shown while the top window was displayed, so we want to ignore |
| 5950 | // it here because this is just a very transient change and it |
| 5951 | // will quickly lose focus once it correctly gets hidden. |
| 5952 | return 0; |
| 5953 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5954 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 5955 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5956 | & ~mResettingSystemUiFlags |
| 5957 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5958 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5959 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5960 | } |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5961 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5962 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5963 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 5964 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5965 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5966 | return 0; |
| 5967 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5968 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5969 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5970 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5971 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5972 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5973 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5974 | try { |
| 5975 | IStatusBarService statusbar = getStatusBarService(); |
| 5976 | if (statusbar != null) { |
| 5977 | statusbar.setSystemUiVisibility(visibility, 0xffffffff); |
| 5978 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5979 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5980 | } catch (RemoteException e) { |
| 5981 | // re-acquire status bar service next time it is needed. |
| 5982 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5983 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5984 | } |
| 5985 | }); |
| 5986 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5987 | } |
| 5988 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5989 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5990 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5991 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 5992 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5993 | : mTopFullscreenOpaqueWindowState; |
| 5994 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5995 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5996 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5997 | // prevent status bar interaction from clearing certain flags |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5998 | boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 5999 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6000 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 6001 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 6002 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6003 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6004 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6005 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 6006 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6007 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6008 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6009 | |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 6010 | if (!areTranslucentBarsAllowed() && transWin != mStatusBar) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 6011 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 6012 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6013 | } |
| 6014 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6015 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6016 | boolean immersiveSticky = |
| 6017 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6018 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6019 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6020 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6021 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 6022 | boolean hideStatusBarSysui = |
| 6023 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6024 | boolean hideNavBarSysui = |
| 6025 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6026 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6027 | boolean transientStatusBarAllowed = |
| 6028 | mStatusBar != null && ( |
| 6029 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6030 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6031 | || statusBarHasFocus); |
| 6032 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6033 | boolean transientNavBarAllowed = |
| 6034 | mNavigationBar != null && |
| 6035 | hideNavBarSysui && immersiveSticky; |
| 6036 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6037 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6038 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6039 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6040 | && !transientNavBarAllowed; |
| 6041 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6042 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6043 | clearClearableFlagsLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6044 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6045 | |
| 6046 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 6047 | |
| 6048 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6049 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 6050 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 6051 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6052 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6053 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 6054 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6055 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6056 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6057 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 6058 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6059 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6060 | } |
| 6061 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6062 | private void clearClearableFlagsLw() { |
| 6063 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6064 | if (newVal != mResettingSystemUiFlags) { |
| 6065 | mResettingSystemUiFlags = newVal; |
| 6066 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 6067 | } |
| 6068 | } |
| 6069 | |
| 6070 | private boolean isImmersiveMode(int vis) { |
| 6071 | 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] | 6072 | return mNavigationBar != null |
| 6073 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 6074 | && (vis & flags) != 0 |
| 6075 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6076 | } |
| 6077 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6078 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6079 | * @return whether the navigation or status bar can be made translucent |
| 6080 | * |
| 6081 | * This should return true unless touch exploration is not enabled or |
| 6082 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6083 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6084 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 6085 | return mTranslucentDecorEnabled |
| 6086 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6087 | } |
| 6088 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6089 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 6090 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6091 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6092 | public boolean hasNavigationBar() { |
| 6093 | return mHasNavigationBar; |
| 6094 | } |
| 6095 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 6096 | @Override |
| 6097 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 6098 | mLastInputMethodWindow = ime; |
| 6099 | mLastInputMethodTargetWindow = target; |
| 6100 | } |
| 6101 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6102 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 6103 | public int getInputMethodWindowVisibleHeightLw() { |
| 6104 | return mDockBottom - mCurBottom; |
| 6105 | } |
| 6106 | |
| 6107 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6108 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6109 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6110 | if (mKeyguardDelegate != null) { |
| 6111 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6112 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 6113 | if (mStatusBarService != null) { |
| 6114 | try { |
| 6115 | mStatusBarService.setCurrentUser(newUserId); |
| 6116 | } catch (RemoteException e) { |
| 6117 | // oh well |
| 6118 | } |
| 6119 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6120 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 6124 | public boolean canMagnifyWindow(int windowType) { |
| 6125 | switch (windowType) { |
| 6126 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 6127 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 6128 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 6129 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 6130 | return false; |
| 6131 | } |
| 6132 | } |
| 6133 | return true; |
| 6134 | } |
| 6135 | |
| 6136 | @Override |
| 6137 | public boolean isTopLevelWindow(int windowType) { |
| 6138 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 6139 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 6140 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 6141 | } |
| 6142 | return true; |
| 6143 | } |
| 6144 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 6145 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 6146 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6147 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6148 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 6149 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6150 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6151 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6152 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6153 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6154 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 6155 | || mForceClearedSystemUiFlags != 0) { |
| 6156 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 6157 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 6158 | pw.print(" mResettingSystemUiFlags=0x"); |
| 6159 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 6160 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 6161 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6162 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6163 | if (mLastFocusNeedsMenu) { |
| 6164 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 6165 | pw.println(mLastFocusNeedsMenu); |
| 6166 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6167 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 6168 | pw.println(mWakeGestureEnabledSetting); |
| 6169 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6170 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6171 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 6172 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6173 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 6174 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 6175 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 6176 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6177 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6178 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6179 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 6180 | pw.print(mCarDockEnablesAccelerometer); |
| 6181 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 6182 | pw.println(mDeskDockEnablesAccelerometer); |
| 6183 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 6184 | pw.print(mLidKeyboardAccessibility); |
| 6185 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6186 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6187 | pw.print(prefix); |
| 6188 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 6189 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6190 | pw.print(prefix); |
| 6191 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 6192 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6193 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6194 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 6195 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 6196 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 6197 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 6198 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 6199 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 6200 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 6201 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 6202 | pw.print(","); pw.print(mOverscanScreenTop); |
| 6203 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 6204 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 6205 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 6206 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 6207 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 6208 | pw.print(" top="); pw.print(mOverscanTop); |
| 6209 | pw.print(" right="); pw.print(mOverscanRight); |
| 6210 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 6211 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 6212 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 6213 | pw.print(mRestrictedOverscanScreenLeft); |
| 6214 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 6215 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 6216 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6217 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 6218 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 6219 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 6220 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 6221 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 6222 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 6223 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 6224 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 6225 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 6226 | pw.print(","); pw.print(mStableFullscreenTop); |
| 6227 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 6228 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6229 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 6230 | pw.print(","); pw.print(mStableTop); |
| 6231 | pw.print(")-("); pw.print(mStableRight); |
| 6232 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6233 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 6234 | pw.print(","); pw.print(mSystemTop); |
| 6235 | pw.print(")-("); pw.print(mSystemRight); |
| 6236 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6237 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 6238 | pw.print(","); pw.print(mCurTop); |
| 6239 | pw.print(")-("); pw.print(mCurRight); |
| 6240 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 6241 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 6242 | pw.print(","); pw.print(mContentTop); |
| 6243 | pw.print(")-("); pw.print(mContentRight); |
| 6244 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 6245 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 6246 | pw.print(","); pw.print(mVoiceContentTop); |
| 6247 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 6248 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6249 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 6250 | pw.print(","); pw.print(mDockTop); |
| 6251 | pw.print(")-("); pw.print(mDockRight); |
| 6252 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6253 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 6254 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6255 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 6256 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
| 6257 | pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6258 | if (mLastInputMethodWindow != null) { |
| 6259 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 6260 | pw.println(mLastInputMethodWindow); |
| 6261 | } |
| 6262 | if (mLastInputMethodTargetWindow != null) { |
| 6263 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 6264 | pw.println(mLastInputMethodTargetWindow); |
| 6265 | } |
| 6266 | if (mStatusBar != null) { |
| 6267 | pw.print(prefix); pw.print("mStatusBar="); |
| 6268 | pw.println(mStatusBar); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6269 | pw.print(prefix); pw.print("isStatusBarKeyguard="); |
| 6270 | pw.print(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6271 | } |
| 6272 | if (mNavigationBar != null) { |
| 6273 | pw.print(prefix); pw.print("mNavigationBar="); |
| 6274 | pw.println(mNavigationBar); |
| 6275 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6276 | if (mFocusedWindow != null) { |
| 6277 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 6278 | pw.println(mFocusedWindow); |
| 6279 | } |
| 6280 | if (mFocusedApp != null) { |
| 6281 | pw.print(prefix); pw.print("mFocusedApp="); |
| 6282 | pw.println(mFocusedApp); |
| 6283 | } |
| 6284 | if (mWinDismissingKeyguard != null) { |
| 6285 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 6286 | pw.println(mWinDismissingKeyguard); |
| 6287 | } |
| 6288 | if (mTopFullscreenOpaqueWindowState != null) { |
| 6289 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 6290 | pw.println(mTopFullscreenOpaqueWindowState); |
| 6291 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6292 | if (mForcingShowNavBar) { |
| 6293 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 6294 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 6295 | pw.println(mForcingShowNavBarLayer); |
| 6296 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6297 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6298 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6299 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 6300 | pw.print(" mForceStatusBarFromKeyguard="); |
| 6301 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6302 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 6303 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6304 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 6305 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 6306 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 6307 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 6308 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 6309 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 6310 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 6311 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 6312 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 6313 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 6314 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6315 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 6316 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 6317 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6318 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 6319 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6320 | mStatusBarController.dump(pw, prefix); |
| 6321 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6322 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6323 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6324 | if (mWakeGestureListener != null) { |
| 6325 | mWakeGestureListener.dump(pw, prefix); |
| 6326 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6327 | if (mOrientationListener != null) { |
| 6328 | mOrientationListener.dump(pw, prefix); |
| 6329 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6330 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6331 | } |