The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
Jeff Brown | 37df39a9 | 2015-02-25 15:42:31 -0800 | [diff] [blame] | 2 | * Copyright (C) 2006 The Android Open Source Project |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 17 | package com.android.server.policy; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 20 | import android.app.ActivityManagerInternal; |
| 21 | import android.app.ActivityManagerInternal.SleepToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 22 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 23 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 24 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 25 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 26 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 27 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 28 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 29 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 30 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 31 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 32 | import android.content.ContentResolver; |
| 33 | import android.content.Context; |
| 34 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 35 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 36 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 37 | import android.content.pm.ActivityInfo; |
| 38 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 39 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 40 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 41 | import android.content.res.Configuration; |
| 42 | import android.content.res.Resources; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 43 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 44 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 45 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 46 | import android.graphics.Rect; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 47 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 48 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 49 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 50 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 51 | import android.media.Ringtone; |
| 52 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 53 | import android.media.session.MediaSessionLegacyHelper; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 54 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 55 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 56 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 57 | import android.os.Handler; |
| 58 | import android.os.IBinder; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 59 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 60 | import android.os.Message; |
| 61 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 62 | import android.os.PowerManager; |
| 63 | import android.os.RemoteException; |
| 64 | import android.os.ServiceManager; |
| 65 | import android.os.SystemClock; |
| 66 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 67 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 68 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 69 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 70 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 71 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 72 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 73 | import android.service.dreams.DreamService; |
| 74 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 75 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 76 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 77 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 78 | import android.util.EventLog; |
| 79 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 80 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 81 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 82 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 83 | import android.view.Gravity; |
| 84 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 85 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 86 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 87 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 88 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 89 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 90 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 91 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 92 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 93 | import android.view.KeyEvent; |
| 94 | import android.view.MotionEvent; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 95 | import com.android.internal.policy.PhoneWindow; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 96 | import android.view.Surface; |
| 97 | import android.view.View; |
| 98 | import android.view.ViewConfiguration; |
| 99 | import android.view.Window; |
| 100 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 101 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 102 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 103 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 104 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 105 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 106 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 107 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 108 | import android.view.animation.AnimationUtils; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 109 | import com.android.internal.R; |
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; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 113 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
| 114 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 115 | |
| 116 | import java.io.File; |
| 117 | import java.io.FileReader; |
| 118 | import java.io.IOException; |
| 119 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 120 | import java.util.HashSet; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 121 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 122 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 123 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 124 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 125 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 126 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 127 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 128 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
| 129 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 130 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 131 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 132 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 133 | * introduces a new method suffix, Lp, for an internal lock of the |
| 134 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 135 | * can be acquired with either the Lw and Li lock held, so has the restrictions |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 136 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 137 | */ |
| 138 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 139 | static final String TAG = "WindowManager"; |
| 140 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 141 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 142 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 143 | static final boolean DEBUG_KEYGUARD = false; |
| 144 | static final boolean DEBUG_LAYOUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 145 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 146 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 147 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 148 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 149 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 150 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 151 | // No longer recommended for desk docks; still useful in car docks. |
| 152 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 153 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 154 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 155 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 156 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 157 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 158 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 159 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 160 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 161 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 162 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 163 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 164 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 165 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 166 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 167 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 168 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 169 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 170 | // These need to match the documentation/constant in |
| 171 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 172 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 173 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 174 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 175 | |
| 176 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 177 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 178 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 179 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 180 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 181 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 182 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 183 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 184 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 185 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 186 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 187 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 188 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 189 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 190 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 191 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 192 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 193 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 194 | /** |
| 195 | * These are the system UI flags that, when changing, can cause the layout |
| 196 | * of the screen to change. |
| 197 | */ |
| 198 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 199 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 200 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 201 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 202 | | View.NAVIGATION_BAR_TRANSLUCENT |
| 203 | | View.SYSTEM_UI_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 204 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 205 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 206 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 207 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 208 | .build(); |
| 209 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 210 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 211 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 212 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 213 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 214 | /** |
| 215 | * Keyguard stuff |
| 216 | */ |
| 217 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 218 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 219 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 220 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 221 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 222 | * |
| 223 | * These are special keys that are used to launch particular kinds of applications, |
| 224 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 225 | * usage page. We don't support quite that many yet... |
| 226 | */ |
| 227 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 228 | static { |
| 229 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 230 | sApplicationLaunchKeyCategories.append( |
| 231 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 232 | sApplicationLaunchKeyCategories.append( |
| 233 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 234 | sApplicationLaunchKeyCategories.append( |
| 235 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 236 | sApplicationLaunchKeyCategories.append( |
| 237 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 238 | sApplicationLaunchKeyCategories.append( |
| 239 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 240 | sApplicationLaunchKeyCategories.append( |
| 241 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 242 | } |
| 243 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 244 | /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ |
| 245 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
| 246 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 247 | /** |
| 248 | * Lock protecting internal state. Must not call out into window |
| 249 | * manager with lock held. (This lock will be acquired in places |
| 250 | * where the window manager is calling in with its own lock held.) |
| 251 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 252 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 253 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 254 | Context mContext; |
| 255 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 256 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 257 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 258 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 259 | ActivityManagerInternal mActivityManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 260 | DreamManagerInternal mDreamManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 261 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 262 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 263 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 264 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 265 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 266 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 267 | BurnInProtectionHelper mBurnInProtectionHelper; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 268 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 269 | // Vibrator pattern for haptic feedback of a long press. |
| 270 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 271 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 272 | // Vibrator pattern for haptic feedback of virtual key press. |
| 273 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 274 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 275 | // Vibrator pattern for a short vibration. |
| 276 | long[] mKeyboardTapVibePattern; |
| 277 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 278 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 279 | long[] mClockTickVibePattern; |
| 280 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 281 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 282 | long[] mCalendarDateVibePattern; |
| 283 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 284 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 285 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 286 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 287 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 288 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 289 | |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 290 | // Vibrator pattern for haptic feedback of a stylus button press. |
| 291 | long[] mStylusButtonPressVibePattern; |
| 292 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 293 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 294 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 295 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 296 | boolean mSafeMode; |
| 297 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 298 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 299 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 300 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 301 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 302 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 303 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 304 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 305 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 306 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 307 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 308 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 309 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 310 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 311 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 312 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 313 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 314 | } |
| 315 | }; |
| 316 | final ShowListener mKeyguardDelegateCallback = new ShowListener() { |
| 317 | @Override |
| 318 | public void onShown(IBinder windowToken) { |
| 319 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown."); |
| 320 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 321 | } |
| 322 | }; |
| 323 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 324 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 325 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 326 | WindowState mLastInputMethodWindow = null; |
| 327 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 328 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 329 | // FIXME This state is shared between the input reader and handler thread. |
| 330 | // Technically it's broken and buggy but it has been like this for many years |
| 331 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 332 | // so that only one thread is involved in handling input policy. Unfortunately |
| 333 | // it's on a critical path for power management so we can't just post the work to the |
| 334 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 335 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 336 | volatile boolean mPowerKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 337 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 338 | volatile int mPowerKeyPressCounter; |
| 339 | volatile boolean mEndCallKeyHandled; |
| 340 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 341 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 342 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 343 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 344 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 345 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 346 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 347 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 348 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 349 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 350 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 351 | boolean mHdmiPlugged; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 352 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 353 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 354 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 355 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 356 | int mCarDockRotation; |
| 357 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 358 | int mUndockedHdmiRotation; |
| 359 | int mDemoHdmiRotation; |
| 360 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 361 | int mDemoRotation; |
| 362 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 363 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 364 | boolean mWakeGestureEnabledSetting; |
| 365 | MyWakeGestureListener mWakeGestureListener; |
| 366 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 367 | // Default display does not rotate, apps that require non-default orientation will have to |
| 368 | // have the orientation emulated. |
| 369 | private boolean mForceDefaultOrientation = false; |
| 370 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 371 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 372 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 373 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 374 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 375 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 376 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 377 | boolean mCarDockEnablesAccelerometer; |
| 378 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 379 | int mLidKeyboardAccessibility; |
| 380 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 381 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 382 | int mShortPressOnPowerBehavior; |
| 383 | int mLongPressOnPowerBehavior; |
| 384 | int mDoublePressOnPowerBehavior; |
| 385 | int mTriplePressOnPowerBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 386 | int mShortPressOnSleepBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 387 | boolean mAwake; |
| 388 | boolean mScreenOnEarly; |
| 389 | boolean mScreenOnFully; |
| 390 | ScreenOnListener mScreenOnListener; |
| 391 | boolean mKeyguardDrawComplete; |
| 392 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 393 | boolean mOrientationSensorEnabled = false; |
| 394 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 395 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 396 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 397 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 398 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 399 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 400 | |
| 401 | // The last window we were told about in focusChanged. |
| 402 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 403 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 404 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 405 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 406 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 407 | // The current size of the screen; really; extends into the overscan area of |
| 408 | // the screen and doesn't account for any system elements like the status bar. |
| 409 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 410 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 411 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 412 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 413 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 414 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 415 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 416 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 417 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 418 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 419 | // if the status bar can't be hidden; in that case it effectively carves out |
| 420 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 421 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 422 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 423 | // During layout, the current screen borders accounting for any currently |
| 424 | // visible system UI elements. |
| 425 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 426 | // For applications requesting stable content insets, these are them. |
| 427 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 428 | // For applications requesting stable content insets but have also set the |
| 429 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 430 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 431 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 432 | // During layout, the current screen borders with all outer decoration |
| 433 | // (status bar, input method dock) accounted for. |
| 434 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 435 | // During layout, the frame in which content should be displayed |
| 436 | // to the user, accounting for all screen decoration except for any |
| 437 | // space they deem as available for other content. This is usually |
| 438 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 439 | // content insets. |
| 440 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 441 | // During layout, the frame in which voice content should be displayed |
| 442 | // to the user, accounting for all screen decoration except for any |
| 443 | // space they deem as available for other content. |
| 444 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 445 | // 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] | 446 | // windows are placed. |
| 447 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 448 | // During layout, the layer at which the doc window is placed. |
| 449 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 450 | // During layout, this is the layer of the status bar. |
| 451 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 452 | int mLastSystemUiFlags; |
| 453 | // Bits that we are in the process of clearing, so we want to prevent |
| 454 | // them from being set by applications until everything has been updated |
| 455 | // to have them clear. |
| 456 | int mResettingSystemUiFlags = 0; |
| 457 | // Bits that we are currently always keeping cleared. |
| 458 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 459 | // What we last reported to system UI about whether the compatibility |
| 460 | // menu needs to be displayed. |
| 461 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 462 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 463 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 464 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 465 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 466 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 467 | static final Rect mTmpParentFrame = new Rect(); |
| 468 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 469 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 470 | static final Rect mTmpContentFrame = new Rect(); |
| 471 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 472 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 473 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 474 | static final Rect mTmpNavigationFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 475 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 476 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 477 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 478 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 479 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 480 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 481 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 482 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 483 | private boolean mForceStatusBarTransparent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 484 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 485 | boolean mForcingShowNavBar; |
| 486 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 487 | |
| 488 | // States of keyguard dismiss. |
| 489 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 490 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 491 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 492 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 493 | |
| 494 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 495 | * be done once per window. */ |
| 496 | private WindowState mWinDismissingKeyguard; |
| 497 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 498 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 499 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 500 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 501 | * the wallpaper. */ |
| 502 | private WindowState mWinShowWhenLocked; |
| 503 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 504 | boolean mShowingLockscreen; |
| 505 | boolean mShowingDream; |
| 506 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 507 | boolean mDreamingSleepTokenNeeded; |
| 508 | SleepToken mDreamingSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 509 | boolean mKeyguardSecure; |
| 510 | boolean mKeyguardSecureIncludingHidden; |
| 511 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 512 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 513 | boolean mHomeConsumed; |
| 514 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 515 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 516 | Intent mCarDockIntent; |
| 517 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 518 | boolean mSearchKeyShortcutPending; |
| 519 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 520 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 521 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 522 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 523 | // support for activating the lock screen while the screen is on |
| 524 | boolean mAllowLockscreenWhenOn; |
| 525 | int mLockScreenTimeout; |
| 526 | boolean mLockScreenTimerActive; |
| 527 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 528 | // 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] | 529 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 530 | |
| 531 | // Behavior of POWER button while in-call and screen on. |
| 532 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 533 | int mIncallPowerBehavior; |
| 534 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 535 | Display mDisplay; |
| 536 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 537 | int mLandscapeRotation = 0; // default landscape rotation |
| 538 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 539 | int mPortraitRotation = 0; // default portrait rotation |
| 540 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 541 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 542 | int mOverscanLeft = 0; |
| 543 | int mOverscanTop = 0; |
| 544 | int mOverscanRight = 0; |
| 545 | int mOverscanBottom = 0; |
| 546 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 547 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 548 | private int mLongPressOnHomeBehavior; |
| 549 | |
| 550 | // What we do when the user double-taps on home |
| 551 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 552 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 553 | // Allowed theater mode wake actions |
| 554 | private boolean mAllowTheaterModeWakeFromKey; |
| 555 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 556 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 557 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 558 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 559 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 560 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 561 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 562 | // Whether to support long press from power button in non-interactive mode |
| 563 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 564 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 565 | // Whether to go to sleep entering theater mode from power button |
| 566 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 567 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 568 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 569 | // Time to volume and power must be pressed within this interval of each other. |
| 570 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 571 | // Increase the chord delay when taking a screenshot from the keyguard |
| 572 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 573 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 574 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 575 | private long mScreenshotChordVolumeDownKeyTime; |
| 576 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 577 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 578 | private boolean mScreenshotChordPowerKeyTriggered; |
| 579 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 580 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 581 | /* The number of steps between min and max brightness */ |
| 582 | private static final int BRIGHTNESS_STEPS = 10; |
| 583 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 584 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 585 | ShortcutManager mShortcutManager; |
| 586 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 587 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 588 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 589 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 590 | private int mCurrentUserId; |
| 591 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 592 | // Maps global key codes to the components that will handle them. |
| 593 | private GlobalKeyManager mGlobalKeyManager; |
| 594 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 595 | // Fallback actions by key code. |
| 596 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 597 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 598 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 599 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 600 | = new LogDecelerateInterpolator(100, 0); |
| 601 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 602 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 603 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 604 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 605 | 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] | 606 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 607 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 608 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 609 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 610 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 611 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 612 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 613 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 614 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 615 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 616 | |
| 617 | private class PolicyHandler extends Handler { |
| 618 | @Override |
| 619 | public void handleMessage(Message msg) { |
| 620 | switch (msg.what) { |
| 621 | case MSG_ENABLE_POINTER_LOCATION: |
| 622 | enablePointerLocation(); |
| 623 | break; |
| 624 | case MSG_DISABLE_POINTER_LOCATION: |
| 625 | disablePointerLocation(); |
| 626 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 627 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 628 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 629 | break; |
| 630 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 631 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 632 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 633 | case MSG_DISPATCH_SHOW_RECENTS: |
| 634 | showRecentApps(false); |
| 635 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 636 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 637 | showGlobalActionsInternal(); |
| 638 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 639 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 640 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 641 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 642 | break; |
| 643 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 644 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 645 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 646 | break; |
| 647 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 648 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 649 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 650 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 651 | case MSG_HIDE_BOOT_MESSAGE: |
| 652 | handleHideBootMessage(); |
| 653 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 654 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 655 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 656 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 657 | case MSG_POWER_DELAYED_PRESS: |
| 658 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 659 | finishPowerKeyPress(); |
| 660 | break; |
| 661 | case MSG_POWER_LONG_PRESS: |
| 662 | powerLongPress(); |
| 663 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 664 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 665 | updateDreamingSleepToken(msg.arg1 != 0); |
| 666 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 671 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 672 | @Override |
| 673 | public void onUEvent(UEventObserver.UEvent event) { |
| 674 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 675 | } |
| 676 | }; |
| 677 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 678 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 679 | SettingsObserver(Handler handler) { |
| 680 | super(handler); |
| 681 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 682 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 683 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 684 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 685 | ContentResolver resolver = mContext.getContentResolver(); |
| 686 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 687 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 688 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 689 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 690 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 691 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 692 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 693 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 694 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 695 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 696 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 697 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 698 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 699 | Settings.System.USER_ROTATION), false, this, |
| 700 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 701 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 702 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 703 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 704 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 705 | Settings.System.POINTER_LOCATION), false, this, |
| 706 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 707 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 708 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 709 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 710 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 711 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 712 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 713 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 714 | Settings.Global.POLICY_CONTROL), false, this, |
| 715 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 716 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 720 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 721 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 722 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 723 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 724 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 725 | class MyWakeGestureListener extends WakeGestureListener { |
| 726 | MyWakeGestureListener(Context context, Handler handler) { |
| 727 | super(context, handler); |
| 728 | } |
| 729 | |
| 730 | @Override |
| 731 | public void onWakeUp() { |
| 732 | synchronized (mLock) { |
| 733 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 734 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 735 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 741 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 742 | MyOrientationListener(Context context, Handler handler) { |
| 743 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 744 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 745 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 746 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 747 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 748 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 749 | updateRotation(false); |
| 750 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 751 | } |
| 752 | MyOrientationListener mOrientationListener; |
| 753 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 754 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 755 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 756 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 757 | View.NAVIGATION_BAR_TRANSIENT, |
| 758 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 759 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 760 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 761 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 762 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 763 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 764 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 765 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 766 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 767 | IStatusBarService getStatusBarService() { |
| 768 | synchronized (mServiceAquireLock) { |
| 769 | if (mStatusBarService == null) { |
| 770 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 771 | ServiceManager.getService("statusbar")); |
| 772 | } |
| 773 | return mStatusBarService; |
| 774 | } |
| 775 | } |
| 776 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 777 | /* |
| 778 | * We always let the sensor be switched on by default except when |
| 779 | * the user has explicitly disabled sensor based rotation or when the |
| 780 | * screen is switched off. |
| 781 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 782 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 783 | if (mSupportAutoRotation) { |
| 784 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 785 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 786 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 787 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 788 | // If the application has explicitly requested to follow the |
| 789 | // orientation, then we need to turn the sensor on. |
| 790 | return true; |
| 791 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 792 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 793 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 794 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 795 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 796 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 797 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 798 | // orientation management, |
| 799 | return true; |
| 800 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 801 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 802 | // If the setting for using the sensor by default is enabled, then |
| 803 | // we will always leave it on. Note that the user could go to |
| 804 | // a window that forces an orientation that does not use the |
| 805 | // sensor and in theory we could turn it off... however, when next |
| 806 | // turning it on we won't have a good value for the current |
| 807 | // orientation for a little bit, which can cause orientation |
| 808 | // changes to lag, so we'd like to keep it always on. (It will |
| 809 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 810 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 811 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 812 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 813 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 814 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 815 | /* |
| 816 | * Various use cases for invoking this function |
| 817 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 818 | * 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] | 819 | * if not already enabled |
| 820 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 821 | * already enabled |
| 822 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 823 | * screen turning on and current app has nosensor based orientation, do nothing |
| 824 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 825 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 826 | if (!mOrientationListener.canDetectOrientation()) { |
| 827 | // If sensor is turned off or nonexistent for some reason |
| 828 | return; |
| 829 | } |
| 830 | //Could have been invoked due to screen turning on or off or |
| 831 | //change of the currently visible window's orientation |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 832 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 833 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
| 834 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 835 | boolean disable = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 836 | if (mScreenOnEarly && mAwake) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 837 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 838 | disable = false; |
| 839 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 840 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 841 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 842 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 843 | mOrientationSensorEnabled = true; |
| 844 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 845 | } |
| 846 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 847 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 848 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 849 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 850 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 851 | mOrientationSensorEnabled = false; |
| 852 | } |
| 853 | } |
| 854 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 855 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 856 | // Hold a wake lock until the power key is released. |
| 857 | if (!mPowerKeyWakeLock.isHeld()) { |
| 858 | mPowerKeyWakeLock.acquire(); |
| 859 | } |
| 860 | |
| 861 | // Cancel multi-press detection timeout. |
| 862 | if (mPowerKeyPressCounter != 0) { |
| 863 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 864 | } |
| 865 | |
| 866 | // Detect user pressing the power button in panic when an application has |
| 867 | // taken over the whole screen. |
| 868 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Craig Mautner | 0124980e9 | 2014-11-30 21:15:34 -0800 | [diff] [blame] | 869 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 870 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 871 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | // Latch power key state to detect screenshot chord. |
| 875 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 876 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 877 | mScreenshotChordPowerKeyTriggered = true; |
| 878 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 879 | interceptScreenshotChord(); |
| 880 | } |
| 881 | |
| 882 | // Stop ringing or end call if configured to do so when power is pressed. |
| 883 | TelecomManager telecomManager = getTelecommService(); |
| 884 | boolean hungUp = false; |
| 885 | if (telecomManager != null) { |
| 886 | if (telecomManager.isRinging()) { |
| 887 | // Pressing Power while there's a ringing incoming |
| 888 | // call should silence the ringer. |
| 889 | telecomManager.silenceRinger(); |
| 890 | } else if ((mIncallPowerBehavior |
| 891 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 892 | && telecomManager.isInCall() && interactive) { |
| 893 | // Otherwise, if "Power button ends call" is enabled, |
| 894 | // the Power button will hang up any current active call. |
| 895 | hungUp = telecomManager.endCall(); |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | // If the power key has still not yet been handled, then detect short |
| 900 | // press, long press, or multi press and decide what to do. |
| 901 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
| 902 | || mScreenshotChordVolumeUpKeyTriggered; |
| 903 | if (!mPowerKeyHandled) { |
| 904 | if (interactive) { |
| 905 | // When interactive, we're already awake. |
| 906 | // Wait for a long press or for the button to be released to decide what to do. |
| 907 | if (hasLongPressOnPowerBehavior()) { |
| 908 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 909 | msg.setAsynchronous(true); |
| 910 | mHandler.sendMessageDelayed(msg, |
| 911 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 912 | } |
| 913 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 914 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 915 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 916 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 917 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 918 | msg.setAsynchronous(true); |
| 919 | mHandler.sendMessageDelayed(msg, |
| 920 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 921 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 922 | } else { |
| 923 | final int maxCount = getMaxMultiPressPowerCount(); |
| 924 | |
| 925 | if (maxCount <= 1) { |
| 926 | mPowerKeyHandled = true; |
| 927 | } else { |
| 928 | mBeganFromNonInteractive = true; |
| 929 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 930 | } |
| 931 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 935 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 936 | final boolean handled = canceled || mPowerKeyHandled; |
| 937 | mScreenshotChordPowerKeyTriggered = false; |
| 938 | cancelPendingScreenshotChordAction(); |
| 939 | cancelPendingPowerKeyAction(); |
| 940 | |
| 941 | if (!handled) { |
| 942 | // Figure out how to handle the key now that it has been released. |
| 943 | mPowerKeyPressCounter += 1; |
| 944 | |
| 945 | final int maxCount = getMaxMultiPressPowerCount(); |
| 946 | final long eventTime = event.getDownTime(); |
| 947 | if (mPowerKeyPressCounter < maxCount) { |
| 948 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 949 | // Continue holding the wake lock. |
| 950 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 951 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 952 | msg.setAsynchronous(true); |
| 953 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 954 | return; |
| 955 | } |
| 956 | |
| 957 | // No other actions. Handle it immediately. |
| 958 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 959 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 960 | |
| 961 | // Done. Reset our state. |
| 962 | finishPowerKeyPress(); |
| 963 | } |
| 964 | |
| 965 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 966 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 967 | mPowerKeyPressCounter = 0; |
| 968 | if (mPowerKeyWakeLock.isHeld()) { |
| 969 | mPowerKeyWakeLock.release(); |
| 970 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | private void cancelPendingPowerKeyAction() { |
| 974 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 975 | mPowerKeyHandled = true; |
| 976 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 977 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 981 | if (mScreenOnEarly && !mScreenOnFully) { |
| 982 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 983 | + "already in the process of turning the screen on."); |
| 984 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 985 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 986 | |
| 987 | if (count == 2) { |
| 988 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 989 | } else if (count == 3) { |
| 990 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 991 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 992 | switch (mShortPressOnPowerBehavior) { |
| 993 | case SHORT_PRESS_POWER_NOTHING: |
| 994 | break; |
| 995 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 996 | mPowerManager.goToSleep(eventTime, |
| 997 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 998 | break; |
| 999 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1000 | mPowerManager.goToSleep(eventTime, |
| 1001 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1002 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1003 | break; |
| 1004 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1005 | mPowerManager.goToSleep(eventTime, |
| 1006 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1007 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1008 | launchHomeFromHotKey(); |
| 1009 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1010 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1011 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1012 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1018 | switch (behavior) { |
| 1019 | case MULTI_PRESS_POWER_NOTHING: |
| 1020 | break; |
| 1021 | case MULTI_PRESS_POWER_THEATER_MODE: |
| 1022 | if (isTheaterModeEnabled()) { |
| 1023 | Slog.i(TAG, "Toggling theater mode off."); |
| 1024 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1025 | Settings.Global.THEATER_MODE_ON, 0); |
| 1026 | if (!interactive) { |
| 1027 | wakeUpFromPowerKey(eventTime); |
| 1028 | } |
| 1029 | } else { |
| 1030 | Slog.i(TAG, "Toggling theater mode on."); |
| 1031 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1032 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1033 | |
| 1034 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1035 | mPowerManager.goToSleep(eventTime, |
| 1036 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1037 | } |
| 1038 | } |
| 1039 | break; |
| 1040 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1041 | Slog.i(TAG, "Starting brightness boost."); |
| 1042 | if (!interactive) { |
| 1043 | wakeUpFromPowerKey(eventTime); |
| 1044 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1045 | mPowerManager.boostScreenBrightness(eventTime); |
| 1046 | break; |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | private int getMaxMultiPressPowerCount() { |
| 1051 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1052 | return 3; |
| 1053 | } |
| 1054 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1055 | return 2; |
| 1056 | } |
| 1057 | return 1; |
| 1058 | } |
| 1059 | |
| 1060 | private void powerLongPress() { |
| 1061 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1062 | switch (behavior) { |
| 1063 | case LONG_PRESS_POWER_NOTHING: |
| 1064 | break; |
| 1065 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1066 | mPowerKeyHandled = true; |
| 1067 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1068 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1069 | } |
| 1070 | showGlobalActionsInternal(); |
| 1071 | break; |
| 1072 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1073 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1074 | mPowerKeyHandled = true; |
| 1075 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1076 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1077 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1078 | break; |
| 1079 | } |
| 1080 | } |
| 1081 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1082 | private void sleepPress(KeyEvent event) { |
| 1083 | switch (mShortPressOnSleepBehavior) { |
| 1084 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
| 1085 | mPowerManager.goToSleep(event.getEventTime(), |
| 1086 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
| 1087 | break; |
| 1088 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1089 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1090 | mPowerManager.goToSleep(event.getEventTime(), |
| 1091 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
| 1092 | break; |
| 1093 | } |
| 1094 | } |
| 1095 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1096 | private int getResolvedLongPressOnPowerBehavior() { |
| 1097 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1098 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1099 | } |
| 1100 | return mLongPressOnPowerBehavior; |
| 1101 | } |
| 1102 | |
| 1103 | private boolean hasLongPressOnPowerBehavior() { |
| 1104 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1108 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1109 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1110 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1111 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1112 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1113 | && now <= mScreenshotChordPowerKeyTime |
| 1114 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1115 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1116 | cancelPendingPowerKeyAction(); |
| 1117 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1118 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1123 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1124 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1125 | // Double the time it takes to take a screenshot from the keyguard |
| 1126 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1127 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1128 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1129 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1132 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1133 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1136 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1137 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1138 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1139 | mEndCallKeyHandled = true; |
| 1140 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1141 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1142 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1143 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1144 | } |
| 1145 | }; |
| 1146 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1147 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1148 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1149 | public void run() { |
| 1150 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1151 | } |
| 1152 | }; |
| 1153 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1154 | @Override |
| 1155 | public void showGlobalActions() { |
| 1156 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1157 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1158 | } |
| 1159 | |
| 1160 | void showGlobalActionsInternal() { |
| 1161 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1162 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1163 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1164 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1165 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1166 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1167 | if (keyguardShowing) { |
| 1168 | // since it took two seconds of long press to bring this up, |
| 1169 | // 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] | 1170 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1175 | return Settings.Global.getInt( |
| 1176 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1177 | } |
| 1178 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1179 | boolean isUserSetupComplete() { |
| 1180 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1181 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1182 | } |
| 1183 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1184 | private void handleShortPressOnHome() { |
| 1185 | // If there's a dream running then use home to escape the dream |
| 1186 | // but don't actually go home. |
| 1187 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1188 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1189 | return; |
| 1190 | } |
| 1191 | |
| 1192 | // Go home! |
| 1193 | launchHomeFromHotKey(); |
| 1194 | } |
| 1195 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1196 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1197 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1198 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1199 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1200 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1201 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 1202 | toggleRecentApps(); |
| 1203 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 1204 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1205 | } |
| 1206 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1207 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1208 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1209 | private void handleDoubleTapOnHome() { |
| 1210 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1211 | mHomeConsumed = true; |
| 1212 | toggleRecentApps(); |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1217 | @Override |
| 1218 | public void run() { |
| 1219 | if (mHomeDoubleTapPending) { |
| 1220 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1221 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | }; |
| 1225 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1226 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1227 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1228 | } |
| 1229 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1230 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1231 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1232 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1233 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1234 | mContext = context; |
| 1235 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1236 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1237 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1238 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1239 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1240 | |
| 1241 | // Init display burn-in protection |
| 1242 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1243 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1244 | // Allow a system property to override this. Used by developer settings. |
| 1245 | boolean burnInProtectionDevMode = |
| 1246 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1247 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1248 | final int minHorizontal; |
| 1249 | final int maxHorizontal; |
| 1250 | final int minVertical; |
| 1251 | final int maxVertical; |
| 1252 | final int maxRadius; |
| 1253 | if (burnInProtectionDevMode) { |
| 1254 | minHorizontal = -8; |
| 1255 | maxHorizontal = 8; |
| 1256 | minVertical = -8; |
| 1257 | maxVertical = -4; |
| 1258 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1259 | } else { |
| 1260 | Resources resources = context.getResources(); |
| 1261 | minHorizontal = resources.getInteger( |
| 1262 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1263 | maxHorizontal = resources.getInteger( |
| 1264 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1265 | minVertical = resources.getInteger( |
| 1266 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1267 | maxVertical = resources.getInteger( |
| 1268 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1269 | maxRadius = resources.getInteger( |
| 1270 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1271 | } |
| 1272 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1273 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1274 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1275 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1276 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1277 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1278 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1279 | try { |
| 1280 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1281 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1282 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1283 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1284 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1285 | mUiMode = context.getResources().getInteger( |
| 1286 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1287 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1288 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1289 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1290 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1291 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1292 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1293 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1294 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1295 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1296 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1297 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1298 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1299 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1300 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1301 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1302 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1303 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1304 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1305 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1306 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1307 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1308 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1309 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1310 | mCarDockRotation = readRotation( |
| 1311 | com.android.internal.R.integer.config_carDockRotation); |
| 1312 | mDeskDockRotation = readRotation( |
| 1313 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1314 | mUndockedHdmiRotation = readRotation( |
| 1315 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1316 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1317 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1318 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1319 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1320 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1321 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1322 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1323 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1324 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1325 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1326 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1327 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1328 | |
| 1329 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1330 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1331 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1332 | || mContext.getResources().getBoolean( |
| 1333 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1334 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1335 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1336 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1337 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1338 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1339 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1340 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1341 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1342 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1343 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1344 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1345 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1346 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1347 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1348 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1349 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1350 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1351 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1352 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1353 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1354 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1355 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1356 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1357 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1358 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1359 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1360 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1361 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1362 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1363 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1364 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1365 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1366 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1367 | Context.ACCESSIBILITY_SERVICE); |
| 1368 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1369 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1370 | IntentFilter filter = new IntentFilter(); |
| 1371 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1372 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1373 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1374 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1375 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1376 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1377 | if (intent != null) { |
| 1378 | // Retrieve current sticky dock event broadcast. |
| 1379 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1380 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1381 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1382 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1383 | // register for dream-related broadcasts |
| 1384 | filter = new IntentFilter(); |
| 1385 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1386 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1387 | context.registerReceiver(mDreamReceiver, filter); |
| 1388 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1389 | // register for multiuser-relevant broadcasts |
| 1390 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1391 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1392 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1393 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1394 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1395 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1396 | @Override |
| 1397 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1398 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1399 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1400 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1401 | } |
| 1402 | @Override |
| 1403 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1404 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1405 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1406 | } |
| 1407 | } |
| 1408 | @Override |
| 1409 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1410 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1411 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1412 | } |
| 1413 | } |
| 1414 | @Override |
| 1415 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1416 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1417 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1418 | @Override |
| 1419 | public void onDown() { |
| 1420 | mOrientationListener.onTouchStart(); |
| 1421 | } |
| 1422 | @Override |
| 1423 | public void onUpOrCancel() { |
| 1424 | mOrientationListener.onTouchEnd(); |
| 1425 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1426 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1427 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1428 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1429 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1430 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1431 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1432 | com.android.internal.R.array.config_longPressVibePattern); |
| 1433 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1434 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1435 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1436 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1437 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1438 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1439 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1440 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1441 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1442 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1443 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1444 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 1445 | mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1446 | com.android.internal.R.array.config_stylusButtonPressVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1447 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1448 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1449 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1450 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1451 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1452 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1453 | // Controls rotation and the like. |
| 1454 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1455 | |
| 1456 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1457 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 1458 | goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1459 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1460 | |
| 1461 | mWindowManagerInternal.registerAppTransitionListener( |
| 1462 | mStatusBarController.getAppTransitionListener()); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1465 | /** |
| 1466 | * Read values from config.xml that may be overridden depending on |
| 1467 | * the configuration of the device. |
| 1468 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1469 | */ |
| 1470 | private void readConfigurationDependentBehaviors() { |
| 1471 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1472 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1473 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1474 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1475 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1476 | } |
| 1477 | |
| 1478 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1479 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1480 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1481 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1482 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1483 | } |
| 1484 | } |
| 1485 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1486 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1487 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1488 | // This method might be called before the policy has been fully initialized |
| 1489 | // or for other displays we don't care about. |
| 1490 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1491 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1492 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1493 | mDisplay = display; |
| 1494 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1495 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1496 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1497 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1498 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1499 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1500 | mLandscapeRotation = Surface.ROTATION_0; |
| 1501 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1502 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1503 | mPortraitRotation = Surface.ROTATION_90; |
| 1504 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1505 | } else { |
| 1506 | mPortraitRotation = Surface.ROTATION_270; |
| 1507 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1508 | } |
| 1509 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1510 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1511 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1512 | mPortraitRotation = Surface.ROTATION_0; |
| 1513 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1514 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1515 | mLandscapeRotation = Surface.ROTATION_270; |
| 1516 | mSeascapeRotation = Surface.ROTATION_90; |
| 1517 | } else { |
| 1518 | mLandscapeRotation = Surface.ROTATION_90; |
| 1519 | mSeascapeRotation = Surface.ROTATION_270; |
| 1520 | } |
| 1521 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1522 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1523 | mStatusBarHeight = |
| 1524 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1525 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1526 | // Height of the navigation bar when presented horizontally at bottom |
| 1527 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1528 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1529 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1530 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1531 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1532 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1533 | |
| 1534 | // Width of the navigation bar when presented vertically along one side |
| 1535 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1536 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1537 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1538 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1539 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1540 | |
| 1541 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1542 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1543 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1544 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 1545 | // Allow the navigation bar to move on non-square small devices (phones). |
| 1546 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1547 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1548 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1549 | // Allow a system property to override this. Used by the emulator. |
| 1550 | // See also hasNavigationBar(). |
| 1551 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1552 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1553 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1554 | } else if ("0".equals(navBarOverride)) { |
| 1555 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1556 | } |
| 1557 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1558 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1559 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1560 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1561 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1562 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1563 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1564 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1565 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1566 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 1567 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 1568 | // By default, remote display locks rotation to landscape. |
| 1569 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 1570 | mDemoRotation = mPortraitRotation; |
| 1571 | } else { |
| 1572 | mDemoRotation = mLandscapeRotation; |
| 1573 | } |
| 1574 | mDemoRotationLock = SystemProperties.getBoolean( |
| 1575 | "persist.demo.rotationlock", false); |
| 1576 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1577 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1578 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1579 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1580 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1581 | // For debug purposes the next line turns this feature off with: |
| 1582 | // $ adb shell setprop config.override_forced_orient true |
| 1583 | // $ adb shell wm size reset |
| 1584 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1585 | } |
| 1586 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1587 | /** |
| 1588 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1589 | * navigation bar and touch exploration is not enabled |
| 1590 | */ |
| 1591 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1592 | return mHasNavigationBar |
| 1593 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1596 | @Override |
| 1597 | public boolean isDefaultOrientationForced() { |
| 1598 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1601 | @Override |
| 1602 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1603 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1604 | mOverscanLeft = left; |
| 1605 | mOverscanTop = top; |
| 1606 | mOverscanRight = right; |
| 1607 | mOverscanBottom = bottom; |
| 1608 | } |
| 1609 | } |
| 1610 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1611 | public void updateSettings() { |
| 1612 | ContentResolver resolver = mContext.getContentResolver(); |
| 1613 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1614 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1615 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1616 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1617 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1618 | UserHandle.USER_CURRENT); |
| 1619 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1620 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1621 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1622 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1623 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1624 | // Configure wake gesture. |
| 1625 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1626 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1627 | UserHandle.USER_CURRENT) != 0; |
| 1628 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1629 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1630 | updateWakeGestureListenerLp(); |
| 1631 | } |
| 1632 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1633 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1634 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1635 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1636 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1637 | if (mUserRotation != userRotation) { |
| 1638 | mUserRotation = userRotation; |
| 1639 | updateRotation = true; |
| 1640 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1641 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1642 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1643 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1644 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1645 | if (mUserRotationMode != userRotationMode) { |
| 1646 | mUserRotationMode = userRotationMode; |
| 1647 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1648 | updateOrientationListenerLp(); |
| 1649 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1650 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1651 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1652 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1653 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1654 | if (mPointerLocationMode != pointerLocation) { |
| 1655 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1656 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1657 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1661 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1662 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1663 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1664 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1665 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1666 | if (mHasSoftInput != hasSoftInput) { |
| 1667 | mHasSoftInput = hasSoftInput; |
| 1668 | updateRotation = true; |
| 1669 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1670 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1671 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1672 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1673 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1674 | } |
| 1675 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1676 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1677 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1680 | private void updateWakeGestureListenerLp() { |
| 1681 | if (shouldEnableWakeGestureLp()) { |
| 1682 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1683 | } else { |
| 1684 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1689 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1690 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1691 | && mWakeGestureListener.isSupported(); |
| 1692 | } |
| 1693 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1694 | private void enablePointerLocation() { |
| 1695 | if (mPointerLocationView == null) { |
| 1696 | mPointerLocationView = new PointerLocationView(mContext); |
| 1697 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1698 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1699 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1700 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1701 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1702 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1703 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1704 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1705 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1706 | if (ActivityManager.isHighEndGfx()) { |
| 1707 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1708 | lp.privateFlags |= |
| 1709 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1710 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1711 | lp.format = PixelFormat.TRANSLUCENT; |
| 1712 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1713 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1714 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1715 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1716 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1717 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1718 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1719 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1720 | |
| 1721 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1722 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1723 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1724 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1725 | wm.removeView(mPointerLocationView); |
| 1726 | mPointerLocationView = null; |
| 1727 | } |
| 1728 | } |
| 1729 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1730 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1731 | try { |
| 1732 | int rotation = mContext.getResources().getInteger(resID); |
| 1733 | switch (rotation) { |
| 1734 | case 0: |
| 1735 | return Surface.ROTATION_0; |
| 1736 | case 90: |
| 1737 | return Surface.ROTATION_90; |
| 1738 | case 180: |
| 1739 | return Surface.ROTATION_180; |
| 1740 | case 270: |
| 1741 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1742 | } |
| 1743 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1744 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1745 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1746 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1750 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1751 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1752 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1753 | |
| 1754 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1755 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 1756 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 1757 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 1758 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 1759 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 1760 | } |
| 1761 | |
| 1762 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 1763 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1764 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1765 | } |
| 1766 | String permission = null; |
| 1767 | switch (type) { |
| 1768 | case TYPE_TOAST: |
| 1769 | // XXX right now the app process has complete control over |
| 1770 | // this... should introduce a token to let the system |
| 1771 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1772 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1773 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1774 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1775 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1776 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1777 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1778 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1779 | case TYPE_ACCESSIBILITY_OVERLAY: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1780 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1781 | break; |
| 1782 | case TYPE_PHONE: |
| 1783 | case TYPE_PRIORITY_PHONE: |
| 1784 | case TYPE_SYSTEM_ALERT: |
| 1785 | case TYPE_SYSTEM_ERROR: |
| 1786 | case TYPE_SYSTEM_OVERLAY: |
| 1787 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1788 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1789 | break; |
| 1790 | default: |
| 1791 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1792 | } |
| 1793 | if (permission != null) { |
| 1794 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1795 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1796 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1797 | } |
| 1798 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1799 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1800 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1801 | |
| 1802 | @Override |
| 1803 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1804 | |
| 1805 | // If this switch statement is modified, modify the comment in the declarations of |
| 1806 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1807 | switch (attrs.type) { |
| 1808 | default: |
| 1809 | // These are the windows that by default are shown only to the user that created |
| 1810 | // them. If this needs to be overridden, set |
| 1811 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1812 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1813 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1814 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1815 | return true; |
| 1816 | } |
| 1817 | break; |
| 1818 | |
| 1819 | // These are the windows that by default are shown to all users. However, to |
| 1820 | // protect against spoofing, check permissions below. |
| 1821 | case TYPE_APPLICATION_STARTING: |
| 1822 | case TYPE_BOOT_PROGRESS: |
| 1823 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1824 | case TYPE_INPUT_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1825 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1826 | case TYPE_KEYGUARD_DIALOG: |
| 1827 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1828 | case TYPE_NAVIGATION_BAR: |
| 1829 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1830 | case TYPE_PHONE: |
| 1831 | case TYPE_POINTER: |
| 1832 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1833 | case TYPE_SEARCH_BAR: |
| 1834 | case TYPE_STATUS_BAR: |
| 1835 | case TYPE_STATUS_BAR_PANEL: |
| 1836 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1837 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1838 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1839 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1840 | break; |
| 1841 | } |
| 1842 | |
| 1843 | // Check if third party app has set window to system window type. |
| 1844 | return mContext.checkCallingOrSelfPermission( |
| 1845 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1846 | != PackageManager.PERMISSION_GRANTED; |
| 1847 | } |
| 1848 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1849 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1850 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1851 | switch (attrs.type) { |
| 1852 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1853 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1854 | // These types of windows can't receive input events. |
| 1855 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1856 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1857 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1858 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1859 | case TYPE_STATUS_BAR: |
| 1860 | |
| 1861 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 1862 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 1863 | // the keyguard as occluded wouldn't set these flags again. |
| 1864 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 1865 | if (mKeyguardHidden) { |
| 1866 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 1867 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1868 | } |
| 1869 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1870 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 1871 | |
| 1872 | if (attrs.type != TYPE_STATUS_BAR) { |
| 1873 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 1874 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1875 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1876 | |
| 1877 | if (ActivityManager.isHighEndGfx() |
| 1878 | && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
Adrian Roos | f5e9b5c | 2014-09-10 15:27:41 +0200 | [diff] [blame] | 1879 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1880 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1881 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1882 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1883 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1884 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1885 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1886 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1887 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 1888 | private void readCameraLensCoverState() { |
| 1889 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 1890 | } |
| 1891 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1892 | private boolean isHidden(int accessibilityMode) { |
| 1893 | switch (accessibilityMode) { |
| 1894 | case 1: |
| 1895 | return mLidState == LID_CLOSED; |
| 1896 | case 2: |
| 1897 | return mLidState == LID_OPEN; |
| 1898 | default: |
| 1899 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1900 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1901 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1902 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1903 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1904 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1905 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1906 | int navigationPresence) { |
| 1907 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1908 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1909 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1910 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1911 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1912 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1913 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1914 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1915 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1916 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1917 | if (!mHasSoftInput) { |
| 1918 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1919 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1920 | } |
| 1921 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1922 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1923 | || (navigationPresence == PRESENCE_INTERNAL |
| 1924 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1925 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1926 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1927 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1928 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1929 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1930 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1931 | public int windowTypeToLayerLw(int type) { |
| 1932 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1933 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1934 | } |
| 1935 | switch (type) { |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1936 | case TYPE_PRIVATE_PRESENTATION: |
| 1937 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1938 | case TYPE_WALLPAPER: |
| 1939 | // wallpaper is at the bottom, though the window manager may move it. |
| 1940 | return 2; |
| 1941 | case TYPE_PHONE: |
| 1942 | return 3; |
| 1943 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 1944 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1945 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1946 | case TYPE_VOICE_INTERACTION: |
| 1947 | // voice interaction layer is almost immediately above apps. |
| 1948 | return 5; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1949 | case TYPE_INPUT_CONSUMER: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1950 | return 6; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1951 | case TYPE_SYSTEM_DIALOG: |
| 1952 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1953 | case TYPE_TOAST: |
| 1954 | // toasts and the plugged-in battery thing |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1955 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1956 | case TYPE_PRIORITY_PHONE: |
| 1957 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1958 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1959 | case TYPE_DREAM: |
| 1960 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1961 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1962 | case TYPE_SYSTEM_ALERT: |
| 1963 | // like the ANR / app crashed dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1964 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1965 | case TYPE_INPUT_METHOD: |
| 1966 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1967 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1968 | case TYPE_INPUT_METHOD_DIALOG: |
| 1969 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1970 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1971 | case TYPE_KEYGUARD_SCRIM: |
| 1972 | // the safety window that shows behind keyguard while keyguard is starting |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1973 | return 14; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1974 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1975 | return 15; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1976 | case TYPE_STATUS_BAR: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1977 | return 16; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1978 | case TYPE_STATUS_BAR_PANEL: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1979 | return 17; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1980 | case TYPE_KEYGUARD_DIALOG: |
| 1981 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1982 | case TYPE_VOLUME_OVERLAY: |
| 1983 | // the on-screen volume indicator and controller shown when the user |
| 1984 | // changes the device volume |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1985 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1986 | case TYPE_SYSTEM_OVERLAY: |
| 1987 | // the on-screen volume indicator and controller shown when the user |
| 1988 | // changes the device volume |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1989 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1990 | case TYPE_NAVIGATION_BAR: |
| 1991 | // the navigation bar, if available, shows atop most things |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1992 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1993 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1994 | // some panels (e.g. search) need to show on top of the navigation bar |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1995 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1996 | case TYPE_SYSTEM_ERROR: |
| 1997 | // system-level error dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1998 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1999 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2000 | // used to highlight the magnified portion of a display |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2001 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2002 | case TYPE_DISPLAY_OVERLAY: |
| 2003 | // used to simulate secondary display devices |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2004 | return 25; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2005 | case TYPE_DRAG: |
| 2006 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2007 | // which sits above all other focusable windows |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2008 | return 26; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2009 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2010 | // overlay put by accessibility services to intercept user interaction |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2011 | return 27; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2012 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2013 | return 28; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2014 | case TYPE_BOOT_PROGRESS: |
| 2015 | return 29; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2016 | case TYPE_POINTER: |
| 2017 | // the (mouse) pointer layer |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2018 | return 30; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2019 | } |
| 2020 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2021 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2025 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2026 | public int subWindowTypeToLayerLw(int type) { |
| 2027 | switch (type) { |
| 2028 | case TYPE_APPLICATION_PANEL: |
| 2029 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2030 | return APPLICATION_PANEL_SUBLAYER; |
| 2031 | case TYPE_APPLICATION_MEDIA: |
| 2032 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2033 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2034 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2035 | case TYPE_APPLICATION_SUB_PANEL: |
| 2036 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2037 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2038 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2039 | } |
| 2040 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2041 | return 0; |
| 2042 | } |
| 2043 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2044 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2045 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2046 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2049 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2050 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2051 | if (mHasNavigationBar) { |
| 2052 | // For a basic navigation bar, when we are in landscape mode we place |
| 2053 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2054 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 2055 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2056 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2057 | } |
| 2058 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2059 | } |
| 2060 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2061 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2062 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2063 | if (mHasNavigationBar) { |
| 2064 | // For a basic navigation bar, when we are in portrait mode we place |
| 2065 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2066 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 2067 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2073 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2074 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 2075 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2078 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2079 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2080 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2081 | // 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] | 2082 | // we do want to exclude it since applications can't generally use that part |
| 2083 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2084 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2085 | } |
| 2086 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2087 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 2088 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 2089 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2090 | (isKeyguardHostWindow(attrs) && |
| 2091 | (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 2092 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2093 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2094 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2095 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2096 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2097 | return attrs.type == TYPE_STATUS_BAR; |
| 2098 | } |
| 2099 | |
| 2100 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2101 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2102 | switch (attrs.type) { |
| 2103 | case TYPE_STATUS_BAR: |
| 2104 | case TYPE_NAVIGATION_BAR: |
| 2105 | case TYPE_WALLPAPER: |
| 2106 | case TYPE_DREAM: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2107 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2108 | return false; |
| 2109 | default: |
| 2110 | return true; |
| 2111 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2112 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2113 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2114 | @Override |
| 2115 | public WindowState getWinShowWhenLockedLw() { |
| 2116 | return mWinShowWhenLocked; |
| 2117 | } |
| 2118 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2119 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2120 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2121 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2122 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2123 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2124 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2125 | return null; |
| 2126 | } |
| 2127 | if (packageName == null) { |
| 2128 | return null; |
| 2129 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2130 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2131 | WindowManager wm = null; |
| 2132 | View view = null; |
| 2133 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2134 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2135 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2136 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2137 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2138 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2139 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2140 | try { |
| 2141 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2142 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2143 | } catch (PackageManager.NameNotFoundException e) { |
| 2144 | // Ignore |
| 2145 | } |
| 2146 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2147 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 2148 | Window win = new PhoneWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2149 | final TypedArray ta = win.getWindowStyle(); |
| 2150 | if (ta.getBoolean( |
| 2151 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 2152 | || ta.getBoolean( |
| 2153 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2154 | return null; |
| 2155 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2156 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2157 | Resources r = context.getResources(); |
| 2158 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2159 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2160 | win.setType( |
| 2161 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2162 | |
| 2163 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2164 | // Assumes it's safe to show starting windows of launched apps while |
| 2165 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2166 | // secret information. |
| 2167 | if (mKeyguardHidden) { |
| 2168 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2169 | } |
| 2170 | } |
| 2171 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2172 | // Force the window flags: this is a fake window, so it is not really |
| 2173 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2174 | // flag because we do know that the next window will take input |
| 2175 | // focus, so we want to get the IME window up on top of us right away. |
| 2176 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2177 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2178 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2179 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2180 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2181 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2182 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2183 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2184 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2185 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2186 | win.setDefaultIcon(icon); |
| 2187 | win.setDefaultLogo(logo); |
| 2188 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2189 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2190 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2191 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2192 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2193 | params.token = appToken; |
| 2194 | params.packageName = packageName; |
| 2195 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2196 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2197 | params.privateFlags |= |
| 2198 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2199 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2200 | |
| 2201 | if (!compatInfo.supportsScreen()) { |
| 2202 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2203 | } |
| 2204 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2205 | params.setTitle("Starting " + packageName); |
| 2206 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2207 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2208 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2209 | |
| 2210 | if (win.isFloating()) { |
| 2211 | // Whoops, there is no way to display an animation/preview |
| 2212 | // of such a thing! After all that work... let's skip it. |
| 2213 | // (Note that we must do this here because it is in |
| 2214 | // getDecorView() where the theme is evaluated... maybe |
| 2215 | // we should peek the floating attribute from the theme |
| 2216 | // earlier.) |
| 2217 | return null; |
| 2218 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2219 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2220 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2221 | TAG, "Adding starting window for " + packageName |
| 2222 | + " / " + appToken + ": " |
| 2223 | + (view.getParent() != null ? view : null)); |
| 2224 | |
| 2225 | wm.addView(view, params); |
| 2226 | |
| 2227 | // Only return the view if it was successfully added to the |
| 2228 | // window manager... which we can tell by it having a parent. |
| 2229 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2230 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2231 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2232 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2233 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2234 | } catch (RuntimeException e) { |
| 2235 | // don't crash if something else bad happens, for example a |
| 2236 | // failure loading resources because we are loading from an app |
| 2237 | // on external storage that has been unmounted. |
| 2238 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2239 | } finally { |
| 2240 | if (view != null && view.getParent() == null) { |
| 2241 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2242 | wm.removeViewImmediate(view); |
| 2243 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | return null; |
| 2247 | } |
| 2248 | |
| 2249 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2250 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2251 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2252 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2253 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2254 | |
| 2255 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2256 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2257 | wm.removeView(window); |
| 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | /** |
| 2262 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2263 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2264 | * Currently enforces that three window types are singletons: |
| 2265 | * <ul> |
| 2266 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2267 | * <li>KEYGUARD_TYPE</li> |
| 2268 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2269 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2270 | * @param win The window to be added |
| 2271 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2272 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2273 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2274 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2275 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2276 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2277 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2278 | switch (attrs.type) { |
| 2279 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2280 | mContext.enforceCallingOrSelfPermission( |
| 2281 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2282 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2283 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2284 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2285 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2286 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2287 | } |
| 2288 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2289 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2290 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2291 | case TYPE_NAVIGATION_BAR: |
| 2292 | mContext.enforceCallingOrSelfPermission( |
| 2293 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2294 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2295 | if (mNavigationBar != null) { |
| 2296 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2297 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2298 | } |
| 2299 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2300 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2301 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2302 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2303 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2304 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2305 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2306 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2307 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2308 | mContext.enforceCallingOrSelfPermission( |
| 2309 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2310 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2311 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2312 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2313 | if (mKeyguardScrim != null) { |
| 2314 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2315 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2316 | mKeyguardScrim = win; |
| 2317 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2318 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2319 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2323 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2324 | public void removeWindowLw(WindowState win) { |
| 2325 | if (mStatusBar == win) { |
| 2326 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2327 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2328 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2329 | } else if (mKeyguardScrim == win) { |
| 2330 | Log.v(TAG, "Removing keyguard scrim"); |
| 2331 | mKeyguardScrim = null; |
| 2332 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2333 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2334 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2339 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2340 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2341 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2342 | public int selectAnimationLw(WindowState win, int transit) { |
| 2343 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2344 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2345 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2346 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2347 | if (transit == TRANSIT_EXIT |
| 2348 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2349 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2350 | } else if (transit == TRANSIT_ENTER |
| 2351 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2352 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2353 | } |
| 2354 | } else if (win == mNavigationBar) { |
| 2355 | // This can be on either the bottom or the right. |
| 2356 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2357 | if (transit == TRANSIT_EXIT |
| 2358 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2359 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2360 | } else if (transit == TRANSIT_ENTER |
| 2361 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2362 | return R.anim.dock_bottom_enter; |
| 2363 | } |
| 2364 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2365 | if (transit == TRANSIT_EXIT |
| 2366 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2367 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2368 | } else if (transit == TRANSIT_ENTER |
| 2369 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2370 | return R.anim.dock_right_enter; |
| 2371 | } |
| 2372 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2376 | if (win.hasAppShownWindows()) { |
| 2377 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2378 | return com.android.internal.R.anim.app_starting_exit; |
| 2379 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2380 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2381 | && transit == TRANSIT_ENTER) { |
| 2382 | // Special case: we are animating in a dream, while the keyguard |
| 2383 | // is shown. We don't want an animation on the dream, because |
| 2384 | // we need it shown immediately with the keyguard animating away |
| 2385 | // to reveal it. |
| 2386 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | return 0; |
| 2390 | } |
| 2391 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2392 | @Override |
| 2393 | public void selectRotationAnimationLw(int anim[]) { |
| 2394 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2395 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2396 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2397 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2398 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2399 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2400 | case ROTATION_ANIMATION_CROSSFADE: |
| 2401 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2402 | anim[1] = R.anim.rotation_animation_enter; |
| 2403 | break; |
| 2404 | case ROTATION_ANIMATION_JUMPCUT: |
| 2405 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2406 | anim[1] = R.anim.rotation_animation_enter; |
| 2407 | break; |
| 2408 | case ROTATION_ANIMATION_ROTATE: |
| 2409 | default: |
| 2410 | anim[0] = anim[1] = 0; |
| 2411 | break; |
| 2412 | } |
| 2413 | } else { |
| 2414 | anim[0] = anim[1] = 0; |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | @Override |
| 2419 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2420 | boolean forceDefault) { |
| 2421 | switch (exitAnimId) { |
| 2422 | case R.anim.rotation_animation_xfade_exit: |
| 2423 | case R.anim.rotation_animation_jump_exit: |
| 2424 | // These are the only cases that matter. |
| 2425 | if (forceDefault) { |
| 2426 | return false; |
| 2427 | } |
| 2428 | int anim[] = new int[2]; |
| 2429 | selectRotationAnimationLw(anim); |
| 2430 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2431 | default: |
| 2432 | return true; |
| 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2437 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2438 | boolean goingToNotificationShade) { |
| 2439 | if (goingToNotificationShade) { |
| 2440 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2441 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2442 | |
| 2443 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 2444 | R.anim.lock_screen_behind_enter_wallpaper : |
| 2445 | R.anim.lock_screen_behind_enter); |
| 2446 | |
| 2447 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2448 | final List<Animation> animations = set.getAnimations(); |
| 2449 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 2450 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 2451 | } |
| 2452 | |
| 2453 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | |
| 2457 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2458 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2459 | if (goingToNotificationShade) { |
| 2460 | return null; |
| 2461 | } else { |
| 2462 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2463 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2464 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2465 | |
| 2466 | private static void awakenDreams() { |
| 2467 | IDreamManager dreamManager = getDreamManager(); |
| 2468 | if (dreamManager != null) { |
| 2469 | try { |
| 2470 | dreamManager.awaken(); |
| 2471 | } catch (RemoteException e) { |
| 2472 | // fine, stay asleep then |
| 2473 | } |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | static IDreamManager getDreamManager() { |
| 2478 | return IDreamManager.Stub.asInterface( |
| 2479 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2480 | } |
| 2481 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2482 | TelecomManager getTelecommService() { |
| 2483 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2484 | } |
| 2485 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2486 | static IAudioService getAudioService() { |
| 2487 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2488 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2489 | if (audioService == null) { |
| 2490 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2491 | } |
| 2492 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2496 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2500 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2501 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2502 | }; |
| 2503 | |
| 2504 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2505 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2506 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2507 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2508 | final int keyCode = event.getKeyCode(); |
| 2509 | final int repeatCount = event.getRepeatCount(); |
| 2510 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2511 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2512 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2513 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2514 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2515 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2516 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2517 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2518 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2519 | } |
| 2520 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2521 | // If we think we might have a volume down & power key chord on the way |
| 2522 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2523 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2524 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2525 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2526 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2527 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2528 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2529 | if (now < timeoutTime) { |
| 2530 | return timeoutTime - now; |
| 2531 | } |
| 2532 | } |
| 2533 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2534 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2535 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2536 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2537 | } |
| 2538 | return -1; |
| 2539 | } |
| 2540 | } |
| 2541 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2542 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2543 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2544 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2545 | mPendingMetaAction = false; |
| 2546 | } |
| 2547 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2548 | // First we always handle the home key here, so applications |
| 2549 | // can never break it, although if keyguard is on, we do let |
| 2550 | // it handle it, because that gives us the correct 5 second |
| 2551 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2552 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2553 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2554 | // If we have released the home key, and didn't do anything else |
| 2555 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2556 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2557 | cancelPreloadRecentApps(); |
| 2558 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2559 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2560 | if (mHomeConsumed) { |
| 2561 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2562 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2563 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2564 | |
| 2565 | if (canceled) { |
| 2566 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2567 | return -1; |
| 2568 | } |
| 2569 | |
Yorke Lee | 4f80324 | 2014-12-15 23:22:06 +0000 | [diff] [blame] | 2570 | // If an incoming call is ringing, HOME is totally disabled. |
| 2571 | // (The user is already on the InCallUI at this point, |
| 2572 | // and his ONLY options are to answer or reject the call.) |
| 2573 | TelecomManager telecomManager = getTelecommService(); |
| 2574 | if (telecomManager != null && telecomManager.isRinging()) { |
| 2575 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2576 | return -1; |
| 2577 | } |
| 2578 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2579 | // Delay handling home if a double-tap is possible. |
| 2580 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2581 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2582 | mHomeDoubleTapPending = true; |
| 2583 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2584 | ViewConfiguration.getDoubleTapTimeout()); |
| 2585 | return -1; |
| 2586 | } |
| 2587 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2588 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2589 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2590 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2591 | |
| 2592 | // If a system window has focus, then it doesn't make sense |
| 2593 | // right now to interact with applications. |
| 2594 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2595 | if (attrs != null) { |
| 2596 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2597 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2598 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2599 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2600 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2601 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2602 | } |
| 2603 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2604 | for (int i=0; i<typeCount; i++) { |
| 2605 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2606 | // 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] | 2607 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2608 | } |
| 2609 | } |
| 2610 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2611 | |
| 2612 | // Remember that home is pressed and handle special actions. |
| 2613 | if (repeatCount == 0) { |
| 2614 | mHomePressed = true; |
| 2615 | if (mHomeDoubleTapPending) { |
| 2616 | mHomeDoubleTapPending = false; |
| 2617 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2618 | handleDoubleTapOnHome(); |
| 2619 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2620 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2621 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2622 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2623 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2624 | if (!keyguardOn) { |
| 2625 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2626 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2627 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2628 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2629 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2630 | // Hijack modified menu keys for debugging features |
| 2631 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2632 | |
| 2633 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2634 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2635 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2636 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2637 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2638 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2639 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2640 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2641 | Intent service = new Intent(); |
| 2642 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2643 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2644 | boolean shown = Settings.Global.getInt( |
| 2645 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2646 | if (!shown) { |
| 2647 | mContext.startService(service); |
| 2648 | } else { |
| 2649 | mContext.stopService(service); |
| 2650 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2651 | Settings.Global.putInt( |
| 2652 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2653 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2654 | } |
| 2655 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2656 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2657 | if (down) { |
| 2658 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2659 | mSearchKeyShortcutPending = true; |
| 2660 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2661 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2662 | } else { |
| 2663 | mSearchKeyShortcutPending = false; |
| 2664 | if (mConsumeSearchKeyUp) { |
| 2665 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2666 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2667 | } |
| 2668 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2669 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2670 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2671 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2672 | if (down && repeatCount == 0) { |
| 2673 | preloadRecentApps(); |
| 2674 | } else if (!down) { |
| 2675 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2676 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2677 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2678 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 2679 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 2680 | if (down) { |
| 2681 | IStatusBarService service = getStatusBarService(); |
| 2682 | if (service != null) { |
| 2683 | try { |
| 2684 | service.expandNotificationsPanel(); |
| 2685 | } catch (RemoteException e) { |
| 2686 | // do nothing. |
| 2687 | } |
| 2688 | } |
| 2689 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2690 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2691 | if (down) { |
| 2692 | if (repeatCount == 0) { |
| 2693 | mAssistKeyLongPressed = false; |
| 2694 | } else if (repeatCount == 1) { |
| 2695 | mAssistKeyLongPressed = true; |
| 2696 | if (!keyguardOn) { |
| 2697 | launchAssistLongPressAction(); |
| 2698 | } |
| 2699 | } |
| 2700 | } else { |
| 2701 | if (mAssistKeyLongPressed) { |
| 2702 | mAssistKeyLongPressed = false; |
| 2703 | } else { |
| 2704 | if (!keyguardOn) { |
| 2705 | launchAssistAction(); |
| 2706 | } |
| 2707 | } |
| 2708 | } |
| 2709 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2710 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2711 | if (!down) { |
| 2712 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2713 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2714 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2715 | } else { |
| 2716 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2717 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2718 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2719 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2720 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2721 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2722 | if (down && repeatCount == 0) { |
| 2723 | mHandler.post(mScreenshotRunnable); |
| 2724 | } |
| 2725 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2726 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2727 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2728 | if (down) { |
| 2729 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2730 | |
| 2731 | // Disable autobrightness if it's on |
| 2732 | int auto = Settings.System.getIntForUser( |
| 2733 | mContext.getContentResolver(), |
| 2734 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2735 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2736 | UserHandle.USER_CURRENT_OR_SELF); |
| 2737 | if (auto != 0) { |
| 2738 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2739 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2740 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2741 | UserHandle.USER_CURRENT_OR_SELF); |
| 2742 | } |
| 2743 | |
| 2744 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2745 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2746 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2747 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2748 | Settings.System.SCREEN_BRIGHTNESS, |
| 2749 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2750 | UserHandle.USER_CURRENT_OR_SELF); |
| 2751 | brightness += step; |
| 2752 | // Make sure we don't go beyond the limits. |
| 2753 | brightness = Math.min(max, brightness); |
| 2754 | brightness = Math.max(min, brightness); |
| 2755 | |
| 2756 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2757 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2758 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2759 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 2760 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2761 | } |
| 2762 | return -1; |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2763 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2764 | if (down) { |
| 2765 | mPendingMetaAction = true; |
| 2766 | } else if (mPendingMetaAction) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2767 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2768 | } |
| 2769 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2770 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2771 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2772 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2773 | // Any printing key that is chorded with Search should be consumed |
| 2774 | // even if no shortcut was invoked. This prevents text from being |
| 2775 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2776 | // 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] | 2777 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2778 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2779 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2780 | mConsumeSearchKeyUp = true; |
| 2781 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2782 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2783 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2784 | if (shortcutIntent != null) { |
| 2785 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2786 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2787 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2788 | } catch (ActivityNotFoundException ex) { |
| 2789 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2790 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2791 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2792 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2793 | } else { |
| 2794 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2795 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2796 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2797 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2798 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2799 | } |
| 2800 | } |
| 2801 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2802 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2803 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2804 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2805 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2806 | if (kcm.isPrintingKey(keyCode)) { |
| 2807 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2808 | metaState & ~(KeyEvent.META_META_ON |
| 2809 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2810 | if (shortcutIntent != null) { |
| 2811 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2812 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2813 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2814 | } catch (ActivityNotFoundException ex) { |
| 2815 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2816 | + "the activity to which it is registered was not found: " |
| 2817 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2818 | } |
| 2819 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2820 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2821 | } |
| 2822 | } |
| 2823 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2824 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2825 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2826 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2827 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2828 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2829 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2830 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2831 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2832 | } catch (ActivityNotFoundException ex) { |
| 2833 | Slog.w(TAG, "Dropping application launch key because " |
| 2834 | + "the activity to which it is registered was not found: " |
| 2835 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2836 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2837 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2838 | } |
| 2839 | } |
| 2840 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2841 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2842 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2843 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2844 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2845 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2846 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 2847 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2848 | return -1; |
| 2849 | } |
| 2850 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2851 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 2852 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 2853 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2854 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2855 | } |
| 2856 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2857 | // Handle keyboard language switching. |
| 2858 | if (down && repeatCount == 0 |
| 2859 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2860 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2861 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2862 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2863 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2864 | return -1; |
| 2865 | } |
| 2866 | if (mLanguageSwitchKeyPressed && !down |
| 2867 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2868 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2869 | mLanguageSwitchKeyPressed = false; |
| 2870 | return -1; |
| 2871 | } |
| 2872 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2873 | if (isValidGlobalKey(keyCode) |
| 2874 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2875 | return -1; |
| 2876 | } |
| 2877 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2878 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2879 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2880 | return -1; |
| 2881 | } |
| 2882 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2883 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2884 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2885 | } |
| 2886 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2887 | /** {@inheritDoc} */ |
| 2888 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2889 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2890 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2891 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2892 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2893 | + ", flags=" + event.getFlags() |
| 2894 | + ", keyCode=" + event.getKeyCode() |
| 2895 | + ", scanCode=" + event.getScanCode() |
| 2896 | + ", metaState=" + event.getMetaState() |
| 2897 | + ", repeatCount=" + event.getRepeatCount() |
| 2898 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2899 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2900 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2901 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2902 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2903 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2904 | final int keyCode = event.getKeyCode(); |
| 2905 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2906 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2907 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2908 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2909 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2910 | final FallbackAction fallbackAction; |
| 2911 | if (initialDown) { |
| 2912 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2913 | } else { |
| 2914 | fallbackAction = mFallbackActions.get(keyCode); |
| 2915 | } |
| 2916 | |
| 2917 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2918 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2919 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2920 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2921 | } |
| 2922 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2923 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2924 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2925 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2926 | event.getAction(), fallbackAction.keyCode, |
| 2927 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2928 | event.getDeviceId(), event.getScanCode(), |
| 2929 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2930 | |
| 2931 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2932 | fallbackEvent.recycle(); |
| 2933 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2934 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2935 | |
| 2936 | if (initialDown) { |
| 2937 | mFallbackActions.put(keyCode, fallbackAction); |
| 2938 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2939 | mFallbackActions.remove(keyCode); |
| 2940 | fallbackAction.recycle(); |
| 2941 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2945 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2946 | if (fallbackEvent == null) { |
| 2947 | Slog.d(TAG, "No fallback."); |
| 2948 | } else { |
| 2949 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2950 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2951 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2952 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2955 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2956 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2957 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2958 | long delayMillis = interceptKeyBeforeDispatching( |
| 2959 | win, fallbackEvent, policyFlags); |
| 2960 | if (delayMillis == 0) { |
| 2961 | return true; |
| 2962 | } |
| 2963 | } |
| 2964 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2965 | } |
| 2966 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2967 | private void launchAssistLongPressAction() { |
| 2968 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2969 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2970 | |
| 2971 | // launch the search activity |
| 2972 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2973 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2974 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2975 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2976 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2977 | SearchManager searchManager = getSearchManager(); |
| 2978 | if (searchManager != null) { |
| 2979 | searchManager.stopSearch(); |
| 2980 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2981 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2982 | } catch (ActivityNotFoundException e) { |
| 2983 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | private void launchAssistAction() { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2988 | launchAssistAction(null); |
| 2989 | } |
| 2990 | |
| 2991 | private void launchAssistAction(String hint) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2992 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2993 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2994 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2995 | if (intent != null) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2996 | if (hint != null) { |
| 2997 | intent.putExtra(hint, true); |
| 2998 | } |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2999 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 3000 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 3001 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 3002 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3003 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3004 | } catch (ActivityNotFoundException e) { |
| 3005 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3006 | } |
| 3007 | } |
| 3008 | } |
| 3009 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3010 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3011 | if (isUserSetupComplete()) { |
| 3012 | mContext.startActivityAsUser(intent, handle); |
| 3013 | } else { |
| 3014 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3015 | } |
| 3016 | } |
| 3017 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3018 | private SearchManager getSearchManager() { |
| 3019 | if (mSearchManager == null) { |
| 3020 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3021 | } |
| 3022 | return mSearchManager; |
| 3023 | } |
| 3024 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3025 | private void preloadRecentApps() { |
| 3026 | mPreloadedRecentApps = true; |
| 3027 | try { |
| 3028 | IStatusBarService statusbar = getStatusBarService(); |
| 3029 | if (statusbar != null) { |
| 3030 | statusbar.preloadRecentApps(); |
| 3031 | } |
| 3032 | } catch (RemoteException e) { |
| 3033 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 3034 | // re-acquire status bar service next time it is needed. |
| 3035 | mStatusBarService = null; |
| 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | private void cancelPreloadRecentApps() { |
| 3040 | if (mPreloadedRecentApps) { |
| 3041 | mPreloadedRecentApps = false; |
| 3042 | try { |
| 3043 | IStatusBarService statusbar = getStatusBarService(); |
| 3044 | if (statusbar != null) { |
| 3045 | statusbar.cancelPreloadRecentApps(); |
| 3046 | } |
| 3047 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3048 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3049 | // re-acquire status bar service next time it is needed. |
| 3050 | mStatusBarService = null; |
| 3051 | } |
| 3052 | } |
| 3053 | } |
| 3054 | |
| 3055 | private void toggleRecentApps() { |
| 3056 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3057 | try { |
| 3058 | IStatusBarService statusbar = getStatusBarService(); |
| 3059 | if (statusbar != null) { |
| 3060 | statusbar.toggleRecentApps(); |
| 3061 | } |
| 3062 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3063 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 3064 | // re-acquire status bar service next time it is needed. |
| 3065 | mStatusBarService = null; |
| 3066 | } |
| 3067 | } |
| 3068 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3069 | @Override |
| 3070 | public void showRecentApps() { |
| 3071 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 3072 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 3073 | } |
| 3074 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3075 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 3076 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3077 | try { |
| 3078 | IStatusBarService statusbar = getStatusBarService(); |
| 3079 | if (statusbar != null) { |
| 3080 | statusbar.showRecentApps(triggeredFromAltTab); |
| 3081 | } |
| 3082 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3083 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 3084 | // re-acquire status bar service next time it is needed. |
| 3085 | mStatusBarService = null; |
| 3086 | } |
| 3087 | } |
| 3088 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3089 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3090 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3091 | try { |
| 3092 | IStatusBarService statusbar = getStatusBarService(); |
| 3093 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3094 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3095 | } |
| 3096 | } catch (RemoteException e) { |
| 3097 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 3098 | // re-acquire status bar service next time it is needed. |
| 3099 | mStatusBarService = null; |
| 3100 | } |
| 3101 | } |
| 3102 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3103 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3104 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3105 | } |
| 3106 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3107 | /** |
| 3108 | * A home key -> launch home action was detected. Take the appropriate action |
| 3109 | * given the situation with the keyguard. |
| 3110 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3111 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3112 | if (respectKeyguard) { |
| 3113 | if (isKeyguardShowingAndNotOccluded()) { |
| 3114 | // don't launch home if keyguard showing |
| 3115 | return; |
| 3116 | } |
| 3117 | |
| 3118 | if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
| 3119 | // when in keyguard restricted mode, must first verify unlock |
| 3120 | // before launching home |
| 3121 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3122 | @Override |
| 3123 | public void onKeyguardExitResult(boolean success) { |
| 3124 | if (success) { |
| 3125 | try { |
| 3126 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3127 | } catch (RemoteException e) { |
| 3128 | } |
| 3129 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3130 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3131 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3132 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3133 | }); |
| 3134 | return; |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | // no keyguard stuff to worry about, just launch home! |
| 3139 | try { |
| 3140 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3141 | } catch (RemoteException e) { |
| 3142 | } |
| 3143 | if (mRecentsVisible) { |
| 3144 | // Hide Recents and notify it to launch Home |
| 3145 | if (awakenFromDreams) { |
| 3146 | awakenDreams(); |
| 3147 | } |
| 3148 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3149 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3150 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3151 | // Otherwise, just launch Home |
| 3152 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3153 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3154 | } |
| 3155 | } |
| 3156 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3157 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3158 | @Override |
| 3159 | public void run() { |
| 3160 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3161 | // Clear flags. |
| 3162 | mForceClearedSystemUiFlags &= |
| 3163 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3164 | } |
| 3165 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3166 | } |
| 3167 | }; |
| 3168 | |
| 3169 | /** |
| 3170 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3171 | * to determine when the nav bar should be shown and prevent applications from |
| 3172 | * receiving those touches. |
| 3173 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3174 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3175 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3176 | super(inputChannel, looper); |
| 3177 | } |
| 3178 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3179 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3180 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3181 | boolean handled = false; |
| 3182 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3183 | if (event instanceof MotionEvent |
| 3184 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3185 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3186 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3187 | // When the user taps down, we re-show the nav bar. |
| 3188 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3189 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3190 | // Any user activity always causes us to show the |
| 3191 | // navigation controls, if they had been hidden. |
| 3192 | // We also clear the low profile and only content |
| 3193 | // flags so that tapping on the screen will atomically |
| 3194 | // restore all currently hidden screen decorations. |
| 3195 | int newVal = mResettingSystemUiFlags | |
| 3196 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3197 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3198 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3199 | if (mResettingSystemUiFlags != newVal) { |
| 3200 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3201 | changed = true; |
| 3202 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3203 | // We don't allow the system's nav bar to be hidden |
| 3204 | // again for 1 second, to prevent applications from |
| 3205 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3206 | newVal = mForceClearedSystemUiFlags | |
| 3207 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3208 | if (mForceClearedSystemUiFlags != newVal) { |
| 3209 | mForceClearedSystemUiFlags = newVal; |
| 3210 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3211 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3212 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3213 | } |
| 3214 | if (changed) { |
| 3215 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3216 | } |
| 3217 | } |
| 3218 | } |
| 3219 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3220 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3221 | } |
| 3222 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3223 | } |
| 3224 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3225 | new InputEventReceiver.Factory() { |
| 3226 | @Override |
| 3227 | public InputEventReceiver createInputEventReceiver( |
| 3228 | InputChannel inputChannel, Looper looper) { |
| 3229 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3230 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3231 | }; |
| 3232 | |
| 3233 | @Override |
| 3234 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3235 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3236 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3237 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3238 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3239 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3240 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3241 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3242 | // Clear any bits in the new visibility that are currently being |
| 3243 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3244 | return visibility & ~mResettingSystemUiFlags |
| 3245 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3246 | } |
| 3247 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3248 | @Override |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3249 | public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets, |
| 3250 | Rect outStableInsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3251 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3252 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3253 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3254 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3255 | 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] | 3256 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3257 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3258 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3259 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3260 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3261 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3262 | } else { |
| 3263 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3264 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3265 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3266 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3267 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3268 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3269 | availRight - mStableFullscreenRight, |
| 3270 | availBottom - mStableFullscreenBottom); |
| 3271 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3272 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3273 | availRight - mStableRight, availBottom - mStableBottom); |
| 3274 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3275 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3276 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3277 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3278 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3279 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3280 | availRight - mCurRight, availBottom - mCurBottom); |
| 3281 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3282 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3283 | availRight - mCurRight, availBottom - mCurBottom); |
| 3284 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3285 | |
| 3286 | outStableInsets.set(mStableLeft, mStableTop, |
| 3287 | availRight - mStableRight, availBottom - mStableBottom); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3288 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3289 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3290 | outContentInsets.setEmpty(); |
| 3291 | outStableInsets.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3292 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3293 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3294 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3295 | @Override |
| 3296 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 3297 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3298 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3299 | if (isDefaultDisplay) { |
| 3300 | switch (displayRotation) { |
| 3301 | case Surface.ROTATION_90: |
| 3302 | overscanLeft = mOverscanTop; |
| 3303 | overscanTop = mOverscanRight; |
| 3304 | overscanRight = mOverscanBottom; |
| 3305 | overscanBottom = mOverscanLeft; |
| 3306 | break; |
| 3307 | case Surface.ROTATION_180: |
| 3308 | overscanLeft = mOverscanRight; |
| 3309 | overscanTop = mOverscanBottom; |
| 3310 | overscanRight = mOverscanLeft; |
| 3311 | overscanBottom = mOverscanTop; |
| 3312 | break; |
| 3313 | case Surface.ROTATION_270: |
| 3314 | overscanLeft = mOverscanBottom; |
| 3315 | overscanTop = mOverscanLeft; |
| 3316 | overscanRight = mOverscanTop; |
| 3317 | overscanBottom = mOverscanRight; |
| 3318 | break; |
| 3319 | default: |
| 3320 | overscanLeft = mOverscanLeft; |
| 3321 | overscanTop = mOverscanTop; |
| 3322 | overscanRight = mOverscanRight; |
| 3323 | overscanBottom = mOverscanBottom; |
| 3324 | break; |
| 3325 | } |
| 3326 | } else { |
| 3327 | overscanLeft = 0; |
| 3328 | overscanTop = 0; |
| 3329 | overscanRight = 0; |
| 3330 | overscanBottom = 0; |
| 3331 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3332 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3333 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3334 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3335 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3336 | mSystemLeft = 0; |
| 3337 | mSystemTop = 0; |
| 3338 | mSystemRight = displayWidth; |
| 3339 | mSystemBottom = displayHeight; |
| 3340 | mUnrestrictedScreenLeft = overscanLeft; |
| 3341 | mUnrestrictedScreenTop = overscanTop; |
| 3342 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3343 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3344 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3345 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3346 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3347 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3348 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3349 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3350 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3351 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3352 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3353 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3354 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3355 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3356 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3357 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3358 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3359 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3360 | final Rect pf = mTmpParentFrame; |
| 3361 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3362 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3363 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3364 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3365 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3366 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3367 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3368 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3369 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3370 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3371 | if (isDefaultDisplay) { |
| 3372 | // For purposes of putting out fake window up to steal focus, we will |
| 3373 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3374 | final int sysui = mLastSystemUiFlags; |
| 3375 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3376 | boolean navTranslucent = (sysui |
| 3377 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3378 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3379 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3380 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3381 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3382 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3383 | if (!isKeyguardShowing) { |
| 3384 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3385 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3386 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3387 | // When the navigation bar isn't visible, we put up a fake |
| 3388 | // input window to catch all touch events. This way we can |
| 3389 | // detect when the user presses anywhere to bring back the nav |
| 3390 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3391 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3392 | if (mInputConsumer != null) { |
| 3393 | mInputConsumer.dismiss(); |
| 3394 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3395 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3396 | } else if (mInputConsumer == null) { |
| 3397 | mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(), |
| 3398 | mHideNavInputEventReceiverFactory); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3399 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3400 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3401 | // For purposes of positioning and showing the nav bar, if we have |
| 3402 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3403 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3404 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3405 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3406 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3407 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3408 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3409 | // Force the navigation bar to its appropriate place and |
| 3410 | // size. We need to do this directly, instead of relying on |
| 3411 | // it to bubble up from the nav bar, because this needs to |
| 3412 | // change atomically with screen rotations. |
| 3413 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 3414 | if (mNavigationBarOnBottom) { |
| 3415 | // 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] | 3416 | int top = displayHeight - overscanBottom |
| 3417 | - mNavigationBarHeightForRotation[displayRotation]; |
| 3418 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3419 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3420 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3421 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3422 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3423 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3424 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3425 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3426 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3427 | } else { |
| 3428 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3429 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3430 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3431 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3432 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3433 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3434 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3435 | // and not in the process of animating on or off, then |
| 3436 | // we can tell the app that it is covered by it. |
| 3437 | mSystemBottom = mTmpNavigationFrame.top; |
| 3438 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3439 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3440 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3441 | int left = displayWidth - overscanRight |
| 3442 | - mNavigationBarWidthForRotation[displayRotation]; |
| 3443 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3444 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3445 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3446 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3447 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3448 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3449 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3450 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3451 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3452 | } else { |
| 3453 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3454 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3455 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3456 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 3457 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3458 | // If the nav bar is currently requested to be visible, |
| 3459 | // and not in the process of animating on or off, then |
| 3460 | // we can tell the app that it is covered by it. |
| 3461 | mSystemRight = mTmpNavigationFrame.left; |
| 3462 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3463 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3464 | // Make sure the content and current rectangles are updated to |
| 3465 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3466 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3467 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3468 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3469 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3470 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3471 | // And compute the final frame. |
| 3472 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3473 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
Dianne Hackborn | 4bb6b75 | 2015-05-22 16:34:44 -0700 | [diff] [blame] | 3474 | mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3475 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3476 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3477 | updateSysUiVisibility = true; |
| 3478 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3479 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3480 | 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] | 3481 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 3482 | |
| 3483 | // decide where the status bar goes ahead of time |
| 3484 | if (mStatusBar != null) { |
| 3485 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3486 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3487 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3488 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3489 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3490 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3491 | vf.left = mStableLeft; |
| 3492 | vf.top = mStableTop; |
| 3493 | vf.right = mStableRight; |
| 3494 | vf.bottom = mStableBottom; |
| 3495 | |
| 3496 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3497 | |
| 3498 | // Let the status bar determine its size. |
Dianne Hackborn | 4bb6b75 | 2015-05-22 16:34:44 -0700 | [diff] [blame] | 3499 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3500 | |
| 3501 | // For layout, the status bar is always at the top with our fixed height. |
| 3502 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3503 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3504 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3505 | boolean statusBarTranslucent = (sysui |
| 3506 | & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3507 | if (!isKeyguardShowing) { |
| 3508 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3509 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3510 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3511 | // If the status bar is hidden, we don't want to cause |
| 3512 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 3513 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3514 | // Status bar may go away, so the screen area it occupies |
| 3515 | // is available to apps but just covering them when the |
| 3516 | // status bar is visible. |
| 3517 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3518 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3519 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3520 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3521 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3522 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3523 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3524 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3525 | String.format( |
| 3526 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3527 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3528 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3529 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3530 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3531 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3532 | && !statusBarTransient && !statusBarTranslucent |
| 3533 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3534 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3535 | // and not in the process of animating on or off, then |
| 3536 | // we can tell the app that it is covered by it. |
| 3537 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3538 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3539 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3540 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3541 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3542 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3543 | if (updateSysUiVisibility) { |
| 3544 | updateSystemUiVisibilityLw(); |
| 3545 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3546 | } |
| 3547 | } |
| 3548 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3549 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3550 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3551 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 3552 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 3553 | return mStatusBar.getSurfaceLayer(); |
| 3554 | } |
| 3555 | |
| 3556 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 3557 | return mNavigationBar.getSurfaceLayer(); |
| 3558 | } |
| 3559 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3560 | return 0; |
| 3561 | } |
| 3562 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3563 | @Override |
| 3564 | public void getContentRectLw(Rect r) { |
| 3565 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3566 | } |
| 3567 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3568 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3569 | 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] | 3570 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3571 | // Here's a special case: if this attached window is a panel that is |
| 3572 | // above the dock window, and the window it is attached to is below |
| 3573 | // the dock window, then the frames we computed for the window it is |
| 3574 | // attached to can not be used because the dock is effectively part |
| 3575 | // of the underlying window and the attached window is floating on top |
| 3576 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3577 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3578 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3579 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3580 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3581 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3582 | } else { |
| 3583 | // The effective display frame of the attached window depends on |
| 3584 | // whether it is taking care of insetting its content. If not, |
| 3585 | // we need to use the parent's content frame so that the entire |
| 3586 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3587 | // the overscan frame and let the attached window take care of |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3588 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3589 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3590 | // Set the content frame of the attached window to the parent's decor frame |
| 3591 | // (same as content frame when IME isn't present) if specifically requested by |
| 3592 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 3593 | // Otherwise, use the overscan frame. |
| 3594 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 3595 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3596 | } else { |
| 3597 | // If the window is resizing, then we want to base the content |
| 3598 | // frame on our attached content frame to resize... however, |
| 3599 | // things can be tricky if the attached window is NOT in resize |
| 3600 | // mode, in which case its content frame will be larger. |
| 3601 | // Ungh. So to deal with that, make sure the content frame |
| 3602 | // we end up using is not covering the IM dock. |
| 3603 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3604 | if (attached.isVoiceInteraction()) { |
| 3605 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3606 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3607 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3608 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3609 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3610 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3611 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3612 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3613 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3614 | } |
| 3615 | } |
| 3616 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3617 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3618 | vf.set(attached.getVisibleFrameLw()); |
| 3619 | } |
| 3620 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3621 | // window should be positioned relative to its parent or the entire |
| 3622 | // screen. |
| 3623 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3624 | ? attached.getFrameLw() : df); |
| 3625 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3626 | |
| 3627 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3628 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3629 | // If app is requesting a stable layout, don't let the |
| 3630 | // content insets go below the stable values. |
| 3631 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3632 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3633 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3634 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3635 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3636 | } else { |
| 3637 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3638 | if (r.top < mStableTop) r.top = mStableTop; |
| 3639 | if (r.right > mStableRight) r.right = mStableRight; |
| 3640 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3641 | } |
| 3642 | } |
| 3643 | } |
| 3644 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3645 | private boolean canReceiveInput(WindowState win) { |
| 3646 | boolean notFocusable = |
| 3647 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 3648 | boolean altFocusableIm = |
| 3649 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 3650 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 3651 | return !notFocusableForIm; |
| 3652 | } |
| 3653 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3654 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3655 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3656 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3657 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 3658 | // input, we need to layout it again to accomodate for the IME window. |
| 3659 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3660 | return; |
| 3661 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3662 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3663 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 3664 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3665 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 3666 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3667 | 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] | 3668 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 3669 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3670 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3671 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3672 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3673 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3674 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3675 | final Rect pf = mTmpParentFrame; |
| 3676 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3677 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3678 | final Rect cf = mTmpContentFrame; |
| 3679 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3680 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3681 | final Rect sf = mTmpStableFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3682 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3683 | |
| 3684 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3685 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3686 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 3687 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 3688 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3689 | if (isDefaultDisplay) { |
| 3690 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 3691 | } else { |
| 3692 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 3693 | } |
| 3694 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3695 | if (!isDefaultDisplay) { |
| 3696 | if (attached != null) { |
| 3697 | // If this window is attached to another, our display |
| 3698 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3699 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3700 | } else { |
| 3701 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3702 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3703 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3704 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3705 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3706 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3707 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3708 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3709 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3710 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3711 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3712 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3713 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3714 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3715 | // ...with content insets above the nav bar |
| 3716 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3717 | // IM dock windows always go to the bottom of the screen. |
| 3718 | attrs.gravity = Gravity.BOTTOM; |
| 3719 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3720 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
| 3721 | pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft; |
| 3722 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3723 | pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft |
| 3724 | + mUnrestrictedScreenWidth; |
| 3725 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3726 | + mUnrestrictedScreenHeight; |
| 3727 | cf.bottom = vf.bottom = mStableBottom; |
| 3728 | cf.top = vf.top = mStableTop; |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3729 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 3730 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3731 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3732 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3733 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 3734 | cf.left = vf.left = mStableLeft; |
| 3735 | cf.top = vf.top = mStableTop; |
| 3736 | cf.right = vf.right = mStableRight; |
| 3737 | vf.bottom = mStableBottom; |
| 3738 | cf.bottom = mContentBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3739 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3740 | |
| 3741 | // Default policy decor for the default display |
| 3742 | dcf.left = mSystemLeft; |
| 3743 | dcf.top = mSystemTop; |
| 3744 | dcf.right = mSystemRight; |
| 3745 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3746 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3747 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3748 | final boolean isAppWindow = |
| 3749 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3750 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3751 | final boolean topAtRest = |
| 3752 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3753 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3754 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3755 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3756 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 3757 | && (fl & WindowManager.LayoutParams. |
| 3758 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3759 | // Ensure policy decor includes status bar |
| 3760 | dcf.top = mStableTop; |
| 3761 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3762 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3763 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 3764 | && (fl & WindowManager.LayoutParams. |
| 3765 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3766 | // Ensure policy decor includes navigation bar |
| 3767 | dcf.bottom = mStableBottom; |
| 3768 | dcf.right = mStableRight; |
| 3769 | } |
| 3770 | } |
| 3771 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3772 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3773 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3774 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3775 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3776 | // This is the case for a normal activity window: we want it |
| 3777 | // to cover all of the screen space, and it can take care of |
| 3778 | // moving its contents to account for screen decorations that |
| 3779 | // intrude into that space. |
| 3780 | if (attached != null) { |
| 3781 | // If this window is attached to another, our display |
| 3782 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3783 | 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] | 3784 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3785 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3786 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3787 | // Status bar panels are the only windows who can go on top of |
| 3788 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3789 | // permission, so they have the same privileges as the status |
| 3790 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3791 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3792 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3793 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3794 | pf.left = df.left = of.left = hasNavBar |
| 3795 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3796 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3797 | pf.right = df.right = of.right = hasNavBar |
| 3798 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3799 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3800 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3801 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3802 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3803 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3804 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3805 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3806 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3807 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3808 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3809 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3810 | // Asking to layout into the overscan region, so give it that pure |
| 3811 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3812 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3813 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3814 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3815 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3816 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3817 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3818 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3819 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3820 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3821 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3822 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3823 | // only do this for application windows to ensure no window that |
| 3824 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3825 | pf.left = df.left = mOverscanScreenLeft; |
| 3826 | pf.top = df.top = mOverscanScreenTop; |
| 3827 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3828 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3829 | // We need to tell the app about where the frame inside the overscan |
| 3830 | // is, so it can inset its content by that amount -- it didn't ask |
| 3831 | // to actually extend itself into the overscan region. |
| 3832 | of.left = mUnrestrictedScreenLeft; |
| 3833 | of.top = mUnrestrictedScreenTop; |
| 3834 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3835 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3836 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3837 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3838 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3839 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3840 | + mRestrictedOverscanScreenWidth; |
| 3841 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3842 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3843 | // We need to tell the app about where the frame inside the overscan |
| 3844 | // is, so it can inset its content by that amount -- it didn't ask |
| 3845 | // to actually extend itself into the overscan region. |
| 3846 | of.left = mUnrestrictedScreenLeft; |
| 3847 | of.top = mUnrestrictedScreenTop; |
| 3848 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3849 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3850 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3851 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3852 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3853 | if (win.isVoiceInteraction()) { |
| 3854 | cf.left = mVoiceContentLeft; |
| 3855 | cf.top = mVoiceContentTop; |
| 3856 | cf.right = mVoiceContentRight; |
| 3857 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3858 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3859 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3860 | cf.left = mDockLeft; |
| 3861 | cf.top = mDockTop; |
| 3862 | cf.right = mDockRight; |
| 3863 | cf.bottom = mDockBottom; |
| 3864 | } else { |
| 3865 | cf.left = mContentLeft; |
| 3866 | cf.top = mContentTop; |
| 3867 | cf.right = mContentRight; |
| 3868 | cf.bottom = mContentBottom; |
| 3869 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3870 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3871 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3872 | // Full screen windows are always given a layout that is as if the |
| 3873 | // status bar and other transient decors are gone. This is to avoid |
| 3874 | // bad states when moving from a window that is not hding the |
| 3875 | // status bar to one that is. |
| 3876 | cf.left = mRestrictedScreenLeft; |
| 3877 | cf.top = mRestrictedScreenTop; |
| 3878 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3879 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3880 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3881 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3882 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3883 | vf.left = mCurLeft; |
| 3884 | vf.top = mCurTop; |
| 3885 | vf.right = mCurRight; |
| 3886 | vf.bottom = mCurBottom; |
| 3887 | } else { |
| 3888 | vf.set(cf); |
| 3889 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3890 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3891 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3892 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3893 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3894 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3895 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3896 | // A window that has requested to fill the entire screen just |
| 3897 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3898 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3899 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3900 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3901 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3902 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3903 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3904 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3905 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3906 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3907 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3908 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3909 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3910 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3911 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3912 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3913 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3914 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3915 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3916 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3917 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3918 | + mUnrestrictedScreenWidth; |
| 3919 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3920 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3921 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3922 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3923 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3924 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3925 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3926 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3927 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3928 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3929 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3930 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3931 | + mOverscanScreenWidth; |
| 3932 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3933 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 3934 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3935 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3936 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3937 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3938 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3939 | + mOverscanScreenWidth; |
| 3940 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3941 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3942 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3943 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 3944 | // it about the overscan area. |
| 3945 | pf.left = df.left = mOverscanScreenLeft; |
| 3946 | pf.top = df.top = mOverscanScreenTop; |
| 3947 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3948 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 3949 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 3950 | of.top = cf.top = mUnrestrictedScreenTop; |
| 3951 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3952 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3953 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3954 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3955 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3956 | // Asking to layout into the overscan region, so give it that pure |
| 3957 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3958 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3959 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3960 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3961 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3962 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3963 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3964 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3965 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 3966 | && (attrs.type == TYPE_STATUS_BAR |
| 3967 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 3968 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3969 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3970 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3971 | // Asking for layout as if the nav bar is hidden, lets the |
| 3972 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3973 | // 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] | 3974 | // can be above the nav bar can do this. |
| 3975 | // XXX This assumes that an app asking for this will also |
| 3976 | // ask for layout in only content. We can't currently figure out |
| 3977 | // 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] | 3978 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3979 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3980 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3981 | + mUnrestrictedScreenWidth; |
| 3982 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3983 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3984 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3985 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3986 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3987 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3988 | + mRestrictedScreenWidth; |
| 3989 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3990 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3991 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3992 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3993 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3994 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3995 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3996 | vf.left = mCurLeft; |
| 3997 | vf.top = mCurTop; |
| 3998 | vf.right = mCurRight; |
| 3999 | vf.bottom = mCurBottom; |
| 4000 | } else { |
| 4001 | vf.set(cf); |
| 4002 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4003 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4004 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4005 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4006 | // A child window should be placed inside of the same visible |
| 4007 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4008 | 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] | 4009 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4010 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4011 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4012 | // Otherwise, a normal window must be placed inside the content |
| 4013 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4014 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 4015 | // Status bar panels are the only windows who can go on top of |
| 4016 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4017 | // permission, so they have the same privileges as the status |
| 4018 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4019 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4020 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4021 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4022 | + mRestrictedScreenWidth; |
| 4023 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4024 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4025 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 4026 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 4027 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4028 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 4029 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 4030 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 4031 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4032 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4033 | pf.left = mContentLeft; |
| 4034 | pf.top = mContentTop; |
| 4035 | pf.right = mContentRight; |
| 4036 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 4037 | if (win.isVoiceInteraction()) { |
| 4038 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 4039 | df.top = of.top = cf.top = mVoiceContentTop; |
| 4040 | df.right = of.right = cf.right = mVoiceContentRight; |
| 4041 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 4042 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4043 | df.left = of.left = cf.left = mDockLeft; |
| 4044 | df.top = of.top = cf.top = mDockTop; |
| 4045 | df.right = of.right = cf.right = mDockRight; |
| 4046 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4047 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4048 | df.left = of.left = cf.left = mContentLeft; |
| 4049 | df.top = of.top = cf.top = mContentTop; |
| 4050 | df.right = of.right = cf.right = mContentRight; |
| 4051 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4052 | } |
| 4053 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4054 | vf.left = mCurLeft; |
| 4055 | vf.top = mCurTop; |
| 4056 | vf.right = mCurRight; |
| 4057 | vf.bottom = mCurBottom; |
| 4058 | } else { |
| 4059 | vf.set(cf); |
| 4060 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4061 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4062 | } |
| 4063 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4064 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 4065 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 4066 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4067 | df.left = df.top = -10000; |
| 4068 | df.right = df.bottom = 10000; |
| 4069 | if (attrs.type != TYPE_WALLPAPER) { |
| 4070 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 4071 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 4072 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4073 | } |
| 4074 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4075 | 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] | 4076 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4077 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4078 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 4079 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4080 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4081 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4082 | + " dcf=" + dcf.toShortString() |
Dianne Hackborn | 4bb6b75 | 2015-05-22 16:34:44 -0700 | [diff] [blame] | 4083 | + " sf=" + sf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4084 | |
Dianne Hackborn | 4bb6b75 | 2015-05-22 16:34:44 -0700 | [diff] [blame] | 4085 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4086 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4087 | // Dock windows carve out the bottom of the screen, so normal windows |
| 4088 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 4089 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 4090 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4091 | setLastInputMethodWindowLw(null, null); |
| 4092 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4093 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4094 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 4095 | && !win.getGivenInsetsPendingLw()) { |
| 4096 | offsetVoiceInputWindowLw(win); |
| 4097 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4098 | } |
| 4099 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4100 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4101 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4102 | top += win.getGivenContentInsetsLw().top; |
| 4103 | if (mContentBottom > top) { |
| 4104 | mContentBottom = top; |
| 4105 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4106 | if (mVoiceContentBottom > top) { |
| 4107 | mVoiceContentBottom = top; |
| 4108 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4109 | top = win.getVisibleFrameLw().top; |
| 4110 | top += win.getGivenVisibleInsetsLw().top; |
| 4111 | if (mCurBottom > top) { |
| 4112 | mCurBottom = top; |
| 4113 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4114 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4115 | + mDockBottom + " mContentBottom=" |
| 4116 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 4117 | } |
| 4118 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4119 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4120 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 4121 | top += win.getGivenContentInsetsLw().top; |
| 4122 | if (mVoiceContentBottom > top) { |
| 4123 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4124 | } |
| 4125 | } |
| 4126 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4127 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 4128 | @Override |
| 4129 | public void finishLayoutLw() { |
| 4130 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4134 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4135 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4136 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4137 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4138 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4139 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4140 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4141 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4142 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4143 | mForcingShowNavBar = false; |
| 4144 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4145 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4146 | mHideLockScreen = false; |
| 4147 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4148 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4149 | mShowingLockscreen = false; |
| 4150 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4151 | mWinShowWhenLocked = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4152 | mKeyguardSecure = isKeyguardSecure(); |
| 4153 | mKeyguardSecureIncludingHidden = mKeyguardSecure |
| 4154 | && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4158 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4159 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4160 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 4161 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4162 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4163 | if (mTopFullscreenOpaqueWindowState == null |
| 4164 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 4165 | mForcingShowNavBar = true; |
| 4166 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4167 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4168 | if (attrs.type == TYPE_STATUS_BAR) { |
| 4169 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 4170 | mForceStatusBarFromKeyguard = true; |
| 4171 | } |
| 4172 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 4173 | mForceStatusBarTransparent = true; |
| 4174 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4175 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4176 | |
| 4177 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 4178 | && attrs.type < FIRST_SYSTEM_WINDOW; |
| 4179 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 4180 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
| 4181 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4182 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 4183 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4184 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4185 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4186 | mForceStatusBarFromKeyguard = true; |
| 4187 | } else { |
| 4188 | mForceStatusBar = true; |
| 4189 | } |
| 4190 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4191 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4192 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4193 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4194 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4195 | // If the lockscreen was showing when the dream started then wait |
| 4196 | // for the dream to draw before hiding the lockscreen. |
| 4197 | if (!mDreamingLockscreen |
| 4198 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4199 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4200 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4201 | } |
| 4202 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4203 | |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4204 | if (appWindow) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4205 | final IApplicationToken appToken = win.getAppToken(); |
| 4206 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4207 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4208 | mAppsToBeHidden.remove(appToken); |
| 4209 | mAppsThatDismissKeyguard.remove(appToken); |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4210 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | 192d604 | 2014-12-02 23:24:48 -0800 | [diff] [blame] | 4211 | if (dismissKeyguard && !mKeyguardSecure) { |
| 4212 | mAppsThatDismissKeyguard.add(appToken); |
| 4213 | } else { |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4214 | mWinShowWhenLocked = win; |
| 4215 | mHideLockScreen = true; |
| 4216 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4217 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4218 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4219 | } else if (dismissKeyguard) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4220 | if (mKeyguardSecure) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4221 | mAppsToBeHidden.add(appToken); |
| 4222 | } else { |
| 4223 | mAppsToBeHidden.remove(appToken); |
| 4224 | } |
| 4225 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4226 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4227 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4228 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4229 | if (attrs.x == 0 && attrs.y == 0 |
| 4230 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4231 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 4232 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4233 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4234 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 4235 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4236 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4237 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4238 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4239 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4240 | "Setting mDismissKeyguard true by win " + win); |
| 4241 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 4242 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 4243 | mWinDismissingKeyguard = win; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4244 | mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4245 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) { |
| 4246 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4247 | "Setting mHideLockScreen to true by win " + win); |
| 4248 | mHideLockScreen = true; |
| 4249 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4250 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4251 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4252 | mAllowLockscreenWhenOn = true; |
| 4253 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4254 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4255 | |
| 4256 | if (mWinShowWhenLocked != null && |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4257 | mWinShowWhenLocked.getAppToken() != win.getAppToken() && |
| 4258 | (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4259 | win.hideLw(false); |
| 4260 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4261 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4262 | } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) { |
| 4263 | // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window |
| 4264 | // that is being hidden in an animation - keep the |
| 4265 | // keyguard hidden until the new window shows up and |
| 4266 | // we know whether to show the keyguard or not. |
Adrian Roos | b85e1ec | 2015-05-29 15:23:18 -0700 | [diff] [blame^] | 4267 | if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4268 | mHideLockScreen = true; |
| 4269 | mWinShowWhenLocked = win; |
| 4270 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4271 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4272 | if (mTopFullscreenOpaqueOrDimmingWindowState == null |
| 4273 | && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw() |
| 4274 | && win.isDimming()) { |
| 4275 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4276 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4277 | } |
| 4278 | |
| 4279 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4280 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4281 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c5e73bf | 2015-04-21 15:41:26 +0000 | [diff] [blame] | 4282 | if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null && |
| 4283 | mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken() |
| 4284 | && isKeyguardLocked()) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4285 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4286 | // fullscreen window. |
| 4287 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4288 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4289 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4290 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4291 | } |
| 4292 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4293 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4294 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4295 | |
| 4296 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4297 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4298 | : null; |
| 4299 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4300 | // If we are not currently showing a dream then remember the current |
| 4301 | // lockscreen state. We will use this to determine whether the dream |
| 4302 | // started while the lockscreen was showing and remember this state |
| 4303 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4304 | if (!mShowingDream) { |
| 4305 | mDreamingLockscreen = mShowingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 4306 | if (mDreamingSleepTokenNeeded) { |
| 4307 | mDreamingSleepTokenNeeded = false; |
| 4308 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 4309 | } |
| 4310 | } else { |
| 4311 | if (!mDreamingSleepTokenNeeded) { |
| 4312 | mDreamingSleepTokenNeeded = true; |
| 4313 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 4314 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4315 | } |
| 4316 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4317 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4318 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4319 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 4320 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4321 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 4322 | && !mForceStatusBar |
| 4323 | && !mForceStatusBarFromKeyguard; |
| 4324 | if (!shouldBeTransparent) { |
| 4325 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 4326 | } else if (!mStatusBar.isVisibleLw()) { |
| 4327 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 4328 | } |
| 4329 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4330 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4331 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4332 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4333 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4334 | // Maintain fullscreen layout until incoming animation is complete. |
| 4335 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 4336 | // Transient status bar on the lockscreen is not allowed |
| 4337 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 4338 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 4339 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 4340 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4341 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4342 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4343 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4344 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4345 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4346 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4347 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4348 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4349 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4350 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4351 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 4352 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4353 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 4354 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4355 | if (mStatusBarController.isTransientShowing()) { |
| 4356 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4357 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4358 | } |
| 4359 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4360 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4361 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4362 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4363 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 4364 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 4365 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4366 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4367 | 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] | 4368 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4369 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4370 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4371 | } |
| 4372 | } |
| 4373 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4374 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4375 | if (mTopIsFullscreen != topIsFullscreen) { |
| 4376 | if (!topIsFullscreen) { |
| 4377 | // Force another layout when status bar becomes fully shown. |
| 4378 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4379 | } |
| 4380 | mTopIsFullscreen = topIsFullscreen; |
| 4381 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4382 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4383 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 4384 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4385 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 4386 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 4387 | + mHideLockScreen); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4388 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4389 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4390 | if (setKeyguardOccludedLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4391 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4392 | | FINISH_LAYOUT_REDO_CONFIG |
| 4393 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4394 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4395 | if (mKeyguardDelegate.isShowing()) { |
| 4396 | mHandler.post(new Runnable() { |
| 4397 | @Override |
| 4398 | public void run() { |
| 4399 | mKeyguardDelegate.keyguardDone(false, false); |
| 4400 | } |
| 4401 | }); |
| 4402 | } |
| 4403 | } else if (mHideLockScreen) { |
| 4404 | mKeyguardHidden = true; |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4405 | mWinDismissingKeyguard = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4406 | if (setKeyguardOccludedLw(true)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4407 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4408 | | FINISH_LAYOUT_REDO_CONFIG |
| 4409 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4410 | } |
| 4411 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4412 | mKeyguardHidden = false; |
| 4413 | if (setKeyguardOccludedLw(false)) { |
| 4414 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4415 | | FINISH_LAYOUT_REDO_CONFIG |
| 4416 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4417 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4418 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 4419 | // Only launch the next keyguard unlock window once per window. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4420 | mHandler.post(new Runnable() { |
| 4421 | @Override |
| 4422 | public void run() { |
| 4423 | mKeyguardDelegate.dismiss(); |
| 4424 | } |
| 4425 | }); |
| 4426 | } |
| 4427 | } else { |
| 4428 | mWinDismissingKeyguard = null; |
| 4429 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4430 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4431 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4432 | | FINISH_LAYOUT_REDO_CONFIG |
| 4433 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4434 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 4435 | } |
| 4436 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4437 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4438 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4439 | // If the navigation bar has been hidden or shown, we need to do another |
| 4440 | // layout pass to update that window. |
| 4441 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4442 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4443 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4444 | // update since mAllowLockscreenWhenOn might have changed |
| 4445 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4446 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4447 | } |
| 4448 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4449 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4450 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4451 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4452 | * @return Whether the flags have changed and we have to redo the layout. |
| 4453 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4454 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
| 4455 | boolean wasOccluded = mKeyguardOccluded; |
| 4456 | boolean showing = mKeyguardDelegate.isShowing(); |
| 4457 | if (wasOccluded && !isOccluded && showing) { |
| 4458 | mKeyguardOccluded = false; |
| 4459 | mKeyguardDelegate.setOccluded(false); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4460 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4461 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4462 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4463 | } else if (!wasOccluded && isOccluded && showing) { |
| 4464 | mKeyguardOccluded = true; |
| 4465 | mKeyguardDelegate.setOccluded(true); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4466 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4467 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4468 | return true; |
| 4469 | } else { |
| 4470 | return false; |
| 4471 | } |
| 4472 | } |
| 4473 | |
| 4474 | private boolean isStatusBarKeyguard() { |
| 4475 | return mStatusBar != null |
| 4476 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4477 | } |
| 4478 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4479 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4480 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4481 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4482 | // 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] | 4483 | return false; |
| 4484 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4485 | return true; |
| 4486 | } |
| 4487 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4488 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4489 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4490 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4491 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4492 | // If the navigation bar has been hidden or shown, we need to do another |
| 4493 | // layout pass to update that window. |
| 4494 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4495 | } |
| 4496 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4497 | } |
| 4498 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4499 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4500 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4501 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4502 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4503 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4504 | if (newLidState == mLidState) { |
| 4505 | return; |
| 4506 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4507 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4508 | mLidState = newLidState; |
| 4509 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4510 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4511 | |
| 4512 | if (lidOpen) { |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4513 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4514 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4515 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4516 | } |
| 4517 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4518 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4519 | @Override |
| 4520 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 4521 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 4522 | if (mCameraLensCoverState == lensCoverState) { |
| 4523 | return; |
| 4524 | } |
| 4525 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 4526 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 4527 | Intent intent; |
| 4528 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 4529 | mKeyguardDelegate.isShowing(); |
| 4530 | if (keyguardActive) { |
| 4531 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 4532 | } else { |
| 4533 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 4534 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4535 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4536 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4537 | } |
| 4538 | mCameraLensCoverState = lensCoverState; |
| 4539 | } |
| 4540 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4541 | void setHdmiPlugged(boolean plugged) { |
| 4542 | if (mHdmiPlugged != plugged) { |
| 4543 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4544 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4545 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4546 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4547 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4548 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4549 | } |
| 4550 | } |
| 4551 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4552 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4553 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4554 | // watch for HDMI plug messages if the hdmi switch exists |
| 4555 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4556 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4557 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4558 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4559 | FileReader reader = null; |
| 4560 | try { |
| 4561 | reader = new FileReader(filename); |
| 4562 | char[] buf = new char[15]; |
| 4563 | int n = reader.read(buf); |
| 4564 | if (n > 1) { |
| 4565 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4566 | } |
| 4567 | } catch (IOException ex) { |
| 4568 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4569 | } catch (NumberFormatException ex) { |
| 4570 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4571 | } finally { |
| 4572 | if (reader != null) { |
| 4573 | try { |
| 4574 | reader.close(); |
| 4575 | } catch (IOException ex) { |
| 4576 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4577 | } |
| 4578 | } |
| 4579 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4580 | // This dance forces the code in setHdmiPlugged to run. |
| 4581 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4582 | mHdmiPlugged = !plugged; |
| 4583 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4584 | } |
| 4585 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4586 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4587 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4588 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4589 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4590 | @Override public void run() { |
| 4591 | synchronized (mScreenshotLock) { |
| 4592 | if (mScreenshotConnection != null) { |
| 4593 | mContext.unbindService(mScreenshotConnection); |
| 4594 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4595 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4596 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4597 | } |
| 4598 | }; |
| 4599 | |
| 4600 | // Assume this is called from the Handler thread. |
| 4601 | private void takeScreenshot() { |
| 4602 | synchronized (mScreenshotLock) { |
| 4603 | if (mScreenshotConnection != null) { |
| 4604 | return; |
| 4605 | } |
| 4606 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4607 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 4608 | Intent intent = new Intent(); |
| 4609 | intent.setComponent(cn); |
| 4610 | ServiceConnection conn = new ServiceConnection() { |
| 4611 | @Override |
| 4612 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 4613 | synchronized (mScreenshotLock) { |
| 4614 | if (mScreenshotConnection != this) { |
| 4615 | return; |
| 4616 | } |
| 4617 | Messenger messenger = new Messenger(service); |
| 4618 | Message msg = Message.obtain(null, 1); |
| 4619 | final ServiceConnection myConn = this; |
| 4620 | Handler h = new Handler(mHandler.getLooper()) { |
| 4621 | @Override |
| 4622 | public void handleMessage(Message msg) { |
| 4623 | synchronized (mScreenshotLock) { |
| 4624 | if (mScreenshotConnection == myConn) { |
| 4625 | mContext.unbindService(mScreenshotConnection); |
| 4626 | mScreenshotConnection = null; |
| 4627 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 4628 | } |
| 4629 | } |
| 4630 | } |
| 4631 | }; |
| 4632 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 4633 | msg.arg1 = msg.arg2 = 0; |
| 4634 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 4635 | msg.arg1 = 1; |
| 4636 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 4637 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4638 | try { |
| 4639 | messenger.send(msg); |
| 4640 | } catch (RemoteException e) { |
| 4641 | } |
| 4642 | } |
| 4643 | } |
| 4644 | @Override |
| 4645 | public void onServiceDisconnected(ComponentName name) {} |
| 4646 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 4647 | if (mContext.bindServiceAsUser( |
| 4648 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4649 | mScreenshotConnection = conn; |
| 4650 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 4651 | } |
| 4652 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4655 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4656 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4657 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4658 | if (!mSystemBooted) { |
| 4659 | // If we have not yet booted, don't let key events do anything. |
| 4660 | return 0; |
| 4661 | } |
| 4662 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4663 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4664 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 4665 | final boolean canceled = event.isCanceled(); |
| 4666 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 4667 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4668 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4669 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 4670 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 4671 | // the same as if it were open and in front. |
| 4672 | // This will prevent any keys other than the power button from waking the screen |
| 4673 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4674 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4675 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4676 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4677 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4678 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4679 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4680 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4681 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4682 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4683 | } |
| 4684 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4685 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4686 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 4687 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 4688 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4689 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4690 | // When the device is interactive or the key is injected pass the |
| 4691 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4692 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4693 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4694 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 4695 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 4696 | // to the application but preserve its wake key status to make sure we still move |
| 4697 | // from dozing to fully interactive if we would normally go from off to fully |
| 4698 | // interactive. |
| 4699 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4700 | } else { |
| 4701 | // When the screen is off and the key is not injected, determine whether |
| 4702 | // to wake the device but don't pass the key to the application. |
| 4703 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4704 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 4705 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4706 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4707 | } |
| 4708 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4709 | // If the key would be handled globally, just return the result, don't worry about special |
| 4710 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4711 | if (isValidGlobalKey(keyCode) |
| 4712 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4713 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4714 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4715 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4716 | return result; |
| 4717 | } |
| 4718 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4719 | boolean useHapticFeedback = down |
| 4720 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 4721 | && event.getRepeatCount() == 0; |
| 4722 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4723 | // Handle special keys. |
| 4724 | switch (keyCode) { |
| 4725 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 4726 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4727 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4728 | if (mUseTvRouting) { |
| 4729 | // On TVs volume keys never go to the foreground app |
| 4730 | result &= ~ACTION_PASS_TO_USER; |
| 4731 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4732 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 4733 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4734 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4735 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4736 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 4737 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 4738 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4739 | cancelPendingPowerKeyAction(); |
| 4740 | interceptScreenshotChord(); |
| 4741 | } |
| 4742 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4743 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4744 | cancelPendingScreenshotChordAction(); |
| 4745 | } |
| 4746 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 4747 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4748 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4749 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4750 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4751 | cancelPendingPowerKeyAction(); |
| 4752 | cancelPendingScreenshotChordAction(); |
| 4753 | } |
| 4754 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4755 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4756 | cancelPendingScreenshotChordAction(); |
| 4757 | } |
| 4758 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4759 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4760 | TelecomManager telecomManager = getTelecommService(); |
| 4761 | if (telecomManager != null) { |
| 4762 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4763 | // If an incoming call is ringing, either VOLUME key means |
| 4764 | // "silence ringer". We handle these keys here, rather than |
| 4765 | // in the InCallScreen, to make sure we'll respond to them |
| 4766 | // even if the InCallScreen hasn't come to the foreground yet. |
| 4767 | // Look for the DOWN event here, to agree with the "fallback" |
| 4768 | // behavior in the InCallScreen. |
| 4769 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4770 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4771 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4772 | // Silence the ringer. (It's safe to call this |
| 4773 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4774 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4775 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4776 | // And *don't* pass this key thru to the current activity |
| 4777 | // (which is probably the InCallScreen.) |
| 4778 | result &= ~ACTION_PASS_TO_USER; |
| 4779 | break; |
| 4780 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4781 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4782 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 4783 | // 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] | 4784 | // the application, just pass it to the session service. |
| 4785 | |
| 4786 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4787 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4788 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4789 | } |
| 4790 | } |
| 4791 | |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4792 | if ((result & ACTION_PASS_TO_USER) == 0) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4793 | if (mUseTvRouting) { |
| 4794 | dispatchDirectAudioEvent(event); |
| 4795 | } else { |
| 4796 | // If we aren't passing to the user and no one else |
| 4797 | // handled it send it to the session manager to |
| 4798 | // figure out. |
| 4799 | MediaSessionLegacyHelper.getHelper(mContext) |
| 4800 | .sendVolumeKeyEvent(event, true); |
| 4801 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4802 | break; |
| 4803 | } |
| 4804 | } |
| 4805 | break; |
| 4806 | } |
| 4807 | |
| 4808 | case KeyEvent.KEYCODE_ENDCALL: { |
| 4809 | result &= ~ACTION_PASS_TO_USER; |
| 4810 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4811 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4812 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4813 | if (telecomManager != null) { |
| 4814 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4815 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4816 | if (interactive && !hungUp) { |
| 4817 | mEndCallKeyHandled = false; |
| 4818 | mHandler.postDelayed(mEndCallLongPress, |
| 4819 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 4820 | } else { |
| 4821 | mEndCallKeyHandled = true; |
| 4822 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4823 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4824 | if (!mEndCallKeyHandled) { |
| 4825 | mHandler.removeCallbacks(mEndCallLongPress); |
| 4826 | if (!canceled) { |
| 4827 | if ((mEndcallBehavior |
| 4828 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 4829 | if (goHome()) { |
| 4830 | break; |
| 4831 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 4832 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4833 | if ((mEndcallBehavior |
| 4834 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 4835 | mPowerManager.goToSleep(event.getEventTime(), |
| 4836 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 4837 | isWakeKey = false; |
| 4838 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4839 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4840 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4841 | } |
| 4842 | break; |
| 4843 | } |
| 4844 | |
| 4845 | case KeyEvent.KEYCODE_POWER: { |
| 4846 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4847 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4848 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4849 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4850 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4851 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4852 | } |
| 4853 | break; |
| 4854 | } |
| 4855 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4856 | case KeyEvent.KEYCODE_SLEEP: { |
| 4857 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4858 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4859 | if (!mPowerManager.isInteractive()) { |
| 4860 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 4861 | } |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4862 | sleepPress(event); |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4863 | break; |
| 4864 | } |
| 4865 | |
| 4866 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4867 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4868 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4869 | break; |
| 4870 | } |
| 4871 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4872 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4873 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4874 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4875 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4876 | case KeyEvent.KEYCODE_MUTE: |
| 4877 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4878 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4879 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4880 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4881 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4882 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4883 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4884 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 4885 | // If the global session is active pass all media keys to it |
| 4886 | // instead of the active window. |
| 4887 | result &= ~ACTION_PASS_TO_USER; |
| 4888 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4889 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4890 | // Only do this if we would otherwise not pass it to the user. In that |
| 4891 | // case, the PhoneWindow class will do the same thing, except it will |
| 4892 | // 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] | 4893 | // Note that we need to make a copy of the key event here because the |
| 4894 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4895 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4896 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4897 | new KeyEvent(event)); |
| 4898 | msg.setAsynchronous(true); |
| 4899 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4900 | } |
| 4901 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4902 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4903 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4904 | case KeyEvent.KEYCODE_CALL: { |
| 4905 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4906 | TelecomManager telecomManager = getTelecommService(); |
| 4907 | if (telecomManager != null) { |
| 4908 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4909 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4910 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4911 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4912 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4913 | // And *don't* pass this key thru to the current activity |
| 4914 | // (which is presumably the InCallScreen.) |
| 4915 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4916 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4917 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4918 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4919 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4920 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 4921 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 4922 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 4923 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 4924 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 4925 | // key event here because the original key event will be recycled when we return. |
| 4926 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 4927 | mBroadcastWakeLock.acquire(); |
| 4928 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 4929 | keyguardActive ? 1 : 0, 0); |
| 4930 | msg.setAsynchronous(true); |
| 4931 | msg.sendToTarget(); |
| 4932 | } |
| 4933 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4934 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4935 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4936 | if (useHapticFeedback) { |
| 4937 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 4938 | } |
| 4939 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4940 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4941 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4942 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4943 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4944 | return result; |
| 4945 | } |
| 4946 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4947 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4948 | * Returns true if the key can have global actions attached to it. |
| 4949 | * We reserve all power management keys for the system since they require |
| 4950 | * very careful handling. |
| 4951 | */ |
| 4952 | private static boolean isValidGlobalKey(int keyCode) { |
| 4953 | switch (keyCode) { |
| 4954 | case KeyEvent.KEYCODE_POWER: |
| 4955 | case KeyEvent.KEYCODE_WAKEUP: |
| 4956 | case KeyEvent.KEYCODE_SLEEP: |
| 4957 | return false; |
| 4958 | default: |
| 4959 | return true; |
| 4960 | } |
| 4961 | } |
| 4962 | |
| 4963 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4964 | * When the screen is off we ignore some keys that might otherwise typically |
| 4965 | * be considered wake keys. We filter them out here. |
| 4966 | * |
| 4967 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 4968 | * is always considered a wake key. |
| 4969 | */ |
| 4970 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 4971 | switch (keyCode) { |
| 4972 | // ignore volume keys unless docked |
| 4973 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4974 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4975 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4976 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4977 | |
| 4978 | // ignore media and camera keys |
| 4979 | case KeyEvent.KEYCODE_MUTE: |
| 4980 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4981 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4982 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4983 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4984 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4985 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4986 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4987 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4988 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4989 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4990 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4991 | case KeyEvent.KEYCODE_CAMERA: |
| 4992 | return false; |
| 4993 | } |
| 4994 | return true; |
| 4995 | } |
| 4996 | |
| 4997 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4998 | /** {@inheritDoc} */ |
| 4999 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5000 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 5001 | if ((policyFlags & FLAG_WAKE) != 0) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5002 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) { |
| 5003 | return 0; |
| 5004 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5005 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5006 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5007 | if (shouldDispatchInputWhenNonInteractive()) { |
| 5008 | return ACTION_PASS_TO_USER; |
| 5009 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5010 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5011 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 5012 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 5013 | // wake up in this case. |
| 5014 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
| 5015 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming); |
| 5016 | } |
| 5017 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5018 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5019 | } |
| 5020 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5021 | private boolean shouldDispatchInputWhenNonInteractive() { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5022 | // Send events to keyguard while the screen is on. |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5023 | if (isKeyguardShowingAndNotOccluded() && mDisplay != null |
| 5024 | && mDisplay.getState() != Display.STATE_OFF) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5025 | return true; |
| 5026 | } |
| 5027 | |
| 5028 | // Send events to a dozing dream even if the screen is off since the dream |
| 5029 | // is in control of the state of the screen. |
| 5030 | IDreamManager dreamManager = getDreamManager(); |
| 5031 | |
| 5032 | try { |
| 5033 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 5034 | return true; |
| 5035 | } |
| 5036 | } catch (RemoteException e) { |
| 5037 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 5038 | } |
| 5039 | |
| 5040 | // Otherwise, consume events since the user can't see what is being |
| 5041 | // interacted with. |
| 5042 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5043 | } |
| 5044 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5045 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 5046 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 5047 | return; |
| 5048 | } |
| 5049 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 5050 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 5051 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5052 | String pkgName = mContext.getOpPackageName(); |
| 5053 | switch (keyCode) { |
| 5054 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5055 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5056 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5057 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5058 | } catch (RemoteException e) { |
| 5059 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 5060 | } |
| 5061 | break; |
| 5062 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5063 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5064 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5065 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5066 | } catch (RemoteException e) { |
| 5067 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 5068 | } |
| 5069 | break; |
| 5070 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5071 | try { |
| 5072 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5073 | getAudioService().adjustSuggestedStreamVolume( |
| 5074 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5075 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5076 | } |
| 5077 | } catch (RemoteException e) { |
| 5078 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 5079 | } |
| 5080 | break; |
| 5081 | } |
| 5082 | } |
| 5083 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5084 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 5085 | if (DEBUG_INPUT) { |
| 5086 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5087 | } |
| 5088 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5089 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 5090 | if (DEBUG_INPUT) { |
| 5091 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 5092 | } |
| 5093 | |
| 5094 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 5095 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5096 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 5097 | } |
| 5098 | |
| 5099 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 5100 | |
| 5101 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5102 | && event.getRepeatCount() == 0) { |
| 5103 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 5104 | |
| 5105 | Message msg = mHandler.obtainMessage( |
| 5106 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 5107 | msg.setAsynchronous(true); |
| 5108 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 5109 | } else { |
| 5110 | mBroadcastWakeLock.release(); |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 5115 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5116 | |
| 5117 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 5118 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 5119 | if (DEBUG_INPUT) { |
| 5120 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 5121 | } |
| 5122 | |
| 5123 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 5124 | mBroadcastWakeLock.release(); |
| 5125 | } |
| 5126 | |
| 5127 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 5128 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5129 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5130 | } |
| 5131 | } |
| 5132 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5133 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
| 5134 | Intent voiceIntent = |
| 5135 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 5136 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5137 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5138 | mBroadcastWakeLock.release(); |
| 5139 | } |
| 5140 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5141 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5142 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5143 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 5144 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 5145 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 5146 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5147 | } else { |
| 5148 | try { |
| 5149 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 5150 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5151 | mUiMode = uiModeService.getCurrentModeType(); |
| 5152 | } catch (RemoteException e) { |
| 5153 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 5154 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5155 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5156 | synchronized (mLock) { |
| 5157 | updateOrientationListenerLp(); |
| 5158 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5159 | } |
| 5160 | }; |
| 5161 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5162 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 5163 | @Override |
| 5164 | public void onReceive(Context context, Intent intent) { |
| 5165 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5166 | if (mKeyguardDelegate != null) { |
| 5167 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5168 | } |
| 5169 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5170 | if (mKeyguardDelegate != null) { |
| 5171 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5172 | } |
| 5173 | } |
| 5174 | } |
| 5175 | }; |
| 5176 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5177 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 5178 | @Override |
| 5179 | public void onReceive(Context context, Intent intent) { |
| 5180 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 5181 | // tickle the settings observer: this first ensures that we're |
| 5182 | // observing the relevant settings for the newly-active user, |
| 5183 | // and then updates our own bookkeeping based on the now- |
| 5184 | // current user. |
| 5185 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5186 | |
| 5187 | // force a re-application of focused window sysui visibility. |
| 5188 | // the window may never have been shown for this user |
| 5189 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5190 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5191 | mLastSystemUiFlags = 0; |
| 5192 | updateSystemUiVisibilityLw(); |
| 5193 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5194 | } |
| 5195 | } |
| 5196 | }; |
| 5197 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5198 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5199 | @Override |
| 5200 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5201 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 5202 | if (!isUserSetupComplete()) { |
| 5203 | // Swipe-up for navigation bar is disabled during setup |
| 5204 | return; |
| 5205 | } |
| 5206 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
| 5207 | mNavigationBarController.showTransient(); |
| 5208 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5209 | } |
| 5210 | }; |
| 5211 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5212 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5213 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5214 | if (!isUserSetupComplete()) { |
| 5215 | // Swipe-up for navigation bar is disabled during setup |
| 5216 | return; |
| 5217 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5218 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 5219 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5220 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 5221 | // Don't show status bar when swiping on already visible navigation bar |
| 5222 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5223 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5224 | return; |
| 5225 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5226 | if (sb) mStatusBarController.showTransient(); |
| 5227 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5228 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5229 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5230 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5231 | } |
| 5232 | } |
| 5233 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5234 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5235 | @Override |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 5236 | public void goingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5237 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5238 | if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep..."); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5239 | |
| 5240 | // We must get this work done here because the power manager will drop |
| 5241 | // 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] | 5242 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5243 | mAwake = false; |
| 5244 | mKeyguardDrawComplete = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5245 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5246 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5247 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5248 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5249 | |
| 5250 | if (mKeyguardDelegate != null) { |
| 5251 | mKeyguardDelegate.onScreenTurnedOff(why); |
| 5252 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5253 | } |
| 5254 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5255 | private void wakeUpFromPowerKey(long eventTime) { |
| 5256 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey); |
| 5257 | } |
| 5258 | |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5259 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) { |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5260 | if (!wakeInTheaterMode && isTheaterModeEnabled()) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5261 | return false; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5262 | } |
| 5263 | |
| 5264 | mPowerManager.wakeUp(wakeTime); |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5265 | return true; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5266 | } |
| 5267 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5268 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5269 | @Override |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5270 | public void wakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5271 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5272 | if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5273 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5274 | // Since goToSleep performs these functions synchronously, we must |
| 5275 | // do the same here. We cannot post this work to a handler because |
| 5276 | // that might cause it to become reordered with respect to what |
| 5277 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5278 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5279 | mAwake = true; |
| 5280 | mKeyguardDrawComplete = false; |
| 5281 | if (mKeyguardDelegate != null) { |
| 5282 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5283 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
| 5284 | } |
| 5285 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5286 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5287 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5288 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5289 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5290 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5291 | if (mKeyguardDelegate != null) { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5292 | mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5293 | // ... eventually calls finishKeyguardDrawn |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5294 | } else { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5295 | if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5296 | finishKeyguardDrawn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5297 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5300 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5301 | synchronized (mLock) { |
| 5302 | if (!mAwake || mKeyguardDrawComplete) { |
| 5303 | return; // spurious |
| 5304 | } |
| 5305 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5306 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5307 | if (mKeyguardDelegate != null) { |
| 5308 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5309 | } |
| 5310 | } |
| 5311 | |
| 5312 | finishScreenTurningOn(); |
| 5313 | } |
| 5314 | |
| 5315 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5316 | @Override |
| 5317 | public void screenTurnedOff() { |
| 5318 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 5319 | |
| 5320 | synchronized (mLock) { |
| 5321 | mScreenOnEarly = false; |
| 5322 | mScreenOnFully = false; |
| 5323 | mWindowManagerDrawComplete = false; |
| 5324 | mScreenOnListener = null; |
| 5325 | updateOrientationListenerLp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5326 | } |
| 5327 | } |
| 5328 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5329 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5330 | @Override |
| 5331 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5332 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5333 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5334 | synchronized (mLock) { |
| 5335 | mScreenOnEarly = true; |
| 5336 | mScreenOnFully = false; |
| 5337 | mWindowManagerDrawComplete = false; |
| 5338 | mScreenOnListener = screenOnListener; |
| 5339 | updateOrientationListenerLp(); |
| 5340 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5341 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 5342 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 5343 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5344 | // ... eventually calls finishWindowsDrawn |
| 5345 | } |
| 5346 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5347 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5348 | synchronized (mLock) { |
| 5349 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
| 5350 | return; // spurious |
| 5351 | } |
| 5352 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5353 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5354 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5355 | |
| 5356 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5357 | } |
| 5358 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5359 | private void finishScreenTurningOn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5360 | final ScreenOnListener listener; |
| 5361 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5362 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5363 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5364 | "finishScreenTurningOn: mAwake=" + mAwake |
| 5365 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 5366 | + ", mScreenOnFully=" + mScreenOnFully |
| 5367 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 5368 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 5369 | |
| 5370 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 5371 | || (mAwake && !mKeyguardDrawComplete)) { |
| 5372 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5373 | } |
| 5374 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5375 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 5376 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 5377 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5378 | mScreenOnFully = true; |
| 5379 | |
| 5380 | // Remember the first time we draw the keyguard so we know when we're done with |
| 5381 | // the main part of booting and can enable the screen and hide boot messages. |
| 5382 | if (!mKeyguardDrawnOnce && mAwake) { |
| 5383 | mKeyguardDrawnOnce = true; |
| 5384 | enableScreen = true; |
| 5385 | if (mBootMessageNeedsHiding) { |
| 5386 | mBootMessageNeedsHiding = false; |
| 5387 | hideBootMessages(); |
| 5388 | } |
| 5389 | } else { |
| 5390 | enableScreen = false; |
| 5391 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5392 | } |
| 5393 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5394 | if (listener != null) { |
| 5395 | listener.onScreenOn(); |
| 5396 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 5397 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5398 | if (enableScreen) { |
| 5399 | try { |
| 5400 | mWindowManager.enableScreenIfNeeded(); |
| 5401 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5402 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5403 | } |
| 5404 | } |
| 5405 | |
| 5406 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5407 | synchronized (mLock) { |
| 5408 | if (!mKeyguardDrawnOnce) { |
| 5409 | mBootMessageNeedsHiding = true; |
| 5410 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 5411 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5412 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5413 | |
| 5414 | if (mBootMsgDialog != null) { |
| 5415 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 5416 | mBootMsgDialog.dismiss(); |
| 5417 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5418 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5419 | } |
| 5420 | |
| 5421 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5422 | public boolean isScreenOn() { |
| 5423 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5424 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5425 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5426 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5427 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5428 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5429 | if (mKeyguardDelegate != null) { |
| 5430 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5431 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5435 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5436 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5437 | if (mKeyguardDelegate != null) { |
| 5438 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5439 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5440 | } |
| 5441 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5442 | private boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5443 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5444 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5445 | } |
| 5446 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5447 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5448 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5449 | public boolean isKeyguardLocked() { |
| 5450 | return keyguardOn(); |
| 5451 | } |
| 5452 | |
| 5453 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5454 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5455 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5456 | if (mKeyguardDelegate == null) return false; |
| 5457 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5458 | } |
| 5459 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5460 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5461 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5462 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5463 | if (mKeyguardDelegate == null) return false; |
| 5464 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5465 | } |
| 5466 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5467 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5468 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5469 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5470 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5471 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5472 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5473 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 5474 | // ask the keyguard to prompt the user to authenticate if necessary |
| 5475 | mKeyguardDelegate.dismiss(); |
| 5476 | } |
| 5477 | }); |
| 5478 | } |
| 5479 | } |
| 5480 | |
| 5481 | public void notifyActivityDrawnForKeyguardLw() { |
| 5482 | if (mKeyguardDelegate != null) { |
| 5483 | mHandler.post(new Runnable() { |
| 5484 | @Override |
| 5485 | public void run() { |
| 5486 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5487 | } |
| 5488 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5489 | } |
| 5490 | } |
| 5491 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5492 | @Override |
| 5493 | public boolean isKeyguardDrawnLw() { |
| 5494 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5495 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5496 | } |
| 5497 | } |
| 5498 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5499 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5500 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5501 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5502 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5503 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5504 | } |
| 5505 | } |
| 5506 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5507 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5508 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5512 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5513 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 5514 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5515 | @Override |
| 5516 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5517 | if (false) { |
| 5518 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 5519 | + orientation + ", last=" + lastRotation |
| 5520 | + "); user=" + mUserRotation + " " |
| 5521 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 5522 | ? "USER_ROTATION_LOCKED" : "") |
| 5523 | ); |
| 5524 | } |
| 5525 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 5526 | if (mForceDefaultOrientation) { |
| 5527 | return Surface.ROTATION_0; |
| 5528 | } |
| 5529 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5530 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5531 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 5532 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 5533 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5534 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5535 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5536 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5537 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5538 | // Ignore sensor when lid switch is open and rotation is forced. |
| 5539 | preferredRotation = mLidOpenRotation; |
| 5540 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5541 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5542 | // Ignore sensor when in car dock unless explicitly enabled. |
| 5543 | // This case can override the behavior of NOSENSOR, and can also |
| 5544 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5545 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5546 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 5547 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5548 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 5549 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5550 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5551 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 5552 | // This case can override the behavior of NOSENSOR, and can also |
| 5553 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5554 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5555 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5556 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 5557 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 5558 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5559 | preferredRotation = mDemoHdmiRotation; |
| 5560 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 5561 | && mUndockedHdmiRotation >= 0) { |
| 5562 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 5563 | // been specified in the configuration (only for legacy devices without |
| 5564 | // full multi-display support). |
| 5565 | // Note that the dock orientation overrides the HDMI orientation. |
| 5566 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 5567 | } else if (mDemoRotationLock) { |
| 5568 | // Ignore sensor when demo rotation lock is enabled. |
| 5569 | // Note that the dock orientation and HDMI rotation lock override this. |
| 5570 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5571 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 5572 | // Application just wants to remain locked in the last rotation. |
| 5573 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5574 | } else if (!mSupportAutoRotation) { |
| 5575 | // If we don't support auto-rotation then bail out here and ignore |
| 5576 | // the sensor and any rotation lock settings. |
| 5577 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5578 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5579 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5580 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 5581 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 5582 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 5583 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5584 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 5585 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5586 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 5587 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 5588 | // Otherwise, use sensor only if requested by the application or enabled |
| 5589 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5590 | if (mAllowAllRotations < 0) { |
| 5591 | // Can't read this during init() because the context doesn't |
| 5592 | // have display metrics at that time so we cannot determine |
| 5593 | // tablet vs. phone then. |
| 5594 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 5595 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 5596 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5597 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5598 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5599 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5600 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5601 | preferredRotation = sensorRotation; |
| 5602 | } else { |
| 5603 | preferredRotation = lastRotation; |
| 5604 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5605 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 5606 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 5607 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 5608 | // The idea is that the user rotation expresses a weak preference for the direction |
| 5609 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 5610 | // 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] | 5611 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5612 | } else { |
| 5613 | // No overriding preference. |
| 5614 | // We will do exactly what the application asked us to do. |
| 5615 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5616 | } |
| 5617 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5618 | switch (orientation) { |
| 5619 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5620 | // Return portrait unless overridden. |
| 5621 | if (isAnyPortrait(preferredRotation)) { |
| 5622 | return preferredRotation; |
| 5623 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5624 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5625 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5626 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5627 | // Return landscape unless overridden. |
| 5628 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5629 | return preferredRotation; |
| 5630 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5631 | return mLandscapeRotation; |
| 5632 | |
| 5633 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5634 | // Return reverse portrait unless overridden. |
| 5635 | if (isAnyPortrait(preferredRotation)) { |
| 5636 | return preferredRotation; |
| 5637 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5638 | return mUpsideDownRotation; |
| 5639 | |
| 5640 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5641 | // Return seascape unless overridden. |
| 5642 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5643 | return preferredRotation; |
| 5644 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5645 | return mSeascapeRotation; |
| 5646 | |
| 5647 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5648 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5649 | // Return either landscape rotation. |
| 5650 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5651 | return preferredRotation; |
| 5652 | } |
| 5653 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 5654 | return lastRotation; |
| 5655 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5656 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5657 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5658 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5659 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5660 | // Return either portrait rotation. |
| 5661 | if (isAnyPortrait(preferredRotation)) { |
| 5662 | return preferredRotation; |
| 5663 | } |
| 5664 | if (isAnyPortrait(lastRotation)) { |
| 5665 | return lastRotation; |
| 5666 | } |
| 5667 | return mPortraitRotation; |
| 5668 | |
| 5669 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5670 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 5671 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5672 | if (preferredRotation >= 0) { |
| 5673 | return preferredRotation; |
| 5674 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5675 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 5676 | } |
| 5677 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5678 | } |
| 5679 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5680 | @Override |
| 5681 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 5682 | switch (orientation) { |
| 5683 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 5684 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 5685 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 5686 | return isAnyPortrait(rotation); |
| 5687 | |
| 5688 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 5689 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 5690 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 5691 | return isLandscapeOrSeascape(rotation); |
| 5692 | |
| 5693 | default: |
| 5694 | return true; |
| 5695 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5696 | } |
| 5697 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5698 | @Override |
| 5699 | public void setRotationLw(int rotation) { |
| 5700 | mOrientationListener.setCurrentRotation(rotation); |
| 5701 | } |
| 5702 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5703 | private boolean isLandscapeOrSeascape(int rotation) { |
| 5704 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5705 | } |
| 5706 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5707 | private boolean isAnyPortrait(int rotation) { |
| 5708 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5709 | } |
| 5710 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5711 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5712 | public int getUserRotationMode() { |
| 5713 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 5714 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 5715 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 5716 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5717 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5718 | |
| 5719 | // 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] | 5720 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5721 | public void setUserRotationMode(int mode, int rot) { |
| 5722 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5723 | |
| 5724 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5725 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5726 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5727 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5728 | rot, |
| 5729 | UserHandle.USER_CURRENT); |
| 5730 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5731 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5732 | 0, |
| 5733 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5734 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5735 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5736 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5737 | 1, |
| 5738 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5739 | } |
| 5740 | } |
| 5741 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5742 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5743 | public void setSafeMode(boolean safeMode) { |
| 5744 | mSafeMode = safeMode; |
| 5745 | performHapticFeedbackLw(null, safeMode |
| 5746 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 5747 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5748 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5749 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 5750 | static long[] getLongIntArray(Resources r, int resid) { |
| 5751 | int[] ar = r.getIntArray(resid); |
| 5752 | if (ar == null) { |
| 5753 | return null; |
| 5754 | } |
| 5755 | long[] out = new long[ar.length]; |
| 5756 | for (int i=0; i<ar.length; i++) { |
| 5757 | out[i] = ar[i]; |
| 5758 | } |
| 5759 | return out; |
| 5760 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5761 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5762 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5763 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5764 | public void systemReady() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5765 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 5766 | mKeyguardDelegate.onSystemReady(); |
| 5767 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5768 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5769 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5770 | synchronized (mLock) { |
| 5771 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5772 | mSystemReady = true; |
| 5773 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5774 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5775 | public void run() { |
| 5776 | updateSettings(); |
| 5777 | } |
| 5778 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5779 | } |
| 5780 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5781 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5782 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5783 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5784 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5785 | if (mKeyguardDelegate != null) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 5786 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5787 | mKeyguardDelegate.onBootCompleted(); |
| 5788 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5789 | synchronized (mLock) { |
| 5790 | mSystemBooted = true; |
| 5791 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5792 | wakingUp(); |
| 5793 | screenTurningOn(null); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5794 | } |
| 5795 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5796 | ProgressDialog mBootMsgDialog = null; |
| 5797 | |
| 5798 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5799 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5800 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5801 | mHandler.post(new Runnable() { |
| 5802 | @Override public void run() { |
| 5803 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 5804 | int theme; |
| 5805 | if (mContext.getPackageManager().hasSystemFeature( |
| 5806 | PackageManager.FEATURE_WATCH)) { |
| 5807 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 5808 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 5809 | PackageManager.FEATURE_TELEVISION)) { |
| 5810 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 5811 | } else { |
| 5812 | theme = 0; |
| 5813 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 5814 | |
| 5815 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 5816 | // This dialog will consume all events coming in to |
| 5817 | // it, to avoid it trying to do things too early in boot. |
| 5818 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 5819 | return true; |
| 5820 | } |
| 5821 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5822 | return true; |
| 5823 | } |
| 5824 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 5825 | return true; |
| 5826 | } |
| 5827 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 5828 | return true; |
| 5829 | } |
| 5830 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 5831 | return true; |
| 5832 | } |
| 5833 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 5834 | AccessibilityEvent event) { |
| 5835 | return true; |
| 5836 | } |
| 5837 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 5838 | if (mContext.getPackageManager().isUpgrade()) { |
| 5839 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 5840 | } else { |
| 5841 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 5842 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5843 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 5844 | mBootMsgDialog.setIndeterminate(true); |
| 5845 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5846 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5847 | mBootMsgDialog.getWindow().addFlags( |
| 5848 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 5849 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 5850 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 5851 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 5852 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 5853 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5854 | mBootMsgDialog.setCancelable(false); |
| 5855 | mBootMsgDialog.show(); |
| 5856 | } |
| 5857 | mBootMsgDialog.setMessage(msg); |
| 5858 | } |
| 5859 | }); |
| 5860 | } |
| 5861 | |
| 5862 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5863 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5864 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5865 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5866 | } |
| 5867 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5868 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5869 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5870 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5871 | // *************************************** |
| 5872 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 5873 | // *************************************** |
| 5874 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 5875 | // WITH ITS LOCKS HELD. |
| 5876 | // |
| 5877 | // This code must be VERY careful about the locks |
| 5878 | // it acquires. |
| 5879 | // In fact, the current code acquires way too many, |
| 5880 | // and probably has lurking deadlocks. |
| 5881 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5882 | synchronized (mScreenLockTimeout) { |
| 5883 | if (mLockScreenTimerActive) { |
| 5884 | // reset the timer |
| 5885 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5886 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5887 | } |
| 5888 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5889 | } |
| 5890 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5891 | class ScreenLockTimeout implements Runnable { |
| 5892 | Bundle options; |
| 5893 | |
| 5894 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5895 | public void run() { |
| 5896 | synchronized (this) { |
| 5897 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5898 | if (mKeyguardDelegate != null) { |
| 5899 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5900 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5901 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5902 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5903 | } |
| 5904 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5905 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5906 | public void setLockOptions(Bundle options) { |
| 5907 | this.options = options; |
| 5908 | } |
| 5909 | } |
| 5910 | |
| 5911 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 5912 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5913 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5914 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5915 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 5916 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5917 | if (options != null) { |
| 5918 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 5919 | // until the runnable actually executes. |
| 5920 | mScreenLockTimeout.setLockOptions(options); |
| 5921 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5922 | mHandler.post(mScreenLockTimeout); |
| 5923 | } |
| 5924 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5925 | private void updateLockScreenTimeout() { |
| 5926 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5927 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5928 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5929 | if (mLockScreenTimerActive != enable) { |
| 5930 | if (enable) { |
| 5931 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 5932 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5933 | } else { |
| 5934 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 5935 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5936 | } |
| 5937 | mLockScreenTimerActive = enable; |
| 5938 | } |
| 5939 | } |
| 5940 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5941 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 5942 | private void updateDreamingSleepToken(boolean acquire) { |
| 5943 | if (acquire) { |
| 5944 | if (mDreamingSleepToken == null) { |
| 5945 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 5946 | } |
| 5947 | } else { |
| 5948 | if (mDreamingSleepToken != null) { |
| 5949 | mDreamingSleepToken.release(); |
| 5950 | } |
| 5951 | } |
| 5952 | } |
| 5953 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5954 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5955 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5956 | public void enableScreenAfterBoot() { |
| 5957 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5958 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5959 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5960 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 5961 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5962 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5963 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5964 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 5965 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5966 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5967 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5968 | |
| 5969 | synchronized (mLock) { |
| 5970 | updateWakeGestureListenerLp(); |
| 5971 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5972 | } |
| 5973 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5974 | void updateUiMode() { |
| 5975 | if (mUiModeManager == null) { |
| 5976 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 5977 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5978 | } |
| 5979 | try { |
| 5980 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 5981 | } catch (RemoteException e) { |
| 5982 | } |
| 5983 | } |
| 5984 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5985 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5986 | try { |
| 5987 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5988 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 5989 | } catch (RemoteException e) { |
| 5990 | // Ignore |
| 5991 | } |
| 5992 | } |
| 5993 | |
| 5994 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 5995 | try { |
| 5996 | //set orientation on WindowManager |
| 5997 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5998 | } catch (RemoteException e) { |
| 5999 | // Ignore |
| 6000 | } |
| 6001 | } |
| 6002 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6003 | /** |
| 6004 | * Return an Intent to launch the currently active dock app as home. Returns |
| 6005 | * null if the standard home should be launched, which is the case if any of the following is |
| 6006 | * true: |
| 6007 | * <ul> |
| 6008 | * <li>The device is not in either car mode or desk mode |
| 6009 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 6010 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 6011 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 6012 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 6013 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6014 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6015 | */ |
| 6016 | Intent createHomeDockIntent() { |
| 6017 | Intent intent = null; |
| 6018 | |
| 6019 | // What home does is based on the mode, not the dock state. That |
| 6020 | // is, when in car mode you should be taken to car home regardless |
| 6021 | // of whether we are actually in a car dock. |
| 6022 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 6023 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 6024 | intent = mCarDockIntent; |
| 6025 | } |
| 6026 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 6027 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 6028 | intent = mDeskDockIntent; |
| 6029 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6030 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 6031 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6032 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 6033 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 6034 | // Always launch dock home from home when watch is docked, if it exists. |
| 6035 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6036 | } |
| 6037 | |
| 6038 | if (intent == null) { |
| 6039 | return null; |
| 6040 | } |
| 6041 | |
| 6042 | ActivityInfo ai = null; |
| 6043 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 6044 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 6045 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6046 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6047 | if (info != null) { |
| 6048 | ai = info.activityInfo; |
| 6049 | } |
| 6050 | if (ai != null |
| 6051 | && ai.metaData != null |
| 6052 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 6053 | intent = new Intent(intent); |
| 6054 | intent.setClassName(ai.packageName, ai.name); |
| 6055 | return intent; |
| 6056 | } |
| 6057 | |
| 6058 | return null; |
| 6059 | } |
| 6060 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6061 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 6062 | if (awakenFromDreams) { |
| 6063 | awakenDreams(); |
| 6064 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6065 | |
| 6066 | Intent dock = createHomeDockIntent(); |
| 6067 | if (dock != null) { |
| 6068 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6069 | if (fromHomeKey) { |
| 6070 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6071 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6072 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6073 | return; |
| 6074 | } catch (ActivityNotFoundException e) { |
| 6075 | } |
| 6076 | } |
| 6077 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6078 | Intent intent; |
| 6079 | |
| 6080 | if (fromHomeKey) { |
| 6081 | intent = new Intent(mHomeIntent); |
| 6082 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6083 | } else { |
| 6084 | intent = mHomeIntent; |
| 6085 | } |
| 6086 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 6087 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6088 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6089 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6090 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6091 | * goes to the home screen |
| 6092 | * @return whether it did anything |
| 6093 | */ |
| 6094 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6095 | if (!isUserSetupComplete()) { |
| 6096 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 6097 | return false; |
| 6098 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6099 | if (false) { |
| 6100 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 6101 | try { |
| 6102 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6103 | } catch (RemoteException e) { |
| 6104 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 6105 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6106 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6107 | } else { |
| 6108 | // This code brings home to the front or, if it is already |
| 6109 | // at the front, puts the device to sleep. |
| 6110 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 6111 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 6112 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 6113 | Log.d(TAG, "UTS-TEST-MODE"); |
| 6114 | } else { |
| 6115 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6116 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6117 | Intent dock = createHomeDockIntent(); |
| 6118 | if (dock != null) { |
| 6119 | int result = ActivityManagerNative.getDefault() |
| 6120 | .startActivityAsUser(null, null, dock, |
| 6121 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6122 | null, null, 0, |
| 6123 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6124 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6125 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 6126 | return false; |
| 6127 | } |
| 6128 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6129 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6130 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6131 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6132 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6133 | null, null, 0, |
| 6134 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6135 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6136 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6137 | return false; |
| 6138 | } |
| 6139 | } catch (RemoteException ex) { |
| 6140 | // bummer, the activity manager, which is in this process, is dead |
| 6141 | } |
| 6142 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6143 | return true; |
| 6144 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6145 | |
| 6146 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6147 | public void setCurrentOrientationLw(int newOrientation) { |
| 6148 | synchronized (mLock) { |
| 6149 | if (newOrientation != mCurrentAppOrientation) { |
| 6150 | mCurrentAppOrientation = newOrientation; |
| 6151 | updateOrientationListenerLp(); |
| 6152 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6153 | } |
| 6154 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6155 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6156 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 6157 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 6158 | return; |
| 6159 | } |
| 6160 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 6161 | Context.AUDIO_SERVICE); |
| 6162 | if (audioManager.isSilentMode()) { |
| 6163 | return; |
| 6164 | } |
| 6165 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 6166 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 6167 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 6168 | ringTone.play(); |
| 6169 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6170 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6171 | private boolean isTheaterModeEnabled() { |
| 6172 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6173 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 6174 | } |
| 6175 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6176 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 6177 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6178 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 6179 | } |
| 6180 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6181 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6182 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 6183 | if (!mVibrator.hasVibrator()) { |
| 6184 | return false; |
| 6185 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6186 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 6187 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 6188 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6189 | return false; |
| 6190 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6191 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6192 | switch (effectId) { |
| 6193 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6194 | pattern = mLongPressVibePattern; |
| 6195 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6196 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6197 | pattern = mVirtualKeyVibePattern; |
| 6198 | break; |
| 6199 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 6200 | pattern = mKeyboardTapVibePattern; |
| 6201 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 6202 | case HapticFeedbackConstants.CLOCK_TICK: |
| 6203 | pattern = mClockTickVibePattern; |
| 6204 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 6205 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 6206 | pattern = mCalendarDateVibePattern; |
| 6207 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6208 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6209 | pattern = mSafeModeDisabledVibePattern; |
| 6210 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6211 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6212 | pattern = mSafeModeEnabledVibePattern; |
| 6213 | break; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 6214 | case HapticFeedbackConstants.STYLUS_BUTTON_PRESS: |
| 6215 | pattern = mStylusButtonPressVibePattern; |
| 6216 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6217 | default: |
| 6218 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6219 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6220 | int owningUid; |
| 6221 | String owningPackage; |
| 6222 | if (win != null) { |
| 6223 | owningUid = win.getOwningUid(); |
| 6224 | owningPackage = win.getOwningPackage(); |
| 6225 | } else { |
| 6226 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 6227 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6228 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6229 | if (pattern.length == 1) { |
| 6230 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6231 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6232 | } else { |
| 6233 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6234 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6235 | } |
| 6236 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6237 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6238 | |
| 6239 | @Override |
| 6240 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6241 | } |
| 6242 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6243 | @Override |
| 6244 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6245 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 6246 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6247 | } |
| 6248 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 6249 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6250 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6251 | // If there is no window focused, there will be nobody to handle the events |
| 6252 | // anyway, so just hang on in whatever state we're in until things settle down. |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 6253 | final WindowState win = mFocusedWindow != null ? mFocusedWindow |
| 6254 | : mTopFullscreenOpaqueWindowState; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6255 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6256 | return 0; |
| 6257 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6258 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6259 | // We are updating at a point where the keyguard has gotten |
| 6260 | // focus, but we were last in a state where the top window is |
| 6261 | // hiding it. This is probably because the keyguard as been |
| 6262 | // shown while the top window was displayed, so we want to ignore |
| 6263 | // it here because this is just a very transient change and it |
| 6264 | // will quickly lose focus once it correctly gets hidden. |
| 6265 | return 0; |
| 6266 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6267 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 6268 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6269 | & ~mResettingSystemUiFlags |
| 6270 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6271 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6272 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6273 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6274 | tmpVisibility = updateLightStatusBarLw(tmpVisibility); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6275 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6276 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6277 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 6278 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6279 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6280 | return 0; |
| 6281 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6282 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6283 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6284 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6285 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6286 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6287 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6288 | try { |
| 6289 | IStatusBarService statusbar = getStatusBarService(); |
| 6290 | if (statusbar != null) { |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 6291 | statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString()); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6292 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6293 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6294 | } catch (RemoteException e) { |
| 6295 | // re-acquire status bar service next time it is needed. |
| 6296 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6297 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6298 | } |
| 6299 | }); |
| 6300 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6301 | } |
| 6302 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6303 | private int updateLightStatusBarLw(int vis) { |
| 6304 | WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6305 | ? mStatusBar |
| 6306 | : mTopFullscreenOpaqueOrDimmingWindowState; |
| 6307 | |
| 6308 | if (statusColorWin != null) { |
| 6309 | if (statusColorWin == mTopFullscreenOpaqueWindowState) { |
| 6310 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 6311 | // its light flag. |
| 6312 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6313 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 6314 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6315 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 6316 | // Otherwise if it's dimming, clear the light flag. |
| 6317 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6318 | } |
| 6319 | } |
| 6320 | return vis; |
| 6321 | } |
| 6322 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6323 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6324 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6325 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6326 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6327 | : mTopFullscreenOpaqueWindowState; |
| 6328 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6329 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6330 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6331 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 6332 | int type = win.getAttrs().type; |
| 6333 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6334 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6335 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 6336 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 6337 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 6338 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 6339 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6340 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6341 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 6342 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6343 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6344 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6345 | |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 6346 | if (!areTranslucentBarsAllowed() && transWin != mStatusBar) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 6347 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 6348 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6349 | } |
| 6350 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6351 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6352 | boolean immersiveSticky = |
| 6353 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6354 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6355 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6356 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6357 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 6358 | boolean hideStatusBarSysui = |
| 6359 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6360 | boolean hideNavBarSysui = |
| 6361 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6362 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6363 | boolean transientStatusBarAllowed = |
| 6364 | mStatusBar != null && ( |
| 6365 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6366 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6367 | || statusBarHasFocus); |
| 6368 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6369 | boolean transientNavBarAllowed = |
| 6370 | mNavigationBar != null && |
| 6371 | hideNavBarSysui && immersiveSticky; |
| 6372 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6373 | final long now = SystemClock.uptimeMillis(); |
| 6374 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 6375 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 6376 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 6377 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 6378 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 6379 | mPendingPanicGestureUptime = 0; |
| 6380 | mStatusBarController.showTransient(); |
| 6381 | mNavigationBarController.showTransient(); |
| 6382 | } |
| 6383 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6384 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6385 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6386 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6387 | && !transientNavBarAllowed; |
| 6388 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6389 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6390 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 6391 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6392 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6393 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6394 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 6395 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 6396 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 6397 | |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 6398 | if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType()) |
| 6399 | > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6400 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 6401 | // the input events. |
| 6402 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 6403 | } |
| 6404 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6405 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 6406 | |
| 6407 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6408 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 6409 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 6410 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6411 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6412 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 6413 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6414 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6415 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6416 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 6417 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6418 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6419 | } |
| 6420 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6421 | private void clearClearableFlagsLw() { |
| 6422 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6423 | if (newVal != mResettingSystemUiFlags) { |
| 6424 | mResettingSystemUiFlags = newVal; |
| 6425 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 6426 | } |
| 6427 | } |
| 6428 | |
| 6429 | private boolean isImmersiveMode(int vis) { |
| 6430 | 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] | 6431 | return mNavigationBar != null |
| 6432 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 6433 | && (vis & flags) != 0 |
| 6434 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6435 | } |
| 6436 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6437 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6438 | * @return whether the navigation or status bar can be made translucent |
| 6439 | * |
| 6440 | * This should return true unless touch exploration is not enabled or |
| 6441 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6442 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6443 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 6444 | return mTranslucentDecorEnabled |
| 6445 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6446 | } |
| 6447 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6448 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 6449 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6450 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6451 | public boolean hasNavigationBar() { |
| 6452 | return mHasNavigationBar; |
| 6453 | } |
| 6454 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 6455 | @Override |
| 6456 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 6457 | mLastInputMethodWindow = ime; |
| 6458 | mLastInputMethodTargetWindow = target; |
| 6459 | } |
| 6460 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6461 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 6462 | public int getInputMethodWindowVisibleHeightLw() { |
| 6463 | return mDockBottom - mCurBottom; |
| 6464 | } |
| 6465 | |
| 6466 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6467 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6468 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6469 | if (mKeyguardDelegate != null) { |
| 6470 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6471 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 6472 | if (mStatusBarService != null) { |
| 6473 | try { |
| 6474 | mStatusBarService.setCurrentUser(newUserId); |
| 6475 | } catch (RemoteException e) { |
| 6476 | // oh well |
| 6477 | } |
| 6478 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6479 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6480 | } |
| 6481 | |
| 6482 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 6483 | public boolean canMagnifyWindow(int windowType) { |
| 6484 | switch (windowType) { |
| 6485 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 6486 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 6487 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 6488 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 6489 | return false; |
| 6490 | } |
| 6491 | } |
| 6492 | return true; |
| 6493 | } |
| 6494 | |
| 6495 | @Override |
| 6496 | public boolean isTopLevelWindow(int windowType) { |
| 6497 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 6498 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 6499 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 6500 | } |
| 6501 | return true; |
| 6502 | } |
| 6503 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 6504 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 6505 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6506 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6507 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 6508 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6509 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6510 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6511 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6512 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6513 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 6514 | || mForceClearedSystemUiFlags != 0) { |
| 6515 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 6516 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 6517 | pw.print(" mResettingSystemUiFlags=0x"); |
| 6518 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 6519 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 6520 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6521 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6522 | if (mLastFocusNeedsMenu) { |
| 6523 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 6524 | pw.println(mLastFocusNeedsMenu); |
| 6525 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6526 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 6527 | pw.println(mWakeGestureEnabledSetting); |
| 6528 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6529 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6530 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 6531 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6532 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 6533 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 6534 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 6535 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6536 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6537 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6538 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 6539 | pw.print(mCarDockEnablesAccelerometer); |
| 6540 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 6541 | pw.println(mDeskDockEnablesAccelerometer); |
| 6542 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 6543 | pw.print(mLidKeyboardAccessibility); |
| 6544 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6545 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6546 | pw.print(prefix); |
| 6547 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 6548 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6549 | pw.print(prefix); |
| 6550 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 6551 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6552 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6553 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 6554 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 6555 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 6556 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 6557 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 6558 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 6559 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 6560 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 6561 | pw.print(","); pw.print(mOverscanScreenTop); |
| 6562 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 6563 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 6564 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 6565 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 6566 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 6567 | pw.print(" top="); pw.print(mOverscanTop); |
| 6568 | pw.print(" right="); pw.print(mOverscanRight); |
| 6569 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 6570 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 6571 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 6572 | pw.print(mRestrictedOverscanScreenLeft); |
| 6573 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 6574 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 6575 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6576 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 6577 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 6578 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 6579 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 6580 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 6581 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 6582 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 6583 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 6584 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 6585 | pw.print(","); pw.print(mStableFullscreenTop); |
| 6586 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 6587 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6588 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 6589 | pw.print(","); pw.print(mStableTop); |
| 6590 | pw.print(")-("); pw.print(mStableRight); |
| 6591 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6592 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 6593 | pw.print(","); pw.print(mSystemTop); |
| 6594 | pw.print(")-("); pw.print(mSystemRight); |
| 6595 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6596 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 6597 | pw.print(","); pw.print(mCurTop); |
| 6598 | pw.print(")-("); pw.print(mCurRight); |
| 6599 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 6600 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 6601 | pw.print(","); pw.print(mContentTop); |
| 6602 | pw.print(")-("); pw.print(mContentRight); |
| 6603 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 6604 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 6605 | pw.print(","); pw.print(mVoiceContentTop); |
| 6606 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 6607 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6608 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 6609 | pw.print(","); pw.print(mDockTop); |
| 6610 | pw.print(")-("); pw.print(mDockRight); |
| 6611 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6612 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 6613 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6614 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 6615 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6616 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 6617 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6618 | if (mLastInputMethodWindow != null) { |
| 6619 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 6620 | pw.println(mLastInputMethodWindow); |
| 6621 | } |
| 6622 | if (mLastInputMethodTargetWindow != null) { |
| 6623 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 6624 | pw.println(mLastInputMethodTargetWindow); |
| 6625 | } |
| 6626 | if (mStatusBar != null) { |
| 6627 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 6628 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 6629 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6630 | } |
| 6631 | if (mNavigationBar != null) { |
| 6632 | pw.print(prefix); pw.print("mNavigationBar="); |
| 6633 | pw.println(mNavigationBar); |
| 6634 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6635 | if (mFocusedWindow != null) { |
| 6636 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 6637 | pw.println(mFocusedWindow); |
| 6638 | } |
| 6639 | if (mFocusedApp != null) { |
| 6640 | pw.print(prefix); pw.print("mFocusedApp="); |
| 6641 | pw.println(mFocusedApp); |
| 6642 | } |
| 6643 | if (mWinDismissingKeyguard != null) { |
| 6644 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 6645 | pw.println(mWinDismissingKeyguard); |
| 6646 | } |
| 6647 | if (mTopFullscreenOpaqueWindowState != null) { |
| 6648 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 6649 | pw.println(mTopFullscreenOpaqueWindowState); |
| 6650 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6651 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 6652 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 6653 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 6654 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6655 | if (mForcingShowNavBar) { |
| 6656 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 6657 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 6658 | pw.println(mForcingShowNavBarLayer); |
| 6659 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6660 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6661 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6662 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 6663 | pw.print(" mForceStatusBarFromKeyguard="); |
| 6664 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6665 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 6666 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6667 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 6668 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 6669 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 6670 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 6671 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 6672 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 6673 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 6674 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 6675 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 6676 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 6677 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6678 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 6679 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 6680 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6681 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 6682 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6683 | mStatusBarController.dump(pw, prefix); |
| 6684 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6685 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6686 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6687 | if (mWakeGestureListener != null) { |
| 6688 | mWakeGestureListener.dump(pw, prefix); |
| 6689 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6690 | if (mOrientationListener != null) { |
| 6691 | mOrientationListener.dump(pw, prefix); |
| 6692 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 6693 | if (mBurnInProtectionHelper != null) { |
| 6694 | mBurnInProtectionHelper.dump(prefix, pw); |
| 6695 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6696 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6697 | } |