The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
Jeff Brown | 37df39a9 | 2015-02-25 15:42:31 -0800 | [diff] [blame] | 2 | * Copyright (C) 2006 The Android Open Source Project |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 17 | package com.android.server.policy; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 20 | import android.app.ActivityManagerInternal; |
| 21 | import android.app.ActivityManagerInternal.SleepToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 22 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 23 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 24 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 25 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 26 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 27 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 28 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 29 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 30 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 31 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 32 | import android.content.ContentResolver; |
| 33 | import android.content.Context; |
| 34 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 35 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 36 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 37 | import android.content.pm.ActivityInfo; |
| 38 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 39 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 40 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 41 | import android.content.res.Configuration; |
| 42 | import android.content.res.Resources; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 43 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 44 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 45 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 46 | import android.graphics.Rect; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 47 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 48 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 49 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 50 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 51 | import android.media.Ringtone; |
| 52 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 53 | import android.media.session.MediaSessionLegacyHelper; |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 54 | import android.os.Build; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 55 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 56 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 57 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 58 | import android.os.Handler; |
| 59 | import android.os.IBinder; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 60 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 61 | import android.os.Message; |
| 62 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 63 | import android.os.PowerManager; |
| 64 | import android.os.RemoteException; |
| 65 | import android.os.ServiceManager; |
| 66 | import android.os.SystemClock; |
| 67 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 68 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 69 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 71 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 72 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 73 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 74 | import android.service.dreams.DreamService; |
| 75 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 76 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 77 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 78 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 79 | import android.util.EventLog; |
| 80 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 81 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 82 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 83 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 84 | import android.view.Gravity; |
| 85 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 86 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 87 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 88 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 89 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 90 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 91 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 92 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 93 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 94 | import android.view.KeyEvent; |
| 95 | import android.view.MotionEvent; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 96 | import com.android.internal.policy.PhoneWindow; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 97 | import android.view.Surface; |
| 98 | import android.view.View; |
| 99 | import android.view.ViewConfiguration; |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 100 | import android.view.ViewRootImpl; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 101 | import android.view.Window; |
| 102 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 103 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 104 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 105 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 106 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 107 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 108 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 109 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 110 | import android.view.animation.AnimationUtils; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 111 | import com.android.internal.R; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 112 | import com.android.internal.statusbar.IStatusBarService; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 113 | import com.android.internal.widget.PointerLocationView; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 114 | import com.android.server.LocalServices; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 115 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
| 116 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 117 | |
| 118 | import java.io.File; |
| 119 | import java.io.FileReader; |
| 120 | import java.io.IOException; |
| 121 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 122 | import java.util.HashSet; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 123 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 124 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 125 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 126 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 127 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 128 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 129 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 130 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
| 131 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 132 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 133 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 134 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 135 | * introduces a new method suffix, Lp, for an internal lock of the |
| 136 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 137 | * 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] | 138 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 139 | */ |
| 140 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 141 | static final String TAG = "WindowManager"; |
| 142 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 143 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 145 | static final boolean DEBUG_KEYGUARD = false; |
| 146 | static final boolean DEBUG_LAYOUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 147 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 148 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 149 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 150 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 151 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 152 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 153 | // No longer recommended for desk docks; still useful in car docks. |
| 154 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 155 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 156 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 157 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 158 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 159 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 160 | 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] | 161 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 162 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 163 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 164 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 165 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 166 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 167 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 168 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 169 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 170 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 171 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 172 | // These need to match the documentation/constant in |
| 173 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 174 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 175 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 176 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 177 | |
| 178 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 179 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 180 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 181 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 182 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 183 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 184 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 185 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 186 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 187 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 188 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 189 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 190 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 191 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 192 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 193 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 194 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 195 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 196 | /** |
| 197 | * These are the system UI flags that, when changing, can cause the layout |
| 198 | * of the screen to change. |
| 199 | */ |
| 200 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 201 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 202 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 203 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 204 | | View.NAVIGATION_BAR_TRANSLUCENT |
| 205 | | View.SYSTEM_UI_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 206 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 207 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 208 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 209 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 210 | .build(); |
| 211 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 212 | /** |
| 213 | * Keyguard stuff |
| 214 | */ |
| 215 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 216 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 217 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 218 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 219 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 220 | * |
| 221 | * These are special keys that are used to launch particular kinds of applications, |
| 222 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 223 | * usage page. We don't support quite that many yet... |
| 224 | */ |
| 225 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 226 | static { |
| 227 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 228 | sApplicationLaunchKeyCategories.append( |
| 229 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 230 | sApplicationLaunchKeyCategories.append( |
| 231 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 232 | sApplicationLaunchKeyCategories.append( |
| 233 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 234 | sApplicationLaunchKeyCategories.append( |
| 235 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 236 | sApplicationLaunchKeyCategories.append( |
| 237 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 238 | sApplicationLaunchKeyCategories.append( |
| 239 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 240 | } |
| 241 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 242 | /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ |
| 243 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
| 244 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 245 | /** |
| 246 | * Lock protecting internal state. Must not call out into window |
| 247 | * manager with lock held. (This lock will be acquired in places |
| 248 | * where the window manager is calling in with its own lock held.) |
| 249 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 250 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 251 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 252 | Context mContext; |
| 253 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 254 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 255 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 256 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 257 | ActivityManagerInternal mActivityManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 258 | DreamManagerInternal mDreamManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 259 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 260 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 261 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 262 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 263 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 264 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 265 | BurnInProtectionHelper mBurnInProtectionHelper; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 266 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 267 | // Vibrator pattern for haptic feedback of a long press. |
| 268 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 269 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 270 | // Vibrator pattern for haptic feedback of virtual key press. |
| 271 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 272 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 273 | // Vibrator pattern for a short vibration. |
| 274 | long[] mKeyboardTapVibePattern; |
| 275 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 276 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 277 | long[] mClockTickVibePattern; |
| 278 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 279 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 280 | long[] mCalendarDateVibePattern; |
| 281 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 282 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 283 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 284 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 285 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 286 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 287 | |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 288 | // Vibrator pattern for haptic feedback of a stylus button press. |
| 289 | long[] mStylusButtonPressVibePattern; |
| 290 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 291 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 292 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 293 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 294 | boolean mSafeMode; |
| 295 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 296 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 297 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 298 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 299 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 300 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 301 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 302 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 303 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 304 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 305 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 306 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 307 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 308 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 309 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 310 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 311 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 312 | } |
| 313 | }; |
| 314 | final ShowListener mKeyguardDelegateCallback = new ShowListener() { |
| 315 | @Override |
| 316 | public void onShown(IBinder windowToken) { |
| 317 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown."); |
| 318 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 319 | } |
| 320 | }; |
| 321 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 322 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 323 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 324 | WindowState mLastInputMethodWindow = null; |
| 325 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 326 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 327 | // FIXME This state is shared between the input reader and handler thread. |
| 328 | // Technically it's broken and buggy but it has been like this for many years |
| 329 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 330 | // so that only one thread is involved in handling input policy. Unfortunately |
| 331 | // it's on a critical path for power management so we can't just post the work to the |
| 332 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 333 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 334 | volatile boolean mPowerKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 335 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 336 | volatile int mPowerKeyPressCounter; |
| 337 | volatile boolean mEndCallKeyHandled; |
| 338 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 339 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 340 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 341 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 342 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 343 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 344 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 345 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 346 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 347 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 348 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 349 | boolean mHdmiPlugged; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 350 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 351 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 352 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 353 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 354 | int mCarDockRotation; |
| 355 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 356 | int mUndockedHdmiRotation; |
| 357 | int mDemoHdmiRotation; |
| 358 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 359 | int mDemoRotation; |
| 360 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 361 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 362 | boolean mWakeGestureEnabledSetting; |
| 363 | MyWakeGestureListener mWakeGestureListener; |
| 364 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 365 | // Default display does not rotate, apps that require non-default orientation will have to |
| 366 | // have the orientation emulated. |
| 367 | private boolean mForceDefaultOrientation = false; |
| 368 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 369 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 370 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 371 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 372 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 373 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 374 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 375 | boolean mCarDockEnablesAccelerometer; |
| 376 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 377 | int mLidKeyboardAccessibility; |
| 378 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 379 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 380 | int mShortPressOnPowerBehavior; |
| 381 | int mLongPressOnPowerBehavior; |
| 382 | int mDoublePressOnPowerBehavior; |
| 383 | int mTriplePressOnPowerBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 384 | int mShortPressOnSleepBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 385 | boolean mAwake; |
| 386 | boolean mScreenOnEarly; |
| 387 | boolean mScreenOnFully; |
| 388 | ScreenOnListener mScreenOnListener; |
| 389 | boolean mKeyguardDrawComplete; |
| 390 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 391 | boolean mOrientationSensorEnabled = false; |
| 392 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 393 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 394 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 395 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 396 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 397 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 398 | |
| 399 | // The last window we were told about in focusChanged. |
| 400 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 401 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 402 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 403 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 404 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 405 | // The current size of the screen; really; extends into the overscan area of |
| 406 | // the screen and doesn't account for any system elements like the status bar. |
| 407 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 408 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 409 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 410 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 411 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 412 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 413 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 414 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 415 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 416 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 417 | // if the status bar can't be hidden; in that case it effectively carves out |
| 418 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 419 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 420 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 421 | // During layout, the current screen borders accounting for any currently |
| 422 | // visible system UI elements. |
| 423 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 424 | // For applications requesting stable content insets, these are them. |
| 425 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 426 | // For applications requesting stable content insets but have also set the |
| 427 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 428 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 429 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 430 | // During layout, the current screen borders with all outer decoration |
| 431 | // (status bar, input method dock) accounted for. |
| 432 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 433 | // During layout, the frame in which content should be displayed |
| 434 | // to the user, accounting for all screen decoration except for any |
| 435 | // space they deem as available for other content. This is usually |
| 436 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 437 | // content insets. |
| 438 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 439 | // During layout, the frame in which voice content should be displayed |
| 440 | // to the user, accounting for all screen decoration except for any |
| 441 | // space they deem as available for other content. |
| 442 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 443 | // 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] | 444 | // windows are placed. |
| 445 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 446 | // During layout, the layer at which the doc window is placed. |
| 447 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 448 | // During layout, this is the layer of the status bar. |
| 449 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 450 | int mLastSystemUiFlags; |
| 451 | // Bits that we are in the process of clearing, so we want to prevent |
| 452 | // them from being set by applications until everything has been updated |
| 453 | // to have them clear. |
| 454 | int mResettingSystemUiFlags = 0; |
| 455 | // Bits that we are currently always keeping cleared. |
| 456 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 457 | // What we last reported to system UI about whether the compatibility |
| 458 | // menu needs to be displayed. |
| 459 | boolean mLastFocusNeedsMenu = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 460 | |
| 461 | FakeWindow mHideNavFakeWindow = null; |
| 462 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 463 | static final Rect mTmpParentFrame = new Rect(); |
| 464 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 465 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 466 | static final Rect mTmpContentFrame = new Rect(); |
| 467 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 468 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 469 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 470 | static final Rect mTmpNavigationFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 471 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 472 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 473 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 474 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 475 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 476 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 477 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 478 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 479 | private boolean mForceStatusBarTransparent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 480 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 481 | boolean mForcingShowNavBar; |
| 482 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 483 | |
| 484 | // States of keyguard dismiss. |
| 485 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 486 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 487 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 488 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 489 | |
| 490 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 491 | * be done once per window. */ |
| 492 | private WindowState mWinDismissingKeyguard; |
| 493 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 494 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 495 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 496 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 497 | * the wallpaper. */ |
| 498 | private WindowState mWinShowWhenLocked; |
| 499 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 500 | boolean mShowingLockscreen; |
| 501 | boolean mShowingDream; |
| 502 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 503 | boolean mDreamingSleepTokenNeeded; |
| 504 | SleepToken mDreamingSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 505 | boolean mKeyguardSecure; |
| 506 | boolean mKeyguardSecureIncludingHidden; |
| 507 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 508 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 509 | boolean mHomeConsumed; |
| 510 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 511 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 512 | Intent mCarDockIntent; |
| 513 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 514 | boolean mSearchKeyShortcutPending; |
| 515 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 516 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 517 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 518 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 519 | // support for activating the lock screen while the screen is on |
| 520 | boolean mAllowLockscreenWhenOn; |
| 521 | int mLockScreenTimeout; |
| 522 | boolean mLockScreenTimerActive; |
| 523 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 524 | // 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] | 525 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 526 | |
| 527 | // Behavior of POWER button while in-call and screen on. |
| 528 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 529 | int mIncallPowerBehavior; |
| 530 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 531 | Display mDisplay; |
| 532 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 533 | int mLandscapeRotation = 0; // default landscape rotation |
| 534 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 535 | int mPortraitRotation = 0; // default portrait rotation |
| 536 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 537 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 538 | int mOverscanLeft = 0; |
| 539 | int mOverscanTop = 0; |
| 540 | int mOverscanRight = 0; |
| 541 | int mOverscanBottom = 0; |
| 542 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 543 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 544 | private int mLongPressOnHomeBehavior; |
| 545 | |
| 546 | // What we do when the user double-taps on home |
| 547 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 548 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 549 | // Allowed theater mode wake actions |
| 550 | private boolean mAllowTheaterModeWakeFromKey; |
| 551 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 552 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 553 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 554 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 555 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 556 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 557 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 558 | // Whether to support long press from power button in non-interactive mode |
| 559 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 560 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 561 | // Whether to go to sleep entering theater mode from power button |
| 562 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 563 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 564 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 565 | // Time to volume and power must be pressed within this interval of each other. |
| 566 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 567 | // Increase the chord delay when taking a screenshot from the keyguard |
| 568 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 569 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 570 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 571 | private long mScreenshotChordVolumeDownKeyTime; |
| 572 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 573 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 574 | private boolean mScreenshotChordPowerKeyTriggered; |
| 575 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 576 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 577 | /* The number of steps between min and max brightness */ |
| 578 | private static final int BRIGHTNESS_STEPS = 10; |
| 579 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 580 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 581 | ShortcutManager mShortcutManager; |
| 582 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 583 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 584 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 585 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 586 | private int mCurrentUserId; |
| 587 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 588 | // Maps global key codes to the components that will handle them. |
| 589 | private GlobalKeyManager mGlobalKeyManager; |
| 590 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 591 | // Fallback actions by key code. |
| 592 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 593 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 594 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 595 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 596 | = new LogDecelerateInterpolator(100, 0); |
| 597 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 598 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 599 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 600 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 601 | 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] | 602 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 603 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 604 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 605 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 606 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 607 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 608 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 609 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 610 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 611 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 612 | |
| 613 | private class PolicyHandler extends Handler { |
| 614 | @Override |
| 615 | public void handleMessage(Message msg) { |
| 616 | switch (msg.what) { |
| 617 | case MSG_ENABLE_POINTER_LOCATION: |
| 618 | enablePointerLocation(); |
| 619 | break; |
| 620 | case MSG_DISABLE_POINTER_LOCATION: |
| 621 | disablePointerLocation(); |
| 622 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 623 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 624 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 625 | break; |
| 626 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 627 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 628 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 629 | case MSG_DISPATCH_SHOW_RECENTS: |
| 630 | showRecentApps(false); |
| 631 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 632 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 633 | showGlobalActionsInternal(); |
| 634 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 635 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 636 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 637 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 638 | break; |
| 639 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 640 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 641 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 642 | break; |
| 643 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 644 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 645 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 646 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 647 | case MSG_HIDE_BOOT_MESSAGE: |
| 648 | handleHideBootMessage(); |
| 649 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 650 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 651 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 652 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 653 | case MSG_POWER_DELAYED_PRESS: |
| 654 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 655 | finishPowerKeyPress(); |
| 656 | break; |
| 657 | case MSG_POWER_LONG_PRESS: |
| 658 | powerLongPress(); |
| 659 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 660 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 661 | updateDreamingSleepToken(msg.arg1 != 0); |
| 662 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 667 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 668 | @Override |
| 669 | public void onUEvent(UEventObserver.UEvent event) { |
| 670 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 671 | } |
| 672 | }; |
| 673 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 674 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 675 | SettingsObserver(Handler handler) { |
| 676 | super(handler); |
| 677 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 678 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 679 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 680 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 681 | ContentResolver resolver = mContext.getContentResolver(); |
| 682 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 683 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 684 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 685 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 686 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 687 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 688 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 689 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 690 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 691 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 692 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 693 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 694 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 695 | Settings.System.USER_ROTATION), false, this, |
| 696 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 697 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 698 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 699 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 700 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 701 | Settings.System.POINTER_LOCATION), false, this, |
| 702 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 703 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 704 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 705 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 706 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 707 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 708 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 709 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 710 | Settings.Global.POLICY_CONTROL), false, this, |
| 711 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 712 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 716 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 717 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 718 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 719 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 720 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 721 | class MyWakeGestureListener extends WakeGestureListener { |
| 722 | MyWakeGestureListener(Context context, Handler handler) { |
| 723 | super(context, handler); |
| 724 | } |
| 725 | |
| 726 | @Override |
| 727 | public void onWakeUp() { |
| 728 | synchronized (mLock) { |
| 729 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 730 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 731 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 737 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 738 | MyOrientationListener(Context context, Handler handler) { |
| 739 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 740 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 741 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 742 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 743 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 744 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 745 | updateRotation(false); |
| 746 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 747 | } |
| 748 | MyOrientationListener mOrientationListener; |
| 749 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 750 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 751 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 752 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 753 | View.NAVIGATION_BAR_TRANSIENT, |
| 754 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 755 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 756 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 757 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 758 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 759 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 760 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 761 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 762 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 763 | IStatusBarService getStatusBarService() { |
| 764 | synchronized (mServiceAquireLock) { |
| 765 | if (mStatusBarService == null) { |
| 766 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 767 | ServiceManager.getService("statusbar")); |
| 768 | } |
| 769 | return mStatusBarService; |
| 770 | } |
| 771 | } |
| 772 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 773 | /* |
| 774 | * We always let the sensor be switched on by default except when |
| 775 | * the user has explicitly disabled sensor based rotation or when the |
| 776 | * screen is switched off. |
| 777 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 778 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 779 | if (mSupportAutoRotation) { |
| 780 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 781 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 782 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 783 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 784 | // If the application has explicitly requested to follow the |
| 785 | // orientation, then we need to turn the sensor on. |
| 786 | return true; |
| 787 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 788 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 789 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 790 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 791 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 792 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 793 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 794 | // orientation management, |
| 795 | return true; |
| 796 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 797 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 798 | // If the setting for using the sensor by default is enabled, then |
| 799 | // we will always leave it on. Note that the user could go to |
| 800 | // a window that forces an orientation that does not use the |
| 801 | // sensor and in theory we could turn it off... however, when next |
| 802 | // turning it on we won't have a good value for the current |
| 803 | // orientation for a little bit, which can cause orientation |
| 804 | // changes to lag, so we'd like to keep it always on. (It will |
| 805 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 806 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 807 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 808 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 809 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 810 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 811 | /* |
| 812 | * Various use cases for invoking this function |
| 813 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 814 | * 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] | 815 | * if not already enabled |
| 816 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 817 | * already enabled |
| 818 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 819 | * screen turning on and current app has nosensor based orientation, do nothing |
| 820 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 821 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 822 | if (!mOrientationListener.canDetectOrientation()) { |
| 823 | // If sensor is turned off or nonexistent for some reason |
| 824 | return; |
| 825 | } |
| 826 | //Could have been invoked due to screen turning on or off or |
| 827 | //change of the currently visible window's orientation |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 828 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 829 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
| 830 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 831 | boolean disable = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 832 | if (mScreenOnEarly && mAwake) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 833 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 834 | disable = false; |
| 835 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 836 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 837 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 838 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 839 | mOrientationSensorEnabled = true; |
| 840 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 843 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 844 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 845 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 846 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 847 | mOrientationSensorEnabled = false; |
| 848 | } |
| 849 | } |
| 850 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 851 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 852 | // Hold a wake lock until the power key is released. |
| 853 | if (!mPowerKeyWakeLock.isHeld()) { |
| 854 | mPowerKeyWakeLock.acquire(); |
| 855 | } |
| 856 | |
| 857 | // Cancel multi-press detection timeout. |
| 858 | if (mPowerKeyPressCounter != 0) { |
| 859 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 860 | } |
| 861 | |
| 862 | // Detect user pressing the power button in panic when an application has |
| 863 | // taken over the whole screen. |
| 864 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Craig Mautner | 0124980e9 | 2014-11-30 21:15:34 -0800 | [diff] [blame] | 865 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 866 | if (panic) { |
| 867 | mHandler.post(mRequestTransientNav); |
| 868 | } |
| 869 | |
| 870 | // Latch power key state to detect screenshot chord. |
| 871 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 872 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 873 | mScreenshotChordPowerKeyTriggered = true; |
| 874 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 875 | interceptScreenshotChord(); |
| 876 | } |
| 877 | |
| 878 | // Stop ringing or end call if configured to do so when power is pressed. |
| 879 | TelecomManager telecomManager = getTelecommService(); |
| 880 | boolean hungUp = false; |
| 881 | if (telecomManager != null) { |
| 882 | if (telecomManager.isRinging()) { |
| 883 | // Pressing Power while there's a ringing incoming |
| 884 | // call should silence the ringer. |
| 885 | telecomManager.silenceRinger(); |
| 886 | } else if ((mIncallPowerBehavior |
| 887 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 888 | && telecomManager.isInCall() && interactive) { |
| 889 | // Otherwise, if "Power button ends call" is enabled, |
| 890 | // the Power button will hang up any current active call. |
| 891 | hungUp = telecomManager.endCall(); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | // If the power key has still not yet been handled, then detect short |
| 896 | // press, long press, or multi press and decide what to do. |
| 897 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
| 898 | || mScreenshotChordVolumeUpKeyTriggered; |
| 899 | if (!mPowerKeyHandled) { |
| 900 | if (interactive) { |
| 901 | // When interactive, we're already awake. |
| 902 | // Wait for a long press or for the button to be released to decide what to do. |
| 903 | if (hasLongPressOnPowerBehavior()) { |
| 904 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 905 | msg.setAsynchronous(true); |
| 906 | mHandler.sendMessageDelayed(msg, |
| 907 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 908 | } |
| 909 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 910 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 911 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 912 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 913 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 914 | msg.setAsynchronous(true); |
| 915 | mHandler.sendMessageDelayed(msg, |
| 916 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 917 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 918 | } else { |
| 919 | final int maxCount = getMaxMultiPressPowerCount(); |
| 920 | |
| 921 | if (maxCount <= 1) { |
| 922 | mPowerKeyHandled = true; |
| 923 | } else { |
| 924 | mBeganFromNonInteractive = true; |
| 925 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 926 | } |
| 927 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 931 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 932 | final boolean handled = canceled || mPowerKeyHandled; |
| 933 | mScreenshotChordPowerKeyTriggered = false; |
| 934 | cancelPendingScreenshotChordAction(); |
| 935 | cancelPendingPowerKeyAction(); |
| 936 | |
| 937 | if (!handled) { |
| 938 | // Figure out how to handle the key now that it has been released. |
| 939 | mPowerKeyPressCounter += 1; |
| 940 | |
| 941 | final int maxCount = getMaxMultiPressPowerCount(); |
| 942 | final long eventTime = event.getDownTime(); |
| 943 | if (mPowerKeyPressCounter < maxCount) { |
| 944 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 945 | // Continue holding the wake lock. |
| 946 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 947 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 948 | msg.setAsynchronous(true); |
| 949 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 950 | return; |
| 951 | } |
| 952 | |
| 953 | // No other actions. Handle it immediately. |
| 954 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 955 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 956 | |
| 957 | // Done. Reset our state. |
| 958 | finishPowerKeyPress(); |
| 959 | } |
| 960 | |
| 961 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 962 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 963 | mPowerKeyPressCounter = 0; |
| 964 | if (mPowerKeyWakeLock.isHeld()) { |
| 965 | mPowerKeyWakeLock.release(); |
| 966 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | private void cancelPendingPowerKeyAction() { |
| 970 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 971 | mPowerKeyHandled = true; |
| 972 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 973 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 977 | if (mScreenOnEarly && !mScreenOnFully) { |
| 978 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 979 | + "already in the process of turning the screen on."); |
| 980 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 981 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 982 | |
| 983 | if (count == 2) { |
| 984 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 985 | } else if (count == 3) { |
| 986 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 987 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 988 | switch (mShortPressOnPowerBehavior) { |
| 989 | case SHORT_PRESS_POWER_NOTHING: |
| 990 | break; |
| 991 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 992 | mPowerManager.goToSleep(eventTime, |
| 993 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 994 | break; |
| 995 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 996 | mPowerManager.goToSleep(eventTime, |
| 997 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 998 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 999 | break; |
| 1000 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1001 | mPowerManager.goToSleep(eventTime, |
| 1002 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1003 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1004 | launchHomeFromHotKey(); |
| 1005 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1006 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1007 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1008 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1014 | switch (behavior) { |
| 1015 | case MULTI_PRESS_POWER_NOTHING: |
| 1016 | break; |
| 1017 | case MULTI_PRESS_POWER_THEATER_MODE: |
| 1018 | if (isTheaterModeEnabled()) { |
| 1019 | Slog.i(TAG, "Toggling theater mode off."); |
| 1020 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1021 | Settings.Global.THEATER_MODE_ON, 0); |
| 1022 | if (!interactive) { |
| 1023 | wakeUpFromPowerKey(eventTime); |
| 1024 | } |
| 1025 | } else { |
| 1026 | Slog.i(TAG, "Toggling theater mode on."); |
| 1027 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1028 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1029 | |
| 1030 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1031 | mPowerManager.goToSleep(eventTime, |
| 1032 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1033 | } |
| 1034 | } |
| 1035 | break; |
| 1036 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1037 | Slog.i(TAG, "Starting brightness boost."); |
| 1038 | if (!interactive) { |
| 1039 | wakeUpFromPowerKey(eventTime); |
| 1040 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1041 | mPowerManager.boostScreenBrightness(eventTime); |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | private int getMaxMultiPressPowerCount() { |
| 1047 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1048 | return 3; |
| 1049 | } |
| 1050 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1051 | return 2; |
| 1052 | } |
| 1053 | return 1; |
| 1054 | } |
| 1055 | |
| 1056 | private void powerLongPress() { |
| 1057 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1058 | switch (behavior) { |
| 1059 | case LONG_PRESS_POWER_NOTHING: |
| 1060 | break; |
| 1061 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1062 | mPowerKeyHandled = true; |
| 1063 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1064 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1065 | } |
| 1066 | showGlobalActionsInternal(); |
| 1067 | break; |
| 1068 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1069 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1070 | mPowerKeyHandled = true; |
| 1071 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1072 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1073 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1074 | break; |
| 1075 | } |
| 1076 | } |
| 1077 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1078 | private void sleepPress(KeyEvent event) { |
| 1079 | switch (mShortPressOnSleepBehavior) { |
| 1080 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
| 1081 | mPowerManager.goToSleep(event.getEventTime(), |
| 1082 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
| 1083 | break; |
| 1084 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1085 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1086 | mPowerManager.goToSleep(event.getEventTime(), |
| 1087 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
| 1088 | break; |
| 1089 | } |
| 1090 | } |
| 1091 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1092 | private int getResolvedLongPressOnPowerBehavior() { |
| 1093 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1094 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1095 | } |
| 1096 | return mLongPressOnPowerBehavior; |
| 1097 | } |
| 1098 | |
| 1099 | private boolean hasLongPressOnPowerBehavior() { |
| 1100 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1104 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1105 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1106 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1107 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1108 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1109 | && now <= mScreenshotChordPowerKeyTime |
| 1110 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1111 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1112 | cancelPendingPowerKeyAction(); |
| 1113 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1114 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1119 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1120 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1121 | // Double the time it takes to take a screenshot from the keyguard |
| 1122 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1123 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1124 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1125 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1128 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1129 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1132 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1133 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1134 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1135 | mEndCallKeyHandled = true; |
| 1136 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1137 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1138 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1139 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1140 | } |
| 1141 | }; |
| 1142 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1143 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1144 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1145 | public void run() { |
| 1146 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1147 | } |
| 1148 | }; |
| 1149 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1150 | @Override |
| 1151 | public void showGlobalActions() { |
| 1152 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1153 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1154 | } |
| 1155 | |
| 1156 | void showGlobalActionsInternal() { |
| 1157 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1158 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1159 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1160 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1161 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1162 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1163 | if (keyguardShowing) { |
| 1164 | // since it took two seconds of long press to bring this up, |
| 1165 | // 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] | 1166 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1171 | return Settings.Global.getInt( |
| 1172 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1175 | boolean isUserSetupComplete() { |
| 1176 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1177 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1178 | } |
| 1179 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1180 | private void handleShortPressOnHome() { |
| 1181 | // If there's a dream running then use home to escape the dream |
| 1182 | // but don't actually go home. |
| 1183 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1184 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1185 | return; |
| 1186 | } |
| 1187 | |
| 1188 | // Go home! |
| 1189 | launchHomeFromHotKey(); |
| 1190 | } |
| 1191 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1192 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1193 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1194 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1195 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1196 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1197 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 1198 | toggleRecentApps(); |
| 1199 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 1200 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1201 | } |
| 1202 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1203 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1204 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1205 | private void handleDoubleTapOnHome() { |
| 1206 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1207 | mHomeConsumed = true; |
| 1208 | toggleRecentApps(); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1213 | @Override |
| 1214 | public void run() { |
| 1215 | if (mHomeDoubleTapPending) { |
| 1216 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1217 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | }; |
| 1221 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1222 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1223 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1224 | } |
| 1225 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1226 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1227 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1228 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1229 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1230 | mContext = context; |
| 1231 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1232 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1233 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1234 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1235 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1236 | |
| 1237 | // Init display burn-in protection |
| 1238 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1239 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1240 | // Allow a system property to override this. Used by developer settings. |
| 1241 | boolean burnInProtectionDevMode = |
| 1242 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1243 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1244 | final int minHorizontal; |
| 1245 | final int maxHorizontal; |
| 1246 | final int minVertical; |
| 1247 | final int maxVertical; |
| 1248 | final int maxRadius; |
| 1249 | if (burnInProtectionDevMode) { |
| 1250 | minHorizontal = -8; |
| 1251 | maxHorizontal = 8; |
| 1252 | minVertical = -8; |
| 1253 | maxVertical = -4; |
| 1254 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1255 | } else { |
| 1256 | Resources resources = context.getResources(); |
| 1257 | minHorizontal = resources.getInteger( |
| 1258 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1259 | maxHorizontal = resources.getInteger( |
| 1260 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1261 | minVertical = resources.getInteger( |
| 1262 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1263 | maxVertical = resources.getInteger( |
| 1264 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1265 | maxRadius = resources.getInteger( |
| 1266 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1267 | } |
| 1268 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1269 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1270 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1271 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1272 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1273 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1274 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1275 | try { |
| 1276 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1277 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1278 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1279 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1280 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1281 | mUiMode = context.getResources().getInteger( |
| 1282 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1283 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1284 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1285 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1286 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1287 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1288 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1289 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1290 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1291 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1292 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1293 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1294 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1295 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1296 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1297 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1298 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1299 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1300 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1301 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1302 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1303 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1304 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1305 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1306 | mCarDockRotation = readRotation( |
| 1307 | com.android.internal.R.integer.config_carDockRotation); |
| 1308 | mDeskDockRotation = readRotation( |
| 1309 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1310 | mUndockedHdmiRotation = readRotation( |
| 1311 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1312 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1313 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1314 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1315 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1316 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1317 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1318 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1319 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1320 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1321 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1322 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1323 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1324 | |
| 1325 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1326 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1327 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1328 | || mContext.getResources().getBoolean( |
| 1329 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1330 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1331 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1332 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1333 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1334 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1335 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1336 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1337 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1338 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1339 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1340 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1341 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1342 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1343 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1344 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1345 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1346 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1347 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1348 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1349 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1350 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1351 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1352 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1353 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1354 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1355 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1356 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1357 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1358 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1359 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1360 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1361 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1362 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1363 | Context.ACCESSIBILITY_SERVICE); |
| 1364 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1365 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1366 | IntentFilter filter = new IntentFilter(); |
| 1367 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1368 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1369 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1370 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1371 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1372 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1373 | if (intent != null) { |
| 1374 | // Retrieve current sticky dock event broadcast. |
| 1375 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1376 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1377 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1378 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1379 | // register for dream-related broadcasts |
| 1380 | filter = new IntentFilter(); |
| 1381 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1382 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1383 | context.registerReceiver(mDreamReceiver, filter); |
| 1384 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1385 | // register for multiuser-relevant broadcasts |
| 1386 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1387 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1388 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1389 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1390 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1391 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1392 | @Override |
| 1393 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1394 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1395 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1396 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1397 | } |
| 1398 | @Override |
| 1399 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1400 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1401 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | @Override |
| 1405 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1406 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1407 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1408 | } |
| 1409 | } |
| 1410 | @Override |
| 1411 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1412 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1413 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1414 | @Override |
| 1415 | public void onDown() { |
| 1416 | mOrientationListener.onTouchStart(); |
| 1417 | } |
| 1418 | @Override |
| 1419 | public void onUpOrCancel() { |
| 1420 | mOrientationListener.onTouchEnd(); |
| 1421 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1422 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1423 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1424 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1425 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1426 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1427 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1428 | com.android.internal.R.array.config_longPressVibePattern); |
| 1429 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1430 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1431 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1432 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1433 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1434 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1435 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1436 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1437 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1438 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1439 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1440 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 1441 | mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1442 | com.android.internal.R.array.config_stylusButtonPressVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1443 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1444 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1445 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1446 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1447 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1448 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1449 | // Controls rotation and the like. |
| 1450 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1451 | |
| 1452 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1453 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame^] | 1454 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 1455 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1456 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1457 | |
| 1458 | mWindowManagerInternal.registerAppTransitionListener( |
| 1459 | mStatusBarController.getAppTransitionListener()); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1462 | /** |
| 1463 | * Read values from config.xml that may be overridden depending on |
| 1464 | * the configuration of the device. |
| 1465 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1466 | */ |
| 1467 | private void readConfigurationDependentBehaviors() { |
| 1468 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1469 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1470 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1471 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1472 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1473 | } |
| 1474 | |
| 1475 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1476 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1477 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1478 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1479 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1480 | } |
| 1481 | } |
| 1482 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1483 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1484 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1485 | // This method might be called before the policy has been fully initialized |
| 1486 | // or for other displays we don't care about. |
| 1487 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1488 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1489 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1490 | mDisplay = display; |
| 1491 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1492 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1493 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1494 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1495 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1496 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1497 | mLandscapeRotation = Surface.ROTATION_0; |
| 1498 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1499 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1500 | mPortraitRotation = Surface.ROTATION_90; |
| 1501 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1502 | } else { |
| 1503 | mPortraitRotation = Surface.ROTATION_270; |
| 1504 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1505 | } |
| 1506 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1507 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1508 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1509 | mPortraitRotation = Surface.ROTATION_0; |
| 1510 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1511 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1512 | mLandscapeRotation = Surface.ROTATION_270; |
| 1513 | mSeascapeRotation = Surface.ROTATION_90; |
| 1514 | } else { |
| 1515 | mLandscapeRotation = Surface.ROTATION_90; |
| 1516 | mSeascapeRotation = Surface.ROTATION_270; |
| 1517 | } |
| 1518 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1519 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1520 | mStatusBarHeight = |
| 1521 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1522 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1523 | // Height of the navigation bar when presented horizontally at bottom |
| 1524 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1525 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1526 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1527 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1528 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1529 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1530 | |
| 1531 | // Width of the navigation bar when presented vertically along one side |
| 1532 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1533 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1534 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1535 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1536 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1537 | |
| 1538 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1539 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1540 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1541 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 1542 | // Allow the navigation bar to move on non-square small devices (phones). |
| 1543 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1544 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1545 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1546 | // Allow a system property to override this. Used by the emulator. |
| 1547 | // See also hasNavigationBar(). |
| 1548 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1549 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1550 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1551 | } else if ("0".equals(navBarOverride)) { |
| 1552 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1555 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1556 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1557 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1558 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1559 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1560 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1561 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1562 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1563 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 1564 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 1565 | // By default, remote display locks rotation to landscape. |
| 1566 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 1567 | mDemoRotation = mPortraitRotation; |
| 1568 | } else { |
| 1569 | mDemoRotation = mLandscapeRotation; |
| 1570 | } |
| 1571 | mDemoRotationLock = SystemProperties.getBoolean( |
| 1572 | "persist.demo.rotationlock", false); |
| 1573 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1574 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1575 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1576 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1577 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1578 | // For debug purposes the next line turns this feature off with: |
| 1579 | // $ adb shell setprop config.override_forced_orient true |
| 1580 | // $ adb shell wm size reset |
| 1581 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1582 | } |
| 1583 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1584 | /** |
| 1585 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1586 | * navigation bar and touch exploration is not enabled |
| 1587 | */ |
| 1588 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1589 | return mHasNavigationBar |
| 1590 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1593 | @Override |
| 1594 | public boolean isDefaultOrientationForced() { |
| 1595 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1598 | @Override |
| 1599 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1600 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1601 | mOverscanLeft = left; |
| 1602 | mOverscanTop = top; |
| 1603 | mOverscanRight = right; |
| 1604 | mOverscanBottom = bottom; |
| 1605 | } |
| 1606 | } |
| 1607 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1608 | public void updateSettings() { |
| 1609 | ContentResolver resolver = mContext.getContentResolver(); |
| 1610 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1611 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1612 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1613 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1614 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1615 | UserHandle.USER_CURRENT); |
| 1616 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1617 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1618 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1619 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1620 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1621 | // Configure wake gesture. |
| 1622 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1623 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1624 | UserHandle.USER_CURRENT) != 0; |
| 1625 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1626 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1627 | updateWakeGestureListenerLp(); |
| 1628 | } |
| 1629 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1630 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1631 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1632 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1633 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1634 | if (mUserRotation != userRotation) { |
| 1635 | mUserRotation = userRotation; |
| 1636 | updateRotation = true; |
| 1637 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1638 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1639 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1640 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1641 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1642 | if (mUserRotationMode != userRotationMode) { |
| 1643 | mUserRotationMode = userRotationMode; |
| 1644 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1645 | updateOrientationListenerLp(); |
| 1646 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1647 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1648 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1649 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1650 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1651 | if (mPointerLocationMode != pointerLocation) { |
| 1652 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1653 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1654 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1655 | } |
| 1656 | } |
| 1657 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1658 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1659 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1660 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1661 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1662 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1663 | if (mHasSoftInput != hasSoftInput) { |
| 1664 | mHasSoftInput = hasSoftInput; |
| 1665 | updateRotation = true; |
| 1666 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1667 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1668 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1669 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1670 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1671 | } |
| 1672 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1673 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1674 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1677 | private void updateWakeGestureListenerLp() { |
| 1678 | if (shouldEnableWakeGestureLp()) { |
| 1679 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1680 | } else { |
| 1681 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1686 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1687 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1688 | && mWakeGestureListener.isSupported(); |
| 1689 | } |
| 1690 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1691 | private void enablePointerLocation() { |
| 1692 | if (mPointerLocationView == null) { |
| 1693 | mPointerLocationView = new PointerLocationView(mContext); |
| 1694 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1695 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1696 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1697 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1698 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1699 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1700 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1701 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1702 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1703 | if (ActivityManager.isHighEndGfx()) { |
| 1704 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1705 | lp.privateFlags |= |
| 1706 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1707 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1708 | lp.format = PixelFormat.TRANSLUCENT; |
| 1709 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1710 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1711 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1712 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1713 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1714 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1715 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1716 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1717 | |
| 1718 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1719 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1720 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1721 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1722 | wm.removeView(mPointerLocationView); |
| 1723 | mPointerLocationView = null; |
| 1724 | } |
| 1725 | } |
| 1726 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1727 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1728 | try { |
| 1729 | int rotation = mContext.getResources().getInteger(resID); |
| 1730 | switch (rotation) { |
| 1731 | case 0: |
| 1732 | return Surface.ROTATION_0; |
| 1733 | case 90: |
| 1734 | return Surface.ROTATION_90; |
| 1735 | case 180: |
| 1736 | return Surface.ROTATION_180; |
| 1737 | case 270: |
| 1738 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1739 | } |
| 1740 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1741 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1742 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1743 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1747 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1748 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1749 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1750 | |
| 1751 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1752 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 1753 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 1754 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 1755 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 1756 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 1757 | } |
| 1758 | |
| 1759 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 1760 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1761 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1762 | } |
| 1763 | String permission = null; |
| 1764 | switch (type) { |
| 1765 | case TYPE_TOAST: |
| 1766 | // XXX right now the app process has complete control over |
| 1767 | // this... should introduce a token to let the system |
| 1768 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1769 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1770 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1771 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1772 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1773 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1774 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1775 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1776 | case TYPE_ACCESSIBILITY_OVERLAY: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1777 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1778 | break; |
| 1779 | case TYPE_PHONE: |
| 1780 | case TYPE_PRIORITY_PHONE: |
| 1781 | case TYPE_SYSTEM_ALERT: |
| 1782 | case TYPE_SYSTEM_ERROR: |
| 1783 | case TYPE_SYSTEM_OVERLAY: |
| 1784 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1785 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1786 | break; |
| 1787 | default: |
| 1788 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1789 | } |
| 1790 | if (permission != null) { |
| 1791 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1792 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1793 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1794 | } |
| 1795 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1796 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1797 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1798 | |
| 1799 | @Override |
| 1800 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1801 | |
| 1802 | // If this switch statement is modified, modify the comment in the declarations of |
| 1803 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1804 | switch (attrs.type) { |
| 1805 | default: |
| 1806 | // These are the windows that by default are shown only to the user that created |
| 1807 | // them. If this needs to be overridden, set |
| 1808 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1809 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1810 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1811 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1812 | return true; |
| 1813 | } |
| 1814 | break; |
| 1815 | |
| 1816 | // These are the windows that by default are shown to all users. However, to |
| 1817 | // protect against spoofing, check permissions below. |
| 1818 | case TYPE_APPLICATION_STARTING: |
| 1819 | case TYPE_BOOT_PROGRESS: |
| 1820 | case TYPE_DISPLAY_OVERLAY: |
| 1821 | case TYPE_HIDDEN_NAV_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1822 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1823 | case TYPE_KEYGUARD_DIALOG: |
| 1824 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1825 | case TYPE_NAVIGATION_BAR: |
| 1826 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1827 | case TYPE_PHONE: |
| 1828 | case TYPE_POINTER: |
| 1829 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1830 | case TYPE_SEARCH_BAR: |
| 1831 | case TYPE_STATUS_BAR: |
| 1832 | case TYPE_STATUS_BAR_PANEL: |
| 1833 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1834 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1835 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1836 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1837 | break; |
| 1838 | } |
| 1839 | |
| 1840 | // Check if third party app has set window to system window type. |
| 1841 | return mContext.checkCallingOrSelfPermission( |
| 1842 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1843 | != PackageManager.PERMISSION_GRANTED; |
| 1844 | } |
| 1845 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1846 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1847 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1848 | switch (attrs.type) { |
| 1849 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1850 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1851 | // These types of windows can't receive input events. |
| 1852 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1853 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1854 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1855 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1856 | case TYPE_STATUS_BAR: |
| 1857 | |
| 1858 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 1859 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 1860 | // the keyguard as occluded wouldn't set these flags again. |
| 1861 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 1862 | if (mKeyguardHidden) { |
| 1863 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 1864 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1865 | } |
| 1866 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1867 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 1868 | |
| 1869 | if (attrs.type != TYPE_STATUS_BAR) { |
| 1870 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 1871 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1872 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1873 | |
| 1874 | if (ActivityManager.isHighEndGfx() |
| 1875 | && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
Adrian Roos | f5e9b5c | 2014-09-10 15:27:41 +0200 | [diff] [blame] | 1876 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1877 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1878 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1879 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1880 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1881 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1882 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1883 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1884 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 1885 | private void readCameraLensCoverState() { |
| 1886 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 1887 | } |
| 1888 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1889 | private boolean isHidden(int accessibilityMode) { |
| 1890 | switch (accessibilityMode) { |
| 1891 | case 1: |
| 1892 | return mLidState == LID_CLOSED; |
| 1893 | case 2: |
| 1894 | return mLidState == LID_OPEN; |
| 1895 | default: |
| 1896 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1897 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1898 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1899 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1900 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1901 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1902 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1903 | int navigationPresence) { |
| 1904 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1905 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1906 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1907 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1908 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1909 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1910 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1911 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1912 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1913 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1914 | if (!mHasSoftInput) { |
| 1915 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1916 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1917 | } |
| 1918 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1919 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1920 | || (navigationPresence == PRESENCE_INTERNAL |
| 1921 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1922 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1923 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1924 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1925 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1926 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1927 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1928 | public int windowTypeToLayerLw(int type) { |
| 1929 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1930 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1931 | } |
| 1932 | switch (type) { |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1933 | case TYPE_PRIVATE_PRESENTATION: |
| 1934 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1935 | case TYPE_WALLPAPER: |
| 1936 | // wallpaper is at the bottom, though the window manager may move it. |
| 1937 | return 2; |
| 1938 | case TYPE_PHONE: |
| 1939 | return 3; |
| 1940 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 1941 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1942 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1943 | case TYPE_VOICE_INTERACTION: |
| 1944 | // voice interaction layer is almost immediately above apps. |
| 1945 | return 5; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1946 | case TYPE_SYSTEM_DIALOG: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1947 | return 6; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1948 | case TYPE_TOAST: |
| 1949 | // toasts and the plugged-in battery thing |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1950 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1951 | case TYPE_PRIORITY_PHONE: |
| 1952 | // 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] | 1953 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1954 | case TYPE_DREAM: |
| 1955 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1956 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1957 | case TYPE_SYSTEM_ALERT: |
| 1958 | // like the ANR / app crashed dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1959 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1960 | case TYPE_INPUT_METHOD: |
| 1961 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1962 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1963 | case TYPE_INPUT_METHOD_DIALOG: |
| 1964 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1965 | return 12; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1966 | case TYPE_KEYGUARD_SCRIM: |
| 1967 | // the safety window that shows behind keyguard while keyguard is starting |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1968 | return 13; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1969 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1970 | return 14; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1971 | case TYPE_STATUS_BAR: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1972 | return 15; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1973 | case TYPE_STATUS_BAR_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1974 | return 16; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1975 | case TYPE_KEYGUARD_DIALOG: |
| 1976 | return 17; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1977 | case TYPE_VOLUME_OVERLAY: |
| 1978 | // the on-screen volume indicator and controller shown when the user |
| 1979 | // changes the device volume |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1980 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1981 | case TYPE_SYSTEM_OVERLAY: |
| 1982 | // the on-screen volume indicator and controller shown when the user |
| 1983 | // changes the device volume |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1984 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1985 | case TYPE_NAVIGATION_BAR: |
| 1986 | // the navigation bar, if available, shows atop most things |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1987 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1988 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1989 | // 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] | 1990 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1991 | case TYPE_SYSTEM_ERROR: |
| 1992 | // system-level error dialogs |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1993 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1994 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1995 | // used to highlight the magnified portion of a display |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1996 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1997 | case TYPE_DISPLAY_OVERLAY: |
| 1998 | // used to simulate secondary display devices |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1999 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2000 | case TYPE_DRAG: |
| 2001 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2002 | // which sits above all other focusable windows |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2003 | return 25; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2004 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2005 | // overlay put by accessibility services to intercept user interaction |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2006 | return 26; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2007 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2008 | return 27; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2009 | case TYPE_BOOT_PROGRESS: |
| 2010 | return 28; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2011 | case TYPE_POINTER: |
| 2012 | // the (mouse) pointer layer |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2013 | return 29; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2014 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 2015 | return 30; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2016 | } |
| 2017 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2018 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2022 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2023 | public int subWindowTypeToLayerLw(int type) { |
| 2024 | switch (type) { |
| 2025 | case TYPE_APPLICATION_PANEL: |
| 2026 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2027 | return APPLICATION_PANEL_SUBLAYER; |
| 2028 | case TYPE_APPLICATION_MEDIA: |
| 2029 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2030 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2031 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2032 | case TYPE_APPLICATION_SUB_PANEL: |
| 2033 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2034 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2035 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2036 | } |
| 2037 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2038 | return 0; |
| 2039 | } |
| 2040 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2041 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2042 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2043 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2046 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2047 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2048 | if (mHasNavigationBar) { |
| 2049 | // For a basic navigation bar, when we are in landscape mode we place |
| 2050 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2051 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 2052 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2053 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2054 | } |
| 2055 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2056 | } |
| 2057 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2058 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2059 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2060 | if (mHasNavigationBar) { |
| 2061 | // For a basic navigation bar, when we are in portrait mode we place |
| 2062 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2063 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 2064 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2065 | } |
| 2066 | } |
| 2067 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2070 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2071 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 2072 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2075 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2076 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2077 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2078 | // 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] | 2079 | // we do want to exclude it since applications can't generally use that part |
| 2080 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2081 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2082 | } |
| 2083 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2084 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 2085 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 2086 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2087 | (isKeyguardHostWindow(attrs) && |
| 2088 | (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 2089 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2090 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2091 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2092 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2093 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2094 | return attrs.type == TYPE_STATUS_BAR; |
| 2095 | } |
| 2096 | |
| 2097 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2098 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2099 | switch (attrs.type) { |
| 2100 | case TYPE_STATUS_BAR: |
| 2101 | case TYPE_NAVIGATION_BAR: |
| 2102 | case TYPE_WALLPAPER: |
| 2103 | case TYPE_DREAM: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2104 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2105 | return false; |
| 2106 | default: |
| 2107 | return true; |
| 2108 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2109 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2110 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2111 | @Override |
| 2112 | public WindowState getWinShowWhenLockedLw() { |
| 2113 | return mWinShowWhenLocked; |
| 2114 | } |
| 2115 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2116 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2117 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2118 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2119 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2120 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2121 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2122 | return null; |
| 2123 | } |
| 2124 | if (packageName == null) { |
| 2125 | return null; |
| 2126 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2127 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2128 | WindowManager wm = null; |
| 2129 | View view = null; |
| 2130 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2131 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2132 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2133 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2134 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2135 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2136 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2137 | try { |
| 2138 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2139 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2140 | } catch (PackageManager.NameNotFoundException e) { |
| 2141 | // Ignore |
| 2142 | } |
| 2143 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2144 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 2145 | Window win = new PhoneWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2146 | final TypedArray ta = win.getWindowStyle(); |
| 2147 | if (ta.getBoolean( |
| 2148 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 2149 | || ta.getBoolean( |
| 2150 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2151 | return null; |
| 2152 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2153 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2154 | Resources r = context.getResources(); |
| 2155 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2156 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2157 | win.setType( |
| 2158 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2159 | |
| 2160 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2161 | // Assumes it's safe to show starting windows of launched apps while |
| 2162 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2163 | // secret information. |
| 2164 | if (mKeyguardHidden) { |
| 2165 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2166 | } |
| 2167 | } |
| 2168 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2169 | // Force the window flags: this is a fake window, so it is not really |
| 2170 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2171 | // flag because we do know that the next window will take input |
| 2172 | // focus, so we want to get the IME window up on top of us right away. |
| 2173 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2174 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2175 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2176 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2177 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2178 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2179 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2180 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2181 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2182 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2183 | win.setDefaultIcon(icon); |
| 2184 | win.setDefaultLogo(logo); |
| 2185 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2186 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2187 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2188 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2189 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2190 | params.token = appToken; |
| 2191 | params.packageName = packageName; |
| 2192 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2193 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2194 | params.privateFlags |= |
| 2195 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2196 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2197 | |
| 2198 | if (!compatInfo.supportsScreen()) { |
| 2199 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2200 | } |
| 2201 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2202 | params.setTitle("Starting " + packageName); |
| 2203 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2204 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2205 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2206 | |
| 2207 | if (win.isFloating()) { |
| 2208 | // Whoops, there is no way to display an animation/preview |
| 2209 | // of such a thing! After all that work... let's skip it. |
| 2210 | // (Note that we must do this here because it is in |
| 2211 | // getDecorView() where the theme is evaluated... maybe |
| 2212 | // we should peek the floating attribute from the theme |
| 2213 | // earlier.) |
| 2214 | return null; |
| 2215 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2216 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2217 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2218 | TAG, "Adding starting window for " + packageName |
| 2219 | + " / " + appToken + ": " |
| 2220 | + (view.getParent() != null ? view : null)); |
| 2221 | |
| 2222 | wm.addView(view, params); |
| 2223 | |
| 2224 | // Only return the view if it was successfully added to the |
| 2225 | // window manager... which we can tell by it having a parent. |
| 2226 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2227 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2228 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2229 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2230 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2231 | } catch (RuntimeException e) { |
| 2232 | // don't crash if something else bad happens, for example a |
| 2233 | // failure loading resources because we are loading from an app |
| 2234 | // on external storage that has been unmounted. |
| 2235 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2236 | } finally { |
| 2237 | if (view != null && view.getParent() == null) { |
| 2238 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2239 | wm.removeViewImmediate(view); |
| 2240 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | return null; |
| 2244 | } |
| 2245 | |
| 2246 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2247 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2248 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2249 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2250 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2251 | |
| 2252 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2253 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2254 | wm.removeView(window); |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | /** |
| 2259 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2260 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2261 | * Currently enforces that three window types are singletons: |
| 2262 | * <ul> |
| 2263 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2264 | * <li>KEYGUARD_TYPE</li> |
| 2265 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2266 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2267 | * @param win The window to be added |
| 2268 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2269 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2270 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2271 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2272 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2273 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2274 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2275 | switch (attrs.type) { |
| 2276 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2277 | mContext.enforceCallingOrSelfPermission( |
| 2278 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2279 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2280 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2281 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2282 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2283 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2284 | } |
| 2285 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2286 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2287 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2288 | case TYPE_NAVIGATION_BAR: |
| 2289 | mContext.enforceCallingOrSelfPermission( |
| 2290 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2291 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2292 | if (mNavigationBar != null) { |
| 2293 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2294 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2295 | } |
| 2296 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2297 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2298 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2299 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2300 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2301 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2302 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2303 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2304 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2305 | mContext.enforceCallingOrSelfPermission( |
| 2306 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2307 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2308 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2309 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2310 | if (mKeyguardScrim != null) { |
| 2311 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2312 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2313 | mKeyguardScrim = win; |
| 2314 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2315 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2316 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2320 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2321 | public void removeWindowLw(WindowState win) { |
| 2322 | if (mStatusBar == win) { |
| 2323 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2324 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2325 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2326 | } else if (mKeyguardScrim == win) { |
| 2327 | Log.v(TAG, "Removing keyguard scrim"); |
| 2328 | mKeyguardScrim = null; |
| 2329 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2330 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2331 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2336 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2337 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2338 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2339 | public int selectAnimationLw(WindowState win, int transit) { |
| 2340 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2341 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2342 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2343 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2344 | if (transit == TRANSIT_EXIT |
| 2345 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2346 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2347 | } else if (transit == TRANSIT_ENTER |
| 2348 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2349 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2350 | } |
| 2351 | } else if (win == mNavigationBar) { |
| 2352 | // This can be on either the bottom or the right. |
| 2353 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2354 | if (transit == TRANSIT_EXIT |
| 2355 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2356 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2357 | } else if (transit == TRANSIT_ENTER |
| 2358 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2359 | return R.anim.dock_bottom_enter; |
| 2360 | } |
| 2361 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2362 | if (transit == TRANSIT_EXIT |
| 2363 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2364 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2365 | } else if (transit == TRANSIT_ENTER |
| 2366 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2367 | return R.anim.dock_right_enter; |
| 2368 | } |
| 2369 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2370 | } |
| 2371 | |
| 2372 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2373 | if (win.hasAppShownWindows()) { |
| 2374 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2375 | return com.android.internal.R.anim.app_starting_exit; |
| 2376 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2377 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2378 | && transit == TRANSIT_ENTER) { |
| 2379 | // Special case: we are animating in a dream, while the keyguard |
| 2380 | // is shown. We don't want an animation on the dream, because |
| 2381 | // we need it shown immediately with the keyguard animating away |
| 2382 | // to reveal it. |
| 2383 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | return 0; |
| 2387 | } |
| 2388 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2389 | @Override |
| 2390 | public void selectRotationAnimationLw(int anim[]) { |
| 2391 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2392 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2393 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2394 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2395 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2396 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2397 | case ROTATION_ANIMATION_CROSSFADE: |
| 2398 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2399 | anim[1] = R.anim.rotation_animation_enter; |
| 2400 | break; |
| 2401 | case ROTATION_ANIMATION_JUMPCUT: |
| 2402 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2403 | anim[1] = R.anim.rotation_animation_enter; |
| 2404 | break; |
| 2405 | case ROTATION_ANIMATION_ROTATE: |
| 2406 | default: |
| 2407 | anim[0] = anim[1] = 0; |
| 2408 | break; |
| 2409 | } |
| 2410 | } else { |
| 2411 | anim[0] = anim[1] = 0; |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | @Override |
| 2416 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2417 | boolean forceDefault) { |
| 2418 | switch (exitAnimId) { |
| 2419 | case R.anim.rotation_animation_xfade_exit: |
| 2420 | case R.anim.rotation_animation_jump_exit: |
| 2421 | // These are the only cases that matter. |
| 2422 | if (forceDefault) { |
| 2423 | return false; |
| 2424 | } |
| 2425 | int anim[] = new int[2]; |
| 2426 | selectRotationAnimationLw(anim); |
| 2427 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2428 | default: |
| 2429 | return true; |
| 2430 | } |
| 2431 | } |
| 2432 | |
| 2433 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2434 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2435 | boolean goingToNotificationShade) { |
| 2436 | if (goingToNotificationShade) { |
| 2437 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2438 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2439 | |
| 2440 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 2441 | R.anim.lock_screen_behind_enter_wallpaper : |
| 2442 | R.anim.lock_screen_behind_enter); |
| 2443 | |
| 2444 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2445 | final List<Animation> animations = set.getAnimations(); |
| 2446 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 2447 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 2448 | } |
| 2449 | |
| 2450 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | |
| 2454 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2455 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2456 | if (goingToNotificationShade) { |
| 2457 | return null; |
| 2458 | } else { |
| 2459 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2460 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2461 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2462 | |
| 2463 | private static void awakenDreams() { |
| 2464 | IDreamManager dreamManager = getDreamManager(); |
| 2465 | if (dreamManager != null) { |
| 2466 | try { |
| 2467 | dreamManager.awaken(); |
| 2468 | } catch (RemoteException e) { |
| 2469 | // fine, stay asleep then |
| 2470 | } |
| 2471 | } |
| 2472 | } |
| 2473 | |
| 2474 | static IDreamManager getDreamManager() { |
| 2475 | return IDreamManager.Stub.asInterface( |
| 2476 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2477 | } |
| 2478 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2479 | TelecomManager getTelecommService() { |
| 2480 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2481 | } |
| 2482 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2483 | static IAudioService getAudioService() { |
| 2484 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2485 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2486 | if (audioService == null) { |
| 2487 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2488 | } |
| 2489 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2493 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2497 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2498 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2499 | }; |
| 2500 | |
| 2501 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2502 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2503 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2504 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2505 | final int keyCode = event.getKeyCode(); |
| 2506 | final int repeatCount = event.getRepeatCount(); |
| 2507 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2508 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2509 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2510 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2511 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2512 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2513 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2514 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2515 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2516 | } |
| 2517 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2518 | // If we think we might have a volume down & power key chord on the way |
| 2519 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2520 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2521 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2522 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2523 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2524 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2525 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2526 | if (now < timeoutTime) { |
| 2527 | return timeoutTime - now; |
| 2528 | } |
| 2529 | } |
| 2530 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2531 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2532 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2533 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2534 | } |
| 2535 | return -1; |
| 2536 | } |
| 2537 | } |
| 2538 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2539 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2540 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2541 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2542 | mPendingMetaAction = false; |
| 2543 | } |
| 2544 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2545 | // First we always handle the home key here, so applications |
| 2546 | // can never break it, although if keyguard is on, we do let |
| 2547 | // it handle it, because that gives us the correct 5 second |
| 2548 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2549 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2550 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2551 | // If we have released the home key, and didn't do anything else |
| 2552 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2553 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2554 | cancelPreloadRecentApps(); |
| 2555 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2556 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2557 | if (mHomeConsumed) { |
| 2558 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2559 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2560 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2561 | |
| 2562 | if (canceled) { |
| 2563 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2564 | return -1; |
| 2565 | } |
| 2566 | |
Yorke Lee | 4f80324 | 2014-12-15 23:22:06 +0000 | [diff] [blame] | 2567 | // If an incoming call is ringing, HOME is totally disabled. |
| 2568 | // (The user is already on the InCallUI at this point, |
| 2569 | // and his ONLY options are to answer or reject the call.) |
| 2570 | TelecomManager telecomManager = getTelecommService(); |
| 2571 | if (telecomManager != null && telecomManager.isRinging()) { |
| 2572 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2573 | return -1; |
| 2574 | } |
| 2575 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2576 | // Delay handling home if a double-tap is possible. |
| 2577 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2578 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2579 | mHomeDoubleTapPending = true; |
| 2580 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2581 | ViewConfiguration.getDoubleTapTimeout()); |
| 2582 | return -1; |
| 2583 | } |
| 2584 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2585 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2586 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2587 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2588 | |
| 2589 | // If a system window has focus, then it doesn't make sense |
| 2590 | // right now to interact with applications. |
| 2591 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2592 | if (attrs != null) { |
| 2593 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2594 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2595 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2596 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2597 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2598 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2599 | } |
| 2600 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2601 | for (int i=0; i<typeCount; i++) { |
| 2602 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2603 | // 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] | 2604 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2605 | } |
| 2606 | } |
| 2607 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2608 | |
| 2609 | // Remember that home is pressed and handle special actions. |
| 2610 | if (repeatCount == 0) { |
| 2611 | mHomePressed = true; |
| 2612 | if (mHomeDoubleTapPending) { |
| 2613 | mHomeDoubleTapPending = false; |
| 2614 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2615 | handleDoubleTapOnHome(); |
| 2616 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2617 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2618 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2619 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2620 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2621 | if (!keyguardOn) { |
| 2622 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2623 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2624 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2625 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2626 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2627 | // Hijack modified menu keys for debugging features |
| 2628 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2629 | |
| 2630 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2631 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2632 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2633 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2634 | null, null, null, 0, null, null); |
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 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2637 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2638 | Intent service = new Intent(); |
| 2639 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2640 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2641 | boolean shown = Settings.Global.getInt( |
| 2642 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2643 | if (!shown) { |
| 2644 | mContext.startService(service); |
| 2645 | } else { |
| 2646 | mContext.stopService(service); |
| 2647 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2648 | Settings.Global.putInt( |
| 2649 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2650 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2651 | } |
| 2652 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2653 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2654 | if (down) { |
| 2655 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2656 | mSearchKeyShortcutPending = true; |
| 2657 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2658 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2659 | } else { |
| 2660 | mSearchKeyShortcutPending = false; |
| 2661 | if (mConsumeSearchKeyUp) { |
| 2662 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2663 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2664 | } |
| 2665 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2666 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2667 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2668 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2669 | if (down && repeatCount == 0) { |
| 2670 | preloadRecentApps(); |
| 2671 | } else if (!down) { |
| 2672 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2673 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2674 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2675 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 2676 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 2677 | if (down) { |
| 2678 | IStatusBarService service = getStatusBarService(); |
| 2679 | if (service != null) { |
| 2680 | try { |
| 2681 | service.expandNotificationsPanel(); |
| 2682 | } catch (RemoteException e) { |
| 2683 | // do nothing. |
| 2684 | } |
| 2685 | } |
| 2686 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2687 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2688 | if (down) { |
| 2689 | if (repeatCount == 0) { |
| 2690 | mAssistKeyLongPressed = false; |
| 2691 | } else if (repeatCount == 1) { |
| 2692 | mAssistKeyLongPressed = true; |
| 2693 | if (!keyguardOn) { |
| 2694 | launchAssistLongPressAction(); |
| 2695 | } |
| 2696 | } |
| 2697 | } else { |
| 2698 | if (mAssistKeyLongPressed) { |
| 2699 | mAssistKeyLongPressed = false; |
| 2700 | } else { |
| 2701 | if (!keyguardOn) { |
| 2702 | launchAssistAction(); |
| 2703 | } |
| 2704 | } |
| 2705 | } |
| 2706 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2707 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2708 | if (!down) { |
| 2709 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2710 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2711 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2712 | } else { |
| 2713 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2714 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2715 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2716 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2717 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2718 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2719 | if (down && repeatCount == 0) { |
| 2720 | mHandler.post(mScreenshotRunnable); |
| 2721 | } |
| 2722 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2723 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2724 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2725 | if (down) { |
| 2726 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2727 | |
| 2728 | // Disable autobrightness if it's on |
| 2729 | int auto = Settings.System.getIntForUser( |
| 2730 | mContext.getContentResolver(), |
| 2731 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2732 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2733 | UserHandle.USER_CURRENT_OR_SELF); |
| 2734 | if (auto != 0) { |
| 2735 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2736 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2737 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2738 | UserHandle.USER_CURRENT_OR_SELF); |
| 2739 | } |
| 2740 | |
| 2741 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2742 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2743 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2744 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2745 | Settings.System.SCREEN_BRIGHTNESS, |
| 2746 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2747 | UserHandle.USER_CURRENT_OR_SELF); |
| 2748 | brightness += step; |
| 2749 | // Make sure we don't go beyond the limits. |
| 2750 | brightness = Math.min(max, brightness); |
| 2751 | brightness = Math.max(min, brightness); |
| 2752 | |
| 2753 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2754 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2755 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2756 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 2757 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2758 | } |
| 2759 | return -1; |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2760 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2761 | if (down) { |
| 2762 | mPendingMetaAction = true; |
| 2763 | } else if (mPendingMetaAction) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2764 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2765 | } |
| 2766 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2767 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2768 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2769 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2770 | // Any printing key that is chorded with Search should be consumed |
| 2771 | // even if no shortcut was invoked. This prevents text from being |
| 2772 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2773 | // 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] | 2774 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2775 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2776 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2777 | mConsumeSearchKeyUp = true; |
| 2778 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2779 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2780 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2781 | if (shortcutIntent != null) { |
| 2782 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2783 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2784 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2785 | } catch (ActivityNotFoundException ex) { |
| 2786 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2787 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2788 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2789 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2790 | } else { |
| 2791 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2792 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2793 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2794 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2795 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2796 | } |
| 2797 | } |
| 2798 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2799 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2800 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2801 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2802 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2803 | if (kcm.isPrintingKey(keyCode)) { |
| 2804 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2805 | metaState & ~(KeyEvent.META_META_ON |
| 2806 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2807 | if (shortcutIntent != null) { |
| 2808 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2809 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2810 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2811 | } catch (ActivityNotFoundException ex) { |
| 2812 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2813 | + "the activity to which it is registered was not found: " |
| 2814 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2815 | } |
| 2816 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2817 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2818 | } |
| 2819 | } |
| 2820 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2821 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2822 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2823 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2824 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2825 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2826 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2827 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2828 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2829 | } catch (ActivityNotFoundException ex) { |
| 2830 | Slog.w(TAG, "Dropping application launch key because " |
| 2831 | + "the activity to which it is registered was not found: " |
| 2832 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2833 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2834 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2835 | } |
| 2836 | } |
| 2837 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2838 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2839 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2840 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2841 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2842 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2843 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 2844 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2845 | return -1; |
| 2846 | } |
| 2847 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2848 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 2849 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 2850 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2851 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2852 | } |
| 2853 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2854 | // Handle keyboard language switching. |
| 2855 | if (down && repeatCount == 0 |
| 2856 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2857 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2858 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2859 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2860 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2861 | return -1; |
| 2862 | } |
| 2863 | if (mLanguageSwitchKeyPressed && !down |
| 2864 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2865 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2866 | mLanguageSwitchKeyPressed = false; |
| 2867 | return -1; |
| 2868 | } |
| 2869 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2870 | if (isValidGlobalKey(keyCode) |
| 2871 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2872 | return -1; |
| 2873 | } |
| 2874 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2875 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2876 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2877 | return -1; |
| 2878 | } |
| 2879 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2880 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2881 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2882 | } |
| 2883 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2884 | /** {@inheritDoc} */ |
| 2885 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2886 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2887 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2888 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2889 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2890 | + ", flags=" + event.getFlags() |
| 2891 | + ", keyCode=" + event.getKeyCode() |
| 2892 | + ", scanCode=" + event.getScanCode() |
| 2893 | + ", metaState=" + event.getMetaState() |
| 2894 | + ", repeatCount=" + event.getRepeatCount() |
| 2895 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2896 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2897 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2898 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2899 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2900 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2901 | final int keyCode = event.getKeyCode(); |
| 2902 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2903 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2904 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2905 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2906 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2907 | final FallbackAction fallbackAction; |
| 2908 | if (initialDown) { |
| 2909 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2910 | } else { |
| 2911 | fallbackAction = mFallbackActions.get(keyCode); |
| 2912 | } |
| 2913 | |
| 2914 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2915 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2916 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2917 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2918 | } |
| 2919 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2920 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2921 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2922 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2923 | event.getAction(), fallbackAction.keyCode, |
| 2924 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2925 | event.getDeviceId(), event.getScanCode(), |
| 2926 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2927 | |
| 2928 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2929 | fallbackEvent.recycle(); |
| 2930 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2931 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2932 | |
| 2933 | if (initialDown) { |
| 2934 | mFallbackActions.put(keyCode, fallbackAction); |
| 2935 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2936 | mFallbackActions.remove(keyCode); |
| 2937 | fallbackAction.recycle(); |
| 2938 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2939 | } |
| 2940 | } |
| 2941 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2942 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2943 | if (fallbackEvent == null) { |
| 2944 | Slog.d(TAG, "No fallback."); |
| 2945 | } else { |
| 2946 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2947 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2948 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2949 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2952 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2953 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2954 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2955 | long delayMillis = interceptKeyBeforeDispatching( |
| 2956 | win, fallbackEvent, policyFlags); |
| 2957 | if (delayMillis == 0) { |
| 2958 | return true; |
| 2959 | } |
| 2960 | } |
| 2961 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2962 | } |
| 2963 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2964 | private void launchAssistLongPressAction() { |
| 2965 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2966 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2967 | |
| 2968 | // launch the search activity |
| 2969 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2970 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2971 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2972 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2973 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2974 | SearchManager searchManager = getSearchManager(); |
| 2975 | if (searchManager != null) { |
| 2976 | searchManager.stopSearch(); |
| 2977 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2978 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2979 | } catch (ActivityNotFoundException e) { |
| 2980 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | private void launchAssistAction() { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2985 | launchAssistAction(null); |
| 2986 | } |
| 2987 | |
| 2988 | private void launchAssistAction(String hint) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2989 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2990 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2991 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2992 | if (intent != null) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2993 | if (hint != null) { |
| 2994 | intent.putExtra(hint, true); |
| 2995 | } |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2996 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2997 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2998 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2999 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3000 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3001 | } catch (ActivityNotFoundException e) { |
| 3002 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | } |
| 3006 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3007 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3008 | if (isUserSetupComplete()) { |
| 3009 | mContext.startActivityAsUser(intent, handle); |
| 3010 | } else { |
| 3011 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3012 | } |
| 3013 | } |
| 3014 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3015 | private SearchManager getSearchManager() { |
| 3016 | if (mSearchManager == null) { |
| 3017 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3018 | } |
| 3019 | return mSearchManager; |
| 3020 | } |
| 3021 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3022 | private void preloadRecentApps() { |
| 3023 | mPreloadedRecentApps = true; |
| 3024 | try { |
| 3025 | IStatusBarService statusbar = getStatusBarService(); |
| 3026 | if (statusbar != null) { |
| 3027 | statusbar.preloadRecentApps(); |
| 3028 | } |
| 3029 | } catch (RemoteException e) { |
| 3030 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 3031 | // re-acquire status bar service next time it is needed. |
| 3032 | mStatusBarService = null; |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | private void cancelPreloadRecentApps() { |
| 3037 | if (mPreloadedRecentApps) { |
| 3038 | mPreloadedRecentApps = false; |
| 3039 | try { |
| 3040 | IStatusBarService statusbar = getStatusBarService(); |
| 3041 | if (statusbar != null) { |
| 3042 | statusbar.cancelPreloadRecentApps(); |
| 3043 | } |
| 3044 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3045 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3046 | // re-acquire status bar service next time it is needed. |
| 3047 | mStatusBarService = null; |
| 3048 | } |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | private void toggleRecentApps() { |
| 3053 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3054 | try { |
| 3055 | IStatusBarService statusbar = getStatusBarService(); |
| 3056 | if (statusbar != null) { |
| 3057 | statusbar.toggleRecentApps(); |
| 3058 | } |
| 3059 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3060 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 3061 | // re-acquire status bar service next time it is needed. |
| 3062 | mStatusBarService = null; |
| 3063 | } |
| 3064 | } |
| 3065 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3066 | @Override |
| 3067 | public void showRecentApps() { |
| 3068 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 3069 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 3070 | } |
| 3071 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3072 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 3073 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3074 | try { |
| 3075 | IStatusBarService statusbar = getStatusBarService(); |
| 3076 | if (statusbar != null) { |
| 3077 | statusbar.showRecentApps(triggeredFromAltTab); |
| 3078 | } |
| 3079 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3080 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 3081 | // re-acquire status bar service next time it is needed. |
| 3082 | mStatusBarService = null; |
| 3083 | } |
| 3084 | } |
| 3085 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3086 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3087 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3088 | try { |
| 3089 | IStatusBarService statusbar = getStatusBarService(); |
| 3090 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3091 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3092 | } |
| 3093 | } catch (RemoteException e) { |
| 3094 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 3095 | // re-acquire status bar service next time it is needed. |
| 3096 | mStatusBarService = null; |
| 3097 | } |
| 3098 | } |
| 3099 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3100 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3101 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3102 | } |
| 3103 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3104 | /** |
| 3105 | * A home key -> launch home action was detected. Take the appropriate action |
| 3106 | * given the situation with the keyguard. |
| 3107 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3108 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3109 | if (respectKeyguard) { |
| 3110 | if (isKeyguardShowingAndNotOccluded()) { |
| 3111 | // don't launch home if keyguard showing |
| 3112 | return; |
| 3113 | } |
| 3114 | |
| 3115 | if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
| 3116 | // when in keyguard restricted mode, must first verify unlock |
| 3117 | // before launching home |
| 3118 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3119 | @Override |
| 3120 | public void onKeyguardExitResult(boolean success) { |
| 3121 | if (success) { |
| 3122 | try { |
| 3123 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3124 | } catch (RemoteException e) { |
| 3125 | } |
| 3126 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3127 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3128 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3129 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3130 | }); |
| 3131 | return; |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | // no keyguard stuff to worry about, just launch home! |
| 3136 | try { |
| 3137 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3138 | } catch (RemoteException e) { |
| 3139 | } |
| 3140 | if (mRecentsVisible) { |
| 3141 | // Hide Recents and notify it to launch Home |
| 3142 | if (awakenFromDreams) { |
| 3143 | awakenDreams(); |
| 3144 | } |
| 3145 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3146 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3147 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3148 | // Otherwise, just launch Home |
| 3149 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3150 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3151 | } |
| 3152 | } |
| 3153 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3154 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3155 | @Override |
| 3156 | public void run() { |
| 3157 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3158 | // Clear flags. |
| 3159 | mForceClearedSystemUiFlags &= |
| 3160 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3161 | } |
| 3162 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3163 | } |
| 3164 | }; |
| 3165 | |
| 3166 | /** |
| 3167 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3168 | * to determine when the nav bar should be shown and prevent applications from |
| 3169 | * receiving those touches. |
| 3170 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3171 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3172 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3173 | super(inputChannel, looper); |
| 3174 | } |
| 3175 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3176 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3177 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3178 | boolean handled = false; |
| 3179 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3180 | if (event instanceof MotionEvent |
| 3181 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3182 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3183 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3184 | // When the user taps down, we re-show the nav bar. |
| 3185 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3186 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3187 | // Any user activity always causes us to show the |
| 3188 | // navigation controls, if they had been hidden. |
| 3189 | // We also clear the low profile and only content |
| 3190 | // flags so that tapping on the screen will atomically |
| 3191 | // restore all currently hidden screen decorations. |
| 3192 | int newVal = mResettingSystemUiFlags | |
| 3193 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3194 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3195 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3196 | if (mResettingSystemUiFlags != newVal) { |
| 3197 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3198 | changed = true; |
| 3199 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3200 | // We don't allow the system's nav bar to be hidden |
| 3201 | // again for 1 second, to prevent applications from |
| 3202 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3203 | newVal = mForceClearedSystemUiFlags | |
| 3204 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3205 | if (mForceClearedSystemUiFlags != newVal) { |
| 3206 | mForceClearedSystemUiFlags = newVal; |
| 3207 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3208 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3209 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3210 | } |
| 3211 | if (changed) { |
| 3212 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3213 | } |
| 3214 | } |
| 3215 | } |
| 3216 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3217 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3218 | } |
| 3219 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3220 | } |
| 3221 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3222 | new InputEventReceiver.Factory() { |
| 3223 | @Override |
| 3224 | public InputEventReceiver createInputEventReceiver( |
| 3225 | InputChannel inputChannel, Looper looper) { |
| 3226 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3227 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3228 | }; |
| 3229 | |
| 3230 | @Override |
| 3231 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3232 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3233 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3234 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3235 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3236 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3237 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3238 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3239 | // Clear any bits in the new visibility that are currently being |
| 3240 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3241 | return visibility & ~mResettingSystemUiFlags |
| 3242 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3245 | @Override |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3246 | public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets, |
| 3247 | Rect outStableInsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3248 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3249 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3250 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3251 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3252 | 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] | 3253 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3254 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3255 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3256 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3257 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3258 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3259 | } else { |
| 3260 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3261 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3262 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3263 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3264 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3265 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3266 | availRight - mStableFullscreenRight, |
| 3267 | availBottom - mStableFullscreenBottom); |
| 3268 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3269 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3270 | availRight - mStableRight, availBottom - mStableBottom); |
| 3271 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3272 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3273 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3274 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3275 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3276 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3277 | availRight - mCurRight, availBottom - mCurBottom); |
| 3278 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3279 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3280 | availRight - mCurRight, availBottom - mCurBottom); |
| 3281 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3282 | |
| 3283 | outStableInsets.set(mStableLeft, mStableTop, |
| 3284 | availRight - mStableRight, availBottom - mStableBottom); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3285 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3286 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3287 | outContentInsets.setEmpty(); |
| 3288 | outStableInsets.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3289 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3290 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3291 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3292 | @Override |
| 3293 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 3294 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3295 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3296 | if (isDefaultDisplay) { |
| 3297 | switch (displayRotation) { |
| 3298 | case Surface.ROTATION_90: |
| 3299 | overscanLeft = mOverscanTop; |
| 3300 | overscanTop = mOverscanRight; |
| 3301 | overscanRight = mOverscanBottom; |
| 3302 | overscanBottom = mOverscanLeft; |
| 3303 | break; |
| 3304 | case Surface.ROTATION_180: |
| 3305 | overscanLeft = mOverscanRight; |
| 3306 | overscanTop = mOverscanBottom; |
| 3307 | overscanRight = mOverscanLeft; |
| 3308 | overscanBottom = mOverscanTop; |
| 3309 | break; |
| 3310 | case Surface.ROTATION_270: |
| 3311 | overscanLeft = mOverscanBottom; |
| 3312 | overscanTop = mOverscanLeft; |
| 3313 | overscanRight = mOverscanTop; |
| 3314 | overscanBottom = mOverscanRight; |
| 3315 | break; |
| 3316 | default: |
| 3317 | overscanLeft = mOverscanLeft; |
| 3318 | overscanTop = mOverscanTop; |
| 3319 | overscanRight = mOverscanRight; |
| 3320 | overscanBottom = mOverscanBottom; |
| 3321 | break; |
| 3322 | } |
| 3323 | } else { |
| 3324 | overscanLeft = 0; |
| 3325 | overscanTop = 0; |
| 3326 | overscanRight = 0; |
| 3327 | overscanBottom = 0; |
| 3328 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3329 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3330 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3331 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3332 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3333 | mSystemLeft = 0; |
| 3334 | mSystemTop = 0; |
| 3335 | mSystemRight = displayWidth; |
| 3336 | mSystemBottom = displayHeight; |
| 3337 | mUnrestrictedScreenLeft = overscanLeft; |
| 3338 | mUnrestrictedScreenTop = overscanTop; |
| 3339 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3340 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3341 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3342 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3343 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3344 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3345 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3346 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3347 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3348 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3349 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3350 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3351 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3352 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3353 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3354 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3355 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3356 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3357 | final Rect pf = mTmpParentFrame; |
| 3358 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3359 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3360 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3361 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3362 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3363 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3364 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3365 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3366 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3367 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3368 | if (isDefaultDisplay) { |
| 3369 | // For purposes of putting out fake window up to steal focus, we will |
| 3370 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3371 | final int sysui = mLastSystemUiFlags; |
| 3372 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3373 | boolean navTranslucent = (sysui |
| 3374 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3375 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3376 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3377 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3378 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3379 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3380 | if (!isKeyguardShowing) { |
| 3381 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3382 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3383 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3384 | // When the navigation bar isn't visible, we put up a fake |
| 3385 | // input window to catch all touch events. This way we can |
| 3386 | // detect when the user presses anywhere to bring back the nav |
| 3387 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3388 | if (navVisible || navAllowedHidden) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3389 | if (mHideNavFakeWindow != null) { |
| 3390 | mHideNavFakeWindow.dismiss(); |
| 3391 | mHideNavFakeWindow = null; |
| 3392 | } |
| 3393 | } else if (mHideNavFakeWindow == null) { |
| 3394 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 3395 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 3396 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3397 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3398 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3399 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3400 | // For purposes of positioning and showing the nav bar, if we have |
| 3401 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3402 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3403 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3404 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3405 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3406 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3407 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3408 | // Force the navigation bar to its appropriate place and |
| 3409 | // size. We need to do this directly, instead of relying on |
| 3410 | // it to bubble up from the nav bar, because this needs to |
| 3411 | // change atomically with screen rotations. |
| 3412 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 3413 | if (mNavigationBarOnBottom) { |
| 3414 | // 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] | 3415 | int top = displayHeight - overscanBottom |
| 3416 | - mNavigationBarHeightForRotation[displayRotation]; |
| 3417 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3418 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3419 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3420 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3421 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3422 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3423 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3424 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3425 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3426 | } else { |
| 3427 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3428 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3429 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3430 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3431 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3432 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3433 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3434 | // and not in the process of animating on or off, then |
| 3435 | // we can tell the app that it is covered by it. |
| 3436 | mSystemBottom = mTmpNavigationFrame.top; |
| 3437 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3438 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3439 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3440 | int left = displayWidth - overscanRight |
| 3441 | - mNavigationBarWidthForRotation[displayRotation]; |
| 3442 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3443 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3444 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3445 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3446 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3447 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3448 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3449 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3450 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3451 | } else { |
| 3452 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3453 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3454 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3455 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 3456 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3457 | // If the nav bar is currently requested to be visible, |
| 3458 | // and not in the process of animating on or off, then |
| 3459 | // we can tell the app that it is covered by it. |
| 3460 | mSystemRight = mTmpNavigationFrame.left; |
| 3461 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3462 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3463 | // Make sure the content and current rectangles are updated to |
| 3464 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3465 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3466 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3467 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3468 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3469 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3470 | // And compute the final frame. |
| 3471 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3472 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 3473 | mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3474 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3475 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3476 | updateSysUiVisibility = true; |
| 3477 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3478 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3479 | 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] | 3480 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 3481 | |
| 3482 | // decide where the status bar goes ahead of time |
| 3483 | if (mStatusBar != null) { |
| 3484 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3485 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3486 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3487 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3488 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3489 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3490 | vf.left = mStableLeft; |
| 3491 | vf.top = mStableTop; |
| 3492 | vf.right = mStableRight; |
| 3493 | vf.bottom = mStableBottom; |
| 3494 | |
| 3495 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3496 | |
| 3497 | // Let the status bar determine its size. |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3498 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3499 | |
| 3500 | // For layout, the status bar is always at the top with our fixed height. |
| 3501 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3502 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3503 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3504 | boolean statusBarTranslucent = (sysui |
| 3505 | & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3506 | if (!isKeyguardShowing) { |
| 3507 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3508 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3509 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3510 | // If the status bar is hidden, we don't want to cause |
| 3511 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 3512 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3513 | // Status bar may go away, so the screen area it occupies |
| 3514 | // is available to apps but just covering them when the |
| 3515 | // status bar is visible. |
| 3516 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3517 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3518 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3519 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3520 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3521 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3522 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3523 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3524 | String.format( |
| 3525 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3526 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3527 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3528 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3529 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3530 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3531 | && !statusBarTransient && !statusBarTranslucent |
| 3532 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3533 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3534 | // and not in the process of animating on or off, then |
| 3535 | // we can tell the app that it is covered by it. |
| 3536 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3537 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3538 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3539 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3540 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3541 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3542 | if (updateSysUiVisibility) { |
| 3543 | updateSystemUiVisibilityLw(); |
| 3544 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3545 | } |
| 3546 | } |
| 3547 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3548 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3549 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3550 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 3551 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 3552 | return mStatusBar.getSurfaceLayer(); |
| 3553 | } |
| 3554 | |
| 3555 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 3556 | return mNavigationBar.getSurfaceLayer(); |
| 3557 | } |
| 3558 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3559 | return 0; |
| 3560 | } |
| 3561 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3562 | @Override |
| 3563 | public void getContentRectLw(Rect r) { |
| 3564 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3565 | } |
| 3566 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3567 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3568 | 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] | 3569 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3570 | // Here's a special case: if this attached window is a panel that is |
| 3571 | // above the dock window, and the window it is attached to is below |
| 3572 | // the dock window, then the frames we computed for the window it is |
| 3573 | // attached to can not be used because the dock is effectively part |
| 3574 | // of the underlying window and the attached window is floating on top |
| 3575 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3576 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3577 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3578 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3579 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3580 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3581 | } else { |
| 3582 | // The effective display frame of the attached window depends on |
| 3583 | // whether it is taking care of insetting its content. If not, |
| 3584 | // we need to use the parent's content frame so that the entire |
| 3585 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3586 | // 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] | 3587 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3588 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3589 | // Set the content frame of the attached window to the parent's decor frame |
| 3590 | // (same as content frame when IME isn't present) if specifically requested by |
| 3591 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 3592 | // Otherwise, use the overscan frame. |
| 3593 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 3594 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3595 | } else { |
| 3596 | // If the window is resizing, then we want to base the content |
| 3597 | // frame on our attached content frame to resize... however, |
| 3598 | // things can be tricky if the attached window is NOT in resize |
| 3599 | // mode, in which case its content frame will be larger. |
| 3600 | // Ungh. So to deal with that, make sure the content frame |
| 3601 | // we end up using is not covering the IM dock. |
| 3602 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3603 | if (attached.isVoiceInteraction()) { |
| 3604 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3605 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3606 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3607 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3608 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3609 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3610 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3611 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3612 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3613 | } |
| 3614 | } |
| 3615 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3616 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3617 | vf.set(attached.getVisibleFrameLw()); |
| 3618 | } |
| 3619 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3620 | // window should be positioned relative to its parent or the entire |
| 3621 | // screen. |
| 3622 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3623 | ? attached.getFrameLw() : df); |
| 3624 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3625 | |
| 3626 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3627 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3628 | // If app is requesting a stable layout, don't let the |
| 3629 | // content insets go below the stable values. |
| 3630 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3631 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3632 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3633 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3634 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3635 | } else { |
| 3636 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3637 | if (r.top < mStableTop) r.top = mStableTop; |
| 3638 | if (r.right > mStableRight) r.right = mStableRight; |
| 3639 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3640 | } |
| 3641 | } |
| 3642 | } |
| 3643 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3644 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3645 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3646 | public void layoutWindowLw(WindowState win, WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3647 | // we've already done the status bar |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3648 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
| 3649 | if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) || |
| 3650 | win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3651 | return; |
| 3652 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3653 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 3654 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3655 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 3656 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3657 | 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] | 3658 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 3659 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3660 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3661 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3662 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3663 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3664 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3665 | final Rect pf = mTmpParentFrame; |
| 3666 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3667 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3668 | final Rect cf = mTmpContentFrame; |
| 3669 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3670 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3671 | final Rect sf = mTmpStableFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3672 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3673 | |
| 3674 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3675 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3676 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 3677 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 3678 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3679 | if (isDefaultDisplay) { |
| 3680 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 3681 | } else { |
| 3682 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 3683 | } |
| 3684 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3685 | if (!isDefaultDisplay) { |
| 3686 | if (attached != null) { |
| 3687 | // If this window is attached to another, our display |
| 3688 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3689 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3690 | } else { |
| 3691 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3692 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3693 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3694 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3695 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3696 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3697 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3698 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3699 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3700 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3701 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3702 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3703 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3704 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3705 | // ...with content insets above the nav bar |
| 3706 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3707 | // IM dock windows always go to the bottom of the screen. |
| 3708 | attrs.gravity = Gravity.BOTTOM; |
| 3709 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3710 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
| 3711 | pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft; |
| 3712 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3713 | pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft |
| 3714 | + mUnrestrictedScreenWidth; |
| 3715 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3716 | + mUnrestrictedScreenHeight; |
| 3717 | cf.bottom = vf.bottom = mStableBottom; |
| 3718 | cf.top = vf.top = mStableTop; |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 3719 | } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 3720 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3721 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3722 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3723 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 3724 | cf.left = vf.left = mStableLeft; |
| 3725 | cf.top = vf.top = mStableTop; |
| 3726 | cf.right = vf.right = mStableRight; |
| 3727 | vf.bottom = mStableBottom; |
| 3728 | cf.bottom = mContentBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3729 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3730 | |
| 3731 | // Default policy decor for the default display |
| 3732 | dcf.left = mSystemLeft; |
| 3733 | dcf.top = mSystemTop; |
| 3734 | dcf.right = mSystemRight; |
| 3735 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3736 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3737 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3738 | final boolean isAppWindow = |
| 3739 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3740 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3741 | final boolean topAtRest = |
| 3742 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3743 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3744 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3745 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3746 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 3747 | && (fl & WindowManager.LayoutParams. |
| 3748 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3749 | // Ensure policy decor includes status bar |
| 3750 | dcf.top = mStableTop; |
| 3751 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3752 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3753 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 3754 | && (fl & WindowManager.LayoutParams. |
| 3755 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3756 | // Ensure policy decor includes navigation bar |
| 3757 | dcf.bottom = mStableBottom; |
| 3758 | dcf.right = mStableRight; |
| 3759 | } |
| 3760 | } |
| 3761 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3762 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3763 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3764 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3765 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3766 | // This is the case for a normal activity window: we want it |
| 3767 | // to cover all of the screen space, and it can take care of |
| 3768 | // moving its contents to account for screen decorations that |
| 3769 | // intrude into that space. |
| 3770 | if (attached != null) { |
| 3771 | // If this window is attached to another, our display |
| 3772 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3773 | 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] | 3774 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3775 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3776 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3777 | // Status bar panels are the only windows who can go on top of |
| 3778 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3779 | // permission, so they have the same privileges as the status |
| 3780 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3781 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3782 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3783 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3784 | pf.left = df.left = of.left = hasNavBar |
| 3785 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3786 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3787 | pf.right = df.right = of.right = hasNavBar |
| 3788 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3789 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3790 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3791 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3792 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3793 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3794 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3795 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3796 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3797 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3798 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3799 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3800 | // Asking to layout into the overscan region, so give it that pure |
| 3801 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3802 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3803 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3804 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3805 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3806 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3807 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3808 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3809 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3810 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3811 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3812 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3813 | // only do this for application windows to ensure no window that |
| 3814 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3815 | pf.left = df.left = mOverscanScreenLeft; |
| 3816 | pf.top = df.top = mOverscanScreenTop; |
| 3817 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3818 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3819 | // We need to tell the app about where the frame inside the overscan |
| 3820 | // is, so it can inset its content by that amount -- it didn't ask |
| 3821 | // to actually extend itself into the overscan region. |
| 3822 | of.left = mUnrestrictedScreenLeft; |
| 3823 | of.top = mUnrestrictedScreenTop; |
| 3824 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3825 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3826 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3827 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3828 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3829 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3830 | + mRestrictedOverscanScreenWidth; |
| 3831 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3832 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3833 | // We need to tell the app about where the frame inside the overscan |
| 3834 | // is, so it can inset its content by that amount -- it didn't ask |
| 3835 | // to actually extend itself into the overscan region. |
| 3836 | of.left = mUnrestrictedScreenLeft; |
| 3837 | of.top = mUnrestrictedScreenTop; |
| 3838 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3839 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3840 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3841 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3842 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3843 | if (win.isVoiceInteraction()) { |
| 3844 | cf.left = mVoiceContentLeft; |
| 3845 | cf.top = mVoiceContentTop; |
| 3846 | cf.right = mVoiceContentRight; |
| 3847 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3848 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3849 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3850 | cf.left = mDockLeft; |
| 3851 | cf.top = mDockTop; |
| 3852 | cf.right = mDockRight; |
| 3853 | cf.bottom = mDockBottom; |
| 3854 | } else { |
| 3855 | cf.left = mContentLeft; |
| 3856 | cf.top = mContentTop; |
| 3857 | cf.right = mContentRight; |
| 3858 | cf.bottom = mContentBottom; |
| 3859 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3860 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3861 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3862 | // Full screen windows are always given a layout that is as if the |
| 3863 | // status bar and other transient decors are gone. This is to avoid |
| 3864 | // bad states when moving from a window that is not hding the |
| 3865 | // status bar to one that is. |
| 3866 | cf.left = mRestrictedScreenLeft; |
| 3867 | cf.top = mRestrictedScreenTop; |
| 3868 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3869 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3870 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3871 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3872 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3873 | vf.left = mCurLeft; |
| 3874 | vf.top = mCurTop; |
| 3875 | vf.right = mCurRight; |
| 3876 | vf.bottom = mCurBottom; |
| 3877 | } else { |
| 3878 | vf.set(cf); |
| 3879 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3880 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3881 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3882 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3883 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3884 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3885 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3886 | // A window that has requested to fill the entire screen just |
| 3887 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3888 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3889 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3890 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3891 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3892 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3893 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3894 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3895 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3896 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3897 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3898 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3899 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3900 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3901 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3902 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3903 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3904 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3905 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3906 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3907 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3908 | + mUnrestrictedScreenWidth; |
| 3909 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3910 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3911 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3912 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3913 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3914 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3915 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3916 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3917 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3918 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3919 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3920 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3921 | + mOverscanScreenWidth; |
| 3922 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3923 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 3924 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3925 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3926 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3927 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3928 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3929 | + mOverscanScreenWidth; |
| 3930 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3931 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3932 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3933 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 3934 | // it about the overscan area. |
| 3935 | pf.left = df.left = mOverscanScreenLeft; |
| 3936 | pf.top = df.top = mOverscanScreenTop; |
| 3937 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3938 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 3939 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 3940 | of.top = cf.top = mUnrestrictedScreenTop; |
| 3941 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3942 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3943 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3944 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3945 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3946 | // Asking to layout into the overscan region, so give it that pure |
| 3947 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3948 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3949 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3950 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3951 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3952 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3953 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3954 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3955 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 3956 | && (attrs.type == TYPE_STATUS_BAR |
| 3957 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 3958 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3959 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3960 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3961 | // Asking for layout as if the nav bar is hidden, lets the |
| 3962 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3963 | // 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] | 3964 | // can be above the nav bar can do this. |
| 3965 | // XXX This assumes that an app asking for this will also |
| 3966 | // ask for layout in only content. We can't currently figure out |
| 3967 | // 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] | 3968 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3969 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3970 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3971 | + mUnrestrictedScreenWidth; |
| 3972 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3973 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3974 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3975 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3976 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3977 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3978 | + mRestrictedScreenWidth; |
| 3979 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3980 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3981 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3982 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3983 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3984 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3985 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3986 | vf.left = mCurLeft; |
| 3987 | vf.top = mCurTop; |
| 3988 | vf.right = mCurRight; |
| 3989 | vf.bottom = mCurBottom; |
| 3990 | } else { |
| 3991 | vf.set(cf); |
| 3992 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3993 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3994 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3995 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3996 | // A child window should be placed inside of the same visible |
| 3997 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3998 | 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] | 3999 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4000 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4001 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4002 | // Otherwise, a normal window must be placed inside the content |
| 4003 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4004 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 4005 | // Status bar panels are the only windows who can go on top of |
| 4006 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4007 | // permission, so they have the same privileges as the status |
| 4008 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4009 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4010 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4011 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4012 | + mRestrictedScreenWidth; |
| 4013 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4014 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4015 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 4016 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 4017 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4018 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 4019 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 4020 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 4021 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4022 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4023 | pf.left = mContentLeft; |
| 4024 | pf.top = mContentTop; |
| 4025 | pf.right = mContentRight; |
| 4026 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 4027 | if (win.isVoiceInteraction()) { |
| 4028 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 4029 | df.top = of.top = cf.top = mVoiceContentTop; |
| 4030 | df.right = of.right = cf.right = mVoiceContentRight; |
| 4031 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 4032 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4033 | df.left = of.left = cf.left = mDockLeft; |
| 4034 | df.top = of.top = cf.top = mDockTop; |
| 4035 | df.right = of.right = cf.right = mDockRight; |
| 4036 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4037 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4038 | df.left = of.left = cf.left = mContentLeft; |
| 4039 | df.top = of.top = cf.top = mContentTop; |
| 4040 | df.right = of.right = cf.right = mContentRight; |
| 4041 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4042 | } |
| 4043 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4044 | vf.left = mCurLeft; |
| 4045 | vf.top = mCurTop; |
| 4046 | vf.right = mCurRight; |
| 4047 | vf.bottom = mCurBottom; |
| 4048 | } else { |
| 4049 | vf.set(cf); |
| 4050 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4051 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4052 | } |
| 4053 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4054 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 4055 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 4056 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4057 | df.left = df.top = -10000; |
| 4058 | df.right = df.bottom = 10000; |
| 4059 | if (attrs.type != TYPE_WALLPAPER) { |
| 4060 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 4061 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 4062 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4063 | } |
| 4064 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4065 | 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] | 4066 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4067 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4068 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 4069 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4070 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4071 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4072 | + " dcf=" + dcf.toShortString() |
| 4073 | + " sf=" + sf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4074 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4075 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4076 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4077 | // Dock windows carve out the bottom of the screen, so normal windows |
| 4078 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 4079 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 4080 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4081 | setLastInputMethodWindowLw(null, null); |
| 4082 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4083 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4084 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 4085 | && !win.getGivenInsetsPendingLw()) { |
| 4086 | offsetVoiceInputWindowLw(win); |
| 4087 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4088 | } |
| 4089 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4090 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4091 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4092 | top += win.getGivenContentInsetsLw().top; |
| 4093 | if (mContentBottom > top) { |
| 4094 | mContentBottom = top; |
| 4095 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4096 | if (mVoiceContentBottom > top) { |
| 4097 | mVoiceContentBottom = top; |
| 4098 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4099 | top = win.getVisibleFrameLw().top; |
| 4100 | top += win.getGivenVisibleInsetsLw().top; |
| 4101 | if (mCurBottom > top) { |
| 4102 | mCurBottom = top; |
| 4103 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4104 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4105 | + mDockBottom + " mContentBottom=" |
| 4106 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 4107 | } |
| 4108 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4109 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4110 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 4111 | top += win.getGivenContentInsetsLw().top; |
| 4112 | if (mVoiceContentBottom > top) { |
| 4113 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4114 | } |
| 4115 | } |
| 4116 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4117 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 4118 | @Override |
| 4119 | public void finishLayoutLw() { |
| 4120 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4124 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4125 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4126 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4127 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4128 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4129 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4130 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4131 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4132 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4133 | mForcingShowNavBar = false; |
| 4134 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4135 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4136 | mHideLockScreen = false; |
| 4137 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4138 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4139 | mShowingLockscreen = false; |
| 4140 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4141 | mWinShowWhenLocked = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4142 | mKeyguardSecure = isKeyguardSecure(); |
| 4143 | mKeyguardSecureIncludingHidden = mKeyguardSecure |
| 4144 | && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4148 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4149 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4150 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 4151 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4152 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4153 | if (mTopFullscreenOpaqueWindowState == null |
| 4154 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 4155 | mForcingShowNavBar = true; |
| 4156 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4157 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4158 | if (attrs.type == TYPE_STATUS_BAR) { |
| 4159 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 4160 | mForceStatusBarFromKeyguard = true; |
| 4161 | } |
| 4162 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 4163 | mForceStatusBarTransparent = true; |
| 4164 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4165 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4166 | |
| 4167 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 4168 | && attrs.type < FIRST_SYSTEM_WINDOW; |
| 4169 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 4170 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
| 4171 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4172 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 4173 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4174 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4175 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4176 | mForceStatusBarFromKeyguard = true; |
| 4177 | } else { |
| 4178 | mForceStatusBar = true; |
| 4179 | } |
| 4180 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4181 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4182 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4183 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4184 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4185 | // If the lockscreen was showing when the dream started then wait |
| 4186 | // for the dream to draw before hiding the lockscreen. |
| 4187 | if (!mDreamingLockscreen |
| 4188 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4189 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4190 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4191 | } |
| 4192 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4193 | |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4194 | if (appWindow) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4195 | final IApplicationToken appToken = win.getAppToken(); |
| 4196 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4197 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4198 | mAppsToBeHidden.remove(appToken); |
| 4199 | mAppsThatDismissKeyguard.remove(appToken); |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4200 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | 192d604 | 2014-12-02 23:24:48 -0800 | [diff] [blame] | 4201 | if (dismissKeyguard && !mKeyguardSecure) { |
| 4202 | mAppsThatDismissKeyguard.add(appToken); |
| 4203 | } else { |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4204 | mWinShowWhenLocked = win; |
| 4205 | mHideLockScreen = true; |
| 4206 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4207 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4208 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4209 | } else if (dismissKeyguard) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4210 | if (mKeyguardSecure) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4211 | mAppsToBeHidden.add(appToken); |
| 4212 | } else { |
| 4213 | mAppsToBeHidden.remove(appToken); |
| 4214 | } |
| 4215 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4216 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4217 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4218 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4219 | if (attrs.x == 0 && attrs.y == 0 |
| 4220 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4221 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 4222 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4223 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4224 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 4225 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4226 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4227 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4228 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4229 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4230 | "Setting mDismissKeyguard true by win " + win); |
| 4231 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 4232 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 4233 | mWinDismissingKeyguard = win; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4234 | mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4235 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) { |
| 4236 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4237 | "Setting mHideLockScreen to true by win " + win); |
| 4238 | mHideLockScreen = true; |
| 4239 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4240 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4241 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4242 | mAllowLockscreenWhenOn = true; |
| 4243 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4244 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4245 | |
| 4246 | if (mWinShowWhenLocked != null && |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4247 | mWinShowWhenLocked.getAppToken() != win.getAppToken() && |
| 4248 | (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4249 | win.hideLw(false); |
| 4250 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4251 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4252 | } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) { |
| 4253 | // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window |
| 4254 | // that is being hidden in an animation - keep the |
| 4255 | // keyguard hidden until the new window shows up and |
| 4256 | // we know whether to show the keyguard or not. |
| 4257 | if (win.isAnimatingLw() && appWindow && showWhenLocked) { |
| 4258 | mHideLockScreen = true; |
| 4259 | mWinShowWhenLocked = win; |
| 4260 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4261 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4262 | if (mTopFullscreenOpaqueOrDimmingWindowState == null |
| 4263 | && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw() |
| 4264 | && win.isDimming()) { |
| 4265 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4266 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4270 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4271 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c5e73bf | 2015-04-21 15:41:26 +0000 | [diff] [blame] | 4272 | if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null && |
| 4273 | mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken() |
| 4274 | && isKeyguardLocked()) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4275 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4276 | // fullscreen window. |
| 4277 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4278 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4279 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4280 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4281 | } |
| 4282 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4283 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4284 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4285 | |
| 4286 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4287 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4288 | : null; |
| 4289 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4290 | // If we are not currently showing a dream then remember the current |
| 4291 | // lockscreen state. We will use this to determine whether the dream |
| 4292 | // started while the lockscreen was showing and remember this state |
| 4293 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4294 | if (!mShowingDream) { |
| 4295 | mDreamingLockscreen = mShowingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 4296 | if (mDreamingSleepTokenNeeded) { |
| 4297 | mDreamingSleepTokenNeeded = false; |
| 4298 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 4299 | } |
| 4300 | } else { |
| 4301 | if (!mDreamingSleepTokenNeeded) { |
| 4302 | mDreamingSleepTokenNeeded = true; |
| 4303 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 4304 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4307 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4308 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4309 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 4310 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4311 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 4312 | && !mForceStatusBar |
| 4313 | && !mForceStatusBarFromKeyguard; |
| 4314 | if (!shouldBeTransparent) { |
| 4315 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 4316 | } else if (!mStatusBar.isVisibleLw()) { |
| 4317 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 4318 | } |
| 4319 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4320 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4321 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4322 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4323 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4324 | // Maintain fullscreen layout until incoming animation is complete. |
| 4325 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 4326 | // Transient status bar on the lockscreen is not allowed |
| 4327 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 4328 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 4329 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 4330 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4331 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4332 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4333 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4334 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4335 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4336 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4337 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4338 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4339 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4340 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4341 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 4342 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4343 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 4344 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4345 | if (mStatusBarController.isTransientShowing()) { |
| 4346 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4347 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4348 | } |
| 4349 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4350 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4351 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4352 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4353 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 4354 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 4355 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4356 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4357 | 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] | 4358 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4359 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4360 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4361 | } |
| 4362 | } |
| 4363 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4364 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4365 | if (mTopIsFullscreen != topIsFullscreen) { |
| 4366 | if (!topIsFullscreen) { |
| 4367 | // Force another layout when status bar becomes fully shown. |
| 4368 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4369 | } |
| 4370 | mTopIsFullscreen = topIsFullscreen; |
| 4371 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4372 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4373 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 4374 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4375 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 4376 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 4377 | + mHideLockScreen); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4378 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4379 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4380 | if (setKeyguardOccludedLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4381 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4382 | | FINISH_LAYOUT_REDO_CONFIG |
| 4383 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4384 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4385 | if (mKeyguardDelegate.isShowing()) { |
| 4386 | mHandler.post(new Runnable() { |
| 4387 | @Override |
| 4388 | public void run() { |
| 4389 | mKeyguardDelegate.keyguardDone(false, false); |
| 4390 | } |
| 4391 | }); |
| 4392 | } |
| 4393 | } else if (mHideLockScreen) { |
| 4394 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4395 | if (setKeyguardOccludedLw(true)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4396 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4397 | | FINISH_LAYOUT_REDO_CONFIG |
| 4398 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4399 | } |
| 4400 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 4401 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 4402 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 4403 | // Only launch the next keyguard unlock window once per window. |
| 4404 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4405 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4406 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4407 | | FINISH_LAYOUT_REDO_CONFIG |
| 4408 | | FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4409 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4410 | mHandler.post(new Runnable() { |
| 4411 | @Override |
| 4412 | public void run() { |
| 4413 | mKeyguardDelegate.dismiss(); |
| 4414 | } |
| 4415 | }); |
| 4416 | } |
| 4417 | } else { |
| 4418 | mWinDismissingKeyguard = null; |
| 4419 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4420 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4421 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4422 | | FINISH_LAYOUT_REDO_CONFIG |
| 4423 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4424 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 4425 | } |
| 4426 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4427 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4428 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4429 | // If the navigation bar has been hidden or shown, we need to do another |
| 4430 | // layout pass to update that window. |
| 4431 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4432 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4433 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4434 | // update since mAllowLockscreenWhenOn might have changed |
| 4435 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4436 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4437 | } |
| 4438 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4439 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4440 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4441 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4442 | * @return Whether the flags have changed and we have to redo the layout. |
| 4443 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4444 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
| 4445 | boolean wasOccluded = mKeyguardOccluded; |
| 4446 | boolean showing = mKeyguardDelegate.isShowing(); |
| 4447 | if (wasOccluded && !isOccluded && showing) { |
| 4448 | mKeyguardOccluded = false; |
| 4449 | mKeyguardDelegate.setOccluded(false); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4450 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4451 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4452 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4453 | } else if (!wasOccluded && isOccluded && showing) { |
| 4454 | mKeyguardOccluded = true; |
| 4455 | mKeyguardDelegate.setOccluded(true); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4456 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4457 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4458 | return true; |
| 4459 | } else { |
| 4460 | return false; |
| 4461 | } |
| 4462 | } |
| 4463 | |
| 4464 | private boolean isStatusBarKeyguard() { |
| 4465 | return mStatusBar != null |
| 4466 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4467 | } |
| 4468 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4469 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4470 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4471 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4472 | // 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] | 4473 | return false; |
| 4474 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4475 | return true; |
| 4476 | } |
| 4477 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4478 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4479 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4480 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4481 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4482 | // If the navigation bar has been hidden or shown, we need to do another |
| 4483 | // layout pass to update that window. |
| 4484 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4485 | } |
| 4486 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4487 | } |
| 4488 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4489 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4490 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4491 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4492 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4493 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4494 | if (newLidState == mLidState) { |
| 4495 | return; |
| 4496 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4497 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4498 | mLidState = newLidState; |
| 4499 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4500 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4501 | |
| 4502 | if (lidOpen) { |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4503 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4504 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4505 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4506 | } |
| 4507 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4508 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4509 | @Override |
| 4510 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 4511 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 4512 | if (mCameraLensCoverState == lensCoverState) { |
| 4513 | return; |
| 4514 | } |
| 4515 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 4516 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 4517 | Intent intent; |
| 4518 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 4519 | mKeyguardDelegate.isShowing(); |
| 4520 | if (keyguardActive) { |
| 4521 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 4522 | } else { |
| 4523 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 4524 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4525 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4526 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4527 | } |
| 4528 | mCameraLensCoverState = lensCoverState; |
| 4529 | } |
| 4530 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4531 | void setHdmiPlugged(boolean plugged) { |
| 4532 | if (mHdmiPlugged != plugged) { |
| 4533 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4534 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4535 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4536 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4537 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4538 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4539 | } |
| 4540 | } |
| 4541 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4542 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4543 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4544 | // watch for HDMI plug messages if the hdmi switch exists |
| 4545 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4546 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4547 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4548 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4549 | FileReader reader = null; |
| 4550 | try { |
| 4551 | reader = new FileReader(filename); |
| 4552 | char[] buf = new char[15]; |
| 4553 | int n = reader.read(buf); |
| 4554 | if (n > 1) { |
| 4555 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4556 | } |
| 4557 | } catch (IOException ex) { |
| 4558 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4559 | } catch (NumberFormatException ex) { |
| 4560 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4561 | } finally { |
| 4562 | if (reader != null) { |
| 4563 | try { |
| 4564 | reader.close(); |
| 4565 | } catch (IOException ex) { |
| 4566 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4567 | } |
| 4568 | } |
| 4569 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4570 | // This dance forces the code in setHdmiPlugged to run. |
| 4571 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4572 | mHdmiPlugged = !plugged; |
| 4573 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4574 | } |
| 4575 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4576 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4577 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4578 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4579 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4580 | @Override public void run() { |
| 4581 | synchronized (mScreenshotLock) { |
| 4582 | if (mScreenshotConnection != null) { |
| 4583 | mContext.unbindService(mScreenshotConnection); |
| 4584 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4585 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4586 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4587 | } |
| 4588 | }; |
| 4589 | |
| 4590 | // Assume this is called from the Handler thread. |
| 4591 | private void takeScreenshot() { |
| 4592 | synchronized (mScreenshotLock) { |
| 4593 | if (mScreenshotConnection != null) { |
| 4594 | return; |
| 4595 | } |
| 4596 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4597 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 4598 | Intent intent = new Intent(); |
| 4599 | intent.setComponent(cn); |
| 4600 | ServiceConnection conn = new ServiceConnection() { |
| 4601 | @Override |
| 4602 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 4603 | synchronized (mScreenshotLock) { |
| 4604 | if (mScreenshotConnection != this) { |
| 4605 | return; |
| 4606 | } |
| 4607 | Messenger messenger = new Messenger(service); |
| 4608 | Message msg = Message.obtain(null, 1); |
| 4609 | final ServiceConnection myConn = this; |
| 4610 | Handler h = new Handler(mHandler.getLooper()) { |
| 4611 | @Override |
| 4612 | public void handleMessage(Message msg) { |
| 4613 | synchronized (mScreenshotLock) { |
| 4614 | if (mScreenshotConnection == myConn) { |
| 4615 | mContext.unbindService(mScreenshotConnection); |
| 4616 | mScreenshotConnection = null; |
| 4617 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 4618 | } |
| 4619 | } |
| 4620 | } |
| 4621 | }; |
| 4622 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 4623 | msg.arg1 = msg.arg2 = 0; |
| 4624 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 4625 | msg.arg1 = 1; |
| 4626 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 4627 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4628 | try { |
| 4629 | messenger.send(msg); |
| 4630 | } catch (RemoteException e) { |
| 4631 | } |
| 4632 | } |
| 4633 | } |
| 4634 | @Override |
| 4635 | public void onServiceDisconnected(ComponentName name) {} |
| 4636 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 4637 | if (mContext.bindServiceAsUser( |
| 4638 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4639 | mScreenshotConnection = conn; |
| 4640 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 4641 | } |
| 4642 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4643 | } |
| 4644 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4645 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4646 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4647 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4648 | if (!mSystemBooted) { |
| 4649 | // If we have not yet booted, don't let key events do anything. |
| 4650 | return 0; |
| 4651 | } |
| 4652 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4653 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4654 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 4655 | final boolean canceled = event.isCanceled(); |
| 4656 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 4657 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4658 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4659 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 4660 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 4661 | // the same as if it were open and in front. |
| 4662 | // This will prevent any keys other than the power button from waking the screen |
| 4663 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4664 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4665 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4666 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4667 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4668 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4669 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4670 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4671 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4672 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4673 | } |
| 4674 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4675 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4676 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 4677 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 4678 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4679 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4680 | // When the device is interactive or the key is injected pass the |
| 4681 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4682 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4683 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4684 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 4685 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 4686 | // to the application but preserve its wake key status to make sure we still move |
| 4687 | // from dozing to fully interactive if we would normally go from off to fully |
| 4688 | // interactive. |
| 4689 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4690 | } else { |
| 4691 | // When the screen is off and the key is not injected, determine whether |
| 4692 | // to wake the device but don't pass the key to the application. |
| 4693 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4694 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 4695 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4696 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4697 | } |
| 4698 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4699 | // If the key would be handled globally, just return the result, don't worry about special |
| 4700 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4701 | if (isValidGlobalKey(keyCode) |
| 4702 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4703 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4704 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4705 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4706 | return result; |
| 4707 | } |
| 4708 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4709 | boolean useHapticFeedback = down |
| 4710 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 4711 | && event.getRepeatCount() == 0; |
| 4712 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4713 | // Handle special keys. |
| 4714 | switch (keyCode) { |
| 4715 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 4716 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4717 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4718 | if (mUseTvRouting) { |
| 4719 | // On TVs volume keys never go to the foreground app |
| 4720 | result &= ~ACTION_PASS_TO_USER; |
| 4721 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4722 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 4723 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4724 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4725 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4726 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 4727 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 4728 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4729 | cancelPendingPowerKeyAction(); |
| 4730 | interceptScreenshotChord(); |
| 4731 | } |
| 4732 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4733 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4734 | cancelPendingScreenshotChordAction(); |
| 4735 | } |
| 4736 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 4737 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4738 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4739 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4740 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4741 | cancelPendingPowerKeyAction(); |
| 4742 | cancelPendingScreenshotChordAction(); |
| 4743 | } |
| 4744 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4745 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4746 | cancelPendingScreenshotChordAction(); |
| 4747 | } |
| 4748 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4749 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4750 | TelecomManager telecomManager = getTelecommService(); |
| 4751 | if (telecomManager != null) { |
| 4752 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4753 | // If an incoming call is ringing, either VOLUME key means |
| 4754 | // "silence ringer". We handle these keys here, rather than |
| 4755 | // in the InCallScreen, to make sure we'll respond to them |
| 4756 | // even if the InCallScreen hasn't come to the foreground yet. |
| 4757 | // Look for the DOWN event here, to agree with the "fallback" |
| 4758 | // behavior in the InCallScreen. |
| 4759 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4760 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4761 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4762 | // Silence the ringer. (It's safe to call this |
| 4763 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4764 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4765 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4766 | // And *don't* pass this key thru to the current activity |
| 4767 | // (which is probably the InCallScreen.) |
| 4768 | result &= ~ACTION_PASS_TO_USER; |
| 4769 | break; |
| 4770 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4771 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4772 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 4773 | // 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] | 4774 | // the application, just pass it to the session service. |
| 4775 | |
| 4776 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4777 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4778 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4779 | } |
| 4780 | } |
| 4781 | |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4782 | if ((result & ACTION_PASS_TO_USER) == 0) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4783 | if (mUseTvRouting) { |
| 4784 | dispatchDirectAudioEvent(event); |
| 4785 | } else { |
| 4786 | // If we aren't passing to the user and no one else |
| 4787 | // handled it send it to the session manager to |
| 4788 | // figure out. |
| 4789 | MediaSessionLegacyHelper.getHelper(mContext) |
| 4790 | .sendVolumeKeyEvent(event, true); |
| 4791 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4792 | break; |
| 4793 | } |
| 4794 | } |
| 4795 | break; |
| 4796 | } |
| 4797 | |
| 4798 | case KeyEvent.KEYCODE_ENDCALL: { |
| 4799 | result &= ~ACTION_PASS_TO_USER; |
| 4800 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4801 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4802 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4803 | if (telecomManager != null) { |
| 4804 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4805 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4806 | if (interactive && !hungUp) { |
| 4807 | mEndCallKeyHandled = false; |
| 4808 | mHandler.postDelayed(mEndCallLongPress, |
| 4809 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 4810 | } else { |
| 4811 | mEndCallKeyHandled = true; |
| 4812 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4813 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4814 | if (!mEndCallKeyHandled) { |
| 4815 | mHandler.removeCallbacks(mEndCallLongPress); |
| 4816 | if (!canceled) { |
| 4817 | if ((mEndcallBehavior |
| 4818 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 4819 | if (goHome()) { |
| 4820 | break; |
| 4821 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 4822 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4823 | if ((mEndcallBehavior |
| 4824 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 4825 | mPowerManager.goToSleep(event.getEventTime(), |
| 4826 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 4827 | isWakeKey = false; |
| 4828 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4829 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4830 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4831 | } |
| 4832 | break; |
| 4833 | } |
| 4834 | |
| 4835 | case KeyEvent.KEYCODE_POWER: { |
| 4836 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4837 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4838 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4839 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4840 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4841 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4842 | } |
| 4843 | break; |
| 4844 | } |
| 4845 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4846 | case KeyEvent.KEYCODE_SLEEP: { |
| 4847 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4848 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4849 | if (!mPowerManager.isInteractive()) { |
| 4850 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 4851 | } |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4852 | sleepPress(event); |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4853 | break; |
| 4854 | } |
| 4855 | |
| 4856 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4857 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4858 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4859 | break; |
| 4860 | } |
| 4861 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4862 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4863 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4864 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4865 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4866 | case KeyEvent.KEYCODE_MUTE: |
| 4867 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4868 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4869 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4870 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4871 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4872 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4873 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4874 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 4875 | // If the global session is active pass all media keys to it |
| 4876 | // instead of the active window. |
| 4877 | result &= ~ACTION_PASS_TO_USER; |
| 4878 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4879 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4880 | // Only do this if we would otherwise not pass it to the user. In that |
| 4881 | // case, the PhoneWindow class will do the same thing, except it will |
| 4882 | // 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] | 4883 | // Note that we need to make a copy of the key event here because the |
| 4884 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4885 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4886 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4887 | new KeyEvent(event)); |
| 4888 | msg.setAsynchronous(true); |
| 4889 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4890 | } |
| 4891 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4892 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4893 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4894 | case KeyEvent.KEYCODE_CALL: { |
| 4895 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4896 | TelecomManager telecomManager = getTelecommService(); |
| 4897 | if (telecomManager != null) { |
| 4898 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4899 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4900 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4901 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4902 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4903 | // And *don't* pass this key thru to the current activity |
| 4904 | // (which is presumably the InCallScreen.) |
| 4905 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4906 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4907 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4908 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4909 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4910 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 4911 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 4912 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 4913 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 4914 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 4915 | // key event here because the original key event will be recycled when we return. |
| 4916 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 4917 | mBroadcastWakeLock.acquire(); |
| 4918 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 4919 | keyguardActive ? 1 : 0, 0); |
| 4920 | msg.setAsynchronous(true); |
| 4921 | msg.sendToTarget(); |
| 4922 | } |
| 4923 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4924 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4925 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4926 | if (useHapticFeedback) { |
| 4927 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 4928 | } |
| 4929 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4930 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4931 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4932 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4933 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4934 | return result; |
| 4935 | } |
| 4936 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4937 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4938 | * Returns true if the key can have global actions attached to it. |
| 4939 | * We reserve all power management keys for the system since they require |
| 4940 | * very careful handling. |
| 4941 | */ |
| 4942 | private static boolean isValidGlobalKey(int keyCode) { |
| 4943 | switch (keyCode) { |
| 4944 | case KeyEvent.KEYCODE_POWER: |
| 4945 | case KeyEvent.KEYCODE_WAKEUP: |
| 4946 | case KeyEvent.KEYCODE_SLEEP: |
| 4947 | return false; |
| 4948 | default: |
| 4949 | return true; |
| 4950 | } |
| 4951 | } |
| 4952 | |
| 4953 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4954 | * When the screen is off we ignore some keys that might otherwise typically |
| 4955 | * be considered wake keys. We filter them out here. |
| 4956 | * |
| 4957 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 4958 | * is always considered a wake key. |
| 4959 | */ |
| 4960 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 4961 | switch (keyCode) { |
| 4962 | // ignore volume keys unless docked |
| 4963 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4964 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4965 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4966 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4967 | |
| 4968 | // ignore media and camera keys |
| 4969 | case KeyEvent.KEYCODE_MUTE: |
| 4970 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4971 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4972 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4973 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4974 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4975 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4976 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4977 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4978 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4979 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4980 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4981 | case KeyEvent.KEYCODE_CAMERA: |
| 4982 | return false; |
| 4983 | } |
| 4984 | return true; |
| 4985 | } |
| 4986 | |
| 4987 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4988 | /** {@inheritDoc} */ |
| 4989 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4990 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 4991 | if ((policyFlags & FLAG_WAKE) != 0) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 4992 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) { |
| 4993 | return 0; |
| 4994 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4995 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 4996 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 4997 | if (shouldDispatchInputWhenNonInteractive()) { |
| 4998 | return ACTION_PASS_TO_USER; |
| 4999 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5000 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5001 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 5002 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 5003 | // wake up in this case. |
| 5004 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
| 5005 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming); |
| 5006 | } |
| 5007 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5008 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5009 | } |
| 5010 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5011 | private boolean shouldDispatchInputWhenNonInteractive() { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5012 | // Send events to keyguard while the screen is on. |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5013 | if (isKeyguardShowingAndNotOccluded() && mDisplay != null |
| 5014 | && mDisplay.getState() != Display.STATE_OFF) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5015 | return true; |
| 5016 | } |
| 5017 | |
| 5018 | // Send events to a dozing dream even if the screen is off since the dream |
| 5019 | // is in control of the state of the screen. |
| 5020 | IDreamManager dreamManager = getDreamManager(); |
| 5021 | |
| 5022 | try { |
| 5023 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 5024 | return true; |
| 5025 | } |
| 5026 | } catch (RemoteException e) { |
| 5027 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 5028 | } |
| 5029 | |
| 5030 | // Otherwise, consume events since the user can't see what is being |
| 5031 | // interacted with. |
| 5032 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5033 | } |
| 5034 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5035 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 5036 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 5037 | return; |
| 5038 | } |
| 5039 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 5040 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 5041 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5042 | String pkgName = mContext.getOpPackageName(); |
| 5043 | switch (keyCode) { |
| 5044 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5045 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5046 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5047 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5048 | } catch (RemoteException e) { |
| 5049 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 5050 | } |
| 5051 | break; |
| 5052 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5053 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5054 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5055 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5056 | } catch (RemoteException e) { |
| 5057 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 5058 | } |
| 5059 | break; |
| 5060 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5061 | try { |
| 5062 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5063 | getAudioService().adjustSuggestedStreamVolume( |
| 5064 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5065 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5066 | } |
| 5067 | } catch (RemoteException e) { |
| 5068 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 5069 | } |
| 5070 | break; |
| 5071 | } |
| 5072 | } |
| 5073 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5074 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 5075 | if (DEBUG_INPUT) { |
| 5076 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5077 | } |
| 5078 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5079 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 5080 | if (DEBUG_INPUT) { |
| 5081 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 5082 | } |
| 5083 | |
| 5084 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 5085 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5086 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 5087 | } |
| 5088 | |
| 5089 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 5090 | |
| 5091 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5092 | && event.getRepeatCount() == 0) { |
| 5093 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 5094 | |
| 5095 | Message msg = mHandler.obtainMessage( |
| 5096 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 5097 | msg.setAsynchronous(true); |
| 5098 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 5099 | } else { |
| 5100 | mBroadcastWakeLock.release(); |
| 5101 | } |
| 5102 | } |
| 5103 | |
| 5104 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 5105 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5106 | |
| 5107 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 5108 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 5109 | if (DEBUG_INPUT) { |
| 5110 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 5111 | } |
| 5112 | |
| 5113 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 5114 | mBroadcastWakeLock.release(); |
| 5115 | } |
| 5116 | |
| 5117 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 5118 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5119 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5120 | } |
| 5121 | } |
| 5122 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5123 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
| 5124 | Intent voiceIntent = |
| 5125 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 5126 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5127 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5128 | mBroadcastWakeLock.release(); |
| 5129 | } |
| 5130 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5131 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5132 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5133 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 5134 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 5135 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 5136 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5137 | } else { |
| 5138 | try { |
| 5139 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 5140 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5141 | mUiMode = uiModeService.getCurrentModeType(); |
| 5142 | } catch (RemoteException e) { |
| 5143 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 5144 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5145 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5146 | synchronized (mLock) { |
| 5147 | updateOrientationListenerLp(); |
| 5148 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5149 | } |
| 5150 | }; |
| 5151 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5152 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 5153 | @Override |
| 5154 | public void onReceive(Context context, Intent intent) { |
| 5155 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5156 | if (mKeyguardDelegate != null) { |
| 5157 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5158 | } |
| 5159 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5160 | if (mKeyguardDelegate != null) { |
| 5161 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5162 | } |
| 5163 | } |
| 5164 | } |
| 5165 | }; |
| 5166 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5167 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 5168 | @Override |
| 5169 | public void onReceive(Context context, Intent intent) { |
| 5170 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 5171 | // tickle the settings observer: this first ensures that we're |
| 5172 | // observing the relevant settings for the newly-active user, |
| 5173 | // and then updates our own bookkeeping based on the now- |
| 5174 | // current user. |
| 5175 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5176 | |
| 5177 | // force a re-application of focused window sysui visibility. |
| 5178 | // the window may never have been shown for this user |
| 5179 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5180 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5181 | mLastSystemUiFlags = 0; |
| 5182 | updateSystemUiVisibilityLw(); |
| 5183 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5184 | } |
| 5185 | } |
| 5186 | }; |
| 5187 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5188 | private final Runnable mRequestTransientNav = new Runnable() { |
| 5189 | @Override |
| 5190 | public void run() { |
| 5191 | requestTransientBars(mNavigationBar); |
| 5192 | } |
| 5193 | }; |
| 5194 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5195 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5196 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5197 | if (!isUserSetupComplete()) { |
| 5198 | // Swipe-up for navigation bar is disabled during setup |
| 5199 | return; |
| 5200 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5201 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 5202 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5203 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 5204 | // Don't show status bar when swiping on already visible navigation bar |
| 5205 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5206 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5207 | return; |
| 5208 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5209 | if (sb) mStatusBarController.showTransient(); |
| 5210 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5211 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5212 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5213 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5214 | } |
| 5215 | } |
| 5216 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5217 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5218 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame^] | 5219 | public void startedGoingToSleep(int why) { |
| 5220 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
| 5221 | } |
| 5222 | |
| 5223 | // Called on the PowerManager's Notifier thread. |
| 5224 | @Override |
| 5225 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5226 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame^] | 5227 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5228 | |
| 5229 | // We must get this work done here because the power manager will drop |
| 5230 | // 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] | 5231 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5232 | mAwake = false; |
| 5233 | mKeyguardDrawComplete = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5234 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5235 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5236 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5237 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5238 | |
| 5239 | if (mKeyguardDelegate != null) { |
| 5240 | mKeyguardDelegate.onScreenTurnedOff(why); |
| 5241 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5242 | } |
| 5243 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5244 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5245 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame^] | 5246 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5247 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame^] | 5248 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5249 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5250 | // Since goToSleep performs these functions synchronously, we must |
| 5251 | // do the same here. We cannot post this work to a handler because |
| 5252 | // that might cause it to become reordered with respect to what |
| 5253 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5254 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5255 | mAwake = true; |
| 5256 | mKeyguardDrawComplete = false; |
| 5257 | if (mKeyguardDelegate != null) { |
| 5258 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5259 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
| 5260 | } |
| 5261 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5262 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5263 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5264 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5265 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5266 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5267 | if (mKeyguardDelegate != null) { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5268 | mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5269 | // ... eventually calls finishKeyguardDrawn |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5270 | } else { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5271 | if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5272 | finishKeyguardDrawn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5273 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5274 | } |
| 5275 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame^] | 5276 | // Called on the PowerManager's Notifier thread. |
| 5277 | @Override |
| 5278 | public void finishedWakingUp() { |
| 5279 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
| 5280 | } |
| 5281 | |
| 5282 | private void wakeUpFromPowerKey(long eventTime) { |
| 5283 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey); |
| 5284 | } |
| 5285 | |
| 5286 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) { |
| 5287 | if (!wakeInTheaterMode && isTheaterModeEnabled()) { |
| 5288 | return false; |
| 5289 | } |
| 5290 | |
| 5291 | mPowerManager.wakeUp(wakeTime); |
| 5292 | return true; |
| 5293 | } |
| 5294 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5295 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5296 | synchronized (mLock) { |
| 5297 | if (!mAwake || mKeyguardDrawComplete) { |
| 5298 | return; // spurious |
| 5299 | } |
| 5300 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5301 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5302 | if (mKeyguardDelegate != null) { |
| 5303 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5304 | } |
| 5305 | } |
| 5306 | |
| 5307 | finishScreenTurningOn(); |
| 5308 | } |
| 5309 | |
| 5310 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5311 | @Override |
| 5312 | public void screenTurnedOff() { |
| 5313 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 5314 | |
| 5315 | synchronized (mLock) { |
| 5316 | mScreenOnEarly = false; |
| 5317 | mScreenOnFully = false; |
| 5318 | mWindowManagerDrawComplete = false; |
| 5319 | mScreenOnListener = null; |
| 5320 | updateOrientationListenerLp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5321 | } |
| 5322 | } |
| 5323 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5324 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5325 | @Override |
| 5326 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5327 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5328 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5329 | synchronized (mLock) { |
| 5330 | mScreenOnEarly = true; |
| 5331 | mScreenOnFully = false; |
| 5332 | mWindowManagerDrawComplete = false; |
| 5333 | mScreenOnListener = screenOnListener; |
| 5334 | updateOrientationListenerLp(); |
| 5335 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5336 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 5337 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 5338 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5339 | // ... eventually calls finishWindowsDrawn |
| 5340 | } |
| 5341 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5342 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5343 | synchronized (mLock) { |
| 5344 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
| 5345 | return; // spurious |
| 5346 | } |
| 5347 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5348 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5349 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5350 | |
| 5351 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5352 | } |
| 5353 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5354 | private void finishScreenTurningOn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5355 | final ScreenOnListener listener; |
| 5356 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5357 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5358 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5359 | "finishScreenTurningOn: mAwake=" + mAwake |
| 5360 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 5361 | + ", mScreenOnFully=" + mScreenOnFully |
| 5362 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 5363 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 5364 | |
| 5365 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 5366 | || (mAwake && !mKeyguardDrawComplete)) { |
| 5367 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5368 | } |
| 5369 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5370 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 5371 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 5372 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5373 | mScreenOnFully = true; |
| 5374 | |
| 5375 | // Remember the first time we draw the keyguard so we know when we're done with |
| 5376 | // the main part of booting and can enable the screen and hide boot messages. |
| 5377 | if (!mKeyguardDrawnOnce && mAwake) { |
| 5378 | mKeyguardDrawnOnce = true; |
| 5379 | enableScreen = true; |
| 5380 | if (mBootMessageNeedsHiding) { |
| 5381 | mBootMessageNeedsHiding = false; |
| 5382 | hideBootMessages(); |
| 5383 | } |
| 5384 | } else { |
| 5385 | enableScreen = false; |
| 5386 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5389 | if (listener != null) { |
| 5390 | listener.onScreenOn(); |
| 5391 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 5392 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5393 | if (enableScreen) { |
| 5394 | try { |
| 5395 | mWindowManager.enableScreenIfNeeded(); |
| 5396 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5397 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5398 | } |
| 5399 | } |
| 5400 | |
| 5401 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5402 | synchronized (mLock) { |
| 5403 | if (!mKeyguardDrawnOnce) { |
| 5404 | mBootMessageNeedsHiding = true; |
| 5405 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 5406 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5407 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5408 | |
| 5409 | if (mBootMsgDialog != null) { |
| 5410 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 5411 | mBootMsgDialog.dismiss(); |
| 5412 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5413 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5417 | public boolean isScreenOn() { |
| 5418 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5419 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5420 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5421 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5422 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5423 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5424 | if (mKeyguardDelegate != null) { |
| 5425 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5426 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5430 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5431 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5432 | if (mKeyguardDelegate != null) { |
| 5433 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5434 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5435 | } |
| 5436 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5437 | private boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5438 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5439 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5440 | } |
| 5441 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5442 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5443 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5444 | public boolean isKeyguardLocked() { |
| 5445 | return keyguardOn(); |
| 5446 | } |
| 5447 | |
| 5448 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5449 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5450 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5451 | if (mKeyguardDelegate == null) return false; |
| 5452 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5453 | } |
| 5454 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5455 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5456 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5457 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5458 | if (mKeyguardDelegate == null) return false; |
| 5459 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5460 | } |
| 5461 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5462 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5463 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5464 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5465 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5466 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5467 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5468 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 5469 | // ask the keyguard to prompt the user to authenticate if necessary |
| 5470 | mKeyguardDelegate.dismiss(); |
| 5471 | } |
| 5472 | }); |
| 5473 | } |
| 5474 | } |
| 5475 | |
| 5476 | public void notifyActivityDrawnForKeyguardLw() { |
| 5477 | if (mKeyguardDelegate != null) { |
| 5478 | mHandler.post(new Runnable() { |
| 5479 | @Override |
| 5480 | public void run() { |
| 5481 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5482 | } |
| 5483 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5484 | } |
| 5485 | } |
| 5486 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5487 | @Override |
| 5488 | public boolean isKeyguardDrawnLw() { |
| 5489 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5490 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5491 | } |
| 5492 | } |
| 5493 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5494 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5495 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5496 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5497 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5498 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5499 | } |
| 5500 | } |
| 5501 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5502 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5503 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5504 | } |
| 5505 | |
| 5506 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5507 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5508 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 5509 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5510 | @Override |
| 5511 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5512 | if (false) { |
| 5513 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 5514 | + orientation + ", last=" + lastRotation |
| 5515 | + "); user=" + mUserRotation + " " |
| 5516 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 5517 | ? "USER_ROTATION_LOCKED" : "") |
| 5518 | ); |
| 5519 | } |
| 5520 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 5521 | if (mForceDefaultOrientation) { |
| 5522 | return Surface.ROTATION_0; |
| 5523 | } |
| 5524 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5525 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5526 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 5527 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 5528 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5529 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5530 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5531 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5532 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5533 | // Ignore sensor when lid switch is open and rotation is forced. |
| 5534 | preferredRotation = mLidOpenRotation; |
| 5535 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5536 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5537 | // Ignore sensor when in car dock unless explicitly enabled. |
| 5538 | // This case can override the behavior of NOSENSOR, and can also |
| 5539 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5540 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5541 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 5542 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5543 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 5544 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5545 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5546 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 5547 | // This case can override the behavior of NOSENSOR, and can also |
| 5548 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5549 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5550 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5551 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 5552 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 5553 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5554 | preferredRotation = mDemoHdmiRotation; |
| 5555 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 5556 | && mUndockedHdmiRotation >= 0) { |
| 5557 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 5558 | // been specified in the configuration (only for legacy devices without |
| 5559 | // full multi-display support). |
| 5560 | // Note that the dock orientation overrides the HDMI orientation. |
| 5561 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 5562 | } else if (mDemoRotationLock) { |
| 5563 | // Ignore sensor when demo rotation lock is enabled. |
| 5564 | // Note that the dock orientation and HDMI rotation lock override this. |
| 5565 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5566 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 5567 | // Application just wants to remain locked in the last rotation. |
| 5568 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5569 | } else if (!mSupportAutoRotation) { |
| 5570 | // If we don't support auto-rotation then bail out here and ignore |
| 5571 | // the sensor and any rotation lock settings. |
| 5572 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5573 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5574 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5575 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 5576 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 5577 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 5578 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5579 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 5580 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5581 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 5582 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 5583 | // Otherwise, use sensor only if requested by the application or enabled |
| 5584 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5585 | if (mAllowAllRotations < 0) { |
| 5586 | // Can't read this during init() because the context doesn't |
| 5587 | // have display metrics at that time so we cannot determine |
| 5588 | // tablet vs. phone then. |
| 5589 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 5590 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 5591 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5592 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5593 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5594 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5595 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5596 | preferredRotation = sensorRotation; |
| 5597 | } else { |
| 5598 | preferredRotation = lastRotation; |
| 5599 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5600 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 5601 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 5602 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 5603 | // The idea is that the user rotation expresses a weak preference for the direction |
| 5604 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 5605 | // 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] | 5606 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5607 | } else { |
| 5608 | // No overriding preference. |
| 5609 | // We will do exactly what the application asked us to do. |
| 5610 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5611 | } |
| 5612 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5613 | switch (orientation) { |
| 5614 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5615 | // Return portrait unless overridden. |
| 5616 | if (isAnyPortrait(preferredRotation)) { |
| 5617 | return preferredRotation; |
| 5618 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5619 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5620 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5621 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5622 | // Return landscape unless overridden. |
| 5623 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5624 | return preferredRotation; |
| 5625 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5626 | return mLandscapeRotation; |
| 5627 | |
| 5628 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5629 | // Return reverse portrait unless overridden. |
| 5630 | if (isAnyPortrait(preferredRotation)) { |
| 5631 | return preferredRotation; |
| 5632 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5633 | return mUpsideDownRotation; |
| 5634 | |
| 5635 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5636 | // Return seascape unless overridden. |
| 5637 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5638 | return preferredRotation; |
| 5639 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5640 | return mSeascapeRotation; |
| 5641 | |
| 5642 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5643 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5644 | // Return either landscape rotation. |
| 5645 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5646 | return preferredRotation; |
| 5647 | } |
| 5648 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 5649 | return lastRotation; |
| 5650 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5651 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5652 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5653 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5654 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5655 | // Return either portrait rotation. |
| 5656 | if (isAnyPortrait(preferredRotation)) { |
| 5657 | return preferredRotation; |
| 5658 | } |
| 5659 | if (isAnyPortrait(lastRotation)) { |
| 5660 | return lastRotation; |
| 5661 | } |
| 5662 | return mPortraitRotation; |
| 5663 | |
| 5664 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5665 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 5666 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5667 | if (preferredRotation >= 0) { |
| 5668 | return preferredRotation; |
| 5669 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5670 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 5671 | } |
| 5672 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5673 | } |
| 5674 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5675 | @Override |
| 5676 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 5677 | switch (orientation) { |
| 5678 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 5679 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 5680 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 5681 | return isAnyPortrait(rotation); |
| 5682 | |
| 5683 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 5684 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 5685 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 5686 | return isLandscapeOrSeascape(rotation); |
| 5687 | |
| 5688 | default: |
| 5689 | return true; |
| 5690 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5691 | } |
| 5692 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5693 | @Override |
| 5694 | public void setRotationLw(int rotation) { |
| 5695 | mOrientationListener.setCurrentRotation(rotation); |
| 5696 | } |
| 5697 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5698 | private boolean isLandscapeOrSeascape(int rotation) { |
| 5699 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5700 | } |
| 5701 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5702 | private boolean isAnyPortrait(int rotation) { |
| 5703 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5704 | } |
| 5705 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5706 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5707 | public int getUserRotationMode() { |
| 5708 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 5709 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 5710 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 5711 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5712 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5713 | |
| 5714 | // 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] | 5715 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5716 | public void setUserRotationMode(int mode, int rot) { |
| 5717 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5718 | |
| 5719 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5720 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5721 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5722 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5723 | rot, |
| 5724 | UserHandle.USER_CURRENT); |
| 5725 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5726 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5727 | 0, |
| 5728 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5729 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5730 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5731 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5732 | 1, |
| 5733 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5734 | } |
| 5735 | } |
| 5736 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5737 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5738 | public void setSafeMode(boolean safeMode) { |
| 5739 | mSafeMode = safeMode; |
| 5740 | performHapticFeedbackLw(null, safeMode |
| 5741 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 5742 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5743 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5744 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 5745 | static long[] getLongIntArray(Resources r, int resid) { |
| 5746 | int[] ar = r.getIntArray(resid); |
| 5747 | if (ar == null) { |
| 5748 | return null; |
| 5749 | } |
| 5750 | long[] out = new long[ar.length]; |
| 5751 | for (int i=0; i<ar.length; i++) { |
| 5752 | out[i] = ar[i]; |
| 5753 | } |
| 5754 | return out; |
| 5755 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5756 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5757 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5758 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5759 | public void systemReady() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5760 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 5761 | mKeyguardDelegate.onSystemReady(); |
| 5762 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5763 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5764 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5765 | synchronized (mLock) { |
| 5766 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5767 | mSystemReady = true; |
| 5768 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5769 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5770 | public void run() { |
| 5771 | updateSettings(); |
| 5772 | } |
| 5773 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5774 | } |
| 5775 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5776 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5777 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5778 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5779 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5780 | if (mKeyguardDelegate != null) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 5781 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5782 | mKeyguardDelegate.onBootCompleted(); |
| 5783 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5784 | synchronized (mLock) { |
| 5785 | mSystemBooted = true; |
| 5786 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame^] | 5787 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5788 | screenTurningOn(null); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5789 | } |
| 5790 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5791 | ProgressDialog mBootMsgDialog = null; |
| 5792 | |
| 5793 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5794 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5795 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5796 | mHandler.post(new Runnable() { |
| 5797 | @Override public void run() { |
| 5798 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 5799 | int theme; |
| 5800 | if (mContext.getPackageManager().hasSystemFeature( |
| 5801 | PackageManager.FEATURE_WATCH)) { |
| 5802 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 5803 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 5804 | PackageManager.FEATURE_TELEVISION)) { |
| 5805 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 5806 | } else { |
| 5807 | theme = 0; |
| 5808 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 5809 | |
| 5810 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 5811 | // This dialog will consume all events coming in to |
| 5812 | // it, to avoid it trying to do things too early in boot. |
| 5813 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 5814 | return true; |
| 5815 | } |
| 5816 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5817 | return true; |
| 5818 | } |
| 5819 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 5820 | return true; |
| 5821 | } |
| 5822 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 5823 | return true; |
| 5824 | } |
| 5825 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 5826 | return true; |
| 5827 | } |
| 5828 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 5829 | AccessibilityEvent event) { |
| 5830 | return true; |
| 5831 | } |
| 5832 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 5833 | if (mContext.getPackageManager().isUpgrade()) { |
| 5834 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 5835 | } else { |
| 5836 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 5837 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5838 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 5839 | mBootMsgDialog.setIndeterminate(true); |
| 5840 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5841 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5842 | mBootMsgDialog.getWindow().addFlags( |
| 5843 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 5844 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 5845 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 5846 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 5847 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 5848 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5849 | mBootMsgDialog.setCancelable(false); |
| 5850 | mBootMsgDialog.show(); |
| 5851 | } |
| 5852 | mBootMsgDialog.setMessage(msg); |
| 5853 | } |
| 5854 | }); |
| 5855 | } |
| 5856 | |
| 5857 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5858 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5859 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5860 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5861 | } |
| 5862 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5863 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5864 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5865 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5866 | // *************************************** |
| 5867 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 5868 | // *************************************** |
| 5869 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 5870 | // WITH ITS LOCKS HELD. |
| 5871 | // |
| 5872 | // This code must be VERY careful about the locks |
| 5873 | // it acquires. |
| 5874 | // In fact, the current code acquires way too many, |
| 5875 | // and probably has lurking deadlocks. |
| 5876 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5877 | synchronized (mScreenLockTimeout) { |
| 5878 | if (mLockScreenTimerActive) { |
| 5879 | // reset the timer |
| 5880 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5881 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5882 | } |
| 5883 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5884 | } |
| 5885 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5886 | class ScreenLockTimeout implements Runnable { |
| 5887 | Bundle options; |
| 5888 | |
| 5889 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5890 | public void run() { |
| 5891 | synchronized (this) { |
| 5892 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5893 | if (mKeyguardDelegate != null) { |
| 5894 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5895 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5896 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5897 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5898 | } |
| 5899 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5900 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5901 | public void setLockOptions(Bundle options) { |
| 5902 | this.options = options; |
| 5903 | } |
| 5904 | } |
| 5905 | |
| 5906 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 5907 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5908 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5909 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5910 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 5911 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5912 | if (options != null) { |
| 5913 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 5914 | // until the runnable actually executes. |
| 5915 | mScreenLockTimeout.setLockOptions(options); |
| 5916 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5917 | mHandler.post(mScreenLockTimeout); |
| 5918 | } |
| 5919 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5920 | private void updateLockScreenTimeout() { |
| 5921 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5922 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5923 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5924 | if (mLockScreenTimerActive != enable) { |
| 5925 | if (enable) { |
| 5926 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 5927 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5928 | } else { |
| 5929 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 5930 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5931 | } |
| 5932 | mLockScreenTimerActive = enable; |
| 5933 | } |
| 5934 | } |
| 5935 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5936 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 5937 | private void updateDreamingSleepToken(boolean acquire) { |
| 5938 | if (acquire) { |
| 5939 | if (mDreamingSleepToken == null) { |
| 5940 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 5941 | } |
| 5942 | } else { |
| 5943 | if (mDreamingSleepToken != null) { |
| 5944 | mDreamingSleepToken.release(); |
| 5945 | } |
| 5946 | } |
| 5947 | } |
| 5948 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5949 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5950 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5951 | public void enableScreenAfterBoot() { |
| 5952 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5953 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5954 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5955 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 5956 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5957 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5958 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5959 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 5960 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 5961 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5962 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5963 | |
| 5964 | synchronized (mLock) { |
| 5965 | updateWakeGestureListenerLp(); |
| 5966 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5967 | } |
| 5968 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5969 | void updateUiMode() { |
| 5970 | if (mUiModeManager == null) { |
| 5971 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 5972 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5973 | } |
| 5974 | try { |
| 5975 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 5976 | } catch (RemoteException e) { |
| 5977 | } |
| 5978 | } |
| 5979 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5980 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5981 | try { |
| 5982 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5983 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 5984 | } catch (RemoteException e) { |
| 5985 | // Ignore |
| 5986 | } |
| 5987 | } |
| 5988 | |
| 5989 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 5990 | try { |
| 5991 | //set orientation on WindowManager |
| 5992 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5993 | } catch (RemoteException e) { |
| 5994 | // Ignore |
| 5995 | } |
| 5996 | } |
| 5997 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5998 | /** |
| 5999 | * Return an Intent to launch the currently active dock app as home. Returns |
| 6000 | * null if the standard home should be launched, which is the case if any of the following is |
| 6001 | * true: |
| 6002 | * <ul> |
| 6003 | * <li>The device is not in either car mode or desk mode |
| 6004 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 6005 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 6006 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 6007 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 6008 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6009 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6010 | */ |
| 6011 | Intent createHomeDockIntent() { |
| 6012 | Intent intent = null; |
| 6013 | |
| 6014 | // What home does is based on the mode, not the dock state. That |
| 6015 | // is, when in car mode you should be taken to car home regardless |
| 6016 | // of whether we are actually in a car dock. |
| 6017 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 6018 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 6019 | intent = mCarDockIntent; |
| 6020 | } |
| 6021 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 6022 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 6023 | intent = mDeskDockIntent; |
| 6024 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6025 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 6026 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6027 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 6028 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 6029 | // Always launch dock home from home when watch is docked, if it exists. |
| 6030 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | if (intent == null) { |
| 6034 | return null; |
| 6035 | } |
| 6036 | |
| 6037 | ActivityInfo ai = null; |
| 6038 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 6039 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 6040 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6041 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6042 | if (info != null) { |
| 6043 | ai = info.activityInfo; |
| 6044 | } |
| 6045 | if (ai != null |
| 6046 | && ai.metaData != null |
| 6047 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 6048 | intent = new Intent(intent); |
| 6049 | intent.setClassName(ai.packageName, ai.name); |
| 6050 | return intent; |
| 6051 | } |
| 6052 | |
| 6053 | return null; |
| 6054 | } |
| 6055 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6056 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 6057 | if (awakenFromDreams) { |
| 6058 | awakenDreams(); |
| 6059 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6060 | |
| 6061 | Intent dock = createHomeDockIntent(); |
| 6062 | if (dock != null) { |
| 6063 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6064 | if (fromHomeKey) { |
| 6065 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6066 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6067 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6068 | return; |
| 6069 | } catch (ActivityNotFoundException e) { |
| 6070 | } |
| 6071 | } |
| 6072 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6073 | Intent intent; |
| 6074 | |
| 6075 | if (fromHomeKey) { |
| 6076 | intent = new Intent(mHomeIntent); |
| 6077 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6078 | } else { |
| 6079 | intent = mHomeIntent; |
| 6080 | } |
| 6081 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 6082 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6083 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6084 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6085 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6086 | * goes to the home screen |
| 6087 | * @return whether it did anything |
| 6088 | */ |
| 6089 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6090 | if (!isUserSetupComplete()) { |
| 6091 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 6092 | return false; |
| 6093 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6094 | if (false) { |
| 6095 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 6096 | try { |
| 6097 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6098 | } catch (RemoteException e) { |
| 6099 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 6100 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6101 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6102 | } else { |
| 6103 | // This code brings home to the front or, if it is already |
| 6104 | // at the front, puts the device to sleep. |
| 6105 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 6106 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 6107 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 6108 | Log.d(TAG, "UTS-TEST-MODE"); |
| 6109 | } else { |
| 6110 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6111 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6112 | Intent dock = createHomeDockIntent(); |
| 6113 | if (dock != null) { |
| 6114 | int result = ActivityManagerNative.getDefault() |
| 6115 | .startActivityAsUser(null, null, dock, |
| 6116 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6117 | null, null, 0, |
| 6118 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6119 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6120 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 6121 | return false; |
| 6122 | } |
| 6123 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6124 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6125 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6126 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6127 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6128 | null, null, 0, |
| 6129 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6130 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6131 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6132 | return false; |
| 6133 | } |
| 6134 | } catch (RemoteException ex) { |
| 6135 | // bummer, the activity manager, which is in this process, is dead |
| 6136 | } |
| 6137 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6138 | return true; |
| 6139 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6140 | |
| 6141 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6142 | public void setCurrentOrientationLw(int newOrientation) { |
| 6143 | synchronized (mLock) { |
| 6144 | if (newOrientation != mCurrentAppOrientation) { |
| 6145 | mCurrentAppOrientation = newOrientation; |
| 6146 | updateOrientationListenerLp(); |
| 6147 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6148 | } |
| 6149 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6150 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6151 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 6152 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 6153 | return; |
| 6154 | } |
| 6155 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 6156 | Context.AUDIO_SERVICE); |
| 6157 | if (audioManager.isSilentMode()) { |
| 6158 | return; |
| 6159 | } |
| 6160 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 6161 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 6162 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 6163 | ringTone.play(); |
| 6164 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6165 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6166 | private boolean isTheaterModeEnabled() { |
| 6167 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6168 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 6169 | } |
| 6170 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6171 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 6172 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6173 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 6174 | } |
| 6175 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6176 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6177 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 6178 | if (!mVibrator.hasVibrator()) { |
| 6179 | return false; |
| 6180 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6181 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 6182 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 6183 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6184 | return false; |
| 6185 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6186 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6187 | switch (effectId) { |
| 6188 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6189 | pattern = mLongPressVibePattern; |
| 6190 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6191 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6192 | pattern = mVirtualKeyVibePattern; |
| 6193 | break; |
| 6194 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 6195 | pattern = mKeyboardTapVibePattern; |
| 6196 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 6197 | case HapticFeedbackConstants.CLOCK_TICK: |
| 6198 | pattern = mClockTickVibePattern; |
| 6199 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 6200 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 6201 | pattern = mCalendarDateVibePattern; |
| 6202 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6203 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6204 | pattern = mSafeModeDisabledVibePattern; |
| 6205 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6206 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6207 | pattern = mSafeModeEnabledVibePattern; |
| 6208 | break; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 6209 | case HapticFeedbackConstants.STYLUS_BUTTON_PRESS: |
| 6210 | pattern = mStylusButtonPressVibePattern; |
| 6211 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6212 | default: |
| 6213 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6214 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6215 | int owningUid; |
| 6216 | String owningPackage; |
| 6217 | if (win != null) { |
| 6218 | owningUid = win.getOwningUid(); |
| 6219 | owningPackage = win.getOwningPackage(); |
| 6220 | } else { |
| 6221 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 6222 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6223 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6224 | if (pattern.length == 1) { |
| 6225 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6226 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6227 | } else { |
| 6228 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6229 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6230 | } |
| 6231 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6232 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6233 | |
| 6234 | @Override |
| 6235 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6236 | } |
| 6237 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6238 | @Override |
| 6239 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6240 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 6241 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6242 | } |
| 6243 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 6244 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6245 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6246 | // If there is no window focused, there will be nobody to handle the events |
| 6247 | // 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] | 6248 | final WindowState win = mFocusedWindow != null ? mFocusedWindow |
| 6249 | : mTopFullscreenOpaqueWindowState; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6250 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6251 | return 0; |
| 6252 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6253 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6254 | // We are updating at a point where the keyguard has gotten |
| 6255 | // focus, but we were last in a state where the top window is |
| 6256 | // hiding it. This is probably because the keyguard as been |
| 6257 | // shown while the top window was displayed, so we want to ignore |
| 6258 | // it here because this is just a very transient change and it |
| 6259 | // will quickly lose focus once it correctly gets hidden. |
| 6260 | return 0; |
| 6261 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6262 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 6263 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6264 | & ~mResettingSystemUiFlags |
| 6265 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6266 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6267 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6268 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6269 | tmpVisibility = updateLightStatusBarLw(tmpVisibility); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6270 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6271 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6272 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 6273 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6274 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6275 | return 0; |
| 6276 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6277 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6278 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6279 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6280 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6281 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6282 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6283 | try { |
| 6284 | IStatusBarService statusbar = getStatusBarService(); |
| 6285 | if (statusbar != null) { |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 6286 | statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString()); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6287 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6288 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6289 | } catch (RemoteException e) { |
| 6290 | // re-acquire status bar service next time it is needed. |
| 6291 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6292 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6293 | } |
| 6294 | }); |
| 6295 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6296 | } |
| 6297 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6298 | private int updateLightStatusBarLw(int vis) { |
| 6299 | WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6300 | ? mStatusBar |
| 6301 | : mTopFullscreenOpaqueOrDimmingWindowState; |
| 6302 | |
| 6303 | if (statusColorWin != null) { |
| 6304 | if (statusColorWin == mTopFullscreenOpaqueWindowState) { |
| 6305 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 6306 | // its light flag. |
| 6307 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6308 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 6309 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6310 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 6311 | // Otherwise if it's dimming, clear the light flag. |
| 6312 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6313 | } |
| 6314 | } |
| 6315 | return vis; |
| 6316 | } |
| 6317 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6318 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6319 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6320 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6321 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6322 | : mTopFullscreenOpaqueWindowState; |
| 6323 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6324 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6325 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6326 | // prevent status bar interaction from clearing certain flags |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6327 | boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6328 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6329 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 6330 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 6331 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 6332 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 6333 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6334 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6335 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 6336 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6337 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6338 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6339 | |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 6340 | if (!areTranslucentBarsAllowed() && transWin != mStatusBar) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 6341 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 6342 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6343 | } |
| 6344 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6345 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6346 | boolean immersiveSticky = |
| 6347 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6348 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6349 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6350 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6351 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 6352 | boolean hideStatusBarSysui = |
| 6353 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6354 | boolean hideNavBarSysui = |
| 6355 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6356 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6357 | boolean transientStatusBarAllowed = |
| 6358 | mStatusBar != null && ( |
| 6359 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6360 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6361 | || statusBarHasFocus); |
| 6362 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6363 | boolean transientNavBarAllowed = |
| 6364 | mNavigationBar != null && |
| 6365 | hideNavBarSysui && immersiveSticky; |
| 6366 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6367 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6368 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6369 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6370 | && !transientNavBarAllowed; |
| 6371 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6372 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6373 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 6374 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6375 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6376 | |
| 6377 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 6378 | |
| 6379 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6380 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 6381 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 6382 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6383 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6384 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 6385 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6386 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6387 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6388 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 6389 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6390 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6391 | } |
| 6392 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6393 | private void clearClearableFlagsLw() { |
| 6394 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6395 | if (newVal != mResettingSystemUiFlags) { |
| 6396 | mResettingSystemUiFlags = newVal; |
| 6397 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 6398 | } |
| 6399 | } |
| 6400 | |
| 6401 | private boolean isImmersiveMode(int vis) { |
| 6402 | 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] | 6403 | return mNavigationBar != null |
| 6404 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 6405 | && (vis & flags) != 0 |
| 6406 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6407 | } |
| 6408 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6409 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6410 | * @return whether the navigation or status bar can be made translucent |
| 6411 | * |
| 6412 | * This should return true unless touch exploration is not enabled or |
| 6413 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6414 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6415 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 6416 | return mTranslucentDecorEnabled |
| 6417 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6418 | } |
| 6419 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6420 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 6421 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6422 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6423 | public boolean hasNavigationBar() { |
| 6424 | return mHasNavigationBar; |
| 6425 | } |
| 6426 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 6427 | @Override |
| 6428 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 6429 | mLastInputMethodWindow = ime; |
| 6430 | mLastInputMethodTargetWindow = target; |
| 6431 | } |
| 6432 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6433 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 6434 | public int getInputMethodWindowVisibleHeightLw() { |
| 6435 | return mDockBottom - mCurBottom; |
| 6436 | } |
| 6437 | |
| 6438 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6439 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6440 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6441 | if (mKeyguardDelegate != null) { |
| 6442 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6443 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 6444 | if (mStatusBarService != null) { |
| 6445 | try { |
| 6446 | mStatusBarService.setCurrentUser(newUserId); |
| 6447 | } catch (RemoteException e) { |
| 6448 | // oh well |
| 6449 | } |
| 6450 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6451 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6452 | } |
| 6453 | |
| 6454 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 6455 | public boolean canMagnifyWindow(int windowType) { |
| 6456 | switch (windowType) { |
| 6457 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 6458 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 6459 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 6460 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 6461 | return false; |
| 6462 | } |
| 6463 | } |
| 6464 | return true; |
| 6465 | } |
| 6466 | |
| 6467 | @Override |
| 6468 | public boolean isTopLevelWindow(int windowType) { |
| 6469 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 6470 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 6471 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 6472 | } |
| 6473 | return true; |
| 6474 | } |
| 6475 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 6476 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 6477 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6478 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6479 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 6480 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6481 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6482 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6483 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6484 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6485 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 6486 | || mForceClearedSystemUiFlags != 0) { |
| 6487 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 6488 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 6489 | pw.print(" mResettingSystemUiFlags=0x"); |
| 6490 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 6491 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 6492 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6493 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6494 | if (mLastFocusNeedsMenu) { |
| 6495 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 6496 | pw.println(mLastFocusNeedsMenu); |
| 6497 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6498 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 6499 | pw.println(mWakeGestureEnabledSetting); |
| 6500 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6501 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6502 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 6503 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6504 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 6505 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 6506 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 6507 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6508 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6509 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6510 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 6511 | pw.print(mCarDockEnablesAccelerometer); |
| 6512 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 6513 | pw.println(mDeskDockEnablesAccelerometer); |
| 6514 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 6515 | pw.print(mLidKeyboardAccessibility); |
| 6516 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6517 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6518 | pw.print(prefix); |
| 6519 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 6520 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6521 | pw.print(prefix); |
| 6522 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 6523 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6524 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6525 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 6526 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 6527 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 6528 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 6529 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 6530 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 6531 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 6532 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 6533 | pw.print(","); pw.print(mOverscanScreenTop); |
| 6534 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 6535 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 6536 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 6537 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 6538 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 6539 | pw.print(" top="); pw.print(mOverscanTop); |
| 6540 | pw.print(" right="); pw.print(mOverscanRight); |
| 6541 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 6542 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 6543 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 6544 | pw.print(mRestrictedOverscanScreenLeft); |
| 6545 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 6546 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 6547 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6548 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 6549 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 6550 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 6551 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 6552 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 6553 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 6554 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 6555 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 6556 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 6557 | pw.print(","); pw.print(mStableFullscreenTop); |
| 6558 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 6559 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6560 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 6561 | pw.print(","); pw.print(mStableTop); |
| 6562 | pw.print(")-("); pw.print(mStableRight); |
| 6563 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6564 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 6565 | pw.print(","); pw.print(mSystemTop); |
| 6566 | pw.print(")-("); pw.print(mSystemRight); |
| 6567 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6568 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 6569 | pw.print(","); pw.print(mCurTop); |
| 6570 | pw.print(")-("); pw.print(mCurRight); |
| 6571 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 6572 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 6573 | pw.print(","); pw.print(mContentTop); |
| 6574 | pw.print(")-("); pw.print(mContentRight); |
| 6575 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 6576 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 6577 | pw.print(","); pw.print(mVoiceContentTop); |
| 6578 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 6579 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6580 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 6581 | pw.print(","); pw.print(mDockTop); |
| 6582 | pw.print(")-("); pw.print(mDockRight); |
| 6583 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6584 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 6585 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6586 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 6587 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6588 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 6589 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6590 | if (mLastInputMethodWindow != null) { |
| 6591 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 6592 | pw.println(mLastInputMethodWindow); |
| 6593 | } |
| 6594 | if (mLastInputMethodTargetWindow != null) { |
| 6595 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 6596 | pw.println(mLastInputMethodTargetWindow); |
| 6597 | } |
| 6598 | if (mStatusBar != null) { |
| 6599 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 6600 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 6601 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6602 | } |
| 6603 | if (mNavigationBar != null) { |
| 6604 | pw.print(prefix); pw.print("mNavigationBar="); |
| 6605 | pw.println(mNavigationBar); |
| 6606 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6607 | if (mFocusedWindow != null) { |
| 6608 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 6609 | pw.println(mFocusedWindow); |
| 6610 | } |
| 6611 | if (mFocusedApp != null) { |
| 6612 | pw.print(prefix); pw.print("mFocusedApp="); |
| 6613 | pw.println(mFocusedApp); |
| 6614 | } |
| 6615 | if (mWinDismissingKeyguard != null) { |
| 6616 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 6617 | pw.println(mWinDismissingKeyguard); |
| 6618 | } |
| 6619 | if (mTopFullscreenOpaqueWindowState != null) { |
| 6620 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 6621 | pw.println(mTopFullscreenOpaqueWindowState); |
| 6622 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6623 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 6624 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 6625 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 6626 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6627 | if (mForcingShowNavBar) { |
| 6628 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 6629 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 6630 | pw.println(mForcingShowNavBarLayer); |
| 6631 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6632 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6633 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6634 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 6635 | pw.print(" mForceStatusBarFromKeyguard="); |
| 6636 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6637 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 6638 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6639 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 6640 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 6641 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 6642 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 6643 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 6644 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 6645 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 6646 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 6647 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 6648 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 6649 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6650 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 6651 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 6652 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6653 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 6654 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6655 | mStatusBarController.dump(pw, prefix); |
| 6656 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6657 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6658 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6659 | if (mWakeGestureListener != null) { |
| 6660 | mWakeGestureListener.dump(pw, prefix); |
| 6661 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6662 | if (mOrientationListener != null) { |
| 6663 | mOrientationListener.dump(pw, prefix); |
| 6664 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 6665 | if (mBurnInProtectionHelper != null) { |
| 6666 | mBurnInProtectionHelper.dump(prefix, pw); |
| 6667 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6668 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6669 | } |