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; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 20 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 21 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 22 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 23 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 24 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 25 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 26 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 27 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 28 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 29 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 30 | import android.content.ContentResolver; |
| 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 33 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 34 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 35 | import android.content.pm.ActivityInfo; |
| 36 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 37 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 38 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 39 | import android.content.res.Configuration; |
| 40 | import android.content.res.Resources; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 41 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 42 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 43 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 44 | import android.graphics.Rect; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 45 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 46 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 47 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 48 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 49 | import android.media.Ringtone; |
| 50 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 51 | import android.media.session.MediaSessionLegacyHelper; |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 52 | import android.os.Build; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 53 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 54 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 55 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 56 | import android.os.Handler; |
| 57 | import android.os.IBinder; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 58 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 59 | import android.os.Message; |
| 60 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 61 | import android.os.PowerManager; |
| 62 | import android.os.RemoteException; |
| 63 | import android.os.ServiceManager; |
| 64 | import android.os.SystemClock; |
| 65 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 66 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 67 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 68 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 69 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 71 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 72 | import android.service.dreams.DreamService; |
| 73 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 74 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 75 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 76 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 77 | import android.util.EventLog; |
| 78 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 79 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 80 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 81 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 82 | import android.view.Gravity; |
| 83 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 84 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 85 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 86 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 87 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 88 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 89 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 90 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 91 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 92 | import android.view.KeyEvent; |
| 93 | import android.view.MotionEvent; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 94 | import android.view.PhoneWindow; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 95 | import android.view.Surface; |
| 96 | import android.view.View; |
| 97 | import android.view.ViewConfiguration; |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 98 | import android.view.ViewRootImpl; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 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; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 186 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 187 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 188 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 189 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 190 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 191 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 192 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 193 | /** |
| 194 | * These are the system UI flags that, when changing, can cause the layout |
| 195 | * of the screen to change. |
| 196 | */ |
| 197 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 198 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 199 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 200 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 201 | | View.NAVIGATION_BAR_TRANSLUCENT |
| 202 | | View.SYSTEM_UI_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 203 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 204 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 205 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 206 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 207 | .build(); |
| 208 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 209 | /** |
| 210 | * Keyguard stuff |
| 211 | */ |
| 212 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 213 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 214 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 215 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 216 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 217 | * |
| 218 | * These are special keys that are used to launch particular kinds of applications, |
| 219 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 220 | * usage page. We don't support quite that many yet... |
| 221 | */ |
| 222 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 223 | static { |
| 224 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 225 | sApplicationLaunchKeyCategories.append( |
| 226 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 227 | sApplicationLaunchKeyCategories.append( |
| 228 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 229 | sApplicationLaunchKeyCategories.append( |
| 230 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 231 | sApplicationLaunchKeyCategories.append( |
| 232 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 233 | sApplicationLaunchKeyCategories.append( |
| 234 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 235 | sApplicationLaunchKeyCategories.append( |
| 236 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 237 | } |
| 238 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 239 | /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ |
| 240 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
| 241 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 242 | /** |
| 243 | * Lock protecting internal state. Must not call out into window |
| 244 | * manager with lock held. (This lock will be acquired in places |
| 245 | * where the window manager is calling in with its own lock held.) |
| 246 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 247 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 248 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 249 | Context mContext; |
| 250 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 251 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 252 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 253 | PowerManager mPowerManager; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 254 | DreamManagerInternal mDreamManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 255 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 256 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 257 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 258 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 259 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 260 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 261 | BurnInProtectionHelper mBurnInProtectionHelper; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 262 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 263 | // Vibrator pattern for haptic feedback of a long press. |
| 264 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 265 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 266 | // Vibrator pattern for haptic feedback of virtual key press. |
| 267 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 268 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 269 | // Vibrator pattern for a short vibration. |
| 270 | long[] mKeyboardTapVibePattern; |
| 271 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 272 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 273 | long[] mClockTickVibePattern; |
| 274 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 275 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 276 | long[] mCalendarDateVibePattern; |
| 277 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 278 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 279 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 280 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 281 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 282 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 283 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 284 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 285 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 286 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 287 | boolean mSafeMode; |
| 288 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 289 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 290 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 291 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 292 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 293 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 294 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 295 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 296 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 297 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 298 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 299 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 300 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 301 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 302 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 303 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 304 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 305 | } |
| 306 | }; |
| 307 | final ShowListener mKeyguardDelegateCallback = new ShowListener() { |
| 308 | @Override |
| 309 | public void onShown(IBinder windowToken) { |
| 310 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown."); |
| 311 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 312 | } |
| 313 | }; |
| 314 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 315 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 316 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 317 | WindowState mLastInputMethodWindow = null; |
| 318 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 319 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 320 | // FIXME This state is shared between the input reader and handler thread. |
| 321 | // Technically it's broken and buggy but it has been like this for many years |
| 322 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 323 | // so that only one thread is involved in handling input policy. Unfortunately |
| 324 | // it's on a critical path for power management so we can't just post the work to the |
| 325 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 326 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 327 | volatile boolean mPowerKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 328 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 329 | volatile int mPowerKeyPressCounter; |
| 330 | volatile boolean mEndCallKeyHandled; |
| 331 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 332 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 333 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 334 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 335 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 336 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 337 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 338 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 339 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 340 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 341 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 342 | boolean mHdmiPlugged; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 343 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 344 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 345 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 346 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 347 | int mCarDockRotation; |
| 348 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 349 | int mUndockedHdmiRotation; |
| 350 | int mDemoHdmiRotation; |
| 351 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 352 | int mDemoRotation; |
| 353 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 354 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 355 | boolean mWakeGestureEnabledSetting; |
| 356 | MyWakeGestureListener mWakeGestureListener; |
| 357 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 358 | // Default display does not rotate, apps that require non-default orientation will have to |
| 359 | // have the orientation emulated. |
| 360 | private boolean mForceDefaultOrientation = false; |
| 361 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 362 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 363 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 364 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 365 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 366 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 367 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 368 | boolean mCarDockEnablesAccelerometer; |
| 369 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 370 | int mLidKeyboardAccessibility; |
| 371 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 372 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 373 | int mShortPressOnPowerBehavior; |
| 374 | int mLongPressOnPowerBehavior; |
| 375 | int mDoublePressOnPowerBehavior; |
| 376 | int mTriplePressOnPowerBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 377 | int mShortPressOnSleepBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 378 | boolean mAwake; |
| 379 | boolean mScreenOnEarly; |
| 380 | boolean mScreenOnFully; |
| 381 | ScreenOnListener mScreenOnListener; |
| 382 | boolean mKeyguardDrawComplete; |
| 383 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 384 | boolean mOrientationSensorEnabled = false; |
| 385 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 386 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 387 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 388 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 389 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 390 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 391 | |
| 392 | // The last window we were told about in focusChanged. |
| 393 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 394 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 395 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 396 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 397 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 398 | // The current size of the screen; really; extends into the overscan area of |
| 399 | // the screen and doesn't account for any system elements like the status bar. |
| 400 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 401 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 402 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 403 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 404 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 405 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 406 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 407 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 408 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 409 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 410 | // if the status bar can't be hidden; in that case it effectively carves out |
| 411 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 412 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 413 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 414 | // During layout, the current screen borders accounting for any currently |
| 415 | // visible system UI elements. |
| 416 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 417 | // For applications requesting stable content insets, these are them. |
| 418 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 419 | // For applications requesting stable content insets but have also set the |
| 420 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 421 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 422 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 423 | // During layout, the current screen borders with all outer decoration |
| 424 | // (status bar, input method dock) accounted for. |
| 425 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 426 | // During layout, the frame in which content should be displayed |
| 427 | // to the user, accounting for all screen decoration except for any |
| 428 | // space they deem as available for other content. This is usually |
| 429 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 430 | // content insets. |
| 431 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 432 | // During layout, the frame in which voice content should be displayed |
| 433 | // to the user, accounting for all screen decoration except for any |
| 434 | // space they deem as available for other content. |
| 435 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 436 | // 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] | 437 | // windows are placed. |
| 438 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 439 | // During layout, the layer at which the doc window is placed. |
| 440 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 441 | // During layout, this is the layer of the status bar. |
| 442 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 443 | int mLastSystemUiFlags; |
| 444 | // Bits that we are in the process of clearing, so we want to prevent |
| 445 | // them from being set by applications until everything has been updated |
| 446 | // to have them clear. |
| 447 | int mResettingSystemUiFlags = 0; |
| 448 | // Bits that we are currently always keeping cleared. |
| 449 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 450 | // What we last reported to system UI about whether the compatibility |
| 451 | // menu needs to be displayed. |
| 452 | boolean mLastFocusNeedsMenu = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 453 | |
| 454 | FakeWindow mHideNavFakeWindow = null; |
| 455 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 456 | static final Rect mTmpParentFrame = new Rect(); |
| 457 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 458 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 459 | static final Rect mTmpContentFrame = new Rect(); |
| 460 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 461 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 462 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 463 | static final Rect mTmpNavigationFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 464 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 465 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 466 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 467 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 468 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 469 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 470 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 471 | boolean mForceStatusBarFromKeyguard; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 472 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 473 | boolean mForcingShowNavBar; |
| 474 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 475 | |
| 476 | // States of keyguard dismiss. |
| 477 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 478 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 479 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 480 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 481 | |
| 482 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 483 | * be done once per window. */ |
| 484 | private WindowState mWinDismissingKeyguard; |
| 485 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 486 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 487 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 488 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 489 | * the wallpaper. */ |
| 490 | private WindowState mWinShowWhenLocked; |
| 491 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 492 | boolean mShowingLockscreen; |
| 493 | boolean mShowingDream; |
| 494 | boolean mDreamingLockscreen; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 495 | boolean mKeyguardSecure; |
| 496 | boolean mKeyguardSecureIncludingHidden; |
| 497 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 498 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 499 | boolean mHomeConsumed; |
| 500 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 501 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 502 | Intent mCarDockIntent; |
| 503 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 504 | boolean mSearchKeyShortcutPending; |
| 505 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 506 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 507 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 508 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 509 | // support for activating the lock screen while the screen is on |
| 510 | boolean mAllowLockscreenWhenOn; |
| 511 | int mLockScreenTimeout; |
| 512 | boolean mLockScreenTimerActive; |
| 513 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 514 | // 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] | 515 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 516 | |
| 517 | // Behavior of POWER button while in-call and screen on. |
| 518 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 519 | int mIncallPowerBehavior; |
| 520 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 521 | Display mDisplay; |
| 522 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 523 | int mLandscapeRotation = 0; // default landscape rotation |
| 524 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 525 | int mPortraitRotation = 0; // default portrait rotation |
| 526 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 527 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 528 | int mOverscanLeft = 0; |
| 529 | int mOverscanTop = 0; |
| 530 | int mOverscanRight = 0; |
| 531 | int mOverscanBottom = 0; |
| 532 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 533 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 534 | private int mLongPressOnHomeBehavior; |
| 535 | |
| 536 | // What we do when the user double-taps on home |
| 537 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 538 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 539 | // Allowed theater mode wake actions |
| 540 | private boolean mAllowTheaterModeWakeFromKey; |
| 541 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 542 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 543 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 544 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 545 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 546 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 547 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 548 | // Whether to support long press from power button in non-interactive mode |
| 549 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 550 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 551 | // Whether to go to sleep entering theater mode from power button |
| 552 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 553 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 554 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 555 | // Time to volume and power must be pressed within this interval of each other. |
| 556 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 557 | // Increase the chord delay when taking a screenshot from the keyguard |
| 558 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 559 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 560 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 561 | private long mScreenshotChordVolumeDownKeyTime; |
| 562 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 563 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 564 | private boolean mScreenshotChordPowerKeyTriggered; |
| 565 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 566 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 567 | /* The number of steps between min and max brightness */ |
| 568 | private static final int BRIGHTNESS_STEPS = 10; |
| 569 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 570 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 571 | ShortcutManager mShortcutManager; |
| 572 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 573 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 574 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 575 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 576 | private int mCurrentUserId; |
| 577 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 578 | // Maps global key codes to the components that will handle them. |
| 579 | private GlobalKeyManager mGlobalKeyManager; |
| 580 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 581 | // Fallback actions by key code. |
| 582 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 583 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 584 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 585 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 586 | = new LogDecelerateInterpolator(100, 0); |
| 587 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 588 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 589 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 590 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 591 | 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] | 592 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 593 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 594 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 595 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 596 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 597 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 598 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 599 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 600 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 601 | |
| 602 | private class PolicyHandler extends Handler { |
| 603 | @Override |
| 604 | public void handleMessage(Message msg) { |
| 605 | switch (msg.what) { |
| 606 | case MSG_ENABLE_POINTER_LOCATION: |
| 607 | enablePointerLocation(); |
| 608 | break; |
| 609 | case MSG_DISABLE_POINTER_LOCATION: |
| 610 | disablePointerLocation(); |
| 611 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 612 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 613 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 614 | break; |
| 615 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 616 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 617 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 618 | case MSG_DISPATCH_SHOW_RECENTS: |
| 619 | showRecentApps(false); |
| 620 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 621 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 622 | showGlobalActionsInternal(); |
| 623 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 624 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 625 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 626 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 627 | break; |
| 628 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 629 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 630 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 631 | break; |
| 632 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 633 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 634 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 635 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 636 | case MSG_HIDE_BOOT_MESSAGE: |
| 637 | handleHideBootMessage(); |
| 638 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 639 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 640 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 641 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 642 | case MSG_POWER_DELAYED_PRESS: |
| 643 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 644 | finishPowerKeyPress(); |
| 645 | break; |
| 646 | case MSG_POWER_LONG_PRESS: |
| 647 | powerLongPress(); |
| 648 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | } |
| 652 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 653 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 654 | @Override |
| 655 | public void onUEvent(UEventObserver.UEvent event) { |
| 656 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 657 | } |
| 658 | }; |
| 659 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 660 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 661 | SettingsObserver(Handler handler) { |
| 662 | super(handler); |
| 663 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 664 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 665 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 666 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 667 | ContentResolver resolver = mContext.getContentResolver(); |
| 668 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 669 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 670 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 671 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 672 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 673 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 674 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 675 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 676 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 677 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 678 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 679 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 680 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 681 | Settings.System.USER_ROTATION), false, this, |
| 682 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 683 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 684 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 685 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 686 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 687 | Settings.System.POINTER_LOCATION), false, this, |
| 688 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 689 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 690 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 691 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 692 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 693 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 694 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 695 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 696 | Settings.Global.POLICY_CONTROL), false, this, |
| 697 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 698 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 702 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 703 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 704 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 705 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 706 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 707 | class MyWakeGestureListener extends WakeGestureListener { |
| 708 | MyWakeGestureListener(Context context, Handler handler) { |
| 709 | super(context, handler); |
| 710 | } |
| 711 | |
| 712 | @Override |
| 713 | public void onWakeUp() { |
| 714 | synchronized (mLock) { |
| 715 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 716 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 717 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 723 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 724 | MyOrientationListener(Context context, Handler handler) { |
| 725 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 726 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 727 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 728 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 729 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 730 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 731 | updateRotation(false); |
| 732 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 733 | } |
| 734 | MyOrientationListener mOrientationListener; |
| 735 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 736 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 737 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 738 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 739 | View.NAVIGATION_BAR_TRANSIENT, |
| 740 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 741 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 742 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 743 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 744 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 745 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 746 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 747 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 748 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 749 | IStatusBarService getStatusBarService() { |
| 750 | synchronized (mServiceAquireLock) { |
| 751 | if (mStatusBarService == null) { |
| 752 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 753 | ServiceManager.getService("statusbar")); |
| 754 | } |
| 755 | return mStatusBarService; |
| 756 | } |
| 757 | } |
| 758 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 759 | /* |
| 760 | * We always let the sensor be switched on by default except when |
| 761 | * the user has explicitly disabled sensor based rotation or when the |
| 762 | * screen is switched off. |
| 763 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 764 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 765 | if (mSupportAutoRotation) { |
| 766 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 767 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 768 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 769 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 770 | // If the application has explicitly requested to follow the |
| 771 | // orientation, then we need to turn the sensor on. |
| 772 | return true; |
| 773 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 774 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 775 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 776 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 777 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 778 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 779 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 780 | // orientation management, |
| 781 | return true; |
| 782 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 783 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 784 | // If the setting for using the sensor by default is enabled, then |
| 785 | // we will always leave it on. Note that the user could go to |
| 786 | // a window that forces an orientation that does not use the |
| 787 | // sensor and in theory we could turn it off... however, when next |
| 788 | // turning it on we won't have a good value for the current |
| 789 | // orientation for a little bit, which can cause orientation |
| 790 | // changes to lag, so we'd like to keep it always on. (It will |
| 791 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 792 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 793 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 794 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 795 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 796 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 797 | /* |
| 798 | * Various use cases for invoking this function |
| 799 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 800 | * 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] | 801 | * if not already enabled |
| 802 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 803 | * already enabled |
| 804 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 805 | * screen turning on and current app has nosensor based orientation, do nothing |
| 806 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 807 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 808 | if (!mOrientationListener.canDetectOrientation()) { |
| 809 | // If sensor is turned off or nonexistent for some reason |
| 810 | return; |
| 811 | } |
| 812 | //Could have been invoked due to screen turning on or off or |
| 813 | //change of the currently visible window's orientation |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 814 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 815 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
| 816 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 817 | boolean disable = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 818 | if (mScreenOnEarly && mAwake) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 819 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 820 | disable = false; |
| 821 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 822 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 823 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 824 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 825 | mOrientationSensorEnabled = true; |
| 826 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 827 | } |
| 828 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 829 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 830 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 831 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 832 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 833 | mOrientationSensorEnabled = false; |
| 834 | } |
| 835 | } |
| 836 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 837 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 838 | // Hold a wake lock until the power key is released. |
| 839 | if (!mPowerKeyWakeLock.isHeld()) { |
| 840 | mPowerKeyWakeLock.acquire(); |
| 841 | } |
| 842 | |
| 843 | // Cancel multi-press detection timeout. |
| 844 | if (mPowerKeyPressCounter != 0) { |
| 845 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 846 | } |
| 847 | |
| 848 | // Detect user pressing the power button in panic when an application has |
| 849 | // taken over the whole screen. |
| 850 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Craig Mautner | 0124980e9 | 2014-11-30 21:15:34 -0800 | [diff] [blame] | 851 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 852 | if (panic) { |
| 853 | mHandler.post(mRequestTransientNav); |
| 854 | } |
| 855 | |
| 856 | // Latch power key state to detect screenshot chord. |
| 857 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 858 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 859 | mScreenshotChordPowerKeyTriggered = true; |
| 860 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 861 | interceptScreenshotChord(); |
| 862 | } |
| 863 | |
| 864 | // Stop ringing or end call if configured to do so when power is pressed. |
| 865 | TelecomManager telecomManager = getTelecommService(); |
| 866 | boolean hungUp = false; |
| 867 | if (telecomManager != null) { |
| 868 | if (telecomManager.isRinging()) { |
| 869 | // Pressing Power while there's a ringing incoming |
| 870 | // call should silence the ringer. |
| 871 | telecomManager.silenceRinger(); |
| 872 | } else if ((mIncallPowerBehavior |
| 873 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 874 | && telecomManager.isInCall() && interactive) { |
| 875 | // Otherwise, if "Power button ends call" is enabled, |
| 876 | // the Power button will hang up any current active call. |
| 877 | hungUp = telecomManager.endCall(); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | // If the power key has still not yet been handled, then detect short |
| 882 | // press, long press, or multi press and decide what to do. |
| 883 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
| 884 | || mScreenshotChordVolumeUpKeyTriggered; |
| 885 | if (!mPowerKeyHandled) { |
| 886 | if (interactive) { |
| 887 | // When interactive, we're already awake. |
| 888 | // Wait for a long press or for the button to be released to decide what to do. |
| 889 | if (hasLongPressOnPowerBehavior()) { |
| 890 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 891 | msg.setAsynchronous(true); |
| 892 | mHandler.sendMessageDelayed(msg, |
| 893 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 894 | } |
| 895 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 896 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 897 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 898 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 899 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 900 | msg.setAsynchronous(true); |
| 901 | mHandler.sendMessageDelayed(msg, |
| 902 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 903 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 904 | } else { |
| 905 | final int maxCount = getMaxMultiPressPowerCount(); |
| 906 | |
| 907 | if (maxCount <= 1) { |
| 908 | mPowerKeyHandled = true; |
| 909 | } else { |
| 910 | mBeganFromNonInteractive = true; |
| 911 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 912 | } |
| 913 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 917 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 918 | final boolean handled = canceled || mPowerKeyHandled; |
| 919 | mScreenshotChordPowerKeyTriggered = false; |
| 920 | cancelPendingScreenshotChordAction(); |
| 921 | cancelPendingPowerKeyAction(); |
| 922 | |
| 923 | if (!handled) { |
| 924 | // Figure out how to handle the key now that it has been released. |
| 925 | mPowerKeyPressCounter += 1; |
| 926 | |
| 927 | final int maxCount = getMaxMultiPressPowerCount(); |
| 928 | final long eventTime = event.getDownTime(); |
| 929 | if (mPowerKeyPressCounter < maxCount) { |
| 930 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 931 | // Continue holding the wake lock. |
| 932 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 933 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 934 | msg.setAsynchronous(true); |
| 935 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 936 | return; |
| 937 | } |
| 938 | |
| 939 | // No other actions. Handle it immediately. |
| 940 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 941 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 942 | |
| 943 | // Done. Reset our state. |
| 944 | finishPowerKeyPress(); |
| 945 | } |
| 946 | |
| 947 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 948 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 949 | mPowerKeyPressCounter = 0; |
| 950 | if (mPowerKeyWakeLock.isHeld()) { |
| 951 | mPowerKeyWakeLock.release(); |
| 952 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | private void cancelPendingPowerKeyAction() { |
| 956 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 957 | mPowerKeyHandled = true; |
| 958 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 959 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 963 | if (mScreenOnEarly && !mScreenOnFully) { |
| 964 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 965 | + "already in the process of turning the screen on."); |
| 966 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 967 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 968 | |
| 969 | if (count == 2) { |
| 970 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 971 | } else if (count == 3) { |
| 972 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 973 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 974 | switch (mShortPressOnPowerBehavior) { |
| 975 | case SHORT_PRESS_POWER_NOTHING: |
| 976 | break; |
| 977 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 978 | mPowerManager.goToSleep(eventTime, |
| 979 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 980 | break; |
| 981 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 982 | mPowerManager.goToSleep(eventTime, |
| 983 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 984 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 985 | break; |
| 986 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 987 | mPowerManager.goToSleep(eventTime, |
| 988 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 989 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 990 | launchHomeFromHotKey(); |
| 991 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 992 | case SHORT_PRESS_POWER_GO_HOME: |
| 993 | launchHomeFromHotKey(); |
| 994 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1000 | switch (behavior) { |
| 1001 | case MULTI_PRESS_POWER_NOTHING: |
| 1002 | break; |
| 1003 | case MULTI_PRESS_POWER_THEATER_MODE: |
| 1004 | if (isTheaterModeEnabled()) { |
| 1005 | Slog.i(TAG, "Toggling theater mode off."); |
| 1006 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1007 | Settings.Global.THEATER_MODE_ON, 0); |
| 1008 | if (!interactive) { |
| 1009 | wakeUpFromPowerKey(eventTime); |
| 1010 | } |
| 1011 | } else { |
| 1012 | Slog.i(TAG, "Toggling theater mode on."); |
| 1013 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1014 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1015 | |
| 1016 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1017 | mPowerManager.goToSleep(eventTime, |
| 1018 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1019 | } |
| 1020 | } |
| 1021 | break; |
| 1022 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1023 | Slog.i(TAG, "Starting brightness boost."); |
| 1024 | if (!interactive) { |
| 1025 | wakeUpFromPowerKey(eventTime); |
| 1026 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1027 | mPowerManager.boostScreenBrightness(eventTime); |
| 1028 | break; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | private int getMaxMultiPressPowerCount() { |
| 1033 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1034 | return 3; |
| 1035 | } |
| 1036 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1037 | return 2; |
| 1038 | } |
| 1039 | return 1; |
| 1040 | } |
| 1041 | |
| 1042 | private void powerLongPress() { |
| 1043 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1044 | switch (behavior) { |
| 1045 | case LONG_PRESS_POWER_NOTHING: |
| 1046 | break; |
| 1047 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1048 | mPowerKeyHandled = true; |
| 1049 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1050 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1051 | } |
| 1052 | showGlobalActionsInternal(); |
| 1053 | break; |
| 1054 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1055 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1056 | mPowerKeyHandled = true; |
| 1057 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1058 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1059 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1060 | break; |
| 1061 | } |
| 1062 | } |
| 1063 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1064 | private void sleepPress(KeyEvent event) { |
| 1065 | switch (mShortPressOnSleepBehavior) { |
| 1066 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
| 1067 | mPowerManager.goToSleep(event.getEventTime(), |
| 1068 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
| 1069 | break; |
| 1070 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
| 1071 | launchHomeFromHotKey(false /* awakenDreams */); |
| 1072 | mPowerManager.goToSleep(event.getEventTime(), |
| 1073 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
| 1074 | break; |
| 1075 | } |
| 1076 | } |
| 1077 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1078 | private int getResolvedLongPressOnPowerBehavior() { |
| 1079 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1080 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1081 | } |
| 1082 | return mLongPressOnPowerBehavior; |
| 1083 | } |
| 1084 | |
| 1085 | private boolean hasLongPressOnPowerBehavior() { |
| 1086 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1090 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1091 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1092 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1093 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1094 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1095 | && now <= mScreenshotChordPowerKeyTime |
| 1096 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1097 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1098 | cancelPendingPowerKeyAction(); |
| 1099 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1100 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1105 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1106 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1107 | // Double the time it takes to take a screenshot from the keyguard |
| 1108 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1109 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1110 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1111 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1114 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1115 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1118 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1119 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1120 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1121 | mEndCallKeyHandled = true; |
| 1122 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1123 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1124 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1125 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1126 | } |
| 1127 | }; |
| 1128 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1129 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1130 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1131 | public void run() { |
| 1132 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1133 | } |
| 1134 | }; |
| 1135 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1136 | @Override |
| 1137 | public void showGlobalActions() { |
| 1138 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1139 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1140 | } |
| 1141 | |
| 1142 | void showGlobalActionsInternal() { |
| 1143 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1144 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1145 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1146 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1147 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1148 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1149 | if (keyguardShowing) { |
| 1150 | // since it took two seconds of long press to bring this up, |
| 1151 | // 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] | 1152 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1157 | return Settings.Global.getInt( |
| 1158 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1159 | } |
| 1160 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1161 | boolean isUserSetupComplete() { |
| 1162 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1163 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1164 | } |
| 1165 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1166 | private void handleShortPressOnHome() { |
| 1167 | // If there's a dream running then use home to escape the dream |
| 1168 | // but don't actually go home. |
| 1169 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1170 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1171 | return; |
| 1172 | } |
| 1173 | |
| 1174 | // Go home! |
| 1175 | launchHomeFromHotKey(); |
| 1176 | } |
| 1177 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1178 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1179 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1180 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1181 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1182 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1183 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 1184 | toggleRecentApps(); |
| 1185 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 1186 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1187 | } |
| 1188 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1189 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1190 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1191 | private void handleDoubleTapOnHome() { |
| 1192 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1193 | mHomeConsumed = true; |
| 1194 | toggleRecentApps(); |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1199 | @Override |
| 1200 | public void run() { |
| 1201 | if (mHomeDoubleTapPending) { |
| 1202 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1203 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | }; |
| 1207 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1208 | private boolean isRoundWindow() { |
| 1209 | return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound) |
| 1210 | || (Build.HARDWARE.contains("goldfish") |
| 1211 | && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false)); |
| 1212 | } |
| 1213 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1214 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1215 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1216 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1217 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1218 | mContext = context; |
| 1219 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1220 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1221 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1222 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1223 | |
| 1224 | // Init display burn-in protection |
| 1225 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1226 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1227 | // Allow a system property to override this. Used by developer settings. |
| 1228 | boolean burnInProtectionDevMode = |
| 1229 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1230 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1231 | final int minHorizontal; |
| 1232 | final int maxHorizontal; |
| 1233 | final int minVertical; |
| 1234 | final int maxVertical; |
| 1235 | final int maxRadius; |
| 1236 | if (burnInProtectionDevMode) { |
| 1237 | minHorizontal = -8; |
| 1238 | maxHorizontal = 8; |
| 1239 | minVertical = -8; |
| 1240 | maxVertical = -4; |
| 1241 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1242 | } else { |
| 1243 | Resources resources = context.getResources(); |
| 1244 | minHorizontal = resources.getInteger( |
| 1245 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1246 | maxHorizontal = resources.getInteger( |
| 1247 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1248 | minVertical = resources.getInteger( |
| 1249 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1250 | maxVertical = resources.getInteger( |
| 1251 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1252 | maxRadius = resources.getInteger( |
| 1253 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1254 | } |
| 1255 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1256 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1257 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1258 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1259 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1260 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1261 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1262 | try { |
| 1263 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1264 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1265 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1266 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1267 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1268 | mUiMode = context.getResources().getInteger( |
| 1269 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1270 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1271 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1272 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1273 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1274 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1275 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1276 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1277 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1278 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1279 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1280 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1281 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1282 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1283 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1284 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1285 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1286 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1287 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1288 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1289 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1290 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1291 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1292 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1293 | mCarDockRotation = readRotation( |
| 1294 | com.android.internal.R.integer.config_carDockRotation); |
| 1295 | mDeskDockRotation = readRotation( |
| 1296 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1297 | mUndockedHdmiRotation = readRotation( |
| 1298 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1299 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1300 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1301 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1302 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1303 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1304 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1305 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1306 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1307 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1308 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1309 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1310 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1311 | |
| 1312 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1313 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1314 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1315 | || mContext.getResources().getBoolean( |
| 1316 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1317 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1318 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1319 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1320 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1321 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1322 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1323 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1324 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1325 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1326 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1327 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1328 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1329 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1330 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1331 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1332 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1333 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1334 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1335 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1336 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1337 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1338 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1339 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1340 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1341 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1342 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1343 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1344 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1345 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1346 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1347 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1348 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1349 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1350 | Context.ACCESSIBILITY_SERVICE); |
| 1351 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1352 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1353 | IntentFilter filter = new IntentFilter(); |
| 1354 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1355 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1356 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1357 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1358 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1359 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1360 | if (intent != null) { |
| 1361 | // Retrieve current sticky dock event broadcast. |
| 1362 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1363 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1364 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1365 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1366 | // register for dream-related broadcasts |
| 1367 | filter = new IntentFilter(); |
| 1368 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1369 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1370 | context.registerReceiver(mDreamReceiver, filter); |
| 1371 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1372 | // register for multiuser-relevant broadcasts |
| 1373 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1374 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1375 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1376 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1377 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1378 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1379 | @Override |
| 1380 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1381 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1382 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1383 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1384 | } |
| 1385 | @Override |
| 1386 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1387 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1388 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1389 | } |
| 1390 | } |
| 1391 | @Override |
| 1392 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1393 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1394 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | @Override |
| 1398 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1399 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1400 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1401 | @Override |
| 1402 | public void onDown() { |
| 1403 | mOrientationListener.onTouchStart(); |
| 1404 | } |
| 1405 | @Override |
| 1406 | public void onUpOrCancel() { |
| 1407 | mOrientationListener.onTouchEnd(); |
| 1408 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1409 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1410 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1411 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1412 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1413 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1414 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1415 | com.android.internal.R.array.config_longPressVibePattern); |
| 1416 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1417 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1418 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1419 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1420 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1421 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1422 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1423 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1424 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1425 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1426 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1427 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1428 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1429 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1430 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1431 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1432 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1433 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1434 | // Controls rotation and the like. |
| 1435 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1436 | |
| 1437 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1438 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 1439 | goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1440 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1441 | |
| 1442 | mWindowManagerInternal.registerAppTransitionListener( |
| 1443 | mStatusBarController.getAppTransitionListener()); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1446 | /** |
| 1447 | * Read values from config.xml that may be overridden depending on |
| 1448 | * the configuration of the device. |
| 1449 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1450 | */ |
| 1451 | private void readConfigurationDependentBehaviors() { |
| 1452 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1453 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1454 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1455 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1456 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1457 | } |
| 1458 | |
| 1459 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1460 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1461 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1462 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1463 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1464 | } |
| 1465 | } |
| 1466 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1467 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1468 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1469 | // This method might be called before the policy has been fully initialized |
| 1470 | // or for other displays we don't care about. |
| 1471 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1472 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1473 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1474 | mDisplay = display; |
| 1475 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1476 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1477 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1478 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1479 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1480 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1481 | mLandscapeRotation = Surface.ROTATION_0; |
| 1482 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1483 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1484 | mPortraitRotation = Surface.ROTATION_90; |
| 1485 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1486 | } else { |
| 1487 | mPortraitRotation = Surface.ROTATION_270; |
| 1488 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1489 | } |
| 1490 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1491 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1492 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1493 | mPortraitRotation = Surface.ROTATION_0; |
| 1494 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1495 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1496 | mLandscapeRotation = Surface.ROTATION_270; |
| 1497 | mSeascapeRotation = Surface.ROTATION_90; |
| 1498 | } else { |
| 1499 | mLandscapeRotation = Surface.ROTATION_90; |
| 1500 | mSeascapeRotation = Surface.ROTATION_270; |
| 1501 | } |
| 1502 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1503 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1504 | mStatusBarHeight = |
| 1505 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1506 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1507 | // Height of the navigation bar when presented horizontally at bottom |
| 1508 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1509 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1510 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1511 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1512 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1513 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1514 | |
| 1515 | // Width of the navigation bar when presented vertically along one side |
| 1516 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1517 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1518 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1519 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1520 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1521 | |
| 1522 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1523 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1524 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1525 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 1526 | // Allow the navigation bar to move on non-square small devices (phones). |
| 1527 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1528 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1529 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1530 | // Allow a system property to override this. Used by the emulator. |
| 1531 | // See also hasNavigationBar(). |
| 1532 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1533 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1534 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1535 | } else if ("0".equals(navBarOverride)) { |
| 1536 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1537 | } |
| 1538 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1539 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1540 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1541 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1542 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1543 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1544 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1545 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1546 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1547 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 1548 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 1549 | // By default, remote display locks rotation to landscape. |
| 1550 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 1551 | mDemoRotation = mPortraitRotation; |
| 1552 | } else { |
| 1553 | mDemoRotation = mLandscapeRotation; |
| 1554 | } |
| 1555 | mDemoRotationLock = SystemProperties.getBoolean( |
| 1556 | "persist.demo.rotationlock", false); |
| 1557 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1558 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1559 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1560 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1561 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1562 | // For debug purposes the next line turns this feature off with: |
| 1563 | // $ adb shell setprop config.override_forced_orient true |
| 1564 | // $ adb shell wm size reset |
| 1565 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1566 | } |
| 1567 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1568 | /** |
| 1569 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1570 | * navigation bar and touch exploration is not enabled |
| 1571 | */ |
| 1572 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1573 | return mHasNavigationBar |
| 1574 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1577 | @Override |
| 1578 | public boolean isDefaultOrientationForced() { |
| 1579 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1582 | @Override |
| 1583 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1584 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1585 | mOverscanLeft = left; |
| 1586 | mOverscanTop = top; |
| 1587 | mOverscanRight = right; |
| 1588 | mOverscanBottom = bottom; |
| 1589 | } |
| 1590 | } |
| 1591 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1592 | public void updateSettings() { |
| 1593 | ContentResolver resolver = mContext.getContentResolver(); |
| 1594 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1595 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1596 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1597 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1598 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1599 | UserHandle.USER_CURRENT); |
| 1600 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1601 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1602 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1603 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1604 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1605 | // Configure wake gesture. |
| 1606 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1607 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1608 | UserHandle.USER_CURRENT) != 0; |
| 1609 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1610 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1611 | updateWakeGestureListenerLp(); |
| 1612 | } |
| 1613 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1614 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1615 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1616 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1617 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1618 | if (mUserRotation != userRotation) { |
| 1619 | mUserRotation = userRotation; |
| 1620 | updateRotation = true; |
| 1621 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1622 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1623 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1624 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1625 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1626 | if (mUserRotationMode != userRotationMode) { |
| 1627 | mUserRotationMode = userRotationMode; |
| 1628 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1629 | updateOrientationListenerLp(); |
| 1630 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1631 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1632 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1633 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1634 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1635 | if (mPointerLocationMode != pointerLocation) { |
| 1636 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1637 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1638 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1642 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1643 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1644 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1645 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1646 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1647 | if (mHasSoftInput != hasSoftInput) { |
| 1648 | mHasSoftInput = hasSoftInput; |
| 1649 | updateRotation = true; |
| 1650 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1651 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1652 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1653 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1654 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1655 | } |
| 1656 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1657 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1658 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1661 | private void updateWakeGestureListenerLp() { |
| 1662 | if (shouldEnableWakeGestureLp()) { |
| 1663 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1664 | } else { |
| 1665 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1670 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1671 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1672 | && mWakeGestureListener.isSupported(); |
| 1673 | } |
| 1674 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1675 | private void enablePointerLocation() { |
| 1676 | if (mPointerLocationView == null) { |
| 1677 | mPointerLocationView = new PointerLocationView(mContext); |
| 1678 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1679 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1680 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1681 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1682 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1683 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1684 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1685 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1686 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1687 | if (ActivityManager.isHighEndGfx()) { |
| 1688 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1689 | lp.privateFlags |= |
| 1690 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1691 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1692 | lp.format = PixelFormat.TRANSLUCENT; |
| 1693 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1694 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1695 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1696 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1697 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1698 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1699 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1700 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1701 | |
| 1702 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1703 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1704 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1705 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1706 | wm.removeView(mPointerLocationView); |
| 1707 | mPointerLocationView = null; |
| 1708 | } |
| 1709 | } |
| 1710 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1711 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1712 | try { |
| 1713 | int rotation = mContext.getResources().getInteger(resID); |
| 1714 | switch (rotation) { |
| 1715 | case 0: |
| 1716 | return Surface.ROTATION_0; |
| 1717 | case 90: |
| 1718 | return Surface.ROTATION_90; |
| 1719 | case 180: |
| 1720 | return Surface.ROTATION_180; |
| 1721 | case 270: |
| 1722 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1723 | } |
| 1724 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1725 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1726 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1727 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1731 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1732 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1733 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1734 | |
| 1735 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1736 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 1737 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 1738 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 1739 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 1740 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 1741 | } |
| 1742 | |
| 1743 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 1744 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1745 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1746 | } |
| 1747 | String permission = null; |
| 1748 | switch (type) { |
| 1749 | case TYPE_TOAST: |
| 1750 | // XXX right now the app process has complete control over |
| 1751 | // this... should introduce a token to let the system |
| 1752 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1753 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1754 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1755 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1756 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1757 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1758 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1759 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1760 | case TYPE_ACCESSIBILITY_OVERLAY: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1761 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1762 | break; |
| 1763 | case TYPE_PHONE: |
| 1764 | case TYPE_PRIORITY_PHONE: |
| 1765 | case TYPE_SYSTEM_ALERT: |
| 1766 | case TYPE_SYSTEM_ERROR: |
| 1767 | case TYPE_SYSTEM_OVERLAY: |
| 1768 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1769 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1770 | break; |
| 1771 | default: |
| 1772 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1773 | } |
| 1774 | if (permission != null) { |
| 1775 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1776 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1777 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1778 | } |
| 1779 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1780 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1781 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1782 | |
| 1783 | @Override |
| 1784 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1785 | |
| 1786 | // If this switch statement is modified, modify the comment in the declarations of |
| 1787 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1788 | switch (attrs.type) { |
| 1789 | default: |
| 1790 | // These are the windows that by default are shown only to the user that created |
| 1791 | // them. If this needs to be overridden, set |
| 1792 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1793 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1794 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1795 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1796 | return true; |
| 1797 | } |
| 1798 | break; |
| 1799 | |
| 1800 | // These are the windows that by default are shown to all users. However, to |
| 1801 | // protect against spoofing, check permissions below. |
| 1802 | case TYPE_APPLICATION_STARTING: |
| 1803 | case TYPE_BOOT_PROGRESS: |
| 1804 | case TYPE_DISPLAY_OVERLAY: |
| 1805 | case TYPE_HIDDEN_NAV_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1806 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1807 | case TYPE_KEYGUARD_DIALOG: |
| 1808 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1809 | case TYPE_NAVIGATION_BAR: |
| 1810 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1811 | case TYPE_PHONE: |
| 1812 | case TYPE_POINTER: |
| 1813 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1814 | case TYPE_SEARCH_BAR: |
| 1815 | case TYPE_STATUS_BAR: |
| 1816 | case TYPE_STATUS_BAR_PANEL: |
| 1817 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1818 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1819 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1820 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1821 | break; |
| 1822 | } |
| 1823 | |
| 1824 | // Check if third party app has set window to system window type. |
| 1825 | return mContext.checkCallingOrSelfPermission( |
| 1826 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1827 | != PackageManager.PERMISSION_GRANTED; |
| 1828 | } |
| 1829 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1830 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1831 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1832 | switch (attrs.type) { |
| 1833 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1834 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1835 | // These types of windows can't receive input events. |
| 1836 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1837 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1838 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1839 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1840 | case TYPE_STATUS_BAR: |
| 1841 | |
| 1842 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 1843 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 1844 | // the keyguard as occluded wouldn't set these flags again. |
| 1845 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 1846 | if (mKeyguardHidden) { |
| 1847 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 1848 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1849 | } |
| 1850 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1851 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 1852 | |
| 1853 | if (attrs.type != TYPE_STATUS_BAR) { |
| 1854 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 1855 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1856 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1857 | |
| 1858 | if (ActivityManager.isHighEndGfx() |
| 1859 | && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
Adrian Roos | f5e9b5c | 2014-09-10 15:27:41 +0200 | [diff] [blame] | 1860 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1861 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1862 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1863 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1864 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1865 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1866 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1867 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1868 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 1869 | private void readCameraLensCoverState() { |
| 1870 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 1871 | } |
| 1872 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1873 | private boolean isHidden(int accessibilityMode) { |
| 1874 | switch (accessibilityMode) { |
| 1875 | case 1: |
| 1876 | return mLidState == LID_CLOSED; |
| 1877 | case 2: |
| 1878 | return mLidState == LID_OPEN; |
| 1879 | default: |
| 1880 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1881 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1882 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1883 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1884 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1885 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1886 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1887 | int navigationPresence) { |
| 1888 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1889 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1890 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1891 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1892 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1893 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1894 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1895 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1896 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1897 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1898 | if (!mHasSoftInput) { |
| 1899 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1900 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1901 | } |
| 1902 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1903 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1904 | || (navigationPresence == PRESENCE_INTERNAL |
| 1905 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1906 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1907 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1908 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1909 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1910 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1911 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1912 | public int windowTypeToLayerLw(int type) { |
| 1913 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1914 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1915 | } |
| 1916 | switch (type) { |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1917 | case TYPE_PRIVATE_PRESENTATION: |
| 1918 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1919 | case TYPE_WALLPAPER: |
| 1920 | // wallpaper is at the bottom, though the window manager may move it. |
| 1921 | return 2; |
| 1922 | case TYPE_PHONE: |
| 1923 | return 3; |
| 1924 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame^] | 1925 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1926 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1927 | case TYPE_VOICE_INTERACTION: |
| 1928 | // voice interaction layer is almost immediately above apps. |
| 1929 | return 5; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1930 | case TYPE_SYSTEM_DIALOG: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1931 | return 6; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1932 | case TYPE_TOAST: |
| 1933 | // toasts and the plugged-in battery thing |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1934 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1935 | case TYPE_PRIORITY_PHONE: |
| 1936 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1937 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1938 | case TYPE_DREAM: |
| 1939 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1940 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1941 | case TYPE_SYSTEM_ALERT: |
| 1942 | // like the ANR / app crashed dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1943 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1944 | case TYPE_INPUT_METHOD: |
| 1945 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1946 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1947 | case TYPE_INPUT_METHOD_DIALOG: |
| 1948 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1949 | return 12; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1950 | case TYPE_KEYGUARD_SCRIM: |
| 1951 | // the safety window that shows behind keyguard while keyguard is starting |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1952 | return 13; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1953 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1954 | return 14; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1955 | case TYPE_STATUS_BAR: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1956 | return 15; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1957 | case TYPE_STATUS_BAR_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1958 | return 16; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1959 | case TYPE_KEYGUARD_DIALOG: |
| 1960 | return 17; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1961 | case TYPE_VOLUME_OVERLAY: |
| 1962 | // the on-screen volume indicator and controller shown when the user |
| 1963 | // changes the device volume |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1964 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1965 | case TYPE_SYSTEM_OVERLAY: |
| 1966 | // the on-screen volume indicator and controller shown when the user |
| 1967 | // changes the device volume |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1968 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1969 | case TYPE_NAVIGATION_BAR: |
| 1970 | // the navigation bar, if available, shows atop most things |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1971 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1972 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1973 | // some panels (e.g. search) need to show on top of the navigation bar |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1974 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1975 | case TYPE_SYSTEM_ERROR: |
| 1976 | // system-level error dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1977 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1978 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1979 | // used to highlight the magnified portion of a display |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1980 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1981 | case TYPE_DISPLAY_OVERLAY: |
| 1982 | // used to simulate secondary display devices |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1983 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1984 | case TYPE_DRAG: |
| 1985 | // the drag layer: input for drag-and-drop is associated with this window, |
| 1986 | // which sits above all other focusable windows |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1987 | return 25; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1988 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 1989 | // overlay put by accessibility services to intercept user interaction |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1990 | return 26; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1991 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1992 | return 27; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1993 | case TYPE_BOOT_PROGRESS: |
| 1994 | return 28; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1995 | case TYPE_POINTER: |
| 1996 | // the (mouse) pointer layer |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1997 | return 29; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1998 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1999 | return 30; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2000 | } |
| 2001 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2002 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2006 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2007 | public int subWindowTypeToLayerLw(int type) { |
| 2008 | switch (type) { |
| 2009 | case TYPE_APPLICATION_PANEL: |
| 2010 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2011 | return APPLICATION_PANEL_SUBLAYER; |
| 2012 | case TYPE_APPLICATION_MEDIA: |
| 2013 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2014 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2015 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2016 | case TYPE_APPLICATION_SUB_PANEL: |
| 2017 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 2018 | } |
| 2019 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2020 | return 0; |
| 2021 | } |
| 2022 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2023 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2024 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2025 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2028 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2029 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2030 | if (mHasNavigationBar) { |
| 2031 | // For a basic navigation bar, when we are in landscape mode we place |
| 2032 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2033 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 2034 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2035 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2036 | } |
| 2037 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2038 | } |
| 2039 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2040 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2041 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2042 | if (mHasNavigationBar) { |
| 2043 | // For a basic navigation bar, when we are in portrait mode we place |
| 2044 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2045 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 2046 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2047 | } |
| 2048 | } |
| 2049 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2052 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2053 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 2054 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2057 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2058 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2059 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2060 | // 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] | 2061 | // we do want to exclude it since applications can't generally use that part |
| 2062 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2063 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2064 | } |
| 2065 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2066 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 2067 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 2068 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2069 | (isKeyguardHostWindow(attrs) && |
| 2070 | (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 2071 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2072 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2073 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2074 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2075 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2076 | return attrs.type == TYPE_STATUS_BAR; |
| 2077 | } |
| 2078 | |
| 2079 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2080 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2081 | switch (attrs.type) { |
| 2082 | case TYPE_STATUS_BAR: |
| 2083 | case TYPE_NAVIGATION_BAR: |
| 2084 | case TYPE_WALLPAPER: |
| 2085 | case TYPE_DREAM: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2086 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2087 | return false; |
| 2088 | default: |
| 2089 | return true; |
| 2090 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2091 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2092 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2093 | @Override |
| 2094 | public WindowState getWinShowWhenLockedLw() { |
| 2095 | return mWinShowWhenLocked; |
| 2096 | } |
| 2097 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2098 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2099 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2100 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2101 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2102 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2103 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2104 | return null; |
| 2105 | } |
| 2106 | if (packageName == null) { |
| 2107 | return null; |
| 2108 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2109 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2110 | WindowManager wm = null; |
| 2111 | View view = null; |
| 2112 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2113 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2114 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2115 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2116 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2117 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2118 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2119 | try { |
| 2120 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2121 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2122 | } catch (PackageManager.NameNotFoundException e) { |
| 2123 | // Ignore |
| 2124 | } |
| 2125 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2126 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 2127 | Window win = new PhoneWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2128 | final TypedArray ta = win.getWindowStyle(); |
| 2129 | if (ta.getBoolean( |
| 2130 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 2131 | || ta.getBoolean( |
| 2132 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2133 | return null; |
| 2134 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2135 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2136 | Resources r = context.getResources(); |
| 2137 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2138 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2139 | win.setType( |
| 2140 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 2141 | // Force the window flags: this is a fake window, so it is not really |
| 2142 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2143 | // flag because we do know that the next window will take input |
| 2144 | // focus, so we want to get the IME window up on top of us right away. |
| 2145 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2146 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2147 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2148 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2149 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2150 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2151 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2152 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2153 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2154 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2155 | win.setDefaultIcon(icon); |
| 2156 | win.setDefaultLogo(logo); |
| 2157 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2158 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2159 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2160 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2161 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2162 | params.token = appToken; |
| 2163 | params.packageName = packageName; |
| 2164 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2165 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2166 | params.privateFlags |= |
| 2167 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2168 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2169 | |
| 2170 | if (!compatInfo.supportsScreen()) { |
| 2171 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2172 | } |
| 2173 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2174 | params.setTitle("Starting " + packageName); |
| 2175 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2176 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2177 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2178 | |
| 2179 | if (win.isFloating()) { |
| 2180 | // Whoops, there is no way to display an animation/preview |
| 2181 | // of such a thing! After all that work... let's skip it. |
| 2182 | // (Note that we must do this here because it is in |
| 2183 | // getDecorView() where the theme is evaluated... maybe |
| 2184 | // we should peek the floating attribute from the theme |
| 2185 | // earlier.) |
| 2186 | return null; |
| 2187 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2188 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2189 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2190 | TAG, "Adding starting window for " + packageName |
| 2191 | + " / " + appToken + ": " |
| 2192 | + (view.getParent() != null ? view : null)); |
| 2193 | |
| 2194 | wm.addView(view, params); |
| 2195 | |
| 2196 | // Only return the view if it was successfully added to the |
| 2197 | // window manager... which we can tell by it having a parent. |
| 2198 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2199 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2200 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2201 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2202 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2203 | } catch (RuntimeException e) { |
| 2204 | // don't crash if something else bad happens, for example a |
| 2205 | // failure loading resources because we are loading from an app |
| 2206 | // on external storage that has been unmounted. |
| 2207 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2208 | } finally { |
| 2209 | if (view != null && view.getParent() == null) { |
| 2210 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2211 | wm.removeViewImmediate(view); |
| 2212 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | return null; |
| 2216 | } |
| 2217 | |
| 2218 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2219 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2220 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2221 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2222 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2223 | |
| 2224 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2225 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2226 | wm.removeView(window); |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2232 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2233 | * Currently enforces that three window types are singletons: |
| 2234 | * <ul> |
| 2235 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2236 | * <li>KEYGUARD_TYPE</li> |
| 2237 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2238 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2239 | * @param win The window to be added |
| 2240 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2241 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2242 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2243 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2244 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2245 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2246 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2247 | switch (attrs.type) { |
| 2248 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2249 | mContext.enforceCallingOrSelfPermission( |
| 2250 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2251 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2252 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2253 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2254 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2255 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2256 | } |
| 2257 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2258 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2259 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2260 | case TYPE_NAVIGATION_BAR: |
| 2261 | mContext.enforceCallingOrSelfPermission( |
| 2262 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2263 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2264 | if (mNavigationBar != null) { |
| 2265 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2266 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2267 | } |
| 2268 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2269 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2270 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2271 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2272 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2273 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2274 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2275 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame^] | 2276 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2277 | mContext.enforceCallingOrSelfPermission( |
| 2278 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2279 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2280 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2281 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2282 | if (mKeyguardScrim != null) { |
| 2283 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2284 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2285 | mKeyguardScrim = win; |
| 2286 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2287 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2288 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2292 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2293 | public void removeWindowLw(WindowState win) { |
| 2294 | if (mStatusBar == win) { |
| 2295 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2296 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2297 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2298 | } else if (mKeyguardScrim == win) { |
| 2299 | Log.v(TAG, "Removing keyguard scrim"); |
| 2300 | mKeyguardScrim = null; |
| 2301 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2302 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2303 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2308 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2309 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2310 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2311 | public int selectAnimationLw(WindowState win, int transit) { |
| 2312 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2313 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2314 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2315 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2316 | if (transit == TRANSIT_EXIT |
| 2317 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2318 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2319 | } else if (transit == TRANSIT_ENTER |
| 2320 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2321 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2322 | } |
| 2323 | } else if (win == mNavigationBar) { |
| 2324 | // This can be on either the bottom or the right. |
| 2325 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2326 | if (transit == TRANSIT_EXIT |
| 2327 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2328 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2329 | } else if (transit == TRANSIT_ENTER |
| 2330 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2331 | return R.anim.dock_bottom_enter; |
| 2332 | } |
| 2333 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2334 | if (transit == TRANSIT_EXIT |
| 2335 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2336 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2337 | } else if (transit == TRANSIT_ENTER |
| 2338 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2339 | return R.anim.dock_right_enter; |
| 2340 | } |
| 2341 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2345 | if (win.hasAppShownWindows()) { |
| 2346 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2347 | return com.android.internal.R.anim.app_starting_exit; |
| 2348 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2349 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2350 | && transit == TRANSIT_ENTER) { |
| 2351 | // Special case: we are animating in a dream, while the keyguard |
| 2352 | // is shown. We don't want an animation on the dream, because |
| 2353 | // we need it shown immediately with the keyguard animating away |
| 2354 | // to reveal it. |
| 2355 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | return 0; |
| 2359 | } |
| 2360 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2361 | @Override |
| 2362 | public void selectRotationAnimationLw(int anim[]) { |
| 2363 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2364 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2365 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2366 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2367 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2368 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2369 | case ROTATION_ANIMATION_CROSSFADE: |
| 2370 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2371 | anim[1] = R.anim.rotation_animation_enter; |
| 2372 | break; |
| 2373 | case ROTATION_ANIMATION_JUMPCUT: |
| 2374 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2375 | anim[1] = R.anim.rotation_animation_enter; |
| 2376 | break; |
| 2377 | case ROTATION_ANIMATION_ROTATE: |
| 2378 | default: |
| 2379 | anim[0] = anim[1] = 0; |
| 2380 | break; |
| 2381 | } |
| 2382 | } else { |
| 2383 | anim[0] = anim[1] = 0; |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | @Override |
| 2388 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2389 | boolean forceDefault) { |
| 2390 | switch (exitAnimId) { |
| 2391 | case R.anim.rotation_animation_xfade_exit: |
| 2392 | case R.anim.rotation_animation_jump_exit: |
| 2393 | // These are the only cases that matter. |
| 2394 | if (forceDefault) { |
| 2395 | return false; |
| 2396 | } |
| 2397 | int anim[] = new int[2]; |
| 2398 | selectRotationAnimationLw(anim); |
| 2399 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2400 | default: |
| 2401 | return true; |
| 2402 | } |
| 2403 | } |
| 2404 | |
| 2405 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2406 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2407 | boolean goingToNotificationShade) { |
| 2408 | if (goingToNotificationShade) { |
| 2409 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2410 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2411 | |
| 2412 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 2413 | R.anim.lock_screen_behind_enter_wallpaper : |
| 2414 | R.anim.lock_screen_behind_enter); |
| 2415 | |
| 2416 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2417 | final List<Animation> animations = set.getAnimations(); |
| 2418 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 2419 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 2420 | } |
| 2421 | |
| 2422 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | |
| 2426 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2427 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2428 | if (goingToNotificationShade) { |
| 2429 | return null; |
| 2430 | } else { |
| 2431 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2432 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2433 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2434 | |
| 2435 | private static void awakenDreams() { |
| 2436 | IDreamManager dreamManager = getDreamManager(); |
| 2437 | if (dreamManager != null) { |
| 2438 | try { |
| 2439 | dreamManager.awaken(); |
| 2440 | } catch (RemoteException e) { |
| 2441 | // fine, stay asleep then |
| 2442 | } |
| 2443 | } |
| 2444 | } |
| 2445 | |
| 2446 | static IDreamManager getDreamManager() { |
| 2447 | return IDreamManager.Stub.asInterface( |
| 2448 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2449 | } |
| 2450 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2451 | TelecomManager getTelecommService() { |
| 2452 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2453 | } |
| 2454 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2455 | static IAudioService getAudioService() { |
| 2456 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2457 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2458 | if (audioService == null) { |
| 2459 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2460 | } |
| 2461 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2465 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2469 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2470 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2471 | }; |
| 2472 | |
| 2473 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2474 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2475 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2476 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2477 | final int keyCode = event.getKeyCode(); |
| 2478 | final int repeatCount = event.getRepeatCount(); |
| 2479 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2480 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2481 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2482 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2483 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2484 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2485 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2486 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2487 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2488 | } |
| 2489 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2490 | // If we think we might have a volume down & power key chord on the way |
| 2491 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2492 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2493 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2494 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2495 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2496 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2497 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2498 | if (now < timeoutTime) { |
| 2499 | return timeoutTime - now; |
| 2500 | } |
| 2501 | } |
| 2502 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2503 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2504 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2505 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2506 | } |
| 2507 | return -1; |
| 2508 | } |
| 2509 | } |
| 2510 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2511 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2512 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2513 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2514 | mPendingMetaAction = false; |
| 2515 | } |
| 2516 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2517 | // First we always handle the home key here, so applications |
| 2518 | // can never break it, although if keyguard is on, we do let |
| 2519 | // it handle it, because that gives us the correct 5 second |
| 2520 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2521 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2522 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2523 | // If we have released the home key, and didn't do anything else |
| 2524 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2525 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2526 | cancelPreloadRecentApps(); |
| 2527 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2528 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2529 | if (mHomeConsumed) { |
| 2530 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2531 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2532 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2533 | |
| 2534 | if (canceled) { |
| 2535 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2536 | return -1; |
| 2537 | } |
| 2538 | |
Yorke Lee | 4f80324 | 2014-12-15 23:22:06 +0000 | [diff] [blame] | 2539 | // If an incoming call is ringing, HOME is totally disabled. |
| 2540 | // (The user is already on the InCallUI at this point, |
| 2541 | // and his ONLY options are to answer or reject the call.) |
| 2542 | TelecomManager telecomManager = getTelecommService(); |
| 2543 | if (telecomManager != null && telecomManager.isRinging()) { |
| 2544 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2545 | return -1; |
| 2546 | } |
| 2547 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2548 | // Delay handling home if a double-tap is possible. |
| 2549 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2550 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2551 | mHomeDoubleTapPending = true; |
| 2552 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2553 | ViewConfiguration.getDoubleTapTimeout()); |
| 2554 | return -1; |
| 2555 | } |
| 2556 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2557 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2558 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2559 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2560 | |
| 2561 | // If a system window has focus, then it doesn't make sense |
| 2562 | // right now to interact with applications. |
| 2563 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2564 | if (attrs != null) { |
| 2565 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2566 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2567 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2568 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2569 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2570 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2571 | } |
| 2572 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2573 | for (int i=0; i<typeCount; i++) { |
| 2574 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2575 | // 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] | 2576 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2577 | } |
| 2578 | } |
| 2579 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2580 | |
| 2581 | // Remember that home is pressed and handle special actions. |
| 2582 | if (repeatCount == 0) { |
| 2583 | mHomePressed = true; |
| 2584 | if (mHomeDoubleTapPending) { |
| 2585 | mHomeDoubleTapPending = false; |
| 2586 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2587 | handleDoubleTapOnHome(); |
| 2588 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2589 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2590 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2591 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2592 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2593 | if (!keyguardOn) { |
| 2594 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2595 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2596 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2597 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2598 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2599 | // Hijack modified menu keys for debugging features |
| 2600 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2601 | |
| 2602 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2603 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2604 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2605 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2606 | null, null, null, 0, null, null); |
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 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2609 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2610 | Intent service = new Intent(); |
| 2611 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2612 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2613 | boolean shown = Settings.Global.getInt( |
| 2614 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2615 | if (!shown) { |
| 2616 | mContext.startService(service); |
| 2617 | } else { |
| 2618 | mContext.stopService(service); |
| 2619 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2620 | Settings.Global.putInt( |
| 2621 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2622 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2623 | } |
| 2624 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2625 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2626 | if (down) { |
| 2627 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2628 | mSearchKeyShortcutPending = true; |
| 2629 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2630 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2631 | } else { |
| 2632 | mSearchKeyShortcutPending = false; |
| 2633 | if (mConsumeSearchKeyUp) { |
| 2634 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2635 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2636 | } |
| 2637 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2638 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2639 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2640 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2641 | if (down && repeatCount == 0) { |
| 2642 | preloadRecentApps(); |
| 2643 | } else if (!down) { |
| 2644 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2645 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2646 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2647 | return -1; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2648 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2649 | if (down) { |
| 2650 | if (repeatCount == 0) { |
| 2651 | mAssistKeyLongPressed = false; |
| 2652 | } else if (repeatCount == 1) { |
| 2653 | mAssistKeyLongPressed = true; |
| 2654 | if (!keyguardOn) { |
| 2655 | launchAssistLongPressAction(); |
| 2656 | } |
| 2657 | } |
| 2658 | } else { |
| 2659 | if (mAssistKeyLongPressed) { |
| 2660 | mAssistKeyLongPressed = false; |
| 2661 | } else { |
| 2662 | if (!keyguardOn) { |
| 2663 | launchAssistAction(); |
| 2664 | } |
| 2665 | } |
| 2666 | } |
| 2667 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2668 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2669 | if (!down) { |
| 2670 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2671 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2672 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2673 | } else { |
| 2674 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2675 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2676 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2677 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2678 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2679 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2680 | if (down && repeatCount == 0) { |
| 2681 | mHandler.post(mScreenshotRunnable); |
| 2682 | } |
| 2683 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2684 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2685 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2686 | if (down) { |
| 2687 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2688 | |
| 2689 | // Disable autobrightness if it's on |
| 2690 | int auto = Settings.System.getIntForUser( |
| 2691 | mContext.getContentResolver(), |
| 2692 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2693 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2694 | UserHandle.USER_CURRENT_OR_SELF); |
| 2695 | if (auto != 0) { |
| 2696 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2697 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2698 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2699 | UserHandle.USER_CURRENT_OR_SELF); |
| 2700 | } |
| 2701 | |
| 2702 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2703 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2704 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2705 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2706 | Settings.System.SCREEN_BRIGHTNESS, |
| 2707 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2708 | UserHandle.USER_CURRENT_OR_SELF); |
| 2709 | brightness += step; |
| 2710 | // Make sure we don't go beyond the limits. |
| 2711 | brightness = Math.min(max, brightness); |
| 2712 | brightness = Math.max(min, brightness); |
| 2713 | |
| 2714 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2715 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2716 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2717 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 2718 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2719 | } |
| 2720 | return -1; |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2721 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2722 | if (down) { |
| 2723 | mPendingMetaAction = true; |
| 2724 | } else if (mPendingMetaAction) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2725 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2726 | } |
| 2727 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2728 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2729 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2730 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2731 | // Any printing key that is chorded with Search should be consumed |
| 2732 | // even if no shortcut was invoked. This prevents text from being |
| 2733 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2734 | // 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] | 2735 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2736 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2737 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2738 | mConsumeSearchKeyUp = true; |
| 2739 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2740 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2741 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2742 | if (shortcutIntent != null) { |
| 2743 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2744 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2745 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2746 | } catch (ActivityNotFoundException ex) { |
| 2747 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2748 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2749 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2750 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2751 | } else { |
| 2752 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2753 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2754 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2755 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2756 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2757 | } |
| 2758 | } |
| 2759 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2760 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2761 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2762 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2763 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2764 | if (kcm.isPrintingKey(keyCode)) { |
| 2765 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2766 | metaState & ~(KeyEvent.META_META_ON |
| 2767 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2768 | if (shortcutIntent != null) { |
| 2769 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2770 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2771 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2772 | } catch (ActivityNotFoundException ex) { |
| 2773 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2774 | + "the activity to which it is registered was not found: " |
| 2775 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2776 | } |
| 2777 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2778 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2779 | } |
| 2780 | } |
| 2781 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2782 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2783 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2784 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2785 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2786 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2787 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2788 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2789 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2790 | } catch (ActivityNotFoundException ex) { |
| 2791 | Slog.w(TAG, "Dropping application launch key because " |
| 2792 | + "the activity to which it is registered was not found: " |
| 2793 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2794 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2795 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2796 | } |
| 2797 | } |
| 2798 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2799 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2800 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2801 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2802 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2803 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2804 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 2805 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2806 | return -1; |
| 2807 | } |
| 2808 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2809 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 2810 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 2811 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2812 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2813 | } |
| 2814 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2815 | // Handle keyboard language switching. |
| 2816 | if (down && repeatCount == 0 |
| 2817 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2818 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2819 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2820 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2821 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2822 | return -1; |
| 2823 | } |
| 2824 | if (mLanguageSwitchKeyPressed && !down |
| 2825 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2826 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2827 | mLanguageSwitchKeyPressed = false; |
| 2828 | return -1; |
| 2829 | } |
| 2830 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2831 | if (isValidGlobalKey(keyCode) |
| 2832 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2833 | return -1; |
| 2834 | } |
| 2835 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2836 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2837 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2838 | return -1; |
| 2839 | } |
| 2840 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2841 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2842 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2843 | } |
| 2844 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2845 | /** {@inheritDoc} */ |
| 2846 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2847 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2848 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2849 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2850 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2851 | + ", flags=" + event.getFlags() |
| 2852 | + ", keyCode=" + event.getKeyCode() |
| 2853 | + ", scanCode=" + event.getScanCode() |
| 2854 | + ", metaState=" + event.getMetaState() |
| 2855 | + ", repeatCount=" + event.getRepeatCount() |
| 2856 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2857 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2858 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2859 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2860 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2861 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2862 | final int keyCode = event.getKeyCode(); |
| 2863 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2864 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2865 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2866 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2867 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2868 | final FallbackAction fallbackAction; |
| 2869 | if (initialDown) { |
| 2870 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2871 | } else { |
| 2872 | fallbackAction = mFallbackActions.get(keyCode); |
| 2873 | } |
| 2874 | |
| 2875 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2876 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2877 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2878 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2879 | } |
| 2880 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2881 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2882 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2883 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2884 | event.getAction(), fallbackAction.keyCode, |
| 2885 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2886 | event.getDeviceId(), event.getScanCode(), |
| 2887 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2888 | |
| 2889 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2890 | fallbackEvent.recycle(); |
| 2891 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2892 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2893 | |
| 2894 | if (initialDown) { |
| 2895 | mFallbackActions.put(keyCode, fallbackAction); |
| 2896 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2897 | mFallbackActions.remove(keyCode); |
| 2898 | fallbackAction.recycle(); |
| 2899 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2900 | } |
| 2901 | } |
| 2902 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2903 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2904 | if (fallbackEvent == null) { |
| 2905 | Slog.d(TAG, "No fallback."); |
| 2906 | } else { |
| 2907 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2908 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2909 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2910 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2911 | } |
| 2912 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2913 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2914 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2915 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2916 | long delayMillis = interceptKeyBeforeDispatching( |
| 2917 | win, fallbackEvent, policyFlags); |
| 2918 | if (delayMillis == 0) { |
| 2919 | return true; |
| 2920 | } |
| 2921 | } |
| 2922 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2923 | } |
| 2924 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2925 | private void launchAssistLongPressAction() { |
| 2926 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2927 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2928 | |
| 2929 | // launch the search activity |
| 2930 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2931 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2932 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2933 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2934 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2935 | SearchManager searchManager = getSearchManager(); |
| 2936 | if (searchManager != null) { |
| 2937 | searchManager.stopSearch(); |
| 2938 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2939 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2940 | } catch (ActivityNotFoundException e) { |
| 2941 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | private void launchAssistAction() { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2946 | launchAssistAction(null); |
| 2947 | } |
| 2948 | |
| 2949 | private void launchAssistAction(String hint) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2950 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2951 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2952 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2953 | if (intent != null) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2954 | if (hint != null) { |
| 2955 | intent.putExtra(hint, true); |
| 2956 | } |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2957 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2958 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2959 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2960 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2961 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2962 | } catch (ActivityNotFoundException e) { |
| 2963 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2964 | } |
| 2965 | } |
| 2966 | } |
| 2967 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2968 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 2969 | if (isUserSetupComplete()) { |
| 2970 | mContext.startActivityAsUser(intent, handle); |
| 2971 | } else { |
| 2972 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 2973 | } |
| 2974 | } |
| 2975 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2976 | private SearchManager getSearchManager() { |
| 2977 | if (mSearchManager == null) { |
| 2978 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2979 | } |
| 2980 | return mSearchManager; |
| 2981 | } |
| 2982 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2983 | private void preloadRecentApps() { |
| 2984 | mPreloadedRecentApps = true; |
| 2985 | try { |
| 2986 | IStatusBarService statusbar = getStatusBarService(); |
| 2987 | if (statusbar != null) { |
| 2988 | statusbar.preloadRecentApps(); |
| 2989 | } |
| 2990 | } catch (RemoteException e) { |
| 2991 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 2992 | // re-acquire status bar service next time it is needed. |
| 2993 | mStatusBarService = null; |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | private void cancelPreloadRecentApps() { |
| 2998 | if (mPreloadedRecentApps) { |
| 2999 | mPreloadedRecentApps = false; |
| 3000 | try { |
| 3001 | IStatusBarService statusbar = getStatusBarService(); |
| 3002 | if (statusbar != null) { |
| 3003 | statusbar.cancelPreloadRecentApps(); |
| 3004 | } |
| 3005 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3006 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3007 | // re-acquire status bar service next time it is needed. |
| 3008 | mStatusBarService = null; |
| 3009 | } |
| 3010 | } |
| 3011 | } |
| 3012 | |
| 3013 | private void toggleRecentApps() { |
| 3014 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3015 | try { |
| 3016 | IStatusBarService statusbar = getStatusBarService(); |
| 3017 | if (statusbar != null) { |
| 3018 | statusbar.toggleRecentApps(); |
| 3019 | } |
| 3020 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3021 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 3022 | // re-acquire status bar service next time it is needed. |
| 3023 | mStatusBarService = null; |
| 3024 | } |
| 3025 | } |
| 3026 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3027 | @Override |
| 3028 | public void showRecentApps() { |
| 3029 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 3030 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 3031 | } |
| 3032 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3033 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 3034 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3035 | try { |
| 3036 | IStatusBarService statusbar = getStatusBarService(); |
| 3037 | if (statusbar != null) { |
| 3038 | statusbar.showRecentApps(triggeredFromAltTab); |
| 3039 | } |
| 3040 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3041 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 3042 | // re-acquire status bar service next time it is needed. |
| 3043 | mStatusBarService = null; |
| 3044 | } |
| 3045 | } |
| 3046 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3047 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3048 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3049 | try { |
| 3050 | IStatusBarService statusbar = getStatusBarService(); |
| 3051 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3052 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3053 | } |
| 3054 | } catch (RemoteException e) { |
| 3055 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 3056 | // re-acquire status bar service next time it is needed. |
| 3057 | mStatusBarService = null; |
| 3058 | } |
| 3059 | } |
| 3060 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3061 | void launchHomeFromHotKey() { |
| 3062 | launchHomeFromHotKey(true /* awakenFromDreams */); |
| 3063 | } |
| 3064 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3065 | /** |
| 3066 | * A home key -> launch home action was detected. Take the appropriate action |
| 3067 | * given the situation with the keyguard. |
| 3068 | */ |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3069 | void launchHomeFromHotKey(final boolean awakenFromDreams) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 3070 | if (isKeyguardShowingAndNotOccluded()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3071 | // don't launch home if keyguard showing |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3072 | } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3073 | // when in keyguard restricted mode, must first verify unlock |
| 3074 | // before launching home |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3075 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 3076 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3077 | public void onKeyguardExitResult(boolean success) { |
| 3078 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3079 | try { |
| 3080 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3081 | } catch (RemoteException e) { |
| 3082 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 3083 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3084 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3085 | } |
| 3086 | } |
| 3087 | }); |
| 3088 | } else { |
| 3089 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3090 | try { |
| 3091 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3092 | } catch (RemoteException e) { |
| 3093 | } |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 3094 | if (mRecentsVisible) { |
| 3095 | // Hide Recents and notify it to launch Home |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3096 | if (awakenFromDreams) { |
| 3097 | awakenDreams(); |
| 3098 | } |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 3099 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3100 | hideRecentApps(false, true); |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 3101 | } else { |
| 3102 | // Otherwise, just launch Home |
| 3103 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3104 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 3105 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3106 | } |
| 3107 | } |
| 3108 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3109 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3110 | @Override |
| 3111 | public void run() { |
| 3112 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3113 | // Clear flags. |
| 3114 | mForceClearedSystemUiFlags &= |
| 3115 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3116 | } |
| 3117 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3118 | } |
| 3119 | }; |
| 3120 | |
| 3121 | /** |
| 3122 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3123 | * to determine when the nav bar should be shown and prevent applications from |
| 3124 | * receiving those touches. |
| 3125 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3126 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3127 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3128 | super(inputChannel, looper); |
| 3129 | } |
| 3130 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3131 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3132 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3133 | boolean handled = false; |
| 3134 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3135 | if (event instanceof MotionEvent |
| 3136 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3137 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3138 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3139 | // When the user taps down, we re-show the nav bar. |
| 3140 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3141 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3142 | // Any user activity always causes us to show the |
| 3143 | // navigation controls, if they had been hidden. |
| 3144 | // We also clear the low profile and only content |
| 3145 | // flags so that tapping on the screen will atomically |
| 3146 | // restore all currently hidden screen decorations. |
| 3147 | int newVal = mResettingSystemUiFlags | |
| 3148 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3149 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3150 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3151 | if (mResettingSystemUiFlags != newVal) { |
| 3152 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3153 | changed = true; |
| 3154 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3155 | // We don't allow the system's nav bar to be hidden |
| 3156 | // again for 1 second, to prevent applications from |
| 3157 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3158 | newVal = mForceClearedSystemUiFlags | |
| 3159 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3160 | if (mForceClearedSystemUiFlags != newVal) { |
| 3161 | mForceClearedSystemUiFlags = newVal; |
| 3162 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3163 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3164 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3165 | } |
| 3166 | if (changed) { |
| 3167 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3168 | } |
| 3169 | } |
| 3170 | } |
| 3171 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3172 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3173 | } |
| 3174 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3175 | } |
| 3176 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3177 | new InputEventReceiver.Factory() { |
| 3178 | @Override |
| 3179 | public InputEventReceiver createInputEventReceiver( |
| 3180 | InputChannel inputChannel, Looper looper) { |
| 3181 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3182 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3183 | }; |
| 3184 | |
| 3185 | @Override |
| 3186 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3187 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3188 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3189 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3190 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3191 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3192 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3193 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3194 | // Clear any bits in the new visibility that are currently being |
| 3195 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3196 | return visibility & ~mResettingSystemUiFlags |
| 3197 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3198 | } |
| 3199 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3200 | @Override |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3201 | public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets, |
| 3202 | Rect outStableInsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3203 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3204 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3205 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3206 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3207 | 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] | 3208 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3209 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3210 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3211 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3212 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3213 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3214 | } else { |
| 3215 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3216 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3217 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3218 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3219 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3220 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3221 | availRight - mStableFullscreenRight, |
| 3222 | availBottom - mStableFullscreenBottom); |
| 3223 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3224 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3225 | availRight - mStableRight, availBottom - mStableBottom); |
| 3226 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3227 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3228 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3229 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3230 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3231 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3232 | availRight - mCurRight, availBottom - mCurBottom); |
| 3233 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3234 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3235 | availRight - mCurRight, availBottom - mCurBottom); |
| 3236 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3237 | |
| 3238 | outStableInsets.set(mStableLeft, mStableTop, |
| 3239 | availRight - mStableRight, availBottom - mStableBottom); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3240 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3241 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3242 | outContentInsets.setEmpty(); |
| 3243 | outStableInsets.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3244 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3245 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3246 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3247 | @Override |
| 3248 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 3249 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3250 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3251 | if (isDefaultDisplay) { |
| 3252 | switch (displayRotation) { |
| 3253 | case Surface.ROTATION_90: |
| 3254 | overscanLeft = mOverscanTop; |
| 3255 | overscanTop = mOverscanRight; |
| 3256 | overscanRight = mOverscanBottom; |
| 3257 | overscanBottom = mOverscanLeft; |
| 3258 | break; |
| 3259 | case Surface.ROTATION_180: |
| 3260 | overscanLeft = mOverscanRight; |
| 3261 | overscanTop = mOverscanBottom; |
| 3262 | overscanRight = mOverscanLeft; |
| 3263 | overscanBottom = mOverscanTop; |
| 3264 | break; |
| 3265 | case Surface.ROTATION_270: |
| 3266 | overscanLeft = mOverscanBottom; |
| 3267 | overscanTop = mOverscanLeft; |
| 3268 | overscanRight = mOverscanTop; |
| 3269 | overscanBottom = mOverscanRight; |
| 3270 | break; |
| 3271 | default: |
| 3272 | overscanLeft = mOverscanLeft; |
| 3273 | overscanTop = mOverscanTop; |
| 3274 | overscanRight = mOverscanRight; |
| 3275 | overscanBottom = mOverscanBottom; |
| 3276 | break; |
| 3277 | } |
| 3278 | } else { |
| 3279 | overscanLeft = 0; |
| 3280 | overscanTop = 0; |
| 3281 | overscanRight = 0; |
| 3282 | overscanBottom = 0; |
| 3283 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3284 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3285 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3286 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3287 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3288 | mSystemLeft = 0; |
| 3289 | mSystemTop = 0; |
| 3290 | mSystemRight = displayWidth; |
| 3291 | mSystemBottom = displayHeight; |
| 3292 | mUnrestrictedScreenLeft = overscanLeft; |
| 3293 | mUnrestrictedScreenTop = overscanTop; |
| 3294 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3295 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3296 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3297 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3298 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3299 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3300 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3301 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3302 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3303 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3304 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3305 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3306 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3307 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3308 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3309 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3310 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3311 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3312 | final Rect pf = mTmpParentFrame; |
| 3313 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3314 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3315 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3316 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3317 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3318 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3319 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3320 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3321 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3322 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3323 | if (isDefaultDisplay) { |
| 3324 | // For purposes of putting out fake window up to steal focus, we will |
| 3325 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3326 | final int sysui = mLastSystemUiFlags; |
| 3327 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3328 | boolean navTranslucent = (sysui |
| 3329 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3330 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3331 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3332 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3333 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3334 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3335 | if (!isKeyguardShowing) { |
| 3336 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3337 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3338 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3339 | // When the navigation bar isn't visible, we put up a fake |
| 3340 | // input window to catch all touch events. This way we can |
| 3341 | // detect when the user presses anywhere to bring back the nav |
| 3342 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3343 | if (navVisible || navAllowedHidden) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3344 | if (mHideNavFakeWindow != null) { |
| 3345 | mHideNavFakeWindow.dismiss(); |
| 3346 | mHideNavFakeWindow = null; |
| 3347 | } |
| 3348 | } else if (mHideNavFakeWindow == null) { |
| 3349 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 3350 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 3351 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3352 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3353 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3354 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3355 | // For purposes of positioning and showing the nav bar, if we have |
| 3356 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3357 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3358 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3359 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3360 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3361 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3362 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3363 | // Force the navigation bar to its appropriate place and |
| 3364 | // size. We need to do this directly, instead of relying on |
| 3365 | // it to bubble up from the nav bar, because this needs to |
| 3366 | // change atomically with screen rotations. |
| 3367 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 3368 | if (mNavigationBarOnBottom) { |
| 3369 | // 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] | 3370 | int top = displayHeight - overscanBottom |
| 3371 | - mNavigationBarHeightForRotation[displayRotation]; |
| 3372 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3373 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3374 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3375 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3376 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3377 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3378 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3379 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3380 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3381 | } else { |
| 3382 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3383 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3384 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3385 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3386 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3387 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3388 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3389 | // and not in the process of animating on or off, then |
| 3390 | // we can tell the app that it is covered by it. |
| 3391 | mSystemBottom = mTmpNavigationFrame.top; |
| 3392 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3393 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3394 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3395 | int left = displayWidth - overscanRight |
| 3396 | - mNavigationBarWidthForRotation[displayRotation]; |
| 3397 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3398 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3399 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3400 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3401 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3402 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3403 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3404 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3405 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3406 | } else { |
| 3407 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3408 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3409 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3410 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 3411 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3412 | // If the nav bar is currently requested to be visible, |
| 3413 | // and not in the process of animating on or off, then |
| 3414 | // we can tell the app that it is covered by it. |
| 3415 | mSystemRight = mTmpNavigationFrame.left; |
| 3416 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3417 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3418 | // Make sure the content and current rectangles are updated to |
| 3419 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3420 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3421 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3422 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3423 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3424 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3425 | // And compute the final frame. |
| 3426 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3427 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 3428 | mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3429 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3430 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3431 | updateSysUiVisibility = true; |
| 3432 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3433 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3434 | 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] | 3435 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 3436 | |
| 3437 | // decide where the status bar goes ahead of time |
| 3438 | if (mStatusBar != null) { |
| 3439 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3440 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3441 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3442 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3443 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3444 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3445 | vf.left = mStableLeft; |
| 3446 | vf.top = mStableTop; |
| 3447 | vf.right = mStableRight; |
| 3448 | vf.bottom = mStableBottom; |
| 3449 | |
| 3450 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3451 | |
| 3452 | // Let the status bar determine its size. |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3453 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3454 | |
| 3455 | // For layout, the status bar is always at the top with our fixed height. |
| 3456 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3457 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3458 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3459 | boolean statusBarTranslucent = (sysui |
| 3460 | & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3461 | if (!isKeyguardShowing) { |
| 3462 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3463 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3464 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3465 | // If the status bar is hidden, we don't want to cause |
| 3466 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 3467 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3468 | // Status bar may go away, so the screen area it occupies |
| 3469 | // is available to apps but just covering them when the |
| 3470 | // status bar is visible. |
| 3471 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3472 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3473 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3474 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3475 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3476 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3477 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3478 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3479 | String.format( |
| 3480 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3481 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3482 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3483 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3484 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3485 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3486 | && !statusBarTransient && !statusBarTranslucent |
| 3487 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3488 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3489 | // and not in the process of animating on or off, then |
| 3490 | // we can tell the app that it is covered by it. |
| 3491 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3492 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3493 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3494 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3495 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3496 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3497 | if (updateSysUiVisibility) { |
| 3498 | updateSystemUiVisibilityLw(); |
| 3499 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3503 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3504 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3505 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 3506 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 3507 | return mStatusBar.getSurfaceLayer(); |
| 3508 | } |
| 3509 | |
| 3510 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 3511 | return mNavigationBar.getSurfaceLayer(); |
| 3512 | } |
| 3513 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3514 | return 0; |
| 3515 | } |
| 3516 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3517 | @Override |
| 3518 | public void getContentRectLw(Rect r) { |
| 3519 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3520 | } |
| 3521 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3522 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3523 | 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] | 3524 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3525 | // Here's a special case: if this attached window is a panel that is |
| 3526 | // above the dock window, and the window it is attached to is below |
| 3527 | // the dock window, then the frames we computed for the window it is |
| 3528 | // attached to can not be used because the dock is effectively part |
| 3529 | // of the underlying window and the attached window is floating on top |
| 3530 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3531 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3532 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3533 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3534 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3535 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3536 | } else { |
| 3537 | // The effective display frame of the attached window depends on |
| 3538 | // whether it is taking care of insetting its content. If not, |
| 3539 | // we need to use the parent's content frame so that the entire |
| 3540 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3541 | // 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] | 3542 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3543 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3544 | // Set the content frame of the attached window to the parent's decor frame |
| 3545 | // (same as content frame when IME isn't present) if specifically requested by |
| 3546 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 3547 | // Otherwise, use the overscan frame. |
| 3548 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 3549 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3550 | } else { |
| 3551 | // If the window is resizing, then we want to base the content |
| 3552 | // frame on our attached content frame to resize... however, |
| 3553 | // things can be tricky if the attached window is NOT in resize |
| 3554 | // mode, in which case its content frame will be larger. |
| 3555 | // Ungh. So to deal with that, make sure the content frame |
| 3556 | // we end up using is not covering the IM dock. |
| 3557 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3558 | if (attached.isVoiceInteraction()) { |
| 3559 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3560 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3561 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3562 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3563 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3564 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3565 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3566 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3567 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3568 | } |
| 3569 | } |
| 3570 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3571 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3572 | vf.set(attached.getVisibleFrameLw()); |
| 3573 | } |
| 3574 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3575 | // window should be positioned relative to its parent or the entire |
| 3576 | // screen. |
| 3577 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3578 | ? attached.getFrameLw() : df); |
| 3579 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3580 | |
| 3581 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3582 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3583 | // If app is requesting a stable layout, don't let the |
| 3584 | // content insets go below the stable values. |
| 3585 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3586 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3587 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3588 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3589 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3590 | } else { |
| 3591 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3592 | if (r.top < mStableTop) r.top = mStableTop; |
| 3593 | if (r.right > mStableRight) r.right = mStableRight; |
| 3594 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3595 | } |
| 3596 | } |
| 3597 | } |
| 3598 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3599 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3600 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3601 | public void layoutWindowLw(WindowState win, WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3602 | // we've already done the status bar |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3603 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 3604 | if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) || |
| 3605 | win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3606 | return; |
| 3607 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3608 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 3609 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3610 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 3611 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3612 | 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] | 3613 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 3614 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3615 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3616 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3617 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3618 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3619 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3620 | final Rect pf = mTmpParentFrame; |
| 3621 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3622 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3623 | final Rect cf = mTmpContentFrame; |
| 3624 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3625 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3626 | final Rect sf = mTmpStableFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3627 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3628 | |
| 3629 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3630 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3631 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 3632 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 3633 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3634 | if (isDefaultDisplay) { |
| 3635 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 3636 | } else { |
| 3637 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 3638 | } |
| 3639 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3640 | if (!isDefaultDisplay) { |
| 3641 | if (attached != null) { |
| 3642 | // If this window is attached to another, our display |
| 3643 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3644 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3645 | } else { |
| 3646 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3647 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3648 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3649 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3650 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3651 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3652 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3653 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame^] | 3654 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3655 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3656 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3657 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3658 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3659 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3660 | // ...with content insets above the nav bar |
| 3661 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3662 | // IM dock windows always go to the bottom of the screen. |
| 3663 | attrs.gravity = Gravity.BOTTOM; |
| 3664 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame^] | 3665 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
| 3666 | pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft; |
| 3667 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3668 | pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft |
| 3669 | + mUnrestrictedScreenWidth; |
| 3670 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3671 | + mUnrestrictedScreenHeight; |
| 3672 | cf.bottom = vf.bottom = mStableBottom; |
| 3673 | cf.top = vf.top = mStableTop; |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 3674 | } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 3675 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3676 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3677 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3678 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 3679 | cf.left = vf.left = mStableLeft; |
| 3680 | cf.top = vf.top = mStableTop; |
| 3681 | cf.right = vf.right = mStableRight; |
| 3682 | vf.bottom = mStableBottom; |
| 3683 | cf.bottom = mContentBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3684 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3685 | |
| 3686 | // Default policy decor for the default display |
| 3687 | dcf.left = mSystemLeft; |
| 3688 | dcf.top = mSystemTop; |
| 3689 | dcf.right = mSystemRight; |
| 3690 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3691 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3692 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3693 | final boolean isAppWindow = |
| 3694 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3695 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3696 | final boolean topAtRest = |
| 3697 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3698 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3699 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3700 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3701 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 3702 | && (fl & WindowManager.LayoutParams. |
| 3703 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3704 | // Ensure policy decor includes status bar |
| 3705 | dcf.top = mStableTop; |
| 3706 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3707 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3708 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 3709 | && (fl & WindowManager.LayoutParams. |
| 3710 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3711 | // Ensure policy decor includes navigation bar |
| 3712 | dcf.bottom = mStableBottom; |
| 3713 | dcf.right = mStableRight; |
| 3714 | } |
| 3715 | } |
| 3716 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3717 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3718 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3719 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3720 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3721 | // This is the case for a normal activity window: we want it |
| 3722 | // to cover all of the screen space, and it can take care of |
| 3723 | // moving its contents to account for screen decorations that |
| 3724 | // intrude into that space. |
| 3725 | if (attached != null) { |
| 3726 | // If this window is attached to another, our display |
| 3727 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3728 | 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] | 3729 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3730 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3731 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3732 | // Status bar panels are the only windows who can go on top of |
| 3733 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3734 | // permission, so they have the same privileges as the status |
| 3735 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3736 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3737 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3738 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3739 | pf.left = df.left = of.left = hasNavBar |
| 3740 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3741 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3742 | pf.right = df.right = of.right = hasNavBar |
| 3743 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3744 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3745 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3746 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3747 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3748 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3749 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3750 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3751 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3752 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3753 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3754 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3755 | // Asking to layout into the overscan region, so give it that pure |
| 3756 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3757 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3758 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3759 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3760 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3761 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3762 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3763 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3764 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3765 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3766 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3767 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3768 | // only do this for application windows to ensure no window that |
| 3769 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3770 | pf.left = df.left = mOverscanScreenLeft; |
| 3771 | pf.top = df.top = mOverscanScreenTop; |
| 3772 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3773 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3774 | // We need to tell the app about where the frame inside the overscan |
| 3775 | // is, so it can inset its content by that amount -- it didn't ask |
| 3776 | // to actually extend itself into the overscan region. |
| 3777 | of.left = mUnrestrictedScreenLeft; |
| 3778 | of.top = mUnrestrictedScreenTop; |
| 3779 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3780 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3781 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3782 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3783 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3784 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3785 | + mRestrictedOverscanScreenWidth; |
| 3786 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3787 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3788 | // We need to tell the app about where the frame inside the overscan |
| 3789 | // is, so it can inset its content by that amount -- it didn't ask |
| 3790 | // to actually extend itself into the overscan region. |
| 3791 | of.left = mUnrestrictedScreenLeft; |
| 3792 | of.top = mUnrestrictedScreenTop; |
| 3793 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3794 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3795 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3796 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3797 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3798 | if (win.isVoiceInteraction()) { |
| 3799 | cf.left = mVoiceContentLeft; |
| 3800 | cf.top = mVoiceContentTop; |
| 3801 | cf.right = mVoiceContentRight; |
| 3802 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3803 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3804 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3805 | cf.left = mDockLeft; |
| 3806 | cf.top = mDockTop; |
| 3807 | cf.right = mDockRight; |
| 3808 | cf.bottom = mDockBottom; |
| 3809 | } else { |
| 3810 | cf.left = mContentLeft; |
| 3811 | cf.top = mContentTop; |
| 3812 | cf.right = mContentRight; |
| 3813 | cf.bottom = mContentBottom; |
| 3814 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3815 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3816 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3817 | // Full screen windows are always given a layout that is as if the |
| 3818 | // status bar and other transient decors are gone. This is to avoid |
| 3819 | // bad states when moving from a window that is not hding the |
| 3820 | // status bar to one that is. |
| 3821 | cf.left = mRestrictedScreenLeft; |
| 3822 | cf.top = mRestrictedScreenTop; |
| 3823 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3824 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3825 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3826 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3827 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3828 | vf.left = mCurLeft; |
| 3829 | vf.top = mCurTop; |
| 3830 | vf.right = mCurRight; |
| 3831 | vf.bottom = mCurBottom; |
| 3832 | } else { |
| 3833 | vf.set(cf); |
| 3834 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3835 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3836 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3837 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3838 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3839 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3840 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3841 | // A window that has requested to fill the entire screen just |
| 3842 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3843 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3844 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3845 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3846 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3847 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3848 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3849 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3850 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3851 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3852 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3853 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3854 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3855 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3856 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3857 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3858 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3859 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3860 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3861 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3862 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3863 | + mUnrestrictedScreenWidth; |
| 3864 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3865 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3866 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3867 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3868 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3869 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3870 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3871 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3872 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3873 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3874 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3875 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3876 | + mOverscanScreenWidth; |
| 3877 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3878 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 3879 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3880 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3881 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3882 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3883 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3884 | + mOverscanScreenWidth; |
| 3885 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3886 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3887 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3888 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 3889 | // it about the overscan area. |
| 3890 | pf.left = df.left = mOverscanScreenLeft; |
| 3891 | pf.top = df.top = mOverscanScreenTop; |
| 3892 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3893 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 3894 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 3895 | of.top = cf.top = mUnrestrictedScreenTop; |
| 3896 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3897 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3898 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3899 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3900 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3901 | // Asking to layout into the overscan region, so give it that pure |
| 3902 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3903 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3904 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3905 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3906 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3907 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3908 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3909 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3910 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 3911 | && (attrs.type == TYPE_STATUS_BAR |
| 3912 | || attrs.type == TYPE_TOAST |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3913 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3914 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3915 | // Asking for layout as if the nav bar is hidden, lets the |
| 3916 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3917 | // 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] | 3918 | // can be above the nav bar can do this. |
| 3919 | // XXX This assumes that an app asking for this will also |
| 3920 | // ask for layout in only content. We can't currently figure out |
| 3921 | // 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] | 3922 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3923 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3924 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3925 | + mUnrestrictedScreenWidth; |
| 3926 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3927 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3928 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3929 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3930 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3931 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3932 | + mRestrictedScreenWidth; |
| 3933 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3934 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3935 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3936 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3937 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3938 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3939 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3940 | vf.left = mCurLeft; |
| 3941 | vf.top = mCurTop; |
| 3942 | vf.right = mCurRight; |
| 3943 | vf.bottom = mCurBottom; |
| 3944 | } else { |
| 3945 | vf.set(cf); |
| 3946 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3947 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3948 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3949 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3950 | // A child window should be placed inside of the same visible |
| 3951 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3952 | 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] | 3953 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3954 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3955 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3956 | // Otherwise, a normal window must be placed inside the content |
| 3957 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3958 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 3959 | // Status bar panels are the only windows who can go on top of |
| 3960 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3961 | // permission, so they have the same privileges as the status |
| 3962 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3963 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3964 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3965 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3966 | + mRestrictedScreenWidth; |
| 3967 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3968 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3969 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 3970 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 3971 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3972 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 3973 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 3974 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 3975 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3976 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3977 | pf.left = mContentLeft; |
| 3978 | pf.top = mContentTop; |
| 3979 | pf.right = mContentRight; |
| 3980 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 3981 | if (win.isVoiceInteraction()) { |
| 3982 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 3983 | df.top = of.top = cf.top = mVoiceContentTop; |
| 3984 | df.right = of.right = cf.right = mVoiceContentRight; |
| 3985 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 3986 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3987 | df.left = of.left = cf.left = mDockLeft; |
| 3988 | df.top = of.top = cf.top = mDockTop; |
| 3989 | df.right = of.right = cf.right = mDockRight; |
| 3990 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3991 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3992 | df.left = of.left = cf.left = mContentLeft; |
| 3993 | df.top = of.top = cf.top = mContentTop; |
| 3994 | df.right = of.right = cf.right = mContentRight; |
| 3995 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3996 | } |
| 3997 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3998 | vf.left = mCurLeft; |
| 3999 | vf.top = mCurTop; |
| 4000 | vf.right = mCurRight; |
| 4001 | vf.bottom = mCurBottom; |
| 4002 | } else { |
| 4003 | vf.set(cf); |
| 4004 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4005 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4006 | } |
| 4007 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4008 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 4009 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 4010 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4011 | df.left = df.top = -10000; |
| 4012 | df.right = df.bottom = 10000; |
| 4013 | if (attrs.type != TYPE_WALLPAPER) { |
| 4014 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 4015 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 4016 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4017 | } |
| 4018 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4019 | 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] | 4020 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4021 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4022 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 4023 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4024 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4025 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4026 | + " dcf=" + dcf.toShortString() |
| 4027 | + " sf=" + sf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4028 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4029 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4030 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4031 | // Dock windows carve out the bottom of the screen, so normal windows |
| 4032 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 4033 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 4034 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4035 | setLastInputMethodWindowLw(null, null); |
| 4036 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4037 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4038 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 4039 | && !win.getGivenInsetsPendingLw()) { |
| 4040 | offsetVoiceInputWindowLw(win); |
| 4041 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4042 | } |
| 4043 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4044 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4045 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4046 | top += win.getGivenContentInsetsLw().top; |
| 4047 | if (mContentBottom > top) { |
| 4048 | mContentBottom = top; |
| 4049 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4050 | if (mVoiceContentBottom > top) { |
| 4051 | mVoiceContentBottom = top; |
| 4052 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4053 | top = win.getVisibleFrameLw().top; |
| 4054 | top += win.getGivenVisibleInsetsLw().top; |
| 4055 | if (mCurBottom > top) { |
| 4056 | mCurBottom = top; |
| 4057 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4058 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4059 | + mDockBottom + " mContentBottom=" |
| 4060 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 4061 | } |
| 4062 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4063 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4064 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 4065 | top += win.getGivenContentInsetsLw().top; |
| 4066 | if (mVoiceContentBottom > top) { |
| 4067 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4071 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 4072 | @Override |
| 4073 | public void finishLayoutLw() { |
| 4074 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4078 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4079 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4080 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4081 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4082 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4083 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4084 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4085 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4086 | mForcingShowNavBar = false; |
| 4087 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4088 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4089 | mHideLockScreen = false; |
| 4090 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4091 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4092 | mShowingLockscreen = false; |
| 4093 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4094 | mWinShowWhenLocked = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4095 | mKeyguardSecure = isKeyguardSecure(); |
| 4096 | mKeyguardSecureIncludingHidden = mKeyguardSecure |
| 4097 | && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4101 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4102 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4103 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 4104 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4105 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4106 | if (mTopFullscreenOpaqueWindowState == null |
| 4107 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 4108 | mForcingShowNavBar = true; |
| 4109 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4110 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4111 | if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4112 | mForceStatusBarFromKeyguard = true; |
| 4113 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4114 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 4115 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4116 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4117 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4118 | mForceStatusBarFromKeyguard = true; |
| 4119 | } else { |
| 4120 | mForceStatusBar = true; |
| 4121 | } |
| 4122 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4123 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4124 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4125 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4126 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 4127 | && attrs.type < FIRST_SYSTEM_WINDOW; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4128 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4129 | // If the lockscreen was showing when the dream started then wait |
| 4130 | // for the dream to draw before hiding the lockscreen. |
| 4131 | if (!mDreamingLockscreen |
| 4132 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4133 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4134 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4135 | } |
| 4136 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4137 | |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4138 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
Craig Mautner | 74ee938 | 2014-04-01 15:20:16 -0700 | [diff] [blame] | 4139 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4140 | if (appWindow) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4141 | final IApplicationToken appToken = win.getAppToken(); |
| 4142 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4143 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4144 | mAppsToBeHidden.remove(appToken); |
| 4145 | mAppsThatDismissKeyguard.remove(appToken); |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4146 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | 192d604 | 2014-12-02 23:24:48 -0800 | [diff] [blame] | 4147 | if (dismissKeyguard && !mKeyguardSecure) { |
| 4148 | mAppsThatDismissKeyguard.add(appToken); |
| 4149 | } else { |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4150 | mWinShowWhenLocked = win; |
| 4151 | mHideLockScreen = true; |
| 4152 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4153 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4154 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4155 | } else if (dismissKeyguard) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4156 | if (mKeyguardSecure) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4157 | mAppsToBeHidden.add(appToken); |
| 4158 | } else { |
| 4159 | mAppsToBeHidden.remove(appToken); |
| 4160 | } |
| 4161 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4162 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4163 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4164 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4165 | if (attrs.x == 0 && attrs.y == 0 |
| 4166 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4167 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 4168 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4169 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4170 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 4171 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4172 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4173 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4174 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4175 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4176 | "Setting mDismissKeyguard true by win " + win); |
| 4177 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 4178 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 4179 | mWinDismissingKeyguard = win; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4180 | mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4181 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) { |
| 4182 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4183 | "Setting mHideLockScreen to true by win " + win); |
| 4184 | mHideLockScreen = true; |
| 4185 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4186 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4187 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4188 | mAllowLockscreenWhenOn = true; |
| 4189 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4190 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4191 | |
| 4192 | if (mWinShowWhenLocked != null && |
| 4193 | mWinShowWhenLocked.getAppToken() != win.getAppToken()) { |
| 4194 | win.hideLw(false); |
| 4195 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4196 | } |
| 4197 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4198 | if (mTopFullscreenOpaqueOrDimmingWindowState == null |
| 4199 | && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw() |
| 4200 | && win.isDimming()) { |
| 4201 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4202 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4203 | } |
| 4204 | |
| 4205 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4206 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4207 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4208 | if (mWinShowWhenLocked != null && |
| 4209 | mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) { |
| 4210 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4211 | // fullscreen window. |
| 4212 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4213 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4214 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4215 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4216 | } |
| 4217 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4218 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4219 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4220 | |
| 4221 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4222 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4223 | : null; |
| 4224 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4225 | // If we are not currently showing a dream then remember the current |
| 4226 | // lockscreen state. We will use this to determine whether the dream |
| 4227 | // started while the lockscreen was showing and remember this state |
| 4228 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4229 | if (!mShowingDream) { |
| 4230 | mDreamingLockscreen = mShowingLockscreen; |
| 4231 | } |
| 4232 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4233 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4234 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4235 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 4236 | + " top=" + mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4237 | if (mForceStatusBar || mForceStatusBarFromKeyguard) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4238 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4239 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4240 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4241 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4242 | // Maintain fullscreen layout until incoming animation is complete. |
| 4243 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 4244 | // Transient status bar on the lockscreen is not allowed |
| 4245 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 4246 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 4247 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 4248 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4249 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4250 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4251 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4252 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4253 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4254 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4255 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4256 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4257 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4258 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4259 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 4260 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4261 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 4262 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4263 | if (mStatusBarController.isTransientShowing()) { |
| 4264 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4265 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4266 | } |
| 4267 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4268 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4269 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4270 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4271 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 4272 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 4273 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4274 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4275 | 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] | 4276 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4277 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4278 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4279 | } |
| 4280 | } |
| 4281 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4282 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4283 | if (mTopIsFullscreen != topIsFullscreen) { |
| 4284 | if (!topIsFullscreen) { |
| 4285 | // Force another layout when status bar becomes fully shown. |
| 4286 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4287 | } |
| 4288 | mTopIsFullscreen = topIsFullscreen; |
| 4289 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4290 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4291 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 4292 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4293 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 4294 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 4295 | + mHideLockScreen); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4296 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4297 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4298 | if (setKeyguardOccludedLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4299 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4300 | | FINISH_LAYOUT_REDO_CONFIG |
| 4301 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4302 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4303 | if (mKeyguardDelegate.isShowing()) { |
| 4304 | mHandler.post(new Runnable() { |
| 4305 | @Override |
| 4306 | public void run() { |
| 4307 | mKeyguardDelegate.keyguardDone(false, false); |
| 4308 | } |
| 4309 | }); |
| 4310 | } |
| 4311 | } else if (mHideLockScreen) { |
| 4312 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4313 | if (setKeyguardOccludedLw(true)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4314 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4315 | | FINISH_LAYOUT_REDO_CONFIG |
| 4316 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4317 | } |
| 4318 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 4319 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 4320 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 4321 | // Only launch the next keyguard unlock window once per window. |
| 4322 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4323 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4324 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4325 | | FINISH_LAYOUT_REDO_CONFIG |
| 4326 | | FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4327 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4328 | mHandler.post(new Runnable() { |
| 4329 | @Override |
| 4330 | public void run() { |
| 4331 | mKeyguardDelegate.dismiss(); |
| 4332 | } |
| 4333 | }); |
| 4334 | } |
| 4335 | } else { |
| 4336 | mWinDismissingKeyguard = null; |
| 4337 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4338 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4339 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4340 | | FINISH_LAYOUT_REDO_CONFIG |
| 4341 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4342 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 4343 | } |
| 4344 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4345 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4346 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4347 | // If the navigation bar has been hidden or shown, we need to do another |
| 4348 | // layout pass to update that window. |
| 4349 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4350 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4351 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4352 | // update since mAllowLockscreenWhenOn might have changed |
| 4353 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4354 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4355 | } |
| 4356 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4357 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4358 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4359 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4360 | * @return Whether the flags have changed and we have to redo the layout. |
| 4361 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4362 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
| 4363 | boolean wasOccluded = mKeyguardOccluded; |
| 4364 | boolean showing = mKeyguardDelegate.isShowing(); |
| 4365 | if (wasOccluded && !isOccluded && showing) { |
| 4366 | mKeyguardOccluded = false; |
| 4367 | mKeyguardDelegate.setOccluded(false); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4368 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4369 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4370 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4371 | } else if (!wasOccluded && isOccluded && showing) { |
| 4372 | mKeyguardOccluded = true; |
| 4373 | mKeyguardDelegate.setOccluded(true); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4374 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4375 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4376 | return true; |
| 4377 | } else { |
| 4378 | return false; |
| 4379 | } |
| 4380 | } |
| 4381 | |
| 4382 | private boolean isStatusBarKeyguard() { |
| 4383 | return mStatusBar != null |
| 4384 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4385 | } |
| 4386 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4387 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4388 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4389 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4390 | // 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] | 4391 | return false; |
| 4392 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4393 | return true; |
| 4394 | } |
| 4395 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4396 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4397 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4398 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4399 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4400 | // If the navigation bar has been hidden or shown, we need to do another |
| 4401 | // layout pass to update that window. |
| 4402 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4403 | } |
| 4404 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4405 | } |
| 4406 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4407 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4408 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4409 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4410 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4411 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4412 | if (newLidState == mLidState) { |
| 4413 | return; |
| 4414 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4415 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4416 | mLidState = newLidState; |
| 4417 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4418 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4419 | |
| 4420 | if (lidOpen) { |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4421 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4422 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4423 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4424 | } |
| 4425 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4426 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4427 | @Override |
| 4428 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 4429 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 4430 | if (mCameraLensCoverState == lensCoverState) { |
| 4431 | return; |
| 4432 | } |
| 4433 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 4434 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 4435 | Intent intent; |
| 4436 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 4437 | mKeyguardDelegate.isShowing(); |
| 4438 | if (keyguardActive) { |
| 4439 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 4440 | } else { |
| 4441 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 4442 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4443 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4444 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4445 | } |
| 4446 | mCameraLensCoverState = lensCoverState; |
| 4447 | } |
| 4448 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4449 | void setHdmiPlugged(boolean plugged) { |
| 4450 | if (mHdmiPlugged != plugged) { |
| 4451 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4452 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4453 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4454 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4455 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4456 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4457 | } |
| 4458 | } |
| 4459 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4460 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4461 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4462 | // watch for HDMI plug messages if the hdmi switch exists |
| 4463 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4464 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4465 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4466 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4467 | FileReader reader = null; |
| 4468 | try { |
| 4469 | reader = new FileReader(filename); |
| 4470 | char[] buf = new char[15]; |
| 4471 | int n = reader.read(buf); |
| 4472 | if (n > 1) { |
| 4473 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4474 | } |
| 4475 | } catch (IOException ex) { |
| 4476 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4477 | } catch (NumberFormatException ex) { |
| 4478 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4479 | } finally { |
| 4480 | if (reader != null) { |
| 4481 | try { |
| 4482 | reader.close(); |
| 4483 | } catch (IOException ex) { |
| 4484 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4485 | } |
| 4486 | } |
| 4487 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4488 | // This dance forces the code in setHdmiPlugged to run. |
| 4489 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4490 | mHdmiPlugged = !plugged; |
| 4491 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4492 | } |
| 4493 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4494 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4495 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4496 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4497 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4498 | @Override public void run() { |
| 4499 | synchronized (mScreenshotLock) { |
| 4500 | if (mScreenshotConnection != null) { |
| 4501 | mContext.unbindService(mScreenshotConnection); |
| 4502 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4503 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4504 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4505 | } |
| 4506 | }; |
| 4507 | |
| 4508 | // Assume this is called from the Handler thread. |
| 4509 | private void takeScreenshot() { |
| 4510 | synchronized (mScreenshotLock) { |
| 4511 | if (mScreenshotConnection != null) { |
| 4512 | return; |
| 4513 | } |
| 4514 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4515 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 4516 | Intent intent = new Intent(); |
| 4517 | intent.setComponent(cn); |
| 4518 | ServiceConnection conn = new ServiceConnection() { |
| 4519 | @Override |
| 4520 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 4521 | synchronized (mScreenshotLock) { |
| 4522 | if (mScreenshotConnection != this) { |
| 4523 | return; |
| 4524 | } |
| 4525 | Messenger messenger = new Messenger(service); |
| 4526 | Message msg = Message.obtain(null, 1); |
| 4527 | final ServiceConnection myConn = this; |
| 4528 | Handler h = new Handler(mHandler.getLooper()) { |
| 4529 | @Override |
| 4530 | public void handleMessage(Message msg) { |
| 4531 | synchronized (mScreenshotLock) { |
| 4532 | if (mScreenshotConnection == myConn) { |
| 4533 | mContext.unbindService(mScreenshotConnection); |
| 4534 | mScreenshotConnection = null; |
| 4535 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 4536 | } |
| 4537 | } |
| 4538 | } |
| 4539 | }; |
| 4540 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 4541 | msg.arg1 = msg.arg2 = 0; |
| 4542 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 4543 | msg.arg1 = 1; |
| 4544 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 4545 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4546 | try { |
| 4547 | messenger.send(msg); |
| 4548 | } catch (RemoteException e) { |
| 4549 | } |
| 4550 | } |
| 4551 | } |
| 4552 | @Override |
| 4553 | public void onServiceDisconnected(ComponentName name) {} |
| 4554 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 4555 | if (mContext.bindServiceAsUser( |
| 4556 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4557 | mScreenshotConnection = conn; |
| 4558 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 4559 | } |
| 4560 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4561 | } |
| 4562 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4563 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4564 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4565 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4566 | if (!mSystemBooted) { |
| 4567 | // If we have not yet booted, don't let key events do anything. |
| 4568 | return 0; |
| 4569 | } |
| 4570 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4571 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4572 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 4573 | final boolean canceled = event.isCanceled(); |
| 4574 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 4575 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4576 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4577 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 4578 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 4579 | // the same as if it were open and in front. |
| 4580 | // This will prevent any keys other than the power button from waking the screen |
| 4581 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4582 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4583 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4584 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4585 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4586 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4587 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4588 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4589 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4590 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4591 | } |
| 4592 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4593 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4594 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 4595 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 4596 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4597 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4598 | // When the device is interactive or the key is injected pass the |
| 4599 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4600 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4601 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4602 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 4603 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 4604 | // to the application but preserve its wake key status to make sure we still move |
| 4605 | // from dozing to fully interactive if we would normally go from off to fully |
| 4606 | // interactive. |
| 4607 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4608 | } else { |
| 4609 | // When the screen is off and the key is not injected, determine whether |
| 4610 | // to wake the device but don't pass the key to the application. |
| 4611 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4612 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 4613 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4614 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4615 | } |
| 4616 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4617 | // If the key would be handled globally, just return the result, don't worry about special |
| 4618 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4619 | if (isValidGlobalKey(keyCode) |
| 4620 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4621 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4622 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4623 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4624 | return result; |
| 4625 | } |
| 4626 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4627 | boolean useHapticFeedback = down |
| 4628 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 4629 | && event.getRepeatCount() == 0; |
| 4630 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4631 | // Handle special keys. |
| 4632 | switch (keyCode) { |
| 4633 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 4634 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4635 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4636 | if (mUseTvRouting) { |
| 4637 | // On TVs volume keys never go to the foreground app |
| 4638 | result &= ~ACTION_PASS_TO_USER; |
| 4639 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4640 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 4641 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4642 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4643 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4644 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 4645 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 4646 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4647 | cancelPendingPowerKeyAction(); |
| 4648 | interceptScreenshotChord(); |
| 4649 | } |
| 4650 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4651 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4652 | cancelPendingScreenshotChordAction(); |
| 4653 | } |
| 4654 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 4655 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4656 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4657 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4658 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4659 | cancelPendingPowerKeyAction(); |
| 4660 | cancelPendingScreenshotChordAction(); |
| 4661 | } |
| 4662 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4663 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4664 | cancelPendingScreenshotChordAction(); |
| 4665 | } |
| 4666 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4667 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4668 | TelecomManager telecomManager = getTelecommService(); |
| 4669 | if (telecomManager != null) { |
| 4670 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4671 | // If an incoming call is ringing, either VOLUME key means |
| 4672 | // "silence ringer". We handle these keys here, rather than |
| 4673 | // in the InCallScreen, to make sure we'll respond to them |
| 4674 | // even if the InCallScreen hasn't come to the foreground yet. |
| 4675 | // Look for the DOWN event here, to agree with the "fallback" |
| 4676 | // behavior in the InCallScreen. |
| 4677 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4678 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4679 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4680 | // Silence the ringer. (It's safe to call this |
| 4681 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4682 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4683 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4684 | // And *don't* pass this key thru to the current activity |
| 4685 | // (which is probably the InCallScreen.) |
| 4686 | result &= ~ACTION_PASS_TO_USER; |
| 4687 | break; |
| 4688 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4689 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4690 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 4691 | // 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] | 4692 | // the application, just pass it to the session service. |
| 4693 | |
| 4694 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4695 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4696 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4697 | } |
| 4698 | } |
| 4699 | |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4700 | if ((result & ACTION_PASS_TO_USER) == 0) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4701 | if (mUseTvRouting) { |
| 4702 | dispatchDirectAudioEvent(event); |
| 4703 | } else { |
| 4704 | // If we aren't passing to the user and no one else |
| 4705 | // handled it send it to the session manager to |
| 4706 | // figure out. |
| 4707 | MediaSessionLegacyHelper.getHelper(mContext) |
| 4708 | .sendVolumeKeyEvent(event, true); |
| 4709 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4710 | break; |
| 4711 | } |
| 4712 | } |
| 4713 | break; |
| 4714 | } |
| 4715 | |
| 4716 | case KeyEvent.KEYCODE_ENDCALL: { |
| 4717 | result &= ~ACTION_PASS_TO_USER; |
| 4718 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4719 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4720 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4721 | if (telecomManager != null) { |
| 4722 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4723 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4724 | if (interactive && !hungUp) { |
| 4725 | mEndCallKeyHandled = false; |
| 4726 | mHandler.postDelayed(mEndCallLongPress, |
| 4727 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 4728 | } else { |
| 4729 | mEndCallKeyHandled = true; |
| 4730 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4731 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4732 | if (!mEndCallKeyHandled) { |
| 4733 | mHandler.removeCallbacks(mEndCallLongPress); |
| 4734 | if (!canceled) { |
| 4735 | if ((mEndcallBehavior |
| 4736 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 4737 | if (goHome()) { |
| 4738 | break; |
| 4739 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 4740 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4741 | if ((mEndcallBehavior |
| 4742 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 4743 | mPowerManager.goToSleep(event.getEventTime(), |
| 4744 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 4745 | isWakeKey = false; |
| 4746 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4747 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4748 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4749 | } |
| 4750 | break; |
| 4751 | } |
| 4752 | |
| 4753 | case KeyEvent.KEYCODE_POWER: { |
| 4754 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4755 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4756 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4757 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4758 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4759 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4760 | } |
| 4761 | break; |
| 4762 | } |
| 4763 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4764 | case KeyEvent.KEYCODE_SLEEP: { |
| 4765 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4766 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4767 | if (!mPowerManager.isInteractive()) { |
| 4768 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 4769 | } |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4770 | sleepPress(event); |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4771 | break; |
| 4772 | } |
| 4773 | |
| 4774 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4775 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4776 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4777 | break; |
| 4778 | } |
| 4779 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4780 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4781 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4782 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4783 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4784 | case KeyEvent.KEYCODE_MUTE: |
| 4785 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4786 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4787 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4788 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4789 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4790 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4791 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4792 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 4793 | // If the global session is active pass all media keys to it |
| 4794 | // instead of the active window. |
| 4795 | result &= ~ACTION_PASS_TO_USER; |
| 4796 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4797 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4798 | // Only do this if we would otherwise not pass it to the user. In that |
| 4799 | // case, the PhoneWindow class will do the same thing, except it will |
| 4800 | // 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] | 4801 | // Note that we need to make a copy of the key event here because the |
| 4802 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4803 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4804 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4805 | new KeyEvent(event)); |
| 4806 | msg.setAsynchronous(true); |
| 4807 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4808 | } |
| 4809 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4810 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4811 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4812 | case KeyEvent.KEYCODE_CALL: { |
| 4813 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4814 | TelecomManager telecomManager = getTelecommService(); |
| 4815 | if (telecomManager != null) { |
| 4816 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4817 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4818 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4819 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4820 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4821 | // And *don't* pass this key thru to the current activity |
| 4822 | // (which is presumably the InCallScreen.) |
| 4823 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4824 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4825 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4826 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4827 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4828 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 4829 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 4830 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 4831 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 4832 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 4833 | // key event here because the original key event will be recycled when we return. |
| 4834 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 4835 | mBroadcastWakeLock.acquire(); |
| 4836 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 4837 | keyguardActive ? 1 : 0, 0); |
| 4838 | msg.setAsynchronous(true); |
| 4839 | msg.sendToTarget(); |
| 4840 | } |
| 4841 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4842 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4843 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4844 | if (useHapticFeedback) { |
| 4845 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 4846 | } |
| 4847 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4848 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4849 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4850 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4851 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4852 | return result; |
| 4853 | } |
| 4854 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4855 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4856 | * Returns true if the key can have global actions attached to it. |
| 4857 | * We reserve all power management keys for the system since they require |
| 4858 | * very careful handling. |
| 4859 | */ |
| 4860 | private static boolean isValidGlobalKey(int keyCode) { |
| 4861 | switch (keyCode) { |
| 4862 | case KeyEvent.KEYCODE_POWER: |
| 4863 | case KeyEvent.KEYCODE_WAKEUP: |
| 4864 | case KeyEvent.KEYCODE_SLEEP: |
| 4865 | return false; |
| 4866 | default: |
| 4867 | return true; |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4872 | * When the screen is off we ignore some keys that might otherwise typically |
| 4873 | * be considered wake keys. We filter them out here. |
| 4874 | * |
| 4875 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 4876 | * is always considered a wake key. |
| 4877 | */ |
| 4878 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 4879 | switch (keyCode) { |
| 4880 | // ignore volume keys unless docked |
| 4881 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4882 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4883 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4884 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4885 | |
| 4886 | // ignore media and camera keys |
| 4887 | case KeyEvent.KEYCODE_MUTE: |
| 4888 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4889 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4890 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4891 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4892 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4893 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4894 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4895 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4896 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4897 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4898 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4899 | case KeyEvent.KEYCODE_CAMERA: |
| 4900 | return false; |
| 4901 | } |
| 4902 | return true; |
| 4903 | } |
| 4904 | |
| 4905 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4906 | /** {@inheritDoc} */ |
| 4907 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4908 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 4909 | if ((policyFlags & FLAG_WAKE) != 0) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 4910 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) { |
| 4911 | return 0; |
| 4912 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4913 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 4914 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4915 | if (shouldDispatchInputWhenNonInteractive()) { |
| 4916 | return ACTION_PASS_TO_USER; |
| 4917 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 4918 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 4919 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 4920 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 4921 | // wake up in this case. |
| 4922 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
| 4923 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming); |
| 4924 | } |
| 4925 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4926 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4927 | } |
| 4928 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4929 | private boolean shouldDispatchInputWhenNonInteractive() { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 4930 | // Send events to keyguard while the screen is on. |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4931 | if (isKeyguardShowingAndNotOccluded() && mDisplay != null |
| 4932 | && mDisplay.getState() != Display.STATE_OFF) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 4933 | return true; |
| 4934 | } |
| 4935 | |
| 4936 | // Send events to a dozing dream even if the screen is off since the dream |
| 4937 | // is in control of the state of the screen. |
| 4938 | IDreamManager dreamManager = getDreamManager(); |
| 4939 | |
| 4940 | try { |
| 4941 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 4942 | return true; |
| 4943 | } |
| 4944 | } catch (RemoteException e) { |
| 4945 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 4946 | } |
| 4947 | |
| 4948 | // Otherwise, consume events since the user can't see what is being |
| 4949 | // interacted with. |
| 4950 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4951 | } |
| 4952 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4953 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 4954 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 4955 | return; |
| 4956 | } |
| 4957 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 4958 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 4959 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4960 | String pkgName = mContext.getOpPackageName(); |
| 4961 | switch (keyCode) { |
| 4962 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4963 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 4964 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 4965 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4966 | } catch (RemoteException e) { |
| 4967 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 4968 | } |
| 4969 | break; |
| 4970 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4971 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 4972 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 4973 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4974 | } catch (RemoteException e) { |
| 4975 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 4976 | } |
| 4977 | break; |
| 4978 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4979 | try { |
| 4980 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 4981 | getAudioService().adjustSuggestedStreamVolume( |
| 4982 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 4983 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4984 | } |
| 4985 | } catch (RemoteException e) { |
| 4986 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 4987 | } |
| 4988 | break; |
| 4989 | } |
| 4990 | } |
| 4991 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4992 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 4993 | if (DEBUG_INPUT) { |
| 4994 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4995 | } |
| 4996 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4997 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 4998 | if (DEBUG_INPUT) { |
| 4999 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 5000 | } |
| 5001 | |
| 5002 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 5003 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5004 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 5005 | } |
| 5006 | |
| 5007 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 5008 | |
| 5009 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5010 | && event.getRepeatCount() == 0) { |
| 5011 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 5012 | |
| 5013 | Message msg = mHandler.obtainMessage( |
| 5014 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 5015 | msg.setAsynchronous(true); |
| 5016 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 5017 | } else { |
| 5018 | mBroadcastWakeLock.release(); |
| 5019 | } |
| 5020 | } |
| 5021 | |
| 5022 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 5023 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5024 | |
| 5025 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 5026 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 5027 | if (DEBUG_INPUT) { |
| 5028 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 5029 | } |
| 5030 | |
| 5031 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 5032 | mBroadcastWakeLock.release(); |
| 5033 | } |
| 5034 | |
| 5035 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 5036 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5037 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5038 | } |
| 5039 | } |
| 5040 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5041 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
| 5042 | Intent voiceIntent = |
| 5043 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 5044 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5045 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5046 | mBroadcastWakeLock.release(); |
| 5047 | } |
| 5048 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5049 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5050 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5051 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 5052 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 5053 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 5054 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5055 | } else { |
| 5056 | try { |
| 5057 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 5058 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5059 | mUiMode = uiModeService.getCurrentModeType(); |
| 5060 | } catch (RemoteException e) { |
| 5061 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 5062 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5063 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5064 | synchronized (mLock) { |
| 5065 | updateOrientationListenerLp(); |
| 5066 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5067 | } |
| 5068 | }; |
| 5069 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5070 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 5071 | @Override |
| 5072 | public void onReceive(Context context, Intent intent) { |
| 5073 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5074 | if (mKeyguardDelegate != null) { |
| 5075 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5076 | } |
| 5077 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5078 | if (mKeyguardDelegate != null) { |
| 5079 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5080 | } |
| 5081 | } |
| 5082 | } |
| 5083 | }; |
| 5084 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5085 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 5086 | @Override |
| 5087 | public void onReceive(Context context, Intent intent) { |
| 5088 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 5089 | // tickle the settings observer: this first ensures that we're |
| 5090 | // observing the relevant settings for the newly-active user, |
| 5091 | // and then updates our own bookkeeping based on the now- |
| 5092 | // current user. |
| 5093 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5094 | |
| 5095 | // force a re-application of focused window sysui visibility. |
| 5096 | // the window may never have been shown for this user |
| 5097 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5098 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5099 | mLastSystemUiFlags = 0; |
| 5100 | updateSystemUiVisibilityLw(); |
| 5101 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5102 | } |
| 5103 | } |
| 5104 | }; |
| 5105 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5106 | private final Runnable mRequestTransientNav = new Runnable() { |
| 5107 | @Override |
| 5108 | public void run() { |
| 5109 | requestTransientBars(mNavigationBar); |
| 5110 | } |
| 5111 | }; |
| 5112 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5113 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5114 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5115 | if (!isUserSetupComplete()) { |
| 5116 | // Swipe-up for navigation bar is disabled during setup |
| 5117 | return; |
| 5118 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5119 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 5120 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5121 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 5122 | // Don't show status bar when swiping on already visible navigation bar |
| 5123 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5124 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5125 | return; |
| 5126 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5127 | if (sb) mStatusBarController.showTransient(); |
| 5128 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5129 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5130 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5131 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5132 | } |
| 5133 | } |
| 5134 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5135 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5136 | @Override |
Jeff Brown | 140ffc7 | 2014-05-01 15:18:00 -0700 | [diff] [blame] | 5137 | public void goingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5138 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5139 | if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep..."); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5140 | |
| 5141 | // We must get this work done here because the power manager will drop |
| 5142 | // 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] | 5143 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5144 | mAwake = false; |
| 5145 | mKeyguardDrawComplete = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5146 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5147 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5148 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5149 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5150 | |
| 5151 | if (mKeyguardDelegate != null) { |
| 5152 | mKeyguardDelegate.onScreenTurnedOff(why); |
| 5153 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5154 | } |
| 5155 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5156 | private void wakeUpFromPowerKey(long eventTime) { |
| 5157 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey); |
| 5158 | } |
| 5159 | |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5160 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) { |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5161 | if (!wakeInTheaterMode && isTheaterModeEnabled()) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5162 | return false; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5163 | } |
| 5164 | |
| 5165 | mPowerManager.wakeUp(wakeTime); |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5166 | return true; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5169 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5170 | @Override |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5171 | public void wakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5172 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5173 | if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5174 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5175 | // Since goToSleep performs these functions synchronously, we must |
| 5176 | // do the same here. We cannot post this work to a handler because |
| 5177 | // that might cause it to become reordered with respect to what |
| 5178 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5179 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5180 | mAwake = true; |
| 5181 | mKeyguardDrawComplete = false; |
| 5182 | if (mKeyguardDelegate != null) { |
| 5183 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5184 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
| 5185 | } |
| 5186 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5187 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5188 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5189 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5190 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5191 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5192 | if (mKeyguardDelegate != null) { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5193 | mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5194 | // ... eventually calls finishKeyguardDrawn |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5195 | } else { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5196 | if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5197 | finishKeyguardDrawn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5198 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5201 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5202 | synchronized (mLock) { |
| 5203 | if (!mAwake || mKeyguardDrawComplete) { |
| 5204 | return; // spurious |
| 5205 | } |
| 5206 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5207 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5208 | if (mKeyguardDelegate != null) { |
| 5209 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5210 | } |
| 5211 | } |
| 5212 | |
| 5213 | finishScreenTurningOn(); |
| 5214 | } |
| 5215 | |
| 5216 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5217 | @Override |
| 5218 | public void screenTurnedOff() { |
| 5219 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 5220 | |
| 5221 | synchronized (mLock) { |
| 5222 | mScreenOnEarly = false; |
| 5223 | mScreenOnFully = false; |
| 5224 | mWindowManagerDrawComplete = false; |
| 5225 | mScreenOnListener = null; |
| 5226 | updateOrientationListenerLp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5227 | } |
| 5228 | } |
| 5229 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5230 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5231 | @Override |
| 5232 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5233 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5234 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5235 | synchronized (mLock) { |
| 5236 | mScreenOnEarly = true; |
| 5237 | mScreenOnFully = false; |
| 5238 | mWindowManagerDrawComplete = false; |
| 5239 | mScreenOnListener = screenOnListener; |
| 5240 | updateOrientationListenerLp(); |
| 5241 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5242 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 5243 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 5244 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5245 | // ... eventually calls finishWindowsDrawn |
| 5246 | } |
| 5247 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5248 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5249 | synchronized (mLock) { |
| 5250 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
| 5251 | return; // spurious |
| 5252 | } |
| 5253 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5254 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5255 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5256 | |
| 5257 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5258 | } |
| 5259 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5260 | private void finishScreenTurningOn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5261 | final ScreenOnListener listener; |
| 5262 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5263 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5264 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5265 | "finishScreenTurningOn: mAwake=" + mAwake |
| 5266 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 5267 | + ", mScreenOnFully=" + mScreenOnFully |
| 5268 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 5269 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 5270 | |
| 5271 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 5272 | || (mAwake && !mKeyguardDrawComplete)) { |
| 5273 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5274 | } |
| 5275 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5276 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 5277 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 5278 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5279 | mScreenOnFully = true; |
| 5280 | |
| 5281 | // Remember the first time we draw the keyguard so we know when we're done with |
| 5282 | // the main part of booting and can enable the screen and hide boot messages. |
| 5283 | if (!mKeyguardDrawnOnce && mAwake) { |
| 5284 | mKeyguardDrawnOnce = true; |
| 5285 | enableScreen = true; |
| 5286 | if (mBootMessageNeedsHiding) { |
| 5287 | mBootMessageNeedsHiding = false; |
| 5288 | hideBootMessages(); |
| 5289 | } |
| 5290 | } else { |
| 5291 | enableScreen = false; |
| 5292 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5293 | } |
| 5294 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5295 | if (listener != null) { |
| 5296 | listener.onScreenOn(); |
| 5297 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 5298 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5299 | if (enableScreen) { |
| 5300 | try { |
| 5301 | mWindowManager.enableScreenIfNeeded(); |
| 5302 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5303 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5304 | } |
| 5305 | } |
| 5306 | |
| 5307 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5308 | synchronized (mLock) { |
| 5309 | if (!mKeyguardDrawnOnce) { |
| 5310 | mBootMessageNeedsHiding = true; |
| 5311 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 5312 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5313 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5314 | |
| 5315 | if (mBootMsgDialog != null) { |
| 5316 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 5317 | mBootMsgDialog.dismiss(); |
| 5318 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5319 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5323 | public boolean isScreenOn() { |
| 5324 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5325 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5326 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5327 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5328 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5329 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5330 | if (mKeyguardDelegate != null) { |
| 5331 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5332 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5336 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5337 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5338 | if (mKeyguardDelegate != null) { |
| 5339 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5340 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5341 | } |
| 5342 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5343 | private boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5344 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5345 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5346 | } |
| 5347 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5348 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5349 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5350 | public boolean isKeyguardLocked() { |
| 5351 | return keyguardOn(); |
| 5352 | } |
| 5353 | |
| 5354 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5355 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5356 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5357 | if (mKeyguardDelegate == null) return false; |
| 5358 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5359 | } |
| 5360 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5361 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5362 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5363 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5364 | if (mKeyguardDelegate == null) return false; |
| 5365 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5366 | } |
| 5367 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5368 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5369 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5370 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5371 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5372 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5373 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5374 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 5375 | // ask the keyguard to prompt the user to authenticate if necessary |
| 5376 | mKeyguardDelegate.dismiss(); |
| 5377 | } |
| 5378 | }); |
| 5379 | } |
| 5380 | } |
| 5381 | |
| 5382 | public void notifyActivityDrawnForKeyguardLw() { |
| 5383 | if (mKeyguardDelegate != null) { |
| 5384 | mHandler.post(new Runnable() { |
| 5385 | @Override |
| 5386 | public void run() { |
| 5387 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5388 | } |
| 5389 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5390 | } |
| 5391 | } |
| 5392 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5393 | @Override |
| 5394 | public boolean isKeyguardDrawnLw() { |
| 5395 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5396 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5397 | } |
| 5398 | } |
| 5399 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5400 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5401 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5402 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5403 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5404 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5405 | } |
| 5406 | } |
| 5407 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5408 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5409 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5413 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5414 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 5415 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5416 | @Override |
| 5417 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5418 | if (false) { |
| 5419 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 5420 | + orientation + ", last=" + lastRotation |
| 5421 | + "); user=" + mUserRotation + " " |
| 5422 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 5423 | ? "USER_ROTATION_LOCKED" : "") |
| 5424 | ); |
| 5425 | } |
| 5426 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 5427 | if (mForceDefaultOrientation) { |
| 5428 | return Surface.ROTATION_0; |
| 5429 | } |
| 5430 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5431 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5432 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 5433 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 5434 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5435 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5436 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5437 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5438 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5439 | // Ignore sensor when lid switch is open and rotation is forced. |
| 5440 | preferredRotation = mLidOpenRotation; |
| 5441 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5442 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5443 | // Ignore sensor when in car dock unless explicitly enabled. |
| 5444 | // This case can override the behavior of NOSENSOR, and can also |
| 5445 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5446 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5447 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 5448 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5449 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 5450 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5451 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5452 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 5453 | // This case can override the behavior of NOSENSOR, and can also |
| 5454 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5455 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5456 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5457 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 5458 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 5459 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5460 | preferredRotation = mDemoHdmiRotation; |
| 5461 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 5462 | && mUndockedHdmiRotation >= 0) { |
| 5463 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 5464 | // been specified in the configuration (only for legacy devices without |
| 5465 | // full multi-display support). |
| 5466 | // Note that the dock orientation overrides the HDMI orientation. |
| 5467 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 5468 | } else if (mDemoRotationLock) { |
| 5469 | // Ignore sensor when demo rotation lock is enabled. |
| 5470 | // Note that the dock orientation and HDMI rotation lock override this. |
| 5471 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5472 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 5473 | // Application just wants to remain locked in the last rotation. |
| 5474 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5475 | } else if (!mSupportAutoRotation) { |
| 5476 | // If we don't support auto-rotation then bail out here and ignore |
| 5477 | // the sensor and any rotation lock settings. |
| 5478 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5479 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5480 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5481 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 5482 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 5483 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 5484 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5485 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 5486 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5487 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 5488 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 5489 | // Otherwise, use sensor only if requested by the application or enabled |
| 5490 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5491 | if (mAllowAllRotations < 0) { |
| 5492 | // Can't read this during init() because the context doesn't |
| 5493 | // have display metrics at that time so we cannot determine |
| 5494 | // tablet vs. phone then. |
| 5495 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 5496 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 5497 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5498 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5499 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5500 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5501 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5502 | preferredRotation = sensorRotation; |
| 5503 | } else { |
| 5504 | preferredRotation = lastRotation; |
| 5505 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5506 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 5507 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 5508 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 5509 | // The idea is that the user rotation expresses a weak preference for the direction |
| 5510 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 5511 | // 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] | 5512 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5513 | } else { |
| 5514 | // No overriding preference. |
| 5515 | // We will do exactly what the application asked us to do. |
| 5516 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5517 | } |
| 5518 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5519 | switch (orientation) { |
| 5520 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5521 | // Return portrait unless overridden. |
| 5522 | if (isAnyPortrait(preferredRotation)) { |
| 5523 | return preferredRotation; |
| 5524 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5525 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5526 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5527 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5528 | // Return landscape unless overridden. |
| 5529 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5530 | return preferredRotation; |
| 5531 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5532 | return mLandscapeRotation; |
| 5533 | |
| 5534 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5535 | // Return reverse portrait unless overridden. |
| 5536 | if (isAnyPortrait(preferredRotation)) { |
| 5537 | return preferredRotation; |
| 5538 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5539 | return mUpsideDownRotation; |
| 5540 | |
| 5541 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5542 | // Return seascape unless overridden. |
| 5543 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5544 | return preferredRotation; |
| 5545 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5546 | return mSeascapeRotation; |
| 5547 | |
| 5548 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5549 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5550 | // Return either landscape rotation. |
| 5551 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5552 | return preferredRotation; |
| 5553 | } |
| 5554 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 5555 | return lastRotation; |
| 5556 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5557 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5558 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5559 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5560 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5561 | // Return either portrait rotation. |
| 5562 | if (isAnyPortrait(preferredRotation)) { |
| 5563 | return preferredRotation; |
| 5564 | } |
| 5565 | if (isAnyPortrait(lastRotation)) { |
| 5566 | return lastRotation; |
| 5567 | } |
| 5568 | return mPortraitRotation; |
| 5569 | |
| 5570 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5571 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 5572 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5573 | if (preferredRotation >= 0) { |
| 5574 | return preferredRotation; |
| 5575 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5576 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 5577 | } |
| 5578 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5579 | } |
| 5580 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5581 | @Override |
| 5582 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 5583 | switch (orientation) { |
| 5584 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 5585 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 5586 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 5587 | return isAnyPortrait(rotation); |
| 5588 | |
| 5589 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 5590 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 5591 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 5592 | return isLandscapeOrSeascape(rotation); |
| 5593 | |
| 5594 | default: |
| 5595 | return true; |
| 5596 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5597 | } |
| 5598 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5599 | @Override |
| 5600 | public void setRotationLw(int rotation) { |
| 5601 | mOrientationListener.setCurrentRotation(rotation); |
| 5602 | } |
| 5603 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5604 | private boolean isLandscapeOrSeascape(int rotation) { |
| 5605 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5606 | } |
| 5607 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5608 | private boolean isAnyPortrait(int rotation) { |
| 5609 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5610 | } |
| 5611 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5612 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5613 | public int getUserRotationMode() { |
| 5614 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 5615 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 5616 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 5617 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5618 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5619 | |
| 5620 | // 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] | 5621 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5622 | public void setUserRotationMode(int mode, int rot) { |
| 5623 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5624 | |
| 5625 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5626 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5627 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5628 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5629 | rot, |
| 5630 | UserHandle.USER_CURRENT); |
| 5631 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5632 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5633 | 0, |
| 5634 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5635 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5636 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5637 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5638 | 1, |
| 5639 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5640 | } |
| 5641 | } |
| 5642 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5643 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5644 | public void setSafeMode(boolean safeMode) { |
| 5645 | mSafeMode = safeMode; |
| 5646 | performHapticFeedbackLw(null, safeMode |
| 5647 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 5648 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5649 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5650 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 5651 | static long[] getLongIntArray(Resources r, int resid) { |
| 5652 | int[] ar = r.getIntArray(resid); |
| 5653 | if (ar == null) { |
| 5654 | return null; |
| 5655 | } |
| 5656 | long[] out = new long[ar.length]; |
| 5657 | for (int i=0; i<ar.length; i++) { |
| 5658 | out[i] = ar[i]; |
| 5659 | } |
| 5660 | return out; |
| 5661 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5662 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5663 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5664 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5665 | public void systemReady() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5666 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 5667 | mKeyguardDelegate.onSystemReady(); |
| 5668 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5669 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5670 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5671 | synchronized (mLock) { |
| 5672 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5673 | mSystemReady = true; |
| 5674 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5675 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5676 | public void run() { |
| 5677 | updateSettings(); |
| 5678 | } |
| 5679 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5680 | } |
| 5681 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5682 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5683 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5684 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5685 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5686 | if (mKeyguardDelegate != null) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 5687 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5688 | mKeyguardDelegate.onBootCompleted(); |
| 5689 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5690 | synchronized (mLock) { |
| 5691 | mSystemBooted = true; |
| 5692 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5693 | wakingUp(); |
| 5694 | screenTurningOn(null); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5695 | } |
| 5696 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5697 | ProgressDialog mBootMsgDialog = null; |
| 5698 | |
| 5699 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5700 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5701 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5702 | mHandler.post(new Runnable() { |
| 5703 | @Override public void run() { |
| 5704 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 5705 | int theme; |
| 5706 | if (mContext.getPackageManager().hasSystemFeature( |
| 5707 | PackageManager.FEATURE_WATCH)) { |
| 5708 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 5709 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 5710 | PackageManager.FEATURE_TELEVISION)) { |
| 5711 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 5712 | } else { |
| 5713 | theme = 0; |
| 5714 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 5715 | |
| 5716 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 5717 | // This dialog will consume all events coming in to |
| 5718 | // it, to avoid it trying to do things too early in boot. |
| 5719 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 5720 | return true; |
| 5721 | } |
| 5722 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5723 | return true; |
| 5724 | } |
| 5725 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 5726 | return true; |
| 5727 | } |
| 5728 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 5729 | return true; |
| 5730 | } |
| 5731 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 5732 | return true; |
| 5733 | } |
| 5734 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 5735 | AccessibilityEvent event) { |
| 5736 | return true; |
| 5737 | } |
| 5738 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 5739 | if (mContext.getPackageManager().isUpgrade()) { |
| 5740 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 5741 | } else { |
| 5742 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 5743 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5744 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 5745 | mBootMsgDialog.setIndeterminate(true); |
| 5746 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5747 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5748 | mBootMsgDialog.getWindow().addFlags( |
| 5749 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 5750 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 5751 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 5752 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 5753 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 5754 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5755 | mBootMsgDialog.setCancelable(false); |
| 5756 | mBootMsgDialog.show(); |
| 5757 | } |
| 5758 | mBootMsgDialog.setMessage(msg); |
| 5759 | } |
| 5760 | }); |
| 5761 | } |
| 5762 | |
| 5763 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5764 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5765 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5766 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5767 | } |
| 5768 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5769 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5770 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5771 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5772 | // *************************************** |
| 5773 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 5774 | // *************************************** |
| 5775 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 5776 | // WITH ITS LOCKS HELD. |
| 5777 | // |
| 5778 | // This code must be VERY careful about the locks |
| 5779 | // it acquires. |
| 5780 | // In fact, the current code acquires way too many, |
| 5781 | // and probably has lurking deadlocks. |
| 5782 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5783 | synchronized (mScreenLockTimeout) { |
| 5784 | if (mLockScreenTimerActive) { |
| 5785 | // reset the timer |
| 5786 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5787 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5788 | } |
| 5789 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5790 | } |
| 5791 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5792 | class ScreenLockTimeout implements Runnable { |
| 5793 | Bundle options; |
| 5794 | |
| 5795 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5796 | public void run() { |
| 5797 | synchronized (this) { |
| 5798 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5799 | if (mKeyguardDelegate != null) { |
| 5800 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5801 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5802 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5803 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5804 | } |
| 5805 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5806 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5807 | public void setLockOptions(Bundle options) { |
| 5808 | this.options = options; |
| 5809 | } |
| 5810 | } |
| 5811 | |
| 5812 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 5813 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5814 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5815 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5816 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 5817 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5818 | if (options != null) { |
| 5819 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 5820 | // until the runnable actually executes. |
| 5821 | mScreenLockTimeout.setLockOptions(options); |
| 5822 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5823 | mHandler.post(mScreenLockTimeout); |
| 5824 | } |
| 5825 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5826 | private void updateLockScreenTimeout() { |
| 5827 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5828 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5829 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5830 | if (mLockScreenTimerActive != enable) { |
| 5831 | if (enable) { |
| 5832 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 5833 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5834 | } else { |
| 5835 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 5836 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5837 | } |
| 5838 | mLockScreenTimerActive = enable; |
| 5839 | } |
| 5840 | } |
| 5841 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5842 | |
| 5843 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5844 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5845 | public void enableScreenAfterBoot() { |
| 5846 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5847 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5848 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5849 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 5850 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5851 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5852 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5853 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 5854 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5855 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5856 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5857 | |
| 5858 | synchronized (mLock) { |
| 5859 | updateWakeGestureListenerLp(); |
| 5860 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5861 | } |
| 5862 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5863 | void updateUiMode() { |
| 5864 | if (mUiModeManager == null) { |
| 5865 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 5866 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5867 | } |
| 5868 | try { |
| 5869 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 5870 | } catch (RemoteException e) { |
| 5871 | } |
| 5872 | } |
| 5873 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5874 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5875 | try { |
| 5876 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5877 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 5878 | } catch (RemoteException e) { |
| 5879 | // Ignore |
| 5880 | } |
| 5881 | } |
| 5882 | |
| 5883 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 5884 | try { |
| 5885 | //set orientation on WindowManager |
| 5886 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5887 | } catch (RemoteException e) { |
| 5888 | // Ignore |
| 5889 | } |
| 5890 | } |
| 5891 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5892 | /** |
| 5893 | * Return an Intent to launch the currently active dock app as home. Returns |
| 5894 | * null if the standard home should be launched, which is the case if any of the following is |
| 5895 | * true: |
| 5896 | * <ul> |
| 5897 | * <li>The device is not in either car mode or desk mode |
| 5898 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 5899 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 5900 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 5901 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 5902 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5903 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5904 | */ |
| 5905 | Intent createHomeDockIntent() { |
| 5906 | Intent intent = null; |
| 5907 | |
| 5908 | // What home does is based on the mode, not the dock state. That |
| 5909 | // is, when in car mode you should be taken to car home regardless |
| 5910 | // of whether we are actually in a car dock. |
| 5911 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 5912 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 5913 | intent = mCarDockIntent; |
| 5914 | } |
| 5915 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 5916 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 5917 | intent = mDeskDockIntent; |
| 5918 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5919 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 5920 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5921 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 5922 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 5923 | // Always launch dock home from home when watch is docked, if it exists. |
| 5924 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | if (intent == null) { |
| 5928 | return null; |
| 5929 | } |
| 5930 | |
| 5931 | ActivityInfo ai = null; |
| 5932 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 5933 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 5934 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 5935 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5936 | if (info != null) { |
| 5937 | ai = info.activityInfo; |
| 5938 | } |
| 5939 | if (ai != null |
| 5940 | && ai.metaData != null |
| 5941 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 5942 | intent = new Intent(intent); |
| 5943 | intent.setClassName(ai.packageName, ai.name); |
| 5944 | return intent; |
| 5945 | } |
| 5946 | |
| 5947 | return null; |
| 5948 | } |
| 5949 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 5950 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 5951 | if (awakenFromDreams) { |
| 5952 | awakenDreams(); |
| 5953 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5954 | |
| 5955 | Intent dock = createHomeDockIntent(); |
| 5956 | if (dock != null) { |
| 5957 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 5958 | if (fromHomeKey) { |
| 5959 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 5960 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5961 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5962 | return; |
| 5963 | } catch (ActivityNotFoundException e) { |
| 5964 | } |
| 5965 | } |
| 5966 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 5967 | Intent intent; |
| 5968 | |
| 5969 | if (fromHomeKey) { |
| 5970 | intent = new Intent(mHomeIntent); |
| 5971 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 5972 | } else { |
| 5973 | intent = mHomeIntent; |
| 5974 | } |
| 5975 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 5976 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5977 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5978 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5979 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5980 | * goes to the home screen |
| 5981 | * @return whether it did anything |
| 5982 | */ |
| 5983 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5984 | if (!isUserSetupComplete()) { |
| 5985 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 5986 | return false; |
| 5987 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5988 | if (false) { |
| 5989 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 5990 | try { |
| 5991 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 5992 | } catch (RemoteException e) { |
| 5993 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 5994 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 5995 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5996 | } else { |
| 5997 | // This code brings home to the front or, if it is already |
| 5998 | // at the front, puts the device to sleep. |
| 5999 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 6000 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 6001 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 6002 | Log.d(TAG, "UTS-TEST-MODE"); |
| 6003 | } else { |
| 6004 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6005 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6006 | Intent dock = createHomeDockIntent(); |
| 6007 | if (dock != null) { |
| 6008 | int result = ActivityManagerNative.getDefault() |
| 6009 | .startActivityAsUser(null, null, dock, |
| 6010 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6011 | null, null, 0, |
| 6012 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6013 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6014 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 6015 | return false; |
| 6016 | } |
| 6017 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6018 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6019 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6020 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6021 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6022 | null, null, 0, |
| 6023 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6024 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6025 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6026 | return false; |
| 6027 | } |
| 6028 | } catch (RemoteException ex) { |
| 6029 | // bummer, the activity manager, which is in this process, is dead |
| 6030 | } |
| 6031 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6032 | return true; |
| 6033 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6034 | |
| 6035 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6036 | public void setCurrentOrientationLw(int newOrientation) { |
| 6037 | synchronized (mLock) { |
| 6038 | if (newOrientation != mCurrentAppOrientation) { |
| 6039 | mCurrentAppOrientation = newOrientation; |
| 6040 | updateOrientationListenerLp(); |
| 6041 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6042 | } |
| 6043 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6044 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6045 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 6046 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 6047 | return; |
| 6048 | } |
| 6049 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 6050 | Context.AUDIO_SERVICE); |
| 6051 | if (audioManager.isSilentMode()) { |
| 6052 | return; |
| 6053 | } |
| 6054 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 6055 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 6056 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 6057 | ringTone.play(); |
| 6058 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6059 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6060 | private boolean isTheaterModeEnabled() { |
| 6061 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6062 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 6063 | } |
| 6064 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6065 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 6066 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6067 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 6068 | } |
| 6069 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6070 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6071 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 6072 | if (!mVibrator.hasVibrator()) { |
| 6073 | return false; |
| 6074 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6075 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 6076 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 6077 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6078 | return false; |
| 6079 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6080 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6081 | switch (effectId) { |
| 6082 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6083 | pattern = mLongPressVibePattern; |
| 6084 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6085 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6086 | pattern = mVirtualKeyVibePattern; |
| 6087 | break; |
| 6088 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 6089 | pattern = mKeyboardTapVibePattern; |
| 6090 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 6091 | case HapticFeedbackConstants.CLOCK_TICK: |
| 6092 | pattern = mClockTickVibePattern; |
| 6093 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 6094 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 6095 | pattern = mCalendarDateVibePattern; |
| 6096 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6097 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6098 | pattern = mSafeModeDisabledVibePattern; |
| 6099 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6100 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6101 | pattern = mSafeModeEnabledVibePattern; |
| 6102 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6103 | default: |
| 6104 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6105 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6106 | int owningUid; |
| 6107 | String owningPackage; |
| 6108 | if (win != null) { |
| 6109 | owningUid = win.getOwningUid(); |
| 6110 | owningPackage = win.getOwningPackage(); |
| 6111 | } else { |
| 6112 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 6113 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6114 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6115 | if (pattern.length == 1) { |
| 6116 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6117 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6118 | } else { |
| 6119 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6120 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6121 | } |
| 6122 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6123 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6124 | |
| 6125 | @Override |
| 6126 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6127 | } |
| 6128 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6129 | @Override |
| 6130 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6131 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 6132 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6133 | } |
| 6134 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 6135 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6136 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6137 | // If there is no window focused, there will be nobody to handle the events |
| 6138 | // 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] | 6139 | final WindowState win = mFocusedWindow != null ? mFocusedWindow |
| 6140 | : mTopFullscreenOpaqueWindowState; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6141 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6142 | return 0; |
| 6143 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6144 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6145 | // We are updating at a point where the keyguard has gotten |
| 6146 | // focus, but we were last in a state where the top window is |
| 6147 | // hiding it. This is probably because the keyguard as been |
| 6148 | // shown while the top window was displayed, so we want to ignore |
| 6149 | // it here because this is just a very transient change and it |
| 6150 | // will quickly lose focus once it correctly gets hidden. |
| 6151 | return 0; |
| 6152 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6153 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 6154 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6155 | & ~mResettingSystemUiFlags |
| 6156 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6157 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6158 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6159 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6160 | tmpVisibility = updateLightStatusBarLw(tmpVisibility); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6161 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6162 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6163 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 6164 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6165 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6166 | return 0; |
| 6167 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6168 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6169 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6170 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6171 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6172 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6173 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6174 | try { |
| 6175 | IStatusBarService statusbar = getStatusBarService(); |
| 6176 | if (statusbar != null) { |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 6177 | statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString()); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6178 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6179 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6180 | } catch (RemoteException e) { |
| 6181 | // re-acquire status bar service next time it is needed. |
| 6182 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6183 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6184 | } |
| 6185 | }); |
| 6186 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6187 | } |
| 6188 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6189 | private int updateLightStatusBarLw(int vis) { |
| 6190 | WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6191 | ? mStatusBar |
| 6192 | : mTopFullscreenOpaqueOrDimmingWindowState; |
| 6193 | |
| 6194 | if (statusColorWin != null) { |
| 6195 | if (statusColorWin == mTopFullscreenOpaqueWindowState) { |
| 6196 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 6197 | // its light flag. |
| 6198 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6199 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 6200 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6201 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 6202 | // Otherwise if it's dimming, clear the light flag. |
| 6203 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6204 | } |
| 6205 | } |
| 6206 | return vis; |
| 6207 | } |
| 6208 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6209 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6210 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6211 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6212 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6213 | : mTopFullscreenOpaqueWindowState; |
| 6214 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6215 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6216 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6217 | // prevent status bar interaction from clearing certain flags |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6218 | boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6219 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6220 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 6221 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 6222 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 6223 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 6224 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6225 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6226 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 6227 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6228 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6229 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6230 | |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 6231 | if (!areTranslucentBarsAllowed() && transWin != mStatusBar) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 6232 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 6233 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6234 | } |
| 6235 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6236 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6237 | boolean immersiveSticky = |
| 6238 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6239 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6240 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6241 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6242 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 6243 | boolean hideStatusBarSysui = |
| 6244 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6245 | boolean hideNavBarSysui = |
| 6246 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6247 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6248 | boolean transientStatusBarAllowed = |
| 6249 | mStatusBar != null && ( |
| 6250 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6251 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6252 | || statusBarHasFocus); |
| 6253 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6254 | boolean transientNavBarAllowed = |
| 6255 | mNavigationBar != null && |
| 6256 | hideNavBarSysui && immersiveSticky; |
| 6257 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6258 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6259 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6260 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6261 | && !transientNavBarAllowed; |
| 6262 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6263 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6264 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 6265 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6266 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6267 | |
| 6268 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 6269 | |
| 6270 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6271 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 6272 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 6273 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6274 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6275 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 6276 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6277 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6278 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6279 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 6280 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6281 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6282 | } |
| 6283 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6284 | private void clearClearableFlagsLw() { |
| 6285 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6286 | if (newVal != mResettingSystemUiFlags) { |
| 6287 | mResettingSystemUiFlags = newVal; |
| 6288 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 6289 | } |
| 6290 | } |
| 6291 | |
| 6292 | private boolean isImmersiveMode(int vis) { |
| 6293 | 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] | 6294 | return mNavigationBar != null |
| 6295 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 6296 | && (vis & flags) != 0 |
| 6297 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6298 | } |
| 6299 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6300 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6301 | * @return whether the navigation or status bar can be made translucent |
| 6302 | * |
| 6303 | * This should return true unless touch exploration is not enabled or |
| 6304 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6305 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6306 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 6307 | return mTranslucentDecorEnabled |
| 6308 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6309 | } |
| 6310 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6311 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 6312 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6313 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6314 | public boolean hasNavigationBar() { |
| 6315 | return mHasNavigationBar; |
| 6316 | } |
| 6317 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 6318 | @Override |
| 6319 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 6320 | mLastInputMethodWindow = ime; |
| 6321 | mLastInputMethodTargetWindow = target; |
| 6322 | } |
| 6323 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6324 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 6325 | public int getInputMethodWindowVisibleHeightLw() { |
| 6326 | return mDockBottom - mCurBottom; |
| 6327 | } |
| 6328 | |
| 6329 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6330 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6331 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6332 | if (mKeyguardDelegate != null) { |
| 6333 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6334 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 6335 | if (mStatusBarService != null) { |
| 6336 | try { |
| 6337 | mStatusBarService.setCurrentUser(newUserId); |
| 6338 | } catch (RemoteException e) { |
| 6339 | // oh well |
| 6340 | } |
| 6341 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6342 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 6346 | public boolean canMagnifyWindow(int windowType) { |
| 6347 | switch (windowType) { |
| 6348 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 6349 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 6350 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 6351 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 6352 | return false; |
| 6353 | } |
| 6354 | } |
| 6355 | return true; |
| 6356 | } |
| 6357 | |
| 6358 | @Override |
| 6359 | public boolean isTopLevelWindow(int windowType) { |
| 6360 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 6361 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 6362 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 6363 | } |
| 6364 | return true; |
| 6365 | } |
| 6366 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 6367 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 6368 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6369 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6370 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 6371 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6372 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6373 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6374 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6375 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6376 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 6377 | || mForceClearedSystemUiFlags != 0) { |
| 6378 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 6379 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 6380 | pw.print(" mResettingSystemUiFlags=0x"); |
| 6381 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 6382 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 6383 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6384 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6385 | if (mLastFocusNeedsMenu) { |
| 6386 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 6387 | pw.println(mLastFocusNeedsMenu); |
| 6388 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6389 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 6390 | pw.println(mWakeGestureEnabledSetting); |
| 6391 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6392 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6393 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 6394 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6395 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 6396 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 6397 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 6398 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6399 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6400 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6401 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 6402 | pw.print(mCarDockEnablesAccelerometer); |
| 6403 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 6404 | pw.println(mDeskDockEnablesAccelerometer); |
| 6405 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 6406 | pw.print(mLidKeyboardAccessibility); |
| 6407 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6408 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6409 | pw.print(prefix); |
| 6410 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 6411 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6412 | pw.print(prefix); |
| 6413 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 6414 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6415 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6416 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 6417 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 6418 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 6419 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 6420 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 6421 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 6422 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 6423 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 6424 | pw.print(","); pw.print(mOverscanScreenTop); |
| 6425 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 6426 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 6427 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 6428 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 6429 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 6430 | pw.print(" top="); pw.print(mOverscanTop); |
| 6431 | pw.print(" right="); pw.print(mOverscanRight); |
| 6432 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 6433 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 6434 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 6435 | pw.print(mRestrictedOverscanScreenLeft); |
| 6436 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 6437 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 6438 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6439 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 6440 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 6441 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 6442 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 6443 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 6444 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 6445 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 6446 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 6447 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 6448 | pw.print(","); pw.print(mStableFullscreenTop); |
| 6449 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 6450 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6451 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 6452 | pw.print(","); pw.print(mStableTop); |
| 6453 | pw.print(")-("); pw.print(mStableRight); |
| 6454 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6455 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 6456 | pw.print(","); pw.print(mSystemTop); |
| 6457 | pw.print(")-("); pw.print(mSystemRight); |
| 6458 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6459 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 6460 | pw.print(","); pw.print(mCurTop); |
| 6461 | pw.print(")-("); pw.print(mCurRight); |
| 6462 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 6463 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 6464 | pw.print(","); pw.print(mContentTop); |
| 6465 | pw.print(")-("); pw.print(mContentRight); |
| 6466 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 6467 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 6468 | pw.print(","); pw.print(mVoiceContentTop); |
| 6469 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 6470 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6471 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 6472 | pw.print(","); pw.print(mDockTop); |
| 6473 | pw.print(")-("); pw.print(mDockRight); |
| 6474 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6475 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 6476 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6477 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 6478 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
| 6479 | pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6480 | if (mLastInputMethodWindow != null) { |
| 6481 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 6482 | pw.println(mLastInputMethodWindow); |
| 6483 | } |
| 6484 | if (mLastInputMethodTargetWindow != null) { |
| 6485 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 6486 | pw.println(mLastInputMethodTargetWindow); |
| 6487 | } |
| 6488 | if (mStatusBar != null) { |
| 6489 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 6490 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 6491 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6492 | } |
| 6493 | if (mNavigationBar != null) { |
| 6494 | pw.print(prefix); pw.print("mNavigationBar="); |
| 6495 | pw.println(mNavigationBar); |
| 6496 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6497 | if (mFocusedWindow != null) { |
| 6498 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 6499 | pw.println(mFocusedWindow); |
| 6500 | } |
| 6501 | if (mFocusedApp != null) { |
| 6502 | pw.print(prefix); pw.print("mFocusedApp="); |
| 6503 | pw.println(mFocusedApp); |
| 6504 | } |
| 6505 | if (mWinDismissingKeyguard != null) { |
| 6506 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 6507 | pw.println(mWinDismissingKeyguard); |
| 6508 | } |
| 6509 | if (mTopFullscreenOpaqueWindowState != null) { |
| 6510 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 6511 | pw.println(mTopFullscreenOpaqueWindowState); |
| 6512 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6513 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 6514 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 6515 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 6516 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6517 | if (mForcingShowNavBar) { |
| 6518 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 6519 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 6520 | pw.println(mForcingShowNavBarLayer); |
| 6521 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6522 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6523 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6524 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 6525 | pw.print(" mForceStatusBarFromKeyguard="); |
| 6526 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6527 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 6528 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6529 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 6530 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 6531 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 6532 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 6533 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 6534 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 6535 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 6536 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 6537 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 6538 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 6539 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6540 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 6541 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 6542 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6543 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 6544 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6545 | mStatusBarController.dump(pw, prefix); |
| 6546 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6547 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6548 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6549 | if (mWakeGestureListener != null) { |
| 6550 | mWakeGestureListener.dump(pw, prefix); |
| 6551 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6552 | if (mOrientationListener != null) { |
| 6553 | mOrientationListener.dump(pw, prefix); |
| 6554 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 6555 | if (mBurnInProtectionHelper != null) { |
| 6556 | mBurnInProtectionHelper.dump(prefix, pw); |
| 6557 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6558 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6559 | } |