The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
Jeff Brown | 37df39a9 | 2015-02-25 15:42:31 -0800 | [diff] [blame] | 2 | * Copyright (C) 2006 The Android Open Source Project |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 17 | package com.android.server.policy; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 20 | import android.app.ActivityManagerInternal; |
| 21 | import android.app.ActivityManagerInternal.SleepToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 22 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 23 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 24 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 25 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 26 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 27 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 28 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 29 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 30 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 31 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 32 | import android.content.ContentResolver; |
| 33 | import android.content.Context; |
| 34 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 35 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 36 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 37 | import android.content.pm.ActivityInfo; |
| 38 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 39 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 40 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 41 | import android.content.res.Configuration; |
| 42 | import android.content.res.Resources; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 43 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 44 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 45 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 46 | import android.graphics.Rect; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 47 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 48 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 49 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 50 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 51 | import android.media.Ringtone; |
| 52 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 53 | import android.media.session.MediaSessionLegacyHelper; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 54 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 55 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 56 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 57 | import android.os.Handler; |
| 58 | import android.os.IBinder; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 59 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 60 | import android.os.Message; |
| 61 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 62 | import android.os.PowerManager; |
| 63 | import android.os.RemoteException; |
| 64 | import android.os.ServiceManager; |
| 65 | import android.os.SystemClock; |
| 66 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 67 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 68 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 69 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 70 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 71 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 72 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 73 | import android.service.dreams.DreamService; |
| 74 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 75 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 76 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 77 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 78 | import android.util.EventLog; |
| 79 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 80 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 81 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 82 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 83 | import android.view.Gravity; |
| 84 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 85 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 86 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 87 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 88 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 89 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 90 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 91 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 92 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 93 | import android.view.KeyEvent; |
| 94 | import android.view.MotionEvent; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 95 | import com.android.internal.policy.PhoneWindow; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 96 | import android.view.Surface; |
| 97 | import android.view.View; |
| 98 | import android.view.ViewConfiguration; |
| 99 | import android.view.Window; |
| 100 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 101 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 102 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 103 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 104 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 105 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 106 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 107 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 108 | import android.view.animation.AnimationUtils; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 109 | import com.android.internal.R; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 110 | import com.android.internal.statusbar.IStatusBarService; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 111 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 112 | import com.android.internal.widget.PointerLocationView; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 113 | import com.android.server.LocalServices; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 114 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
| 115 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 116 | |
| 117 | import java.io.File; |
| 118 | import java.io.FileReader; |
| 119 | import java.io.IOException; |
| 120 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 121 | import java.util.HashSet; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 122 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 123 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 124 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 125 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 126 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 127 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 128 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 129 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
| 130 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 131 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 132 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 133 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 134 | * introduces a new method suffix, Lp, for an internal lock of the |
| 135 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 136 | * 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] | 137 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 138 | */ |
| 139 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 140 | static final String TAG = "WindowManager"; |
| 141 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 142 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 143 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_KEYGUARD = false; |
| 145 | static final boolean DEBUG_LAYOUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 146 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 147 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 148 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 149 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 150 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 151 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 152 | // No longer recommended for desk docks; still useful in car docks. |
| 153 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 154 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 155 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 156 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 157 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 158 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 159 | 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] | 160 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 161 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 162 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 163 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 164 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 165 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 166 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 167 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 168 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 169 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 170 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 171 | // These need to match the documentation/constant in |
| 172 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 173 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 174 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 175 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 176 | |
| 177 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 178 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 179 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 180 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 181 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 182 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 183 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 184 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 185 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 186 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 187 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 188 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 189 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 190 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 191 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 192 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 193 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 194 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 195 | /** |
| 196 | * These are the system UI flags that, when changing, can cause the layout |
| 197 | * of the screen to change. |
| 198 | */ |
| 199 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 200 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 201 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 202 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 203 | | View.NAVIGATION_BAR_TRANSLUCENT |
| 204 | | View.SYSTEM_UI_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 205 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 206 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 207 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 208 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 209 | .build(); |
| 210 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 211 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 212 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 213 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 214 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 215 | /** |
| 216 | * Keyguard stuff |
| 217 | */ |
| 218 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 219 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 220 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 221 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 222 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 223 | * |
| 224 | * These are special keys that are used to launch particular kinds of applications, |
| 225 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 226 | * usage page. We don't support quite that many yet... |
| 227 | */ |
| 228 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 229 | static { |
| 230 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 231 | sApplicationLaunchKeyCategories.append( |
| 232 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 233 | sApplicationLaunchKeyCategories.append( |
| 234 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 235 | sApplicationLaunchKeyCategories.append( |
| 236 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 237 | sApplicationLaunchKeyCategories.append( |
| 238 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 239 | sApplicationLaunchKeyCategories.append( |
| 240 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 241 | sApplicationLaunchKeyCategories.append( |
| 242 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 243 | } |
| 244 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 245 | /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ |
| 246 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
| 247 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 248 | /** |
| 249 | * Lock protecting internal state. Must not call out into window |
| 250 | * manager with lock held. (This lock will be acquired in places |
| 251 | * where the window manager is calling in with its own lock held.) |
| 252 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 253 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 254 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 255 | Context mContext; |
| 256 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 257 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 258 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 259 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 260 | ActivityManagerInternal mActivityManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 261 | DreamManagerInternal mDreamManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 262 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 263 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 264 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 265 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 266 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 267 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 268 | BurnInProtectionHelper mBurnInProtectionHelper; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 269 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 270 | // Vibrator pattern for haptic feedback of a long press. |
| 271 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 272 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 273 | // Vibrator pattern for haptic feedback of virtual key press. |
| 274 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 275 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 276 | // Vibrator pattern for a short vibration. |
| 277 | long[] mKeyboardTapVibePattern; |
| 278 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 279 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 280 | long[] mClockTickVibePattern; |
| 281 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 282 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 283 | long[] mCalendarDateVibePattern; |
| 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 disabled. |
| 286 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 287 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 288 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 289 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 290 | |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame^] | 291 | // Vibrator pattern for haptic feedback of a context click. |
| 292 | long[] mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 293 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 294 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 295 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 296 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 297 | boolean mSafeMode; |
| 298 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 299 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 300 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 301 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 302 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 303 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 304 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 305 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 306 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 307 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 308 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 309 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 310 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 311 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 312 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 313 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 314 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 315 | } |
| 316 | }; |
| 317 | final ShowListener mKeyguardDelegateCallback = new ShowListener() { |
| 318 | @Override |
| 319 | public void onShown(IBinder windowToken) { |
| 320 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown."); |
| 321 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 322 | } |
| 323 | }; |
| 324 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 325 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 326 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 327 | WindowState mLastInputMethodWindow = null; |
| 328 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 329 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 330 | // FIXME This state is shared between the input reader and handler thread. |
| 331 | // Technically it's broken and buggy but it has been like this for many years |
| 332 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 333 | // so that only one thread is involved in handling input policy. Unfortunately |
| 334 | // it's on a critical path for power management so we can't just post the work to the |
| 335 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 336 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 337 | volatile boolean mPowerKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 338 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 339 | volatile int mPowerKeyPressCounter; |
| 340 | volatile boolean mEndCallKeyHandled; |
| 341 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 342 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 343 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 344 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 345 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 346 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 347 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 348 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 349 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 350 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 351 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 352 | boolean mHdmiPlugged; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 353 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 354 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 355 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 356 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 357 | int mCarDockRotation; |
| 358 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 359 | int mUndockedHdmiRotation; |
| 360 | int mDemoHdmiRotation; |
| 361 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 362 | int mDemoRotation; |
| 363 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 364 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 365 | boolean mWakeGestureEnabledSetting; |
| 366 | MyWakeGestureListener mWakeGestureListener; |
| 367 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 368 | // Default display does not rotate, apps that require non-default orientation will have to |
| 369 | // have the orientation emulated. |
| 370 | private boolean mForceDefaultOrientation = false; |
| 371 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 372 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 373 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 374 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 375 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 376 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 377 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 378 | boolean mCarDockEnablesAccelerometer; |
| 379 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 380 | int mLidKeyboardAccessibility; |
| 381 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 382 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 383 | int mShortPressOnPowerBehavior; |
| 384 | int mLongPressOnPowerBehavior; |
| 385 | int mDoublePressOnPowerBehavior; |
| 386 | int mTriplePressOnPowerBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 387 | int mShortPressOnSleepBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 388 | boolean mAwake; |
| 389 | boolean mScreenOnEarly; |
| 390 | boolean mScreenOnFully; |
| 391 | ScreenOnListener mScreenOnListener; |
| 392 | boolean mKeyguardDrawComplete; |
| 393 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 394 | boolean mOrientationSensorEnabled = false; |
| 395 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 396 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 397 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 398 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 399 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 400 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 401 | |
| 402 | // The last window we were told about in focusChanged. |
| 403 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 404 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 405 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 406 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 407 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 408 | // The current size of the screen; really; extends into the overscan area of |
| 409 | // the screen and doesn't account for any system elements like the status bar. |
| 410 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 411 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 412 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 413 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 414 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 415 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 416 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 417 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 418 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 419 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 420 | // if the status bar can't be hidden; in that case it effectively carves out |
| 421 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 422 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 423 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 424 | // During layout, the current screen borders accounting for any currently |
| 425 | // visible system UI elements. |
| 426 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 427 | // For applications requesting stable content insets, these are them. |
| 428 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 429 | // For applications requesting stable content insets but have also set the |
| 430 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 431 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 432 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 433 | // During layout, the current screen borders with all outer decoration |
| 434 | // (status bar, input method dock) accounted for. |
| 435 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 436 | // During layout, the frame in which content should be displayed |
| 437 | // to the user, accounting for all screen decoration except for any |
| 438 | // space they deem as available for other content. This is usually |
| 439 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 440 | // content insets. |
| 441 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 442 | // During layout, the frame in which voice content should be displayed |
| 443 | // to the user, accounting for all screen decoration except for any |
| 444 | // space they deem as available for other content. |
| 445 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 446 | // 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] | 447 | // windows are placed. |
| 448 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 449 | // During layout, the layer at which the doc window is placed. |
| 450 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 451 | // During layout, this is the layer of the status bar. |
| 452 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 453 | int mLastSystemUiFlags; |
| 454 | // Bits that we are in the process of clearing, so we want to prevent |
| 455 | // them from being set by applications until everything has been updated |
| 456 | // to have them clear. |
| 457 | int mResettingSystemUiFlags = 0; |
| 458 | // Bits that we are currently always keeping cleared. |
| 459 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 460 | // What we last reported to system UI about whether the compatibility |
| 461 | // menu needs to be displayed. |
| 462 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 463 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 464 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 465 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 466 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 467 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 468 | static final Rect mTmpParentFrame = new Rect(); |
| 469 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 470 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 471 | static final Rect mTmpContentFrame = new Rect(); |
| 472 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 473 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 474 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 475 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 476 | static final Rect mTmpOutsetFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 477 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 478 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 479 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 480 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 481 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 482 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 483 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 484 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 485 | private boolean mForceStatusBarTransparent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 486 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 487 | boolean mForcingShowNavBar; |
| 488 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 489 | |
| 490 | // States of keyguard dismiss. |
| 491 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 492 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 493 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 494 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 495 | |
| 496 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 497 | * be done once per window. */ |
| 498 | private WindowState mWinDismissingKeyguard; |
| 499 | |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 500 | /** When window is currently dismissing the keyguard, dismissing the keyguard must handle |
| 501 | * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN |
| 502 | * lock SIM card. This variable is used to record the previous keyguard secure state for |
| 503 | * monitoring secure state change on window dismissing keyguard. */ |
| 504 | private boolean mSecureDismissingKeyguard; |
| 505 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 506 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 507 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 508 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 509 | * the wallpaper. */ |
| 510 | private WindowState mWinShowWhenLocked; |
| 511 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 512 | boolean mShowingLockscreen; |
| 513 | boolean mShowingDream; |
| 514 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 515 | boolean mDreamingSleepTokenNeeded; |
| 516 | SleepToken mDreamingSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 517 | boolean mKeyguardSecure; |
| 518 | boolean mKeyguardSecureIncludingHidden; |
| 519 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 520 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 521 | boolean mHomeConsumed; |
| 522 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 523 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 524 | Intent mCarDockIntent; |
| 525 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 526 | boolean mSearchKeyShortcutPending; |
| 527 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 528 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 529 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 530 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 531 | // support for activating the lock screen while the screen is on |
| 532 | boolean mAllowLockscreenWhenOn; |
| 533 | int mLockScreenTimeout; |
| 534 | boolean mLockScreenTimerActive; |
| 535 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 536 | // 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] | 537 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 538 | |
| 539 | // Behavior of POWER button while in-call and screen on. |
| 540 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 541 | int mIncallPowerBehavior; |
| 542 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 543 | Display mDisplay; |
| 544 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 545 | int mLandscapeRotation = 0; // default landscape rotation |
| 546 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 547 | int mPortraitRotation = 0; // default portrait rotation |
| 548 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 549 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 550 | int mOverscanLeft = 0; |
| 551 | int mOverscanTop = 0; |
| 552 | int mOverscanRight = 0; |
| 553 | int mOverscanBottom = 0; |
| 554 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 555 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 556 | private int mLongPressOnHomeBehavior; |
| 557 | |
| 558 | // What we do when the user double-taps on home |
| 559 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 560 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 561 | // Allowed theater mode wake actions |
| 562 | private boolean mAllowTheaterModeWakeFromKey; |
| 563 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 564 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 565 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 566 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 567 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 568 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 569 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 570 | // Whether to support long press from power button in non-interactive mode |
| 571 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 572 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 573 | // Whether to go to sleep entering theater mode from power button |
| 574 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 575 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 576 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 577 | // Time to volume and power must be pressed within this interval of each other. |
| 578 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 579 | // Increase the chord delay when taking a screenshot from the keyguard |
| 580 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 581 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 582 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 583 | private long mScreenshotChordVolumeDownKeyTime; |
| 584 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 585 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 586 | private boolean mScreenshotChordPowerKeyTriggered; |
| 587 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 588 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 589 | /* The number of steps between min and max brightness */ |
| 590 | private static final int BRIGHTNESS_STEPS = 10; |
| 591 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 592 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 593 | ShortcutManager mShortcutManager; |
| 594 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 595 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 596 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 597 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 598 | private int mCurrentUserId; |
| 599 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 600 | // Maps global key codes to the components that will handle them. |
| 601 | private GlobalKeyManager mGlobalKeyManager; |
| 602 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 603 | // Fallback actions by key code. |
| 604 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 605 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 606 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 607 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 608 | = new LogDecelerateInterpolator(100, 0); |
| 609 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 610 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 611 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 612 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 613 | 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] | 614 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 615 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 616 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 617 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 618 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 619 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 620 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 621 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 622 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 623 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 624 | |
| 625 | private class PolicyHandler extends Handler { |
| 626 | @Override |
| 627 | public void handleMessage(Message msg) { |
| 628 | switch (msg.what) { |
| 629 | case MSG_ENABLE_POINTER_LOCATION: |
| 630 | enablePointerLocation(); |
| 631 | break; |
| 632 | case MSG_DISABLE_POINTER_LOCATION: |
| 633 | disablePointerLocation(); |
| 634 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 635 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 636 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 637 | break; |
| 638 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 639 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 640 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 641 | case MSG_DISPATCH_SHOW_RECENTS: |
| 642 | showRecentApps(false); |
| 643 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 644 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 645 | showGlobalActionsInternal(); |
| 646 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 647 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 648 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 649 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 650 | break; |
| 651 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 652 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 653 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 654 | break; |
| 655 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 656 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 657 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 658 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 659 | case MSG_HIDE_BOOT_MESSAGE: |
| 660 | handleHideBootMessage(); |
| 661 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 662 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 663 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 664 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 665 | case MSG_POWER_DELAYED_PRESS: |
| 666 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 667 | finishPowerKeyPress(); |
| 668 | break; |
| 669 | case MSG_POWER_LONG_PRESS: |
| 670 | powerLongPress(); |
| 671 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 672 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 673 | updateDreamingSleepToken(msg.arg1 != 0); |
| 674 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | } |
| 678 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 679 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 680 | @Override |
| 681 | public void onUEvent(UEventObserver.UEvent event) { |
| 682 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 683 | } |
| 684 | }; |
| 685 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 686 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 687 | SettingsObserver(Handler handler) { |
| 688 | super(handler); |
| 689 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 690 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 691 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 692 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 693 | ContentResolver resolver = mContext.getContentResolver(); |
| 694 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 695 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 696 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 697 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 698 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 699 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 700 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 701 | Settings.Secure.WAKE_GESTURE_ENABLED), 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.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 704 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 705 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 706 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 707 | Settings.System.USER_ROTATION), false, this, |
| 708 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 709 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 710 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 711 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 712 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 713 | Settings.System.POINTER_LOCATION), false, this, |
| 714 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 715 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 716 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 717 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 718 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 719 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 720 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 721 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 722 | Settings.Global.POLICY_CONTROL), false, this, |
| 723 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 724 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 728 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 729 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 730 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 731 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 732 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 733 | class MyWakeGestureListener extends WakeGestureListener { |
| 734 | MyWakeGestureListener(Context context, Handler handler) { |
| 735 | super(context, handler); |
| 736 | } |
| 737 | |
| 738 | @Override |
| 739 | public void onWakeUp() { |
| 740 | synchronized (mLock) { |
| 741 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 742 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 743 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 749 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 750 | MyOrientationListener(Context context, Handler handler) { |
| 751 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 752 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 753 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 754 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 755 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 756 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 757 | updateRotation(false); |
| 758 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 759 | } |
| 760 | MyOrientationListener mOrientationListener; |
| 761 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 762 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 763 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 764 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 765 | View.NAVIGATION_BAR_TRANSIENT, |
| 766 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 767 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 768 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 769 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 770 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 771 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 772 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 773 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 774 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 775 | IStatusBarService getStatusBarService() { |
| 776 | synchronized (mServiceAquireLock) { |
| 777 | if (mStatusBarService == null) { |
| 778 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 779 | ServiceManager.getService("statusbar")); |
| 780 | } |
| 781 | return mStatusBarService; |
| 782 | } |
| 783 | } |
| 784 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 785 | /* |
| 786 | * We always let the sensor be switched on by default except when |
| 787 | * the user has explicitly disabled sensor based rotation or when the |
| 788 | * screen is switched off. |
| 789 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 790 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 791 | if (mSupportAutoRotation) { |
| 792 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 793 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 794 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 795 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 796 | // If the application has explicitly requested to follow the |
| 797 | // orientation, then we need to turn the sensor on. |
| 798 | return true; |
| 799 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 800 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 801 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 802 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 803 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 804 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 805 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 806 | // orientation management, |
| 807 | return true; |
| 808 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 809 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 810 | // If the setting for using the sensor by default is enabled, then |
| 811 | // we will always leave it on. Note that the user could go to |
| 812 | // a window that forces an orientation that does not use the |
| 813 | // sensor and in theory we could turn it off... however, when next |
| 814 | // turning it on we won't have a good value for the current |
| 815 | // orientation for a little bit, which can cause orientation |
| 816 | // changes to lag, so we'd like to keep it always on. (It will |
| 817 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 818 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 819 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 820 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 821 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 822 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 823 | /* |
| 824 | * Various use cases for invoking this function |
| 825 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 826 | * 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] | 827 | * if not already enabled |
| 828 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 829 | * already enabled |
| 830 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 831 | * screen turning on and current app has nosensor based orientation, do nothing |
| 832 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 833 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 834 | if (!mOrientationListener.canDetectOrientation()) { |
| 835 | // If sensor is turned off or nonexistent for some reason |
| 836 | return; |
| 837 | } |
| 838 | //Could have been invoked due to screen turning on or off or |
| 839 | //change of the currently visible window's orientation |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 840 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 841 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
| 842 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 843 | boolean disable = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 844 | if (mScreenOnEarly && mAwake) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 845 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 846 | disable = false; |
| 847 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 848 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 849 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 850 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 851 | mOrientationSensorEnabled = true; |
| 852 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 853 | } |
| 854 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 855 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 856 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 857 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 858 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 859 | mOrientationSensorEnabled = false; |
| 860 | } |
| 861 | } |
| 862 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 863 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 864 | // Hold a wake lock until the power key is released. |
| 865 | if (!mPowerKeyWakeLock.isHeld()) { |
| 866 | mPowerKeyWakeLock.acquire(); |
| 867 | } |
| 868 | |
| 869 | // Cancel multi-press detection timeout. |
| 870 | if (mPowerKeyPressCounter != 0) { |
| 871 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 872 | } |
| 873 | |
| 874 | // Detect user pressing the power button in panic when an application has |
| 875 | // taken over the whole screen. |
| 876 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Craig Mautner | 0124980e9 | 2014-11-30 21:15:34 -0800 | [diff] [blame] | 877 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 878 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 879 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | // Latch power key state to detect screenshot chord. |
| 883 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 884 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 885 | mScreenshotChordPowerKeyTriggered = true; |
| 886 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 887 | interceptScreenshotChord(); |
| 888 | } |
| 889 | |
| 890 | // Stop ringing or end call if configured to do so when power is pressed. |
| 891 | TelecomManager telecomManager = getTelecommService(); |
| 892 | boolean hungUp = false; |
| 893 | if (telecomManager != null) { |
| 894 | if (telecomManager.isRinging()) { |
| 895 | // Pressing Power while there's a ringing incoming |
| 896 | // call should silence the ringer. |
| 897 | telecomManager.silenceRinger(); |
| 898 | } else if ((mIncallPowerBehavior |
| 899 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 900 | && telecomManager.isInCall() && interactive) { |
| 901 | // Otherwise, if "Power button ends call" is enabled, |
| 902 | // the Power button will hang up any current active call. |
| 903 | hungUp = telecomManager.endCall(); |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | // If the power key has still not yet been handled, then detect short |
| 908 | // press, long press, or multi press and decide what to do. |
| 909 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
| 910 | || mScreenshotChordVolumeUpKeyTriggered; |
| 911 | if (!mPowerKeyHandled) { |
| 912 | if (interactive) { |
| 913 | // When interactive, we're already awake. |
| 914 | // Wait for a long press or for the button to be released to decide what to do. |
| 915 | if (hasLongPressOnPowerBehavior()) { |
| 916 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 917 | msg.setAsynchronous(true); |
| 918 | mHandler.sendMessageDelayed(msg, |
| 919 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 920 | } |
| 921 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 922 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 923 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 924 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 925 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 926 | msg.setAsynchronous(true); |
| 927 | mHandler.sendMessageDelayed(msg, |
| 928 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 929 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 930 | } else { |
| 931 | final int maxCount = getMaxMultiPressPowerCount(); |
| 932 | |
| 933 | if (maxCount <= 1) { |
| 934 | mPowerKeyHandled = true; |
| 935 | } else { |
| 936 | mBeganFromNonInteractive = true; |
| 937 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 938 | } |
| 939 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 943 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 944 | final boolean handled = canceled || mPowerKeyHandled; |
| 945 | mScreenshotChordPowerKeyTriggered = false; |
| 946 | cancelPendingScreenshotChordAction(); |
| 947 | cancelPendingPowerKeyAction(); |
| 948 | |
| 949 | if (!handled) { |
| 950 | // Figure out how to handle the key now that it has been released. |
| 951 | mPowerKeyPressCounter += 1; |
| 952 | |
| 953 | final int maxCount = getMaxMultiPressPowerCount(); |
| 954 | final long eventTime = event.getDownTime(); |
| 955 | if (mPowerKeyPressCounter < maxCount) { |
| 956 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 957 | // Continue holding the wake lock. |
| 958 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 959 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 960 | msg.setAsynchronous(true); |
| 961 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 962 | return; |
| 963 | } |
| 964 | |
| 965 | // No other actions. Handle it immediately. |
| 966 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 967 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 968 | |
| 969 | // Done. Reset our state. |
| 970 | finishPowerKeyPress(); |
| 971 | } |
| 972 | |
| 973 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 974 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 975 | mPowerKeyPressCounter = 0; |
| 976 | if (mPowerKeyWakeLock.isHeld()) { |
| 977 | mPowerKeyWakeLock.release(); |
| 978 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | private void cancelPendingPowerKeyAction() { |
| 982 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 983 | mPowerKeyHandled = true; |
| 984 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 985 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 989 | if (mScreenOnEarly && !mScreenOnFully) { |
| 990 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 991 | + "already in the process of turning the screen on."); |
| 992 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 993 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 994 | |
| 995 | if (count == 2) { |
| 996 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 997 | } else if (count == 3) { |
| 998 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 999 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1000 | switch (mShortPressOnPowerBehavior) { |
| 1001 | case SHORT_PRESS_POWER_NOTHING: |
| 1002 | break; |
| 1003 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 1004 | mPowerManager.goToSleep(eventTime, |
| 1005 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1006 | break; |
| 1007 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1008 | mPowerManager.goToSleep(eventTime, |
| 1009 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1010 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1011 | break; |
| 1012 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1013 | mPowerManager.goToSleep(eventTime, |
| 1014 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1015 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1016 | launchHomeFromHotKey(); |
| 1017 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1018 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1019 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1020 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1026 | switch (behavior) { |
| 1027 | case MULTI_PRESS_POWER_NOTHING: |
| 1028 | break; |
| 1029 | case MULTI_PRESS_POWER_THEATER_MODE: |
| 1030 | if (isTheaterModeEnabled()) { |
| 1031 | Slog.i(TAG, "Toggling theater mode off."); |
| 1032 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1033 | Settings.Global.THEATER_MODE_ON, 0); |
| 1034 | if (!interactive) { |
| 1035 | wakeUpFromPowerKey(eventTime); |
| 1036 | } |
| 1037 | } else { |
| 1038 | Slog.i(TAG, "Toggling theater mode on."); |
| 1039 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1040 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1041 | |
| 1042 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1043 | mPowerManager.goToSleep(eventTime, |
| 1044 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1045 | } |
| 1046 | } |
| 1047 | break; |
| 1048 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1049 | Slog.i(TAG, "Starting brightness boost."); |
| 1050 | if (!interactive) { |
| 1051 | wakeUpFromPowerKey(eventTime); |
| 1052 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1053 | mPowerManager.boostScreenBrightness(eventTime); |
| 1054 | break; |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | private int getMaxMultiPressPowerCount() { |
| 1059 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1060 | return 3; |
| 1061 | } |
| 1062 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1063 | return 2; |
| 1064 | } |
| 1065 | return 1; |
| 1066 | } |
| 1067 | |
| 1068 | private void powerLongPress() { |
| 1069 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1070 | switch (behavior) { |
| 1071 | case LONG_PRESS_POWER_NOTHING: |
| 1072 | break; |
| 1073 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1074 | mPowerKeyHandled = true; |
| 1075 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1076 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1077 | } |
| 1078 | showGlobalActionsInternal(); |
| 1079 | break; |
| 1080 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1081 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1082 | mPowerKeyHandled = true; |
| 1083 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1084 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1085 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1086 | break; |
| 1087 | } |
| 1088 | } |
| 1089 | |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1090 | private void sleepPress(long eventTime) { |
| 1091 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1092 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1097 | switch (mShortPressOnSleepBehavior) { |
| 1098 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1099 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1100 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
| 1101 | mPowerManager.goToSleep(eventTime, |
| 1102 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1103 | break; |
| 1104 | } |
| 1105 | } |
| 1106 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1107 | private int getResolvedLongPressOnPowerBehavior() { |
| 1108 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1109 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1110 | } |
| 1111 | return mLongPressOnPowerBehavior; |
| 1112 | } |
| 1113 | |
| 1114 | private boolean hasLongPressOnPowerBehavior() { |
| 1115 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1119 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1120 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1121 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1122 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1123 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1124 | && now <= mScreenshotChordPowerKeyTime |
| 1125 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1126 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1127 | cancelPendingPowerKeyAction(); |
| 1128 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1129 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1130 | } |
| 1131 | } |
| 1132 | } |
| 1133 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1134 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1135 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1136 | // Double the time it takes to take a screenshot from the keyguard |
| 1137 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1138 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1139 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1140 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1143 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1144 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1147 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1148 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1149 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1150 | mEndCallKeyHandled = true; |
| 1151 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1152 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1153 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1154 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1155 | } |
| 1156 | }; |
| 1157 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1158 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1159 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1160 | public void run() { |
| 1161 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1162 | } |
| 1163 | }; |
| 1164 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1165 | @Override |
| 1166 | public void showGlobalActions() { |
| 1167 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1168 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1169 | } |
| 1170 | |
| 1171 | void showGlobalActionsInternal() { |
| 1172 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1173 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1174 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1175 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1176 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1177 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1178 | if (keyguardShowing) { |
| 1179 | // since it took two seconds of long press to bring this up, |
| 1180 | // 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] | 1181 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1186 | return Settings.Global.getInt( |
| 1187 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1188 | } |
| 1189 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1190 | boolean isUserSetupComplete() { |
| 1191 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1192 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1193 | } |
| 1194 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1195 | private void handleShortPressOnHome() { |
| 1196 | // If there's a dream running then use home to escape the dream |
| 1197 | // but don't actually go home. |
| 1198 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1199 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1200 | return; |
| 1201 | } |
| 1202 | |
| 1203 | // Go home! |
| 1204 | launchHomeFromHotKey(); |
| 1205 | } |
| 1206 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1207 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1208 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1209 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1210 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1211 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1212 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 1213 | toggleRecentApps(); |
| 1214 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 1215 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1216 | } |
| 1217 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1218 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1219 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1220 | private void handleDoubleTapOnHome() { |
| 1221 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1222 | mHomeConsumed = true; |
| 1223 | toggleRecentApps(); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1228 | @Override |
| 1229 | public void run() { |
| 1230 | if (mHomeDoubleTapPending) { |
| 1231 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1232 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | }; |
| 1236 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1237 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1238 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1239 | } |
| 1240 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1241 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1242 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1243 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1244 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1245 | mContext = context; |
| 1246 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1247 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1248 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1249 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1250 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1251 | |
| 1252 | // Init display burn-in protection |
| 1253 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1254 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1255 | // Allow a system property to override this. Used by developer settings. |
| 1256 | boolean burnInProtectionDevMode = |
| 1257 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1258 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1259 | final int minHorizontal; |
| 1260 | final int maxHorizontal; |
| 1261 | final int minVertical; |
| 1262 | final int maxVertical; |
| 1263 | final int maxRadius; |
| 1264 | if (burnInProtectionDevMode) { |
| 1265 | minHorizontal = -8; |
| 1266 | maxHorizontal = 8; |
| 1267 | minVertical = -8; |
| 1268 | maxVertical = -4; |
| 1269 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1270 | } else { |
| 1271 | Resources resources = context.getResources(); |
| 1272 | minHorizontal = resources.getInteger( |
| 1273 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1274 | maxHorizontal = resources.getInteger( |
| 1275 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1276 | minVertical = resources.getInteger( |
| 1277 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1278 | maxVertical = resources.getInteger( |
| 1279 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1280 | maxRadius = resources.getInteger( |
| 1281 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1282 | } |
| 1283 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1284 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1285 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1286 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1287 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1288 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1289 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1290 | try { |
| 1291 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1292 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1293 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1294 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1295 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1296 | mUiMode = context.getResources().getInteger( |
| 1297 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1298 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1299 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1300 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1301 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1302 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1303 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1304 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1305 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1306 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1307 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1308 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1309 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1310 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1311 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1312 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1313 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1314 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1315 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1316 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1317 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1318 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1319 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1320 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1321 | mCarDockRotation = readRotation( |
| 1322 | com.android.internal.R.integer.config_carDockRotation); |
| 1323 | mDeskDockRotation = readRotation( |
| 1324 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1325 | mUndockedHdmiRotation = readRotation( |
| 1326 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1327 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1328 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1329 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1330 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1331 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1332 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1333 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1334 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1335 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1336 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1337 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1338 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1339 | |
| 1340 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1341 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1342 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1343 | || mContext.getResources().getBoolean( |
| 1344 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1345 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1346 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1347 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1348 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1349 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1350 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1351 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1352 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1353 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1354 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1355 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1356 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1357 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1358 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1359 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1360 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1361 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1362 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1363 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1364 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1365 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1366 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1367 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1368 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1369 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1370 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1371 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1372 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1373 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1374 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1375 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1376 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1377 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1378 | Context.ACCESSIBILITY_SERVICE); |
| 1379 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1380 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1381 | IntentFilter filter = new IntentFilter(); |
| 1382 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1383 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1384 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1385 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1386 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1387 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1388 | if (intent != null) { |
| 1389 | // Retrieve current sticky dock event broadcast. |
| 1390 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1391 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1392 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1393 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1394 | // register for dream-related broadcasts |
| 1395 | filter = new IntentFilter(); |
| 1396 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1397 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1398 | context.registerReceiver(mDreamReceiver, filter); |
| 1399 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1400 | // register for multiuser-relevant broadcasts |
| 1401 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1402 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1403 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1404 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1405 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1406 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1407 | @Override |
| 1408 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1409 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1410 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1411 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1412 | } |
| 1413 | @Override |
| 1414 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1415 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1416 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | @Override |
| 1420 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1421 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1422 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | @Override |
| 1426 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1427 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1428 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1429 | @Override |
| 1430 | public void onDown() { |
| 1431 | mOrientationListener.onTouchStart(); |
| 1432 | } |
| 1433 | @Override |
| 1434 | public void onUpOrCancel() { |
| 1435 | mOrientationListener.onTouchEnd(); |
| 1436 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1437 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1438 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1439 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1440 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1441 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1442 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1443 | com.android.internal.R.array.config_longPressVibePattern); |
| 1444 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1445 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1446 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1447 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1448 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1449 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1450 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1451 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1452 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1453 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1454 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1455 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame^] | 1456 | mContextClickVibePattern = getLongIntArray(mContext.getResources(), |
| 1457 | com.android.internal.R.array.config_contextClickVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1458 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1459 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1460 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1461 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1462 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1463 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1464 | // Controls rotation and the like. |
| 1465 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1466 | |
| 1467 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1468 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 1469 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 1470 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1471 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1472 | |
| 1473 | mWindowManagerInternal.registerAppTransitionListener( |
| 1474 | mStatusBarController.getAppTransitionListener()); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1477 | /** |
| 1478 | * Read values from config.xml that may be overridden depending on |
| 1479 | * the configuration of the device. |
| 1480 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1481 | */ |
| 1482 | private void readConfigurationDependentBehaviors() { |
| 1483 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1484 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1485 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1486 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1487 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1488 | } |
| 1489 | |
| 1490 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1491 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1492 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1493 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1494 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1495 | } |
| 1496 | } |
| 1497 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1498 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1499 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1500 | // This method might be called before the policy has been fully initialized |
| 1501 | // or for other displays we don't care about. |
| 1502 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1503 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1504 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1505 | mDisplay = display; |
| 1506 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1507 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1508 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1509 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1510 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1511 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1512 | mLandscapeRotation = Surface.ROTATION_0; |
| 1513 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1514 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1515 | mPortraitRotation = Surface.ROTATION_90; |
| 1516 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1517 | } else { |
| 1518 | mPortraitRotation = Surface.ROTATION_270; |
| 1519 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1520 | } |
| 1521 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1522 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1523 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1524 | mPortraitRotation = Surface.ROTATION_0; |
| 1525 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1526 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1527 | mLandscapeRotation = Surface.ROTATION_270; |
| 1528 | mSeascapeRotation = Surface.ROTATION_90; |
| 1529 | } else { |
| 1530 | mLandscapeRotation = Surface.ROTATION_90; |
| 1531 | mSeascapeRotation = Surface.ROTATION_270; |
| 1532 | } |
| 1533 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1534 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1535 | mStatusBarHeight = |
| 1536 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1537 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1538 | // Height of the navigation bar when presented horizontally at bottom |
| 1539 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1540 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1541 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1542 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1543 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1544 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1545 | |
| 1546 | // Width of the navigation bar when presented vertically along one side |
| 1547 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1548 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1549 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1550 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1551 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1552 | |
| 1553 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1554 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1555 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1556 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 1557 | // Allow the navigation bar to move on non-square small devices (phones). |
| 1558 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1559 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1560 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1561 | // Allow a system property to override this. Used by the emulator. |
| 1562 | // See also hasNavigationBar(). |
| 1563 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1564 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1565 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1566 | } else if ("0".equals(navBarOverride)) { |
| 1567 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1568 | } |
| 1569 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1570 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1571 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1572 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1573 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1574 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1575 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1576 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1577 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1578 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 1579 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 1580 | // By default, remote display locks rotation to landscape. |
| 1581 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 1582 | mDemoRotation = mPortraitRotation; |
| 1583 | } else { |
| 1584 | mDemoRotation = mLandscapeRotation; |
| 1585 | } |
| 1586 | mDemoRotationLock = SystemProperties.getBoolean( |
| 1587 | "persist.demo.rotationlock", false); |
| 1588 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1589 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1590 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1591 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1592 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1593 | // For debug purposes the next line turns this feature off with: |
| 1594 | // $ adb shell setprop config.override_forced_orient true |
| 1595 | // $ adb shell wm size reset |
| 1596 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1597 | } |
| 1598 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1599 | /** |
| 1600 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1601 | * navigation bar and touch exploration is not enabled |
| 1602 | */ |
| 1603 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1604 | return mHasNavigationBar |
| 1605 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1608 | @Override |
| 1609 | public boolean isDefaultOrientationForced() { |
| 1610 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1613 | @Override |
| 1614 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1615 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1616 | mOverscanLeft = left; |
| 1617 | mOverscanTop = top; |
| 1618 | mOverscanRight = right; |
| 1619 | mOverscanBottom = bottom; |
| 1620 | } |
| 1621 | } |
| 1622 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1623 | public void updateSettings() { |
| 1624 | ContentResolver resolver = mContext.getContentResolver(); |
| 1625 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1626 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1627 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1628 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1629 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1630 | UserHandle.USER_CURRENT); |
| 1631 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1632 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1633 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1634 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1635 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1636 | // Configure wake gesture. |
| 1637 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1638 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1639 | UserHandle.USER_CURRENT) != 0; |
| 1640 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1641 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1642 | updateWakeGestureListenerLp(); |
| 1643 | } |
| 1644 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1645 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1646 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1647 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1648 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1649 | if (mUserRotation != userRotation) { |
| 1650 | mUserRotation = userRotation; |
| 1651 | updateRotation = true; |
| 1652 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1653 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1654 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1655 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1656 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1657 | if (mUserRotationMode != userRotationMode) { |
| 1658 | mUserRotationMode = userRotationMode; |
| 1659 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1660 | updateOrientationListenerLp(); |
| 1661 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1662 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1663 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1664 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1665 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1666 | if (mPointerLocationMode != pointerLocation) { |
| 1667 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1668 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1669 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1673 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1674 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1675 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1676 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1677 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1678 | if (mHasSoftInput != hasSoftInput) { |
| 1679 | mHasSoftInput = hasSoftInput; |
| 1680 | updateRotation = true; |
| 1681 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1682 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1683 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1684 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1685 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1686 | } |
| 1687 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1688 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1689 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1692 | private void updateWakeGestureListenerLp() { |
| 1693 | if (shouldEnableWakeGestureLp()) { |
| 1694 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1695 | } else { |
| 1696 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1701 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1702 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1703 | && mWakeGestureListener.isSupported(); |
| 1704 | } |
| 1705 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1706 | private void enablePointerLocation() { |
| 1707 | if (mPointerLocationView == null) { |
| 1708 | mPointerLocationView = new PointerLocationView(mContext); |
| 1709 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1710 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1711 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1712 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1713 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1714 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1715 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1716 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1717 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1718 | if (ActivityManager.isHighEndGfx()) { |
| 1719 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1720 | lp.privateFlags |= |
| 1721 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1722 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1723 | lp.format = PixelFormat.TRANSLUCENT; |
| 1724 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1725 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1726 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1727 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1728 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1729 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1730 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1731 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1732 | |
| 1733 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1734 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1735 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1736 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1737 | wm.removeView(mPointerLocationView); |
| 1738 | mPointerLocationView = null; |
| 1739 | } |
| 1740 | } |
| 1741 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1742 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1743 | try { |
| 1744 | int rotation = mContext.getResources().getInteger(resID); |
| 1745 | switch (rotation) { |
| 1746 | case 0: |
| 1747 | return Surface.ROTATION_0; |
| 1748 | case 90: |
| 1749 | return Surface.ROTATION_90; |
| 1750 | case 180: |
| 1751 | return Surface.ROTATION_180; |
| 1752 | case 270: |
| 1753 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1754 | } |
| 1755 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1756 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1757 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1758 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1762 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1763 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1764 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1765 | |
| 1766 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1767 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 1768 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 1769 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 1770 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 1771 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 1772 | } |
| 1773 | |
| 1774 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 1775 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1776 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1777 | } |
| 1778 | String permission = null; |
| 1779 | switch (type) { |
| 1780 | case TYPE_TOAST: |
| 1781 | // XXX right now the app process has complete control over |
| 1782 | // this... should introduce a token to let the system |
| 1783 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1784 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1785 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1786 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1787 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1788 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1789 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1790 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1791 | case TYPE_ACCESSIBILITY_OVERLAY: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1792 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1793 | break; |
| 1794 | case TYPE_PHONE: |
| 1795 | case TYPE_PRIORITY_PHONE: |
| 1796 | case TYPE_SYSTEM_ALERT: |
| 1797 | case TYPE_SYSTEM_ERROR: |
| 1798 | case TYPE_SYSTEM_OVERLAY: |
| 1799 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1800 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1801 | break; |
| 1802 | default: |
| 1803 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1804 | } |
| 1805 | if (permission != null) { |
| 1806 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1807 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1808 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1809 | } |
| 1810 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1811 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1812 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1813 | |
| 1814 | @Override |
| 1815 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1816 | |
| 1817 | // If this switch statement is modified, modify the comment in the declarations of |
| 1818 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1819 | switch (attrs.type) { |
| 1820 | default: |
| 1821 | // These are the windows that by default are shown only to the user that created |
| 1822 | // them. If this needs to be overridden, set |
| 1823 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1824 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1825 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1826 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1827 | return true; |
| 1828 | } |
| 1829 | break; |
| 1830 | |
| 1831 | // These are the windows that by default are shown to all users. However, to |
| 1832 | // protect against spoofing, check permissions below. |
| 1833 | case TYPE_APPLICATION_STARTING: |
| 1834 | case TYPE_BOOT_PROGRESS: |
| 1835 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1836 | case TYPE_INPUT_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1837 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1838 | case TYPE_KEYGUARD_DIALOG: |
| 1839 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1840 | case TYPE_NAVIGATION_BAR: |
| 1841 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1842 | case TYPE_PHONE: |
| 1843 | case TYPE_POINTER: |
| 1844 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1845 | case TYPE_SEARCH_BAR: |
| 1846 | case TYPE_STATUS_BAR: |
| 1847 | case TYPE_STATUS_BAR_PANEL: |
| 1848 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1849 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1850 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1851 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1852 | break; |
| 1853 | } |
| 1854 | |
| 1855 | // Check if third party app has set window to system window type. |
| 1856 | return mContext.checkCallingOrSelfPermission( |
| 1857 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1858 | != PackageManager.PERMISSION_GRANTED; |
| 1859 | } |
| 1860 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1861 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1862 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1863 | switch (attrs.type) { |
| 1864 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1865 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1866 | // These types of windows can't receive input events. |
| 1867 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1868 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1869 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1870 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1871 | case TYPE_STATUS_BAR: |
| 1872 | |
| 1873 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 1874 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 1875 | // the keyguard as occluded wouldn't set these flags again. |
| 1876 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 1877 | if (mKeyguardHidden) { |
| 1878 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 1879 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1880 | } |
| 1881 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1882 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 1883 | |
| 1884 | if (attrs.type != TYPE_STATUS_BAR) { |
| 1885 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 1886 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1887 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1888 | |
| 1889 | if (ActivityManager.isHighEndGfx() |
| 1890 | && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
Adrian Roos | f5e9b5c | 2014-09-10 15:27:41 +0200 | [diff] [blame] | 1891 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1892 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1893 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1894 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1895 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1896 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1897 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1898 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1899 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 1900 | private void readCameraLensCoverState() { |
| 1901 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 1902 | } |
| 1903 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1904 | private boolean isHidden(int accessibilityMode) { |
| 1905 | switch (accessibilityMode) { |
| 1906 | case 1: |
| 1907 | return mLidState == LID_CLOSED; |
| 1908 | case 2: |
| 1909 | return mLidState == LID_OPEN; |
| 1910 | default: |
| 1911 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1912 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1913 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1914 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1915 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1916 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1917 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1918 | int navigationPresence) { |
| 1919 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1920 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1921 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1922 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1923 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1924 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1925 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1926 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1927 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1928 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1929 | if (!mHasSoftInput) { |
| 1930 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1931 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1932 | } |
| 1933 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1934 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1935 | || (navigationPresence == PRESENCE_INTERNAL |
| 1936 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1937 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1938 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1939 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1940 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1941 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1942 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1943 | public int windowTypeToLayerLw(int type) { |
| 1944 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1945 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1946 | } |
| 1947 | switch (type) { |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1948 | case TYPE_PRIVATE_PRESENTATION: |
| 1949 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1950 | case TYPE_WALLPAPER: |
| 1951 | // wallpaper is at the bottom, though the window manager may move it. |
| 1952 | return 2; |
| 1953 | case TYPE_PHONE: |
| 1954 | return 3; |
| 1955 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 1956 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1957 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1958 | case TYPE_VOICE_INTERACTION: |
| 1959 | // voice interaction layer is almost immediately above apps. |
| 1960 | return 5; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1961 | case TYPE_INPUT_CONSUMER: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1962 | return 6; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1963 | case TYPE_SYSTEM_DIALOG: |
| 1964 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1965 | case TYPE_TOAST: |
| 1966 | // toasts and the plugged-in battery thing |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1967 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1968 | case TYPE_PRIORITY_PHONE: |
| 1969 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1970 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1971 | case TYPE_DREAM: |
| 1972 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1973 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1974 | case TYPE_SYSTEM_ALERT: |
| 1975 | // like the ANR / app crashed dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1976 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1977 | case TYPE_INPUT_METHOD: |
| 1978 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1979 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1980 | case TYPE_INPUT_METHOD_DIALOG: |
| 1981 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1982 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1983 | case TYPE_KEYGUARD_SCRIM: |
| 1984 | // the safety window that shows behind keyguard while keyguard is starting |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1985 | return 14; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1986 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1987 | return 15; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1988 | case TYPE_STATUS_BAR: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1989 | return 16; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1990 | case TYPE_STATUS_BAR_PANEL: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1991 | return 17; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1992 | case TYPE_KEYGUARD_DIALOG: |
| 1993 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1994 | case TYPE_VOLUME_OVERLAY: |
| 1995 | // the on-screen volume indicator and controller shown when the user |
| 1996 | // changes the device volume |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1997 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1998 | case TYPE_SYSTEM_OVERLAY: |
| 1999 | // the on-screen volume indicator and controller shown when the user |
| 2000 | // changes the device volume |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2001 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2002 | case TYPE_NAVIGATION_BAR: |
| 2003 | // the navigation bar, if available, shows atop most things |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2004 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2005 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2006 | // some panels (e.g. search) need to show on top of the navigation bar |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2007 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2008 | case TYPE_SYSTEM_ERROR: |
| 2009 | // system-level error dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2010 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2011 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2012 | // used to highlight the magnified portion of a display |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2013 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2014 | case TYPE_DISPLAY_OVERLAY: |
| 2015 | // used to simulate secondary display devices |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2016 | return 25; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2017 | case TYPE_DRAG: |
| 2018 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2019 | // which sits above all other focusable windows |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2020 | return 26; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2021 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2022 | // overlay put by accessibility services to intercept user interaction |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2023 | return 27; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2024 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2025 | return 28; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2026 | case TYPE_BOOT_PROGRESS: |
| 2027 | return 29; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2028 | case TYPE_POINTER: |
| 2029 | // the (mouse) pointer layer |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2030 | return 30; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2031 | } |
| 2032 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2033 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2037 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2038 | public int subWindowTypeToLayerLw(int type) { |
| 2039 | switch (type) { |
| 2040 | case TYPE_APPLICATION_PANEL: |
| 2041 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2042 | return APPLICATION_PANEL_SUBLAYER; |
| 2043 | case TYPE_APPLICATION_MEDIA: |
| 2044 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2045 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2046 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2047 | case TYPE_APPLICATION_SUB_PANEL: |
| 2048 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2049 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2050 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2051 | } |
| 2052 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2053 | return 0; |
| 2054 | } |
| 2055 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2056 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2057 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2058 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2061 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2062 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2063 | if (mHasNavigationBar) { |
| 2064 | // For a basic navigation bar, when we are in landscape mode we place |
| 2065 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2066 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 2067 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2068 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2069 | } |
| 2070 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2071 | } |
| 2072 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2073 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2074 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2075 | if (mHasNavigationBar) { |
| 2076 | // For a basic navigation bar, when we are in portrait mode we place |
| 2077 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2078 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 2079 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2080 | } |
| 2081 | } |
| 2082 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2085 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2086 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 2087 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2090 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2091 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2092 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2093 | // 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] | 2094 | // we do want to exclude it since applications can't generally use that part |
| 2095 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2096 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2097 | } |
| 2098 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2099 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 2100 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 2101 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2102 | (isKeyguardHostWindow(attrs) && |
| 2103 | (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 2104 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2105 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2106 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2107 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2108 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2109 | return attrs.type == TYPE_STATUS_BAR; |
| 2110 | } |
| 2111 | |
| 2112 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2113 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2114 | switch (attrs.type) { |
| 2115 | case TYPE_STATUS_BAR: |
| 2116 | case TYPE_NAVIGATION_BAR: |
| 2117 | case TYPE_WALLPAPER: |
| 2118 | case TYPE_DREAM: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2119 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2120 | return false; |
| 2121 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 2122 | // Hide only windows below the keyguard host window. |
| 2123 | return windowTypeToLayerLw(win.getBaseType()) |
| 2124 | < windowTypeToLayerLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2125 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2126 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2127 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2128 | @Override |
| 2129 | public WindowState getWinShowWhenLockedLw() { |
| 2130 | return mWinShowWhenLocked; |
| 2131 | } |
| 2132 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2133 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2134 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2135 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2136 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2137 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2138 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2139 | return null; |
| 2140 | } |
| 2141 | if (packageName == null) { |
| 2142 | return null; |
| 2143 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2144 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2145 | WindowManager wm = null; |
| 2146 | View view = null; |
| 2147 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2148 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2149 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2150 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2151 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2152 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2153 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2154 | try { |
| 2155 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2156 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2157 | } catch (PackageManager.NameNotFoundException e) { |
| 2158 | // Ignore |
| 2159 | } |
| 2160 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2161 | |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2162 | PhoneWindow win = new PhoneWindow(context); |
| 2163 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2164 | final TypedArray ta = win.getWindowStyle(); |
| 2165 | if (ta.getBoolean( |
| 2166 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 2167 | || ta.getBoolean( |
| 2168 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2169 | return null; |
| 2170 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2171 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2172 | Resources r = context.getResources(); |
| 2173 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2174 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2175 | win.setType( |
| 2176 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2177 | |
| 2178 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2179 | // Assumes it's safe to show starting windows of launched apps while |
| 2180 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2181 | // secret information. |
| 2182 | if (mKeyguardHidden) { |
| 2183 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2184 | } |
| 2185 | } |
| 2186 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2187 | // Force the window flags: this is a fake window, so it is not really |
| 2188 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2189 | // flag because we do know that the next window will take input |
| 2190 | // focus, so we want to get the IME window up on top of us right away. |
| 2191 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2192 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2193 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2194 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2195 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2196 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2197 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2198 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2199 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2200 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2201 | win.setDefaultIcon(icon); |
| 2202 | win.setDefaultLogo(logo); |
| 2203 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2204 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2205 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2206 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2207 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2208 | params.token = appToken; |
| 2209 | params.packageName = packageName; |
| 2210 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2211 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2212 | params.privateFlags |= |
| 2213 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2214 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2215 | |
| 2216 | if (!compatInfo.supportsScreen()) { |
| 2217 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2218 | } |
| 2219 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2220 | params.setTitle("Starting " + packageName); |
| 2221 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2222 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2223 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2224 | |
| 2225 | if (win.isFloating()) { |
| 2226 | // Whoops, there is no way to display an animation/preview |
| 2227 | // of such a thing! After all that work... let's skip it. |
| 2228 | // (Note that we must do this here because it is in |
| 2229 | // getDecorView() where the theme is evaluated... maybe |
| 2230 | // we should peek the floating attribute from the theme |
| 2231 | // earlier.) |
| 2232 | return null; |
| 2233 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2234 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2235 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2236 | TAG, "Adding starting window for " + packageName |
| 2237 | + " / " + appToken + ": " |
| 2238 | + (view.getParent() != null ? view : null)); |
| 2239 | |
| 2240 | wm.addView(view, params); |
| 2241 | |
| 2242 | // Only return the view if it was successfully added to the |
| 2243 | // window manager... which we can tell by it having a parent. |
| 2244 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2245 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2246 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2247 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2248 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2249 | } catch (RuntimeException e) { |
| 2250 | // don't crash if something else bad happens, for example a |
| 2251 | // failure loading resources because we are loading from an app |
| 2252 | // on external storage that has been unmounted. |
| 2253 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2254 | } finally { |
| 2255 | if (view != null && view.getParent() == null) { |
| 2256 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2257 | wm.removeViewImmediate(view); |
| 2258 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | return null; |
| 2262 | } |
| 2263 | |
| 2264 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2265 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2266 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2267 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2268 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2269 | |
| 2270 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2271 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2272 | wm.removeView(window); |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2278 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2279 | * Currently enforces that three window types are singletons: |
| 2280 | * <ul> |
| 2281 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2282 | * <li>KEYGUARD_TYPE</li> |
| 2283 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2284 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2285 | * @param win The window to be added |
| 2286 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2287 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2288 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2289 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2290 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2291 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2292 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2293 | switch (attrs.type) { |
| 2294 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2295 | mContext.enforceCallingOrSelfPermission( |
| 2296 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2297 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2298 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2299 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2300 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2301 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2302 | } |
| 2303 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2304 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2305 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2306 | case TYPE_NAVIGATION_BAR: |
| 2307 | mContext.enforceCallingOrSelfPermission( |
| 2308 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2309 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2310 | if (mNavigationBar != null) { |
| 2311 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2312 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2313 | } |
| 2314 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2315 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2316 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2317 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2318 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2319 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2320 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2321 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2322 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2323 | mContext.enforceCallingOrSelfPermission( |
| 2324 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2325 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2326 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2327 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2328 | if (mKeyguardScrim != null) { |
| 2329 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2330 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2331 | mKeyguardScrim = win; |
| 2332 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2333 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2334 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2338 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2339 | public void removeWindowLw(WindowState win) { |
| 2340 | if (mStatusBar == win) { |
| 2341 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2342 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2343 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2344 | } else if (mKeyguardScrim == win) { |
| 2345 | Log.v(TAG, "Removing keyguard scrim"); |
| 2346 | mKeyguardScrim = null; |
| 2347 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2348 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2349 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2354 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2355 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2356 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2357 | public int selectAnimationLw(WindowState win, int transit) { |
| 2358 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2359 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2360 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2361 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2362 | if (transit == TRANSIT_EXIT |
| 2363 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2364 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2365 | } else if (transit == TRANSIT_ENTER |
| 2366 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2367 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2368 | } |
| 2369 | } else if (win == mNavigationBar) { |
| 2370 | // This can be on either the bottom or the right. |
| 2371 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2372 | if (transit == TRANSIT_EXIT |
| 2373 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2374 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2375 | } else if (transit == TRANSIT_ENTER |
| 2376 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2377 | return R.anim.dock_bottom_enter; |
| 2378 | } |
| 2379 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2380 | if (transit == TRANSIT_EXIT |
| 2381 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2382 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2383 | } else if (transit == TRANSIT_ENTER |
| 2384 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2385 | return R.anim.dock_right_enter; |
| 2386 | } |
| 2387 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2391 | if (win.hasAppShownWindows()) { |
| 2392 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2393 | return com.android.internal.R.anim.app_starting_exit; |
| 2394 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2395 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2396 | && transit == TRANSIT_ENTER) { |
| 2397 | // Special case: we are animating in a dream, while the keyguard |
| 2398 | // is shown. We don't want an animation on the dream, because |
| 2399 | // we need it shown immediately with the keyguard animating away |
| 2400 | // to reveal it. |
| 2401 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | return 0; |
| 2405 | } |
| 2406 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2407 | @Override |
| 2408 | public void selectRotationAnimationLw(int anim[]) { |
| 2409 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2410 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2411 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2412 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2413 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2414 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2415 | case ROTATION_ANIMATION_CROSSFADE: |
| 2416 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2417 | anim[1] = R.anim.rotation_animation_enter; |
| 2418 | break; |
| 2419 | case ROTATION_ANIMATION_JUMPCUT: |
| 2420 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2421 | anim[1] = R.anim.rotation_animation_enter; |
| 2422 | break; |
| 2423 | case ROTATION_ANIMATION_ROTATE: |
| 2424 | default: |
| 2425 | anim[0] = anim[1] = 0; |
| 2426 | break; |
| 2427 | } |
| 2428 | } else { |
| 2429 | anim[0] = anim[1] = 0; |
| 2430 | } |
| 2431 | } |
| 2432 | |
| 2433 | @Override |
| 2434 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2435 | boolean forceDefault) { |
| 2436 | switch (exitAnimId) { |
| 2437 | case R.anim.rotation_animation_xfade_exit: |
| 2438 | case R.anim.rotation_animation_jump_exit: |
| 2439 | // These are the only cases that matter. |
| 2440 | if (forceDefault) { |
| 2441 | return false; |
| 2442 | } |
| 2443 | int anim[] = new int[2]; |
| 2444 | selectRotationAnimationLw(anim); |
| 2445 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2446 | default: |
| 2447 | return true; |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2452 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2453 | boolean goingToNotificationShade) { |
| 2454 | if (goingToNotificationShade) { |
| 2455 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2456 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2457 | |
| 2458 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 2459 | R.anim.lock_screen_behind_enter_wallpaper : |
| 2460 | R.anim.lock_screen_behind_enter); |
| 2461 | |
| 2462 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2463 | final List<Animation> animations = set.getAnimations(); |
| 2464 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 2465 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 2466 | } |
| 2467 | |
| 2468 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | |
| 2472 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2473 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2474 | if (goingToNotificationShade) { |
| 2475 | return null; |
| 2476 | } else { |
| 2477 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2478 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2479 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2480 | |
| 2481 | private static void awakenDreams() { |
| 2482 | IDreamManager dreamManager = getDreamManager(); |
| 2483 | if (dreamManager != null) { |
| 2484 | try { |
| 2485 | dreamManager.awaken(); |
| 2486 | } catch (RemoteException e) { |
| 2487 | // fine, stay asleep then |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | static IDreamManager getDreamManager() { |
| 2493 | return IDreamManager.Stub.asInterface( |
| 2494 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2495 | } |
| 2496 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2497 | TelecomManager getTelecommService() { |
| 2498 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2499 | } |
| 2500 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2501 | static IAudioService getAudioService() { |
| 2502 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2503 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2504 | if (audioService == null) { |
| 2505 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2506 | } |
| 2507 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2511 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2515 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2516 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2517 | }; |
| 2518 | |
| 2519 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2520 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2521 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2522 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2523 | final int keyCode = event.getKeyCode(); |
| 2524 | final int repeatCount = event.getRepeatCount(); |
| 2525 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2526 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2527 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2528 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2529 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2530 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2531 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2532 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2533 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2534 | } |
| 2535 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2536 | // If we think we might have a volume down & power key chord on the way |
| 2537 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2538 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2539 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2540 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2541 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2542 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2543 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2544 | if (now < timeoutTime) { |
| 2545 | return timeoutTime - now; |
| 2546 | } |
| 2547 | } |
| 2548 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2549 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2550 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2551 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2552 | } |
| 2553 | return -1; |
| 2554 | } |
| 2555 | } |
| 2556 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2557 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2558 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2559 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2560 | mPendingMetaAction = false; |
| 2561 | } |
| 2562 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2563 | // First we always handle the home key here, so applications |
| 2564 | // can never break it, although if keyguard is on, we do let |
| 2565 | // it handle it, because that gives us the correct 5 second |
| 2566 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2567 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2568 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2569 | // If we have released the home key, and didn't do anything else |
| 2570 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2571 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2572 | cancelPreloadRecentApps(); |
| 2573 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2574 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2575 | if (mHomeConsumed) { |
| 2576 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2577 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2578 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2579 | |
| 2580 | if (canceled) { |
| 2581 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2582 | return -1; |
| 2583 | } |
| 2584 | |
Yorke Lee | 4f80324 | 2014-12-15 23:22:06 +0000 | [diff] [blame] | 2585 | // If an incoming call is ringing, HOME is totally disabled. |
| 2586 | // (The user is already on the InCallUI at this point, |
| 2587 | // and his ONLY options are to answer or reject the call.) |
| 2588 | TelecomManager telecomManager = getTelecommService(); |
| 2589 | if (telecomManager != null && telecomManager.isRinging()) { |
| 2590 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2591 | return -1; |
| 2592 | } |
| 2593 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2594 | // Delay handling home if a double-tap is possible. |
| 2595 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2596 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2597 | mHomeDoubleTapPending = true; |
| 2598 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2599 | ViewConfiguration.getDoubleTapTimeout()); |
| 2600 | return -1; |
| 2601 | } |
| 2602 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2603 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2604 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2605 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2606 | |
| 2607 | // If a system window has focus, then it doesn't make sense |
| 2608 | // right now to interact with applications. |
| 2609 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2610 | if (attrs != null) { |
| 2611 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2612 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2613 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2614 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2615 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2616 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2617 | } |
| 2618 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2619 | for (int i=0; i<typeCount; i++) { |
| 2620 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2621 | // 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] | 2622 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2623 | } |
| 2624 | } |
| 2625 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2626 | |
| 2627 | // Remember that home is pressed and handle special actions. |
| 2628 | if (repeatCount == 0) { |
| 2629 | mHomePressed = true; |
| 2630 | if (mHomeDoubleTapPending) { |
| 2631 | mHomeDoubleTapPending = false; |
| 2632 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2633 | handleDoubleTapOnHome(); |
| 2634 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2635 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2636 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2637 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2638 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2639 | if (!keyguardOn) { |
| 2640 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2641 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2642 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2643 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2644 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2645 | // Hijack modified menu keys for debugging features |
| 2646 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2647 | |
| 2648 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2649 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2650 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2651 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2652 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2653 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2654 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2655 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2656 | Intent service = new Intent(); |
| 2657 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2658 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2659 | boolean shown = Settings.Global.getInt( |
| 2660 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2661 | if (!shown) { |
| 2662 | mContext.startService(service); |
| 2663 | } else { |
| 2664 | mContext.stopService(service); |
| 2665 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2666 | Settings.Global.putInt( |
| 2667 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2668 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2669 | } |
| 2670 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2671 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2672 | if (down) { |
| 2673 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2674 | mSearchKeyShortcutPending = true; |
| 2675 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2676 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2677 | } else { |
| 2678 | mSearchKeyShortcutPending = false; |
| 2679 | if (mConsumeSearchKeyUp) { |
| 2680 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2681 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2682 | } |
| 2683 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2684 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2685 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2686 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2687 | if (down && repeatCount == 0) { |
| 2688 | preloadRecentApps(); |
| 2689 | } else if (!down) { |
| 2690 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2691 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2692 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2693 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 2694 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 2695 | if (down) { |
| 2696 | IStatusBarService service = getStatusBarService(); |
| 2697 | if (service != null) { |
| 2698 | try { |
| 2699 | service.expandNotificationsPanel(); |
| 2700 | } catch (RemoteException e) { |
| 2701 | // do nothing. |
| 2702 | } |
| 2703 | } |
| 2704 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2705 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2706 | if (down) { |
| 2707 | if (repeatCount == 0) { |
| 2708 | mAssistKeyLongPressed = false; |
| 2709 | } else if (repeatCount == 1) { |
| 2710 | mAssistKeyLongPressed = true; |
| 2711 | if (!keyguardOn) { |
| 2712 | launchAssistLongPressAction(); |
| 2713 | } |
| 2714 | } |
| 2715 | } else { |
| 2716 | if (mAssistKeyLongPressed) { |
| 2717 | mAssistKeyLongPressed = false; |
| 2718 | } else { |
| 2719 | if (!keyguardOn) { |
| 2720 | launchAssistAction(); |
| 2721 | } |
| 2722 | } |
| 2723 | } |
| 2724 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2725 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2726 | if (!down) { |
| 2727 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2728 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2729 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2730 | } else { |
| 2731 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2732 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2733 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2734 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2735 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2736 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2737 | if (down && repeatCount == 0) { |
| 2738 | mHandler.post(mScreenshotRunnable); |
| 2739 | } |
| 2740 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2741 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2742 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2743 | if (down) { |
| 2744 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2745 | |
| 2746 | // Disable autobrightness if it's on |
| 2747 | int auto = Settings.System.getIntForUser( |
| 2748 | mContext.getContentResolver(), |
| 2749 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2750 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2751 | UserHandle.USER_CURRENT_OR_SELF); |
| 2752 | if (auto != 0) { |
| 2753 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2754 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2755 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2756 | UserHandle.USER_CURRENT_OR_SELF); |
| 2757 | } |
| 2758 | |
| 2759 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2760 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2761 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2762 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2763 | Settings.System.SCREEN_BRIGHTNESS, |
| 2764 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2765 | UserHandle.USER_CURRENT_OR_SELF); |
| 2766 | brightness += step; |
| 2767 | // Make sure we don't go beyond the limits. |
| 2768 | brightness = Math.min(max, brightness); |
| 2769 | brightness = Math.max(min, brightness); |
| 2770 | |
| 2771 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2772 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2773 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2774 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 2775 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2776 | } |
| 2777 | return -1; |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2778 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2779 | if (down) { |
| 2780 | mPendingMetaAction = true; |
| 2781 | } else if (mPendingMetaAction) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 2782 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2783 | } |
| 2784 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2785 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2786 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2787 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2788 | // Any printing key that is chorded with Search should be consumed |
| 2789 | // even if no shortcut was invoked. This prevents text from being |
| 2790 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2791 | // 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] | 2792 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2793 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2794 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2795 | mConsumeSearchKeyUp = true; |
| 2796 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2797 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2798 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2799 | if (shortcutIntent != null) { |
| 2800 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2801 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2802 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2803 | } catch (ActivityNotFoundException ex) { |
| 2804 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2805 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2806 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2807 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2808 | } else { |
| 2809 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2810 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2811 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2812 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2813 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2814 | } |
| 2815 | } |
| 2816 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2817 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2818 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2819 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2820 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2821 | if (kcm.isPrintingKey(keyCode)) { |
| 2822 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2823 | metaState & ~(KeyEvent.META_META_ON |
| 2824 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2825 | if (shortcutIntent != null) { |
| 2826 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2827 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2828 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2829 | } catch (ActivityNotFoundException ex) { |
| 2830 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2831 | + "the activity to which it is registered was not found: " |
| 2832 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2833 | } |
| 2834 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2835 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2839 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2840 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2841 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2842 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2843 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2844 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2845 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2846 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2847 | } catch (ActivityNotFoundException ex) { |
| 2848 | Slog.w(TAG, "Dropping application launch key because " |
| 2849 | + "the activity to which it is registered was not found: " |
| 2850 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2851 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2852 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2853 | } |
| 2854 | } |
| 2855 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2856 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2857 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2858 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2859 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2860 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2861 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 2862 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2863 | return -1; |
| 2864 | } |
| 2865 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2866 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 2867 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 2868 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2869 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2870 | } |
| 2871 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2872 | // Handle keyboard language switching. |
| 2873 | if (down && repeatCount == 0 |
| 2874 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2875 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2876 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2877 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2878 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2879 | return -1; |
| 2880 | } |
| 2881 | if (mLanguageSwitchKeyPressed && !down |
| 2882 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2883 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2884 | mLanguageSwitchKeyPressed = false; |
| 2885 | return -1; |
| 2886 | } |
| 2887 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2888 | if (isValidGlobalKey(keyCode) |
| 2889 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2890 | return -1; |
| 2891 | } |
| 2892 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2893 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2894 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2895 | return -1; |
| 2896 | } |
| 2897 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2898 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2899 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2900 | } |
| 2901 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2902 | /** {@inheritDoc} */ |
| 2903 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2904 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2905 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2906 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2907 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2908 | + ", flags=" + event.getFlags() |
| 2909 | + ", keyCode=" + event.getKeyCode() |
| 2910 | + ", scanCode=" + event.getScanCode() |
| 2911 | + ", metaState=" + event.getMetaState() |
| 2912 | + ", repeatCount=" + event.getRepeatCount() |
| 2913 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2914 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2915 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2916 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2917 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2918 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2919 | final int keyCode = event.getKeyCode(); |
| 2920 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2921 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2922 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2923 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2924 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2925 | final FallbackAction fallbackAction; |
| 2926 | if (initialDown) { |
| 2927 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2928 | } else { |
| 2929 | fallbackAction = mFallbackActions.get(keyCode); |
| 2930 | } |
| 2931 | |
| 2932 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2933 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2934 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2935 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2936 | } |
| 2937 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2938 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2939 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2940 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2941 | event.getAction(), fallbackAction.keyCode, |
| 2942 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2943 | event.getDeviceId(), event.getScanCode(), |
| 2944 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2945 | |
| 2946 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2947 | fallbackEvent.recycle(); |
| 2948 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2949 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2950 | |
| 2951 | if (initialDown) { |
| 2952 | mFallbackActions.put(keyCode, fallbackAction); |
| 2953 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2954 | mFallbackActions.remove(keyCode); |
| 2955 | fallbackAction.recycle(); |
| 2956 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2957 | } |
| 2958 | } |
| 2959 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2960 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2961 | if (fallbackEvent == null) { |
| 2962 | Slog.d(TAG, "No fallback."); |
| 2963 | } else { |
| 2964 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2965 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2966 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2967 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2970 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2971 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2972 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2973 | long delayMillis = interceptKeyBeforeDispatching( |
| 2974 | win, fallbackEvent, policyFlags); |
| 2975 | if (delayMillis == 0) { |
| 2976 | return true; |
| 2977 | } |
| 2978 | } |
| 2979 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2980 | } |
| 2981 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2982 | private void launchAssistLongPressAction() { |
| 2983 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2984 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2985 | |
| 2986 | // launch the search activity |
| 2987 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2988 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2989 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2990 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2991 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2992 | SearchManager searchManager = getSearchManager(); |
| 2993 | if (searchManager != null) { |
| 2994 | searchManager.stopSearch(); |
| 2995 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2996 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2997 | } catch (ActivityNotFoundException e) { |
| 2998 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | private void launchAssistAction() { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 3003 | launchAssistAction(null); |
| 3004 | } |
| 3005 | |
| 3006 | private void launchAssistAction(String hint) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3007 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 3008 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 3009 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3010 | if (intent != null) { |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 3011 | if (hint != null) { |
| 3012 | intent.putExtra(hint, true); |
| 3013 | } |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3014 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 3015 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 3016 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 3017 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3018 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3019 | } catch (ActivityNotFoundException e) { |
| 3020 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | } |
| 3024 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3025 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3026 | if (isUserSetupComplete()) { |
| 3027 | mContext.startActivityAsUser(intent, handle); |
| 3028 | } else { |
| 3029 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3030 | } |
| 3031 | } |
| 3032 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3033 | private SearchManager getSearchManager() { |
| 3034 | if (mSearchManager == null) { |
| 3035 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3036 | } |
| 3037 | return mSearchManager; |
| 3038 | } |
| 3039 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3040 | private void preloadRecentApps() { |
| 3041 | mPreloadedRecentApps = true; |
| 3042 | try { |
| 3043 | IStatusBarService statusbar = getStatusBarService(); |
| 3044 | if (statusbar != null) { |
| 3045 | statusbar.preloadRecentApps(); |
| 3046 | } |
| 3047 | } catch (RemoteException e) { |
| 3048 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 3049 | // re-acquire status bar service next time it is needed. |
| 3050 | mStatusBarService = null; |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | private void cancelPreloadRecentApps() { |
| 3055 | if (mPreloadedRecentApps) { |
| 3056 | mPreloadedRecentApps = false; |
| 3057 | try { |
| 3058 | IStatusBarService statusbar = getStatusBarService(); |
| 3059 | if (statusbar != null) { |
| 3060 | statusbar.cancelPreloadRecentApps(); |
| 3061 | } |
| 3062 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3063 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3064 | // re-acquire status bar service next time it is needed. |
| 3065 | mStatusBarService = null; |
| 3066 | } |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | private void toggleRecentApps() { |
| 3071 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3072 | try { |
| 3073 | IStatusBarService statusbar = getStatusBarService(); |
| 3074 | if (statusbar != null) { |
| 3075 | statusbar.toggleRecentApps(); |
| 3076 | } |
| 3077 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3078 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 3079 | // re-acquire status bar service next time it is needed. |
| 3080 | mStatusBarService = null; |
| 3081 | } |
| 3082 | } |
| 3083 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3084 | @Override |
| 3085 | public void showRecentApps() { |
| 3086 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 3087 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 3088 | } |
| 3089 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3090 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 3091 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3092 | try { |
| 3093 | IStatusBarService statusbar = getStatusBarService(); |
| 3094 | if (statusbar != null) { |
| 3095 | statusbar.showRecentApps(triggeredFromAltTab); |
| 3096 | } |
| 3097 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3098 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 3099 | // re-acquire status bar service next time it is needed. |
| 3100 | mStatusBarService = null; |
| 3101 | } |
| 3102 | } |
| 3103 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3104 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3105 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3106 | try { |
| 3107 | IStatusBarService statusbar = getStatusBarService(); |
| 3108 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3109 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3110 | } |
| 3111 | } catch (RemoteException e) { |
| 3112 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 3113 | // re-acquire status bar service next time it is needed. |
| 3114 | mStatusBarService = null; |
| 3115 | } |
| 3116 | } |
| 3117 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3118 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3119 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3122 | /** |
| 3123 | * A home key -> launch home action was detected. Take the appropriate action |
| 3124 | * given the situation with the keyguard. |
| 3125 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3126 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3127 | if (respectKeyguard) { |
| 3128 | if (isKeyguardShowingAndNotOccluded()) { |
| 3129 | // don't launch home if keyguard showing |
| 3130 | return; |
| 3131 | } |
| 3132 | |
| 3133 | if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
| 3134 | // when in keyguard restricted mode, must first verify unlock |
| 3135 | // before launching home |
| 3136 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3137 | @Override |
| 3138 | public void onKeyguardExitResult(boolean success) { |
| 3139 | if (success) { |
| 3140 | try { |
| 3141 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3142 | } catch (RemoteException e) { |
| 3143 | } |
| 3144 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3145 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3146 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3147 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3148 | }); |
| 3149 | return; |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | // no keyguard stuff to worry about, just launch home! |
| 3154 | try { |
| 3155 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3156 | } catch (RemoteException e) { |
| 3157 | } |
| 3158 | if (mRecentsVisible) { |
| 3159 | // Hide Recents and notify it to launch Home |
| 3160 | if (awakenFromDreams) { |
| 3161 | awakenDreams(); |
| 3162 | } |
| 3163 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3164 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3165 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3166 | // Otherwise, just launch Home |
| 3167 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3168 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3172 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3173 | @Override |
| 3174 | public void run() { |
| 3175 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3176 | // Clear flags. |
| 3177 | mForceClearedSystemUiFlags &= |
| 3178 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3179 | } |
| 3180 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3181 | } |
| 3182 | }; |
| 3183 | |
| 3184 | /** |
| 3185 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3186 | * to determine when the nav bar should be shown and prevent applications from |
| 3187 | * receiving those touches. |
| 3188 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3189 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3190 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3191 | super(inputChannel, looper); |
| 3192 | } |
| 3193 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3194 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3195 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3196 | boolean handled = false; |
| 3197 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3198 | if (event instanceof MotionEvent |
| 3199 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3200 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3201 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3202 | // When the user taps down, we re-show the nav bar. |
| 3203 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3204 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3205 | // Any user activity always causes us to show the |
| 3206 | // navigation controls, if they had been hidden. |
| 3207 | // We also clear the low profile and only content |
| 3208 | // flags so that tapping on the screen will atomically |
| 3209 | // restore all currently hidden screen decorations. |
| 3210 | int newVal = mResettingSystemUiFlags | |
| 3211 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3212 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3213 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3214 | if (mResettingSystemUiFlags != newVal) { |
| 3215 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3216 | changed = true; |
| 3217 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3218 | // We don't allow the system's nav bar to be hidden |
| 3219 | // again for 1 second, to prevent applications from |
| 3220 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3221 | newVal = mForceClearedSystemUiFlags | |
| 3222 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3223 | if (mForceClearedSystemUiFlags != newVal) { |
| 3224 | mForceClearedSystemUiFlags = newVal; |
| 3225 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3226 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3227 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3228 | } |
| 3229 | if (changed) { |
| 3230 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3231 | } |
| 3232 | } |
| 3233 | } |
| 3234 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3235 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3236 | } |
| 3237 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3238 | } |
| 3239 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3240 | new InputEventReceiver.Factory() { |
| 3241 | @Override |
| 3242 | public InputEventReceiver createInputEventReceiver( |
| 3243 | InputChannel inputChannel, Looper looper) { |
| 3244 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3245 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3246 | }; |
| 3247 | |
| 3248 | @Override |
| 3249 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3250 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3251 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3252 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3253 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3254 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3255 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3256 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3257 | // Clear any bits in the new visibility that are currently being |
| 3258 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3259 | return visibility & ~mResettingSystemUiFlags |
| 3260 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3261 | } |
| 3262 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3263 | @Override |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3264 | public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets, |
| 3265 | Rect outStableInsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3266 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3267 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3268 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3269 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3270 | 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] | 3271 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3272 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3273 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3274 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3275 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3276 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3277 | } else { |
| 3278 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3279 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3280 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3281 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3282 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3283 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3284 | availRight - mStableFullscreenRight, |
| 3285 | availBottom - mStableFullscreenBottom); |
| 3286 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3287 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3288 | availRight - mStableRight, availBottom - mStableBottom); |
| 3289 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3290 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3291 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3292 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3293 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3294 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3295 | availRight - mCurRight, availBottom - mCurBottom); |
| 3296 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3297 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3298 | availRight - mCurRight, availBottom - mCurBottom); |
| 3299 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3300 | |
| 3301 | outStableInsets.set(mStableLeft, mStableTop, |
| 3302 | availRight - mStableRight, availBottom - mStableBottom); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3303 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3304 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3305 | outContentInsets.setEmpty(); |
| 3306 | outStableInsets.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3307 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3308 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3309 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3310 | @Override |
| 3311 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 3312 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3313 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3314 | if (isDefaultDisplay) { |
| 3315 | switch (displayRotation) { |
| 3316 | case Surface.ROTATION_90: |
| 3317 | overscanLeft = mOverscanTop; |
| 3318 | overscanTop = mOverscanRight; |
| 3319 | overscanRight = mOverscanBottom; |
| 3320 | overscanBottom = mOverscanLeft; |
| 3321 | break; |
| 3322 | case Surface.ROTATION_180: |
| 3323 | overscanLeft = mOverscanRight; |
| 3324 | overscanTop = mOverscanBottom; |
| 3325 | overscanRight = mOverscanLeft; |
| 3326 | overscanBottom = mOverscanTop; |
| 3327 | break; |
| 3328 | case Surface.ROTATION_270: |
| 3329 | overscanLeft = mOverscanBottom; |
| 3330 | overscanTop = mOverscanLeft; |
| 3331 | overscanRight = mOverscanTop; |
| 3332 | overscanBottom = mOverscanRight; |
| 3333 | break; |
| 3334 | default: |
| 3335 | overscanLeft = mOverscanLeft; |
| 3336 | overscanTop = mOverscanTop; |
| 3337 | overscanRight = mOverscanRight; |
| 3338 | overscanBottom = mOverscanBottom; |
| 3339 | break; |
| 3340 | } |
| 3341 | } else { |
| 3342 | overscanLeft = 0; |
| 3343 | overscanTop = 0; |
| 3344 | overscanRight = 0; |
| 3345 | overscanBottom = 0; |
| 3346 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3347 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3348 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3349 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3350 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3351 | mSystemLeft = 0; |
| 3352 | mSystemTop = 0; |
| 3353 | mSystemRight = displayWidth; |
| 3354 | mSystemBottom = displayHeight; |
| 3355 | mUnrestrictedScreenLeft = overscanLeft; |
| 3356 | mUnrestrictedScreenTop = overscanTop; |
| 3357 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3358 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3359 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3360 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3361 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3362 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3363 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3364 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3365 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3366 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3367 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3368 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3369 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3370 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3371 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3372 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3373 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3374 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3375 | final Rect pf = mTmpParentFrame; |
| 3376 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3377 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3378 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3379 | final Rect dcf = mTmpDecorFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3380 | final Rect osf = mTmpOutsetFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3381 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3382 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3383 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3384 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3385 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3386 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3387 | if (isDefaultDisplay) { |
| 3388 | // For purposes of putting out fake window up to steal focus, we will |
| 3389 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3390 | final int sysui = mLastSystemUiFlags; |
| 3391 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3392 | boolean navTranslucent = (sysui |
| 3393 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3394 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3395 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3396 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3397 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3398 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3399 | if (!isKeyguardShowing) { |
| 3400 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3401 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3402 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3403 | // When the navigation bar isn't visible, we put up a fake |
| 3404 | // input window to catch all touch events. This way we can |
| 3405 | // detect when the user presses anywhere to bring back the nav |
| 3406 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3407 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3408 | if (mInputConsumer != null) { |
| 3409 | mInputConsumer.dismiss(); |
| 3410 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3411 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3412 | } else if (mInputConsumer == null) { |
| 3413 | mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(), |
| 3414 | mHideNavInputEventReceiverFactory); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3415 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3416 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3417 | // For purposes of positioning and showing the nav bar, if we have |
| 3418 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3419 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3420 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3421 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3422 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3423 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3424 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3425 | // Force the navigation bar to its appropriate place and |
| 3426 | // size. We need to do this directly, instead of relying on |
| 3427 | // it to bubble up from the nav bar, because this needs to |
| 3428 | // change atomically with screen rotations. |
| 3429 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 3430 | if (mNavigationBarOnBottom) { |
| 3431 | // 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] | 3432 | int top = displayHeight - overscanBottom |
| 3433 | - mNavigationBarHeightForRotation[displayRotation]; |
| 3434 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3435 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3436 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3437 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3438 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3439 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3440 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3441 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3442 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3443 | } else { |
| 3444 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3445 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3446 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3447 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3448 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3449 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3450 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3451 | // and not in the process of animating on or off, then |
| 3452 | // we can tell the app that it is covered by it. |
| 3453 | mSystemBottom = mTmpNavigationFrame.top; |
| 3454 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3455 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3456 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3457 | int left = displayWidth - overscanRight |
| 3458 | - mNavigationBarWidthForRotation[displayRotation]; |
| 3459 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3460 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3461 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3462 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3463 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3464 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3465 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3466 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3467 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3468 | } else { |
| 3469 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3470 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3471 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3472 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 3473 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3474 | // If the nav bar is currently requested to be visible, |
| 3475 | // and not in the process of animating on or off, then |
| 3476 | // we can tell the app that it is covered by it. |
| 3477 | mSystemRight = mTmpNavigationFrame.left; |
| 3478 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3479 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3480 | // Make sure the content and current rectangles are updated to |
| 3481 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3482 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3483 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3484 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3485 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3486 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3487 | // And compute the final frame. |
| 3488 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3489 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3490 | mTmpNavigationFrame, mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3491 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3492 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3493 | updateSysUiVisibility = true; |
| 3494 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3495 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3496 | 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] | 3497 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 3498 | |
| 3499 | // decide where the status bar goes ahead of time |
| 3500 | if (mStatusBar != null) { |
| 3501 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3502 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3503 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3504 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3505 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3506 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3507 | vf.left = mStableLeft; |
| 3508 | vf.top = mStableTop; |
| 3509 | vf.right = mStableRight; |
| 3510 | vf.bottom = mStableBottom; |
| 3511 | |
| 3512 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3513 | |
| 3514 | // Let the status bar determine its size. |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3515 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 3516 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
| 3517 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3518 | |
| 3519 | // For layout, the status bar is always at the top with our fixed height. |
| 3520 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3521 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3522 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3523 | boolean statusBarTranslucent = (sysui |
| 3524 | & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3525 | if (!isKeyguardShowing) { |
| 3526 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3527 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3528 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3529 | // If the status bar is hidden, we don't want to cause |
| 3530 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 3531 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3532 | // Status bar may go away, so the screen area it occupies |
| 3533 | // is available to apps but just covering them when the |
| 3534 | // status bar is visible. |
| 3535 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3536 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3537 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3538 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3539 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3540 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3541 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3542 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3543 | String.format( |
| 3544 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3545 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3546 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3547 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3548 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3549 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3550 | && !statusBarTransient && !statusBarTranslucent |
| 3551 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3552 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3553 | // and not in the process of animating on or off, then |
| 3554 | // we can tell the app that it is covered by it. |
| 3555 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3556 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3557 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3558 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3559 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3560 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3561 | if (updateSysUiVisibility) { |
| 3562 | updateSystemUiVisibilityLw(); |
| 3563 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3564 | } |
| 3565 | } |
| 3566 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3567 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3568 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3569 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 3570 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 3571 | return mStatusBar.getSurfaceLayer(); |
| 3572 | } |
| 3573 | |
| 3574 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 3575 | return mNavigationBar.getSurfaceLayer(); |
| 3576 | } |
| 3577 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3578 | return 0; |
| 3579 | } |
| 3580 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3581 | @Override |
| 3582 | public void getContentRectLw(Rect r) { |
| 3583 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3584 | } |
| 3585 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3586 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3587 | 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] | 3588 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3589 | // Here's a special case: if this attached window is a panel that is |
| 3590 | // above the dock window, and the window it is attached to is below |
| 3591 | // the dock window, then the frames we computed for the window it is |
| 3592 | // attached to can not be used because the dock is effectively part |
| 3593 | // of the underlying window and the attached window is floating on top |
| 3594 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3595 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3596 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3597 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3598 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3599 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3600 | } else { |
| 3601 | // The effective display frame of the attached window depends on |
| 3602 | // whether it is taking care of insetting its content. If not, |
| 3603 | // we need to use the parent's content frame so that the entire |
| 3604 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3605 | // 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] | 3606 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3607 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3608 | // Set the content frame of the attached window to the parent's decor frame |
| 3609 | // (same as content frame when IME isn't present) if specifically requested by |
| 3610 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 3611 | // Otherwise, use the overscan frame. |
| 3612 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 3613 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3614 | } else { |
| 3615 | // If the window is resizing, then we want to base the content |
| 3616 | // frame on our attached content frame to resize... however, |
| 3617 | // things can be tricky if the attached window is NOT in resize |
| 3618 | // mode, in which case its content frame will be larger. |
| 3619 | // Ungh. So to deal with that, make sure the content frame |
| 3620 | // we end up using is not covering the IM dock. |
| 3621 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3622 | if (attached.isVoiceInteraction()) { |
| 3623 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3624 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3625 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3626 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3627 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3628 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3629 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3630 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3631 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3632 | } |
| 3633 | } |
| 3634 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3635 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3636 | vf.set(attached.getVisibleFrameLw()); |
| 3637 | } |
| 3638 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3639 | // window should be positioned relative to its parent or the entire |
| 3640 | // screen. |
| 3641 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3642 | ? attached.getFrameLw() : df); |
| 3643 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3644 | |
| 3645 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3646 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3647 | // If app is requesting a stable layout, don't let the |
| 3648 | // content insets go below the stable values. |
| 3649 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3650 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3651 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3652 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3653 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3654 | } else { |
| 3655 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3656 | if (r.top < mStableTop) r.top = mStableTop; |
| 3657 | if (r.right > mStableRight) r.right = mStableRight; |
| 3658 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3659 | } |
| 3660 | } |
| 3661 | } |
| 3662 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3663 | private boolean canReceiveInput(WindowState win) { |
| 3664 | boolean notFocusable = |
| 3665 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 3666 | boolean altFocusableIm = |
| 3667 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 3668 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 3669 | return !notFocusableForIm; |
| 3670 | } |
| 3671 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3672 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3673 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3674 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3675 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 3676 | // input, we need to layout it again to accomodate for the IME window. |
| 3677 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3678 | return; |
| 3679 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3680 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3681 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 3682 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3683 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 3684 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3685 | 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] | 3686 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 3687 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3688 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3689 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3690 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3691 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3692 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3693 | final Rect pf = mTmpParentFrame; |
| 3694 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3695 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3696 | final Rect cf = mTmpContentFrame; |
| 3697 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3698 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3699 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3700 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3701 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3702 | |
| 3703 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3704 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3705 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 3706 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 3707 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3708 | if (isDefaultDisplay) { |
| 3709 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 3710 | } else { |
| 3711 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 3712 | } |
| 3713 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3714 | if (!isDefaultDisplay) { |
| 3715 | if (attached != null) { |
| 3716 | // If this window is attached to another, our display |
| 3717 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3718 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3719 | } else { |
| 3720 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3721 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3722 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3723 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3724 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3725 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3726 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3727 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3728 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3729 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3730 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3731 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3732 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3733 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3734 | // ...with content insets above the nav bar |
| 3735 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3736 | // IM dock windows always go to the bottom of the screen. |
| 3737 | attrs.gravity = Gravity.BOTTOM; |
| 3738 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3739 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
| 3740 | pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft; |
| 3741 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3742 | pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft |
| 3743 | + mUnrestrictedScreenWidth; |
| 3744 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3745 | + mUnrestrictedScreenHeight; |
| 3746 | cf.bottom = vf.bottom = mStableBottom; |
| 3747 | cf.top = vf.top = mStableTop; |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3748 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 3749 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3750 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3751 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3752 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 3753 | cf.left = vf.left = mStableLeft; |
| 3754 | cf.top = vf.top = mStableTop; |
| 3755 | cf.right = vf.right = mStableRight; |
| 3756 | vf.bottom = mStableBottom; |
| 3757 | cf.bottom = mContentBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3758 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3759 | |
| 3760 | // Default policy decor for the default display |
| 3761 | dcf.left = mSystemLeft; |
| 3762 | dcf.top = mSystemTop; |
| 3763 | dcf.right = mSystemRight; |
| 3764 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3765 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3766 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3767 | final boolean isAppWindow = |
| 3768 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3769 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3770 | final boolean topAtRest = |
| 3771 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3772 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3773 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3774 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3775 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 3776 | && (fl & WindowManager.LayoutParams. |
| 3777 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3778 | // Ensure policy decor includes status bar |
| 3779 | dcf.top = mStableTop; |
| 3780 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3781 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3782 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 3783 | && (fl & WindowManager.LayoutParams. |
| 3784 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3785 | // Ensure policy decor includes navigation bar |
| 3786 | dcf.bottom = mStableBottom; |
| 3787 | dcf.right = mStableRight; |
| 3788 | } |
| 3789 | } |
| 3790 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3791 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3792 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3793 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3794 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3795 | // This is the case for a normal activity window: we want it |
| 3796 | // to cover all of the screen space, and it can take care of |
| 3797 | // moving its contents to account for screen decorations that |
| 3798 | // intrude into that space. |
| 3799 | if (attached != null) { |
| 3800 | // If this window is attached to another, our display |
| 3801 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3802 | 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] | 3803 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3804 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3805 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3806 | // Status bar panels are the only windows who can go on top of |
| 3807 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3808 | // permission, so they have the same privileges as the status |
| 3809 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3810 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3811 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3812 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3813 | pf.left = df.left = of.left = hasNavBar |
| 3814 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3815 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3816 | pf.right = df.right = of.right = hasNavBar |
| 3817 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3818 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3819 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3820 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3821 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3822 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3823 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3824 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3825 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3826 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3827 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3828 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3829 | // Asking to layout into the overscan region, so give it that pure |
| 3830 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3831 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3832 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3833 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3834 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3835 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3836 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3837 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3838 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3839 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3840 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3841 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3842 | // only do this for application windows to ensure no window that |
| 3843 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3844 | pf.left = df.left = mOverscanScreenLeft; |
| 3845 | pf.top = df.top = mOverscanScreenTop; |
| 3846 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3847 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3848 | // We need to tell the app about where the frame inside the overscan |
| 3849 | // is, so it can inset its content by that amount -- it didn't ask |
| 3850 | // to actually extend itself into the overscan region. |
| 3851 | of.left = mUnrestrictedScreenLeft; |
| 3852 | of.top = mUnrestrictedScreenTop; |
| 3853 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3854 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3855 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3856 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3857 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3858 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3859 | + mRestrictedOverscanScreenWidth; |
| 3860 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3861 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3862 | // We need to tell the app about where the frame inside the overscan |
| 3863 | // is, so it can inset its content by that amount -- it didn't ask |
| 3864 | // to actually extend itself into the overscan region. |
| 3865 | of.left = mUnrestrictedScreenLeft; |
| 3866 | of.top = mUnrestrictedScreenTop; |
| 3867 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3868 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3869 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3870 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3871 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3872 | if (win.isVoiceInteraction()) { |
| 3873 | cf.left = mVoiceContentLeft; |
| 3874 | cf.top = mVoiceContentTop; |
| 3875 | cf.right = mVoiceContentRight; |
| 3876 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3877 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3878 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3879 | cf.left = mDockLeft; |
| 3880 | cf.top = mDockTop; |
| 3881 | cf.right = mDockRight; |
| 3882 | cf.bottom = mDockBottom; |
| 3883 | } else { |
| 3884 | cf.left = mContentLeft; |
| 3885 | cf.top = mContentTop; |
| 3886 | cf.right = mContentRight; |
| 3887 | cf.bottom = mContentBottom; |
| 3888 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3889 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3890 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3891 | // Full screen windows are always given a layout that is as if the |
| 3892 | // status bar and other transient decors are gone. This is to avoid |
| 3893 | // bad states when moving from a window that is not hding the |
| 3894 | // status bar to one that is. |
| 3895 | cf.left = mRestrictedScreenLeft; |
| 3896 | cf.top = mRestrictedScreenTop; |
| 3897 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3898 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3899 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3900 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3901 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3902 | vf.left = mCurLeft; |
| 3903 | vf.top = mCurTop; |
| 3904 | vf.right = mCurRight; |
| 3905 | vf.bottom = mCurBottom; |
| 3906 | } else { |
| 3907 | vf.set(cf); |
| 3908 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3909 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3910 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3911 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3912 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3913 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3914 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3915 | // A window that has requested to fill the entire screen just |
| 3916 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3917 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3918 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3919 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3920 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3921 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3922 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3923 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3924 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3925 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3926 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3927 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3928 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3929 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3930 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3931 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3932 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3933 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3934 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3935 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3936 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3937 | + mUnrestrictedScreenWidth; |
| 3938 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3939 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3940 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3941 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3942 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3943 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3944 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3945 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3946 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3947 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3948 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3949 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3950 | + mOverscanScreenWidth; |
| 3951 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3952 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 3953 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3954 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3955 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3956 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3957 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3958 | + mOverscanScreenWidth; |
| 3959 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3960 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3961 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3962 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 3963 | // it about the overscan area. |
| 3964 | pf.left = df.left = mOverscanScreenLeft; |
| 3965 | pf.top = df.top = mOverscanScreenTop; |
| 3966 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3967 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 3968 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 3969 | of.top = cf.top = mUnrestrictedScreenTop; |
| 3970 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3971 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3972 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3973 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3974 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3975 | // Asking to layout into the overscan region, so give it that pure |
| 3976 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3977 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3978 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3979 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3980 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3981 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3982 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3983 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3984 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 3985 | && (attrs.type == TYPE_STATUS_BAR |
| 3986 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 3987 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3988 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3989 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3990 | // Asking for layout as if the nav bar is hidden, lets the |
| 3991 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3992 | // 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] | 3993 | // can be above the nav bar can do this. |
| 3994 | // XXX This assumes that an app asking for this will also |
| 3995 | // ask for layout in only content. We can't currently figure out |
| 3996 | // 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] | 3997 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3998 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3999 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 4000 | + mUnrestrictedScreenWidth; |
| 4001 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 4002 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4003 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4004 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4005 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4006 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4007 | + mRestrictedScreenWidth; |
| 4008 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4009 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4010 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4011 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4012 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4013 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4014 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4015 | vf.left = mCurLeft; |
| 4016 | vf.top = mCurTop; |
| 4017 | vf.right = mCurRight; |
| 4018 | vf.bottom = mCurBottom; |
| 4019 | } else { |
| 4020 | vf.set(cf); |
| 4021 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4022 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4023 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4024 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4025 | // A child window should be placed inside of the same visible |
| 4026 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4027 | 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] | 4028 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4029 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4030 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4031 | // Otherwise, a normal window must be placed inside the content |
| 4032 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4033 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 4034 | // Status bar panels are the only windows who can go on top of |
| 4035 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4036 | // permission, so they have the same privileges as the status |
| 4037 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4038 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4039 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4040 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4041 | + mRestrictedScreenWidth; |
| 4042 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4043 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4044 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 4045 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 4046 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4047 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 4048 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 4049 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 4050 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4051 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4052 | pf.left = mContentLeft; |
| 4053 | pf.top = mContentTop; |
| 4054 | pf.right = mContentRight; |
| 4055 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 4056 | if (win.isVoiceInteraction()) { |
| 4057 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 4058 | df.top = of.top = cf.top = mVoiceContentTop; |
| 4059 | df.right = of.right = cf.right = mVoiceContentRight; |
| 4060 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 4061 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4062 | df.left = of.left = cf.left = mDockLeft; |
| 4063 | df.top = of.top = cf.top = mDockTop; |
| 4064 | df.right = of.right = cf.right = mDockRight; |
| 4065 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4066 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4067 | df.left = of.left = cf.left = mContentLeft; |
| 4068 | df.top = of.top = cf.top = mContentTop; |
| 4069 | df.right = of.right = cf.right = mContentRight; |
| 4070 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4071 | } |
| 4072 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4073 | vf.left = mCurLeft; |
| 4074 | vf.top = mCurTop; |
| 4075 | vf.right = mCurRight; |
| 4076 | vf.bottom = mCurBottom; |
| 4077 | } else { |
| 4078 | vf.set(cf); |
| 4079 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4080 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4081 | } |
| 4082 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4083 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 4084 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 4085 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4086 | df.left = df.top = -10000; |
| 4087 | df.right = df.bottom = 10000; |
| 4088 | if (attrs.type != TYPE_WALLPAPER) { |
| 4089 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 4090 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 4091 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4092 | } |
| 4093 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4094 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 4095 | // need to provide information to the clients that want to pretend that you can draw there. |
| 4096 | if (isDefaultDisplay && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) { |
| 4097 | osf = mTmpOutsetFrame; |
| 4098 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 4099 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4100 | if (outset > 0) { |
| 4101 | int rotation = Surface.ROTATION_0; |
| 4102 | try { |
| 4103 | rotation = mWindowManager.getRotation(); |
| 4104 | } catch (RemoteException e) { |
| 4105 | } |
| 4106 | if (rotation == Surface.ROTATION_0) { |
| 4107 | osf.bottom += outset; |
| 4108 | } else if (rotation == Surface.ROTATION_90) { |
| 4109 | osf.right += outset; |
| 4110 | } else if (rotation == Surface.ROTATION_180) { |
| 4111 | osf.top -= outset; |
| 4112 | } else if (rotation == Surface.ROTATION_270) { |
| 4113 | osf.left -= outset; |
| 4114 | } |
| 4115 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 4116 | + " with rotation " + rotation + ", result: " + osf); |
| 4117 | } |
| 4118 | } |
| 4119 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4120 | 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] | 4121 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4122 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4123 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 4124 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4125 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4126 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4127 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4128 | + " sf=" + sf.toShortString() |
| 4129 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4130 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4131 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4132 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4133 | // Dock windows carve out the bottom of the screen, so normal windows |
| 4134 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 4135 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 4136 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4137 | setLastInputMethodWindowLw(null, null); |
| 4138 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4139 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4140 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 4141 | && !win.getGivenInsetsPendingLw()) { |
| 4142 | offsetVoiceInputWindowLw(win); |
| 4143 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4144 | } |
| 4145 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4146 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4147 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4148 | top += win.getGivenContentInsetsLw().top; |
| 4149 | if (mContentBottom > top) { |
| 4150 | mContentBottom = top; |
| 4151 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4152 | if (mVoiceContentBottom > top) { |
| 4153 | mVoiceContentBottom = top; |
| 4154 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4155 | top = win.getVisibleFrameLw().top; |
| 4156 | top += win.getGivenVisibleInsetsLw().top; |
| 4157 | if (mCurBottom > top) { |
| 4158 | mCurBottom = top; |
| 4159 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4160 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4161 | + mDockBottom + " mContentBottom=" |
| 4162 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 4163 | } |
| 4164 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4165 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4166 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 4167 | top += win.getGivenContentInsetsLw().top; |
| 4168 | if (mVoiceContentBottom > top) { |
| 4169 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4170 | } |
| 4171 | } |
| 4172 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4173 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 4174 | @Override |
| 4175 | public void finishLayoutLw() { |
| 4176 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4180 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4181 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4182 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4183 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4184 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4185 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4186 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4187 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4188 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4189 | mForcingShowNavBar = false; |
| 4190 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4191 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4192 | mHideLockScreen = false; |
| 4193 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4194 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4195 | mShowingLockscreen = false; |
| 4196 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4197 | mWinShowWhenLocked = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4198 | mKeyguardSecure = isKeyguardSecure(); |
| 4199 | mKeyguardSecureIncludingHidden = mKeyguardSecure |
| 4200 | && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4204 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4205 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4206 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 4207 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4208 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4209 | if (mTopFullscreenOpaqueWindowState == null |
| 4210 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 4211 | mForcingShowNavBar = true; |
| 4212 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4213 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4214 | if (attrs.type == TYPE_STATUS_BAR) { |
| 4215 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 4216 | mForceStatusBarFromKeyguard = true; |
| 4217 | } |
| 4218 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 4219 | mForceStatusBarTransparent = true; |
| 4220 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4221 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4222 | |
| 4223 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 4224 | && attrs.type < FIRST_SYSTEM_WINDOW; |
| 4225 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 4226 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
| 4227 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4228 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 4229 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4230 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4231 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4232 | mForceStatusBarFromKeyguard = true; |
| 4233 | } else { |
| 4234 | mForceStatusBar = true; |
| 4235 | } |
| 4236 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4237 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4238 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4239 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4240 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4241 | // If the lockscreen was showing when the dream started then wait |
| 4242 | // for the dream to draw before hiding the lockscreen. |
| 4243 | if (!mDreamingLockscreen |
| 4244 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4245 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4246 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4247 | } |
| 4248 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4249 | |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4250 | if (appWindow) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4251 | final IApplicationToken appToken = win.getAppToken(); |
| 4252 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4253 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4254 | mAppsToBeHidden.remove(appToken); |
| 4255 | mAppsThatDismissKeyguard.remove(appToken); |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4256 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | 192d604 | 2014-12-02 23:24:48 -0800 | [diff] [blame] | 4257 | if (dismissKeyguard && !mKeyguardSecure) { |
| 4258 | mAppsThatDismissKeyguard.add(appToken); |
| 4259 | } else { |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4260 | mWinShowWhenLocked = win; |
| 4261 | mHideLockScreen = true; |
| 4262 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4263 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4264 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4265 | } else if (dismissKeyguard) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4266 | if (mKeyguardSecure) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4267 | mAppsToBeHidden.add(appToken); |
| 4268 | } else { |
| 4269 | mAppsToBeHidden.remove(appToken); |
| 4270 | } |
| 4271 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4272 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4273 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4274 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4275 | if (attrs.x == 0 && attrs.y == 0 |
| 4276 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4277 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 4278 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4279 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4280 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 4281 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4282 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4283 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4284 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4285 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4286 | "Setting mDismissKeyguard true by win " + win); |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4287 | mDismissKeyguard = (mWinDismissingKeyguard == win |
| 4288 | && mSecureDismissingKeyguard == mKeyguardSecure) |
| 4289 | ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4290 | mWinDismissingKeyguard = win; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4291 | mSecureDismissingKeyguard = mKeyguardSecure; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4292 | mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4293 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) { |
| 4294 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4295 | "Setting mHideLockScreen to true by win " + win); |
| 4296 | mHideLockScreen = true; |
| 4297 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4298 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4299 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4300 | mAllowLockscreenWhenOn = true; |
| 4301 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4302 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4303 | |
| 4304 | if (mWinShowWhenLocked != null && |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4305 | mWinShowWhenLocked.getAppToken() != win.getAppToken() && |
| 4306 | (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4307 | win.hideLw(false); |
| 4308 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4309 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4310 | } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) { |
| 4311 | // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window |
| 4312 | // that is being hidden in an animation - keep the |
| 4313 | // keyguard hidden until the new window shows up and |
| 4314 | // we know whether to show the keyguard or not. |
Adrian Roos | b85e1ec | 2015-05-29 15:23:18 -0700 | [diff] [blame] | 4315 | if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4316 | mHideLockScreen = true; |
| 4317 | mWinShowWhenLocked = win; |
| 4318 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4319 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4320 | if (mTopFullscreenOpaqueOrDimmingWindowState == null |
| 4321 | && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw() |
| 4322 | && win.isDimming()) { |
| 4323 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4324 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4328 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4329 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c5e73bf | 2015-04-21 15:41:26 +0000 | [diff] [blame] | 4330 | if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null && |
| 4331 | mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken() |
| 4332 | && isKeyguardLocked()) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4333 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4334 | // fullscreen window. |
| 4335 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4336 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4337 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4338 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4339 | } |
| 4340 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4341 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4342 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4343 | |
| 4344 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4345 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4346 | : null; |
| 4347 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4348 | // If we are not currently showing a dream then remember the current |
| 4349 | // lockscreen state. We will use this to determine whether the dream |
| 4350 | // started while the lockscreen was showing and remember this state |
| 4351 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4352 | if (!mShowingDream) { |
| 4353 | mDreamingLockscreen = mShowingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 4354 | if (mDreamingSleepTokenNeeded) { |
| 4355 | mDreamingSleepTokenNeeded = false; |
| 4356 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 4357 | } |
| 4358 | } else { |
| 4359 | if (!mDreamingSleepTokenNeeded) { |
| 4360 | mDreamingSleepTokenNeeded = true; |
| 4361 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 4362 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4363 | } |
| 4364 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4365 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4366 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4367 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 4368 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4369 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 4370 | && !mForceStatusBar |
| 4371 | && !mForceStatusBarFromKeyguard; |
| 4372 | if (!shouldBeTransparent) { |
| 4373 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 4374 | } else if (!mStatusBar.isVisibleLw()) { |
| 4375 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 4376 | } |
| 4377 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4378 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4379 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4380 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4381 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4382 | // Maintain fullscreen layout until incoming animation is complete. |
| 4383 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 4384 | // Transient status bar on the lockscreen is not allowed |
| 4385 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 4386 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 4387 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 4388 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4389 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4390 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4391 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4392 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4393 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4394 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4395 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4396 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4397 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4398 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4399 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 4400 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4401 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 4402 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4403 | if (mStatusBarController.isTransientShowing()) { |
| 4404 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4405 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4406 | } |
| 4407 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4408 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4409 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4410 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4411 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 4412 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 4413 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4414 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4415 | 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] | 4416 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4417 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4418 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4419 | } |
| 4420 | } |
| 4421 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4422 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4423 | if (mTopIsFullscreen != topIsFullscreen) { |
| 4424 | if (!topIsFullscreen) { |
| 4425 | // Force another layout when status bar becomes fully shown. |
| 4426 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4427 | } |
| 4428 | mTopIsFullscreen = topIsFullscreen; |
| 4429 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4430 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4431 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 4432 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4433 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 4434 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 4435 | + mHideLockScreen); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4436 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4437 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4438 | if (setKeyguardOccludedLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4439 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4440 | | FINISH_LAYOUT_REDO_CONFIG |
| 4441 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4442 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4443 | if (mKeyguardDelegate.isShowing()) { |
| 4444 | mHandler.post(new Runnable() { |
| 4445 | @Override |
| 4446 | public void run() { |
| 4447 | mKeyguardDelegate.keyguardDone(false, false); |
| 4448 | } |
| 4449 | }); |
| 4450 | } |
| 4451 | } else if (mHideLockScreen) { |
| 4452 | mKeyguardHidden = true; |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4453 | mWinDismissingKeyguard = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4454 | if (setKeyguardOccludedLw(true)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4455 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4456 | | FINISH_LAYOUT_REDO_CONFIG |
| 4457 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4458 | } |
| 4459 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4460 | mKeyguardHidden = false; |
| 4461 | if (setKeyguardOccludedLw(false)) { |
| 4462 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4463 | | FINISH_LAYOUT_REDO_CONFIG |
| 4464 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4465 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4466 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 4467 | // Only launch the next keyguard unlock window once per window. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4468 | mHandler.post(new Runnable() { |
| 4469 | @Override |
| 4470 | public void run() { |
| 4471 | mKeyguardDelegate.dismiss(); |
| 4472 | } |
| 4473 | }); |
| 4474 | } |
| 4475 | } else { |
| 4476 | mWinDismissingKeyguard = null; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4477 | mSecureDismissingKeyguard = false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4478 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4479 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4480 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4481 | | FINISH_LAYOUT_REDO_CONFIG |
| 4482 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4483 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 4484 | } |
| 4485 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4486 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4487 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4488 | // If the navigation bar has been hidden or shown, we need to do another |
| 4489 | // layout pass to update that window. |
| 4490 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4491 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4492 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4493 | // update since mAllowLockscreenWhenOn might have changed |
| 4494 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4495 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4496 | } |
| 4497 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4498 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4499 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4500 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4501 | * @return Whether the flags have changed and we have to redo the layout. |
| 4502 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4503 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
| 4504 | boolean wasOccluded = mKeyguardOccluded; |
| 4505 | boolean showing = mKeyguardDelegate.isShowing(); |
| 4506 | if (wasOccluded && !isOccluded && showing) { |
| 4507 | mKeyguardOccluded = false; |
| 4508 | mKeyguardDelegate.setOccluded(false); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4509 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4510 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4511 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4512 | } else if (!wasOccluded && isOccluded && showing) { |
| 4513 | mKeyguardOccluded = true; |
| 4514 | mKeyguardDelegate.setOccluded(true); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4515 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4516 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4517 | return true; |
| 4518 | } else { |
| 4519 | return false; |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | private boolean isStatusBarKeyguard() { |
| 4524 | return mStatusBar != null |
| 4525 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4526 | } |
| 4527 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4528 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4529 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4530 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4531 | // 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] | 4532 | return false; |
| 4533 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4534 | return true; |
| 4535 | } |
| 4536 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4537 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4538 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4539 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4540 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4541 | // If the navigation bar has been hidden or shown, we need to do another |
| 4542 | // layout pass to update that window. |
| 4543 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4544 | } |
| 4545 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4546 | } |
| 4547 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4548 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4549 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4550 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4551 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4552 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4553 | if (newLidState == mLidState) { |
| 4554 | return; |
| 4555 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4556 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4557 | mLidState = newLidState; |
| 4558 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4559 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4560 | |
| 4561 | if (lidOpen) { |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4562 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4563 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4564 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4565 | } |
| 4566 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4567 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4568 | @Override |
| 4569 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 4570 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 4571 | if (mCameraLensCoverState == lensCoverState) { |
| 4572 | return; |
| 4573 | } |
| 4574 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 4575 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 4576 | Intent intent; |
| 4577 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 4578 | mKeyguardDelegate.isShowing(); |
| 4579 | if (keyguardActive) { |
| 4580 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 4581 | } else { |
| 4582 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 4583 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4584 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4585 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4586 | } |
| 4587 | mCameraLensCoverState = lensCoverState; |
| 4588 | } |
| 4589 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4590 | void setHdmiPlugged(boolean plugged) { |
| 4591 | if (mHdmiPlugged != plugged) { |
| 4592 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4593 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4594 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4595 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4596 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4597 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4598 | } |
| 4599 | } |
| 4600 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4601 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4602 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4603 | // watch for HDMI plug messages if the hdmi switch exists |
| 4604 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4605 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4606 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4607 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4608 | FileReader reader = null; |
| 4609 | try { |
| 4610 | reader = new FileReader(filename); |
| 4611 | char[] buf = new char[15]; |
| 4612 | int n = reader.read(buf); |
| 4613 | if (n > 1) { |
| 4614 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4615 | } |
| 4616 | } catch (IOException ex) { |
| 4617 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4618 | } catch (NumberFormatException ex) { |
| 4619 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4620 | } finally { |
| 4621 | if (reader != null) { |
| 4622 | try { |
| 4623 | reader.close(); |
| 4624 | } catch (IOException ex) { |
| 4625 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4626 | } |
| 4627 | } |
| 4628 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4629 | // This dance forces the code in setHdmiPlugged to run. |
| 4630 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4631 | mHdmiPlugged = !plugged; |
| 4632 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4633 | } |
| 4634 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4635 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4636 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4637 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4638 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4639 | @Override public void run() { |
| 4640 | synchronized (mScreenshotLock) { |
| 4641 | if (mScreenshotConnection != null) { |
| 4642 | mContext.unbindService(mScreenshotConnection); |
| 4643 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4644 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4645 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4646 | } |
| 4647 | }; |
| 4648 | |
| 4649 | // Assume this is called from the Handler thread. |
| 4650 | private void takeScreenshot() { |
| 4651 | synchronized (mScreenshotLock) { |
| 4652 | if (mScreenshotConnection != null) { |
| 4653 | return; |
| 4654 | } |
| 4655 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4656 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 4657 | Intent intent = new Intent(); |
| 4658 | intent.setComponent(cn); |
| 4659 | ServiceConnection conn = new ServiceConnection() { |
| 4660 | @Override |
| 4661 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 4662 | synchronized (mScreenshotLock) { |
| 4663 | if (mScreenshotConnection != this) { |
| 4664 | return; |
| 4665 | } |
| 4666 | Messenger messenger = new Messenger(service); |
| 4667 | Message msg = Message.obtain(null, 1); |
| 4668 | final ServiceConnection myConn = this; |
| 4669 | Handler h = new Handler(mHandler.getLooper()) { |
| 4670 | @Override |
| 4671 | public void handleMessage(Message msg) { |
| 4672 | synchronized (mScreenshotLock) { |
| 4673 | if (mScreenshotConnection == myConn) { |
| 4674 | mContext.unbindService(mScreenshotConnection); |
| 4675 | mScreenshotConnection = null; |
| 4676 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 4677 | } |
| 4678 | } |
| 4679 | } |
| 4680 | }; |
| 4681 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 4682 | msg.arg1 = msg.arg2 = 0; |
| 4683 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 4684 | msg.arg1 = 1; |
| 4685 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 4686 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4687 | try { |
| 4688 | messenger.send(msg); |
| 4689 | } catch (RemoteException e) { |
| 4690 | } |
| 4691 | } |
| 4692 | } |
| 4693 | @Override |
| 4694 | public void onServiceDisconnected(ComponentName name) {} |
| 4695 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 4696 | if (mContext.bindServiceAsUser( |
| 4697 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4698 | mScreenshotConnection = conn; |
| 4699 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 4700 | } |
| 4701 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4702 | } |
| 4703 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4704 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4705 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4706 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4707 | if (!mSystemBooted) { |
| 4708 | // If we have not yet booted, don't let key events do anything. |
| 4709 | return 0; |
| 4710 | } |
| 4711 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4712 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4713 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 4714 | final boolean canceled = event.isCanceled(); |
| 4715 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 4716 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4717 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4718 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 4719 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 4720 | // the same as if it were open and in front. |
| 4721 | // This will prevent any keys other than the power button from waking the screen |
| 4722 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4723 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4724 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4725 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4726 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4727 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4728 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4729 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4730 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4731 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4732 | } |
| 4733 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4734 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4735 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 4736 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 4737 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4738 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4739 | // When the device is interactive or the key is injected pass the |
| 4740 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4741 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4742 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4743 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 4744 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 4745 | // to the application but preserve its wake key status to make sure we still move |
| 4746 | // from dozing to fully interactive if we would normally go from off to fully |
| 4747 | // interactive. |
| 4748 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4749 | } else { |
| 4750 | // When the screen is off and the key is not injected, determine whether |
| 4751 | // to wake the device but don't pass the key to the application. |
| 4752 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4753 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 4754 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4755 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4756 | } |
| 4757 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4758 | // If the key would be handled globally, just return the result, don't worry about special |
| 4759 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4760 | if (isValidGlobalKey(keyCode) |
| 4761 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4762 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4763 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4764 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4765 | return result; |
| 4766 | } |
| 4767 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4768 | boolean useHapticFeedback = down |
| 4769 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 4770 | && event.getRepeatCount() == 0; |
| 4771 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4772 | // Handle special keys. |
| 4773 | switch (keyCode) { |
| 4774 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 4775 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4776 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4777 | if (mUseTvRouting) { |
| 4778 | // On TVs volume keys never go to the foreground app |
| 4779 | result &= ~ACTION_PASS_TO_USER; |
| 4780 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4781 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 4782 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4783 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4784 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4785 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 4786 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 4787 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4788 | cancelPendingPowerKeyAction(); |
| 4789 | interceptScreenshotChord(); |
| 4790 | } |
| 4791 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4792 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4793 | cancelPendingScreenshotChordAction(); |
| 4794 | } |
| 4795 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 4796 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4797 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4798 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4799 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4800 | cancelPendingPowerKeyAction(); |
| 4801 | cancelPendingScreenshotChordAction(); |
| 4802 | } |
| 4803 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4804 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4805 | cancelPendingScreenshotChordAction(); |
| 4806 | } |
| 4807 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4808 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4809 | TelecomManager telecomManager = getTelecommService(); |
| 4810 | if (telecomManager != null) { |
| 4811 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4812 | // If an incoming call is ringing, either VOLUME key means |
| 4813 | // "silence ringer". We handle these keys here, rather than |
| 4814 | // in the InCallScreen, to make sure we'll respond to them |
| 4815 | // even if the InCallScreen hasn't come to the foreground yet. |
| 4816 | // Look for the DOWN event here, to agree with the "fallback" |
| 4817 | // behavior in the InCallScreen. |
| 4818 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4819 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4820 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4821 | // Silence the ringer. (It's safe to call this |
| 4822 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4823 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4824 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4825 | // And *don't* pass this key thru to the current activity |
| 4826 | // (which is probably the InCallScreen.) |
| 4827 | result &= ~ACTION_PASS_TO_USER; |
| 4828 | break; |
| 4829 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4830 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4831 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 4832 | // 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] | 4833 | // the application, just pass it to the session service. |
| 4834 | |
| 4835 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4836 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4837 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4838 | } |
| 4839 | } |
| 4840 | |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4841 | if ((result & ACTION_PASS_TO_USER) == 0) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4842 | if (mUseTvRouting) { |
| 4843 | dispatchDirectAudioEvent(event); |
| 4844 | } else { |
| 4845 | // If we aren't passing to the user and no one else |
| 4846 | // handled it send it to the session manager to |
| 4847 | // figure out. |
| 4848 | MediaSessionLegacyHelper.getHelper(mContext) |
| 4849 | .sendVolumeKeyEvent(event, true); |
| 4850 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4851 | break; |
| 4852 | } |
| 4853 | } |
| 4854 | break; |
| 4855 | } |
| 4856 | |
| 4857 | case KeyEvent.KEYCODE_ENDCALL: { |
| 4858 | result &= ~ACTION_PASS_TO_USER; |
| 4859 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4860 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4861 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4862 | if (telecomManager != null) { |
| 4863 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4864 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4865 | if (interactive && !hungUp) { |
| 4866 | mEndCallKeyHandled = false; |
| 4867 | mHandler.postDelayed(mEndCallLongPress, |
| 4868 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 4869 | } else { |
| 4870 | mEndCallKeyHandled = true; |
| 4871 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4872 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4873 | if (!mEndCallKeyHandled) { |
| 4874 | mHandler.removeCallbacks(mEndCallLongPress); |
| 4875 | if (!canceled) { |
| 4876 | if ((mEndcallBehavior |
| 4877 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 4878 | if (goHome()) { |
| 4879 | break; |
| 4880 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 4881 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4882 | if ((mEndcallBehavior |
| 4883 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 4884 | mPowerManager.goToSleep(event.getEventTime(), |
| 4885 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 4886 | isWakeKey = false; |
| 4887 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4888 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4889 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4890 | } |
| 4891 | break; |
| 4892 | } |
| 4893 | |
| 4894 | case KeyEvent.KEYCODE_POWER: { |
| 4895 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4896 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4897 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4898 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4899 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4900 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4901 | } |
| 4902 | break; |
| 4903 | } |
| 4904 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4905 | case KeyEvent.KEYCODE_SLEEP: { |
| 4906 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4907 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4908 | if (!mPowerManager.isInteractive()) { |
| 4909 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 4910 | } |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 4911 | if (down) { |
| 4912 | sleepPress(event.getEventTime()); |
| 4913 | } else { |
| 4914 | sleepRelease(event.getEventTime()); |
| 4915 | } |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4916 | break; |
| 4917 | } |
| 4918 | |
| 4919 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4920 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4921 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4922 | break; |
| 4923 | } |
| 4924 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4925 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4926 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4927 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4928 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4929 | case KeyEvent.KEYCODE_MUTE: |
| 4930 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4931 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4932 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4933 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4934 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4935 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4936 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4937 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 4938 | // If the global session is active pass all media keys to it |
| 4939 | // instead of the active window. |
| 4940 | result &= ~ACTION_PASS_TO_USER; |
| 4941 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4942 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4943 | // Only do this if we would otherwise not pass it to the user. In that |
| 4944 | // case, the PhoneWindow class will do the same thing, except it will |
| 4945 | // 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] | 4946 | // Note that we need to make a copy of the key event here because the |
| 4947 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4948 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4949 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4950 | new KeyEvent(event)); |
| 4951 | msg.setAsynchronous(true); |
| 4952 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4953 | } |
| 4954 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4955 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4956 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4957 | case KeyEvent.KEYCODE_CALL: { |
| 4958 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4959 | TelecomManager telecomManager = getTelecommService(); |
| 4960 | if (telecomManager != null) { |
| 4961 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4962 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4963 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4964 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4965 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4966 | // And *don't* pass this key thru to the current activity |
| 4967 | // (which is presumably the InCallScreen.) |
| 4968 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4969 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4970 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4971 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4972 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4973 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 4974 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 4975 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 4976 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 4977 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 4978 | // key event here because the original key event will be recycled when we return. |
| 4979 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 4980 | mBroadcastWakeLock.acquire(); |
| 4981 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 4982 | keyguardActive ? 1 : 0, 0); |
| 4983 | msg.setAsynchronous(true); |
| 4984 | msg.sendToTarget(); |
| 4985 | } |
| 4986 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4987 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4988 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4989 | if (useHapticFeedback) { |
| 4990 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 4991 | } |
| 4992 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4993 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4994 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4995 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4996 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4997 | return result; |
| 4998 | } |
| 4999 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5000 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5001 | * Returns true if the key can have global actions attached to it. |
| 5002 | * We reserve all power management keys for the system since they require |
| 5003 | * very careful handling. |
| 5004 | */ |
| 5005 | private static boolean isValidGlobalKey(int keyCode) { |
| 5006 | switch (keyCode) { |
| 5007 | case KeyEvent.KEYCODE_POWER: |
| 5008 | case KeyEvent.KEYCODE_WAKEUP: |
| 5009 | case KeyEvent.KEYCODE_SLEEP: |
| 5010 | return false; |
| 5011 | default: |
| 5012 | return true; |
| 5013 | } |
| 5014 | } |
| 5015 | |
| 5016 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5017 | * When the screen is off we ignore some keys that might otherwise typically |
| 5018 | * be considered wake keys. We filter them out here. |
| 5019 | * |
| 5020 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 5021 | * is always considered a wake key. |
| 5022 | */ |
| 5023 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 5024 | switch (keyCode) { |
| 5025 | // ignore volume keys unless docked |
| 5026 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5027 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5028 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5029 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 5030 | |
| 5031 | // ignore media and camera keys |
| 5032 | case KeyEvent.KEYCODE_MUTE: |
| 5033 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5034 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5035 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5036 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 5037 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5038 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5039 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5040 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5041 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 5042 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5043 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5044 | case KeyEvent.KEYCODE_CAMERA: |
| 5045 | return false; |
| 5046 | } |
| 5047 | return true; |
| 5048 | } |
| 5049 | |
| 5050 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5051 | /** {@inheritDoc} */ |
| 5052 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5053 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 5054 | if ((policyFlags & FLAG_WAKE) != 0) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5055 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) { |
| 5056 | return 0; |
| 5057 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5058 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5059 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5060 | if (shouldDispatchInputWhenNonInteractive()) { |
| 5061 | return ACTION_PASS_TO_USER; |
| 5062 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5063 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5064 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 5065 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 5066 | // wake up in this case. |
| 5067 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
| 5068 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming); |
| 5069 | } |
| 5070 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5071 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5072 | } |
| 5073 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5074 | private boolean shouldDispatchInputWhenNonInteractive() { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5075 | // Send events to keyguard while the screen is on. |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5076 | if (isKeyguardShowingAndNotOccluded() && mDisplay != null |
| 5077 | && mDisplay.getState() != Display.STATE_OFF) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5078 | return true; |
| 5079 | } |
| 5080 | |
| 5081 | // Send events to a dozing dream even if the screen is off since the dream |
| 5082 | // is in control of the state of the screen. |
| 5083 | IDreamManager dreamManager = getDreamManager(); |
| 5084 | |
| 5085 | try { |
| 5086 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 5087 | return true; |
| 5088 | } |
| 5089 | } catch (RemoteException e) { |
| 5090 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 5091 | } |
| 5092 | |
| 5093 | // Otherwise, consume events since the user can't see what is being |
| 5094 | // interacted with. |
| 5095 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5096 | } |
| 5097 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5098 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 5099 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 5100 | return; |
| 5101 | } |
| 5102 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 5103 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 5104 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5105 | String pkgName = mContext.getOpPackageName(); |
| 5106 | switch (keyCode) { |
| 5107 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5108 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5109 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5110 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5111 | } catch (RemoteException e) { |
| 5112 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 5113 | } |
| 5114 | break; |
| 5115 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5116 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5117 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5118 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5119 | } catch (RemoteException e) { |
| 5120 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 5121 | } |
| 5122 | break; |
| 5123 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5124 | try { |
| 5125 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5126 | getAudioService().adjustSuggestedStreamVolume( |
| 5127 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5128 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5129 | } |
| 5130 | } catch (RemoteException e) { |
| 5131 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 5132 | } |
| 5133 | break; |
| 5134 | } |
| 5135 | } |
| 5136 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5137 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 5138 | if (DEBUG_INPUT) { |
| 5139 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5140 | } |
| 5141 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5142 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 5143 | if (DEBUG_INPUT) { |
| 5144 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 5145 | } |
| 5146 | |
| 5147 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 5148 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5149 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 5150 | } |
| 5151 | |
| 5152 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 5153 | |
| 5154 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5155 | && event.getRepeatCount() == 0) { |
| 5156 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 5157 | |
| 5158 | Message msg = mHandler.obtainMessage( |
| 5159 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 5160 | msg.setAsynchronous(true); |
| 5161 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 5162 | } else { |
| 5163 | mBroadcastWakeLock.release(); |
| 5164 | } |
| 5165 | } |
| 5166 | |
| 5167 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 5168 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5169 | |
| 5170 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 5171 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 5172 | if (DEBUG_INPUT) { |
| 5173 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 5174 | } |
| 5175 | |
| 5176 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 5177 | mBroadcastWakeLock.release(); |
| 5178 | } |
| 5179 | |
| 5180 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 5181 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5182 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5183 | } |
| 5184 | } |
| 5185 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5186 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
| 5187 | Intent voiceIntent = |
| 5188 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 5189 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5190 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5191 | mBroadcastWakeLock.release(); |
| 5192 | } |
| 5193 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5194 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5195 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5196 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 5197 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 5198 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 5199 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5200 | } else { |
| 5201 | try { |
| 5202 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 5203 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5204 | mUiMode = uiModeService.getCurrentModeType(); |
| 5205 | } catch (RemoteException e) { |
| 5206 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 5207 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5208 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5209 | synchronized (mLock) { |
| 5210 | updateOrientationListenerLp(); |
| 5211 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5212 | } |
| 5213 | }; |
| 5214 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5215 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 5216 | @Override |
| 5217 | public void onReceive(Context context, Intent intent) { |
| 5218 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5219 | if (mKeyguardDelegate != null) { |
| 5220 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5221 | } |
| 5222 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5223 | if (mKeyguardDelegate != null) { |
| 5224 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5225 | } |
| 5226 | } |
| 5227 | } |
| 5228 | }; |
| 5229 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5230 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 5231 | @Override |
| 5232 | public void onReceive(Context context, Intent intent) { |
| 5233 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 5234 | // tickle the settings observer: this first ensures that we're |
| 5235 | // observing the relevant settings for the newly-active user, |
| 5236 | // and then updates our own bookkeeping based on the now- |
| 5237 | // current user. |
| 5238 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5239 | |
| 5240 | // force a re-application of focused window sysui visibility. |
| 5241 | // the window may never have been shown for this user |
| 5242 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5243 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5244 | mLastSystemUiFlags = 0; |
| 5245 | updateSystemUiVisibilityLw(); |
| 5246 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5247 | } |
| 5248 | } |
| 5249 | }; |
| 5250 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5251 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5252 | @Override |
| 5253 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5254 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 5255 | if (!isUserSetupComplete()) { |
| 5256 | // Swipe-up for navigation bar is disabled during setup |
| 5257 | return; |
| 5258 | } |
| 5259 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
| 5260 | mNavigationBarController.showTransient(); |
| 5261 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5262 | } |
| 5263 | }; |
| 5264 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5265 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5266 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5267 | if (!isUserSetupComplete()) { |
| 5268 | // Swipe-up for navigation bar is disabled during setup |
| 5269 | return; |
| 5270 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5271 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 5272 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5273 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 5274 | // Don't show status bar when swiping on already visible navigation bar |
| 5275 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5276 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5277 | return; |
| 5278 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5279 | if (sb) mStatusBarController.showTransient(); |
| 5280 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5281 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5282 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5283 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5284 | } |
| 5285 | } |
| 5286 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5287 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5288 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5289 | public void startedGoingToSleep(int why) { |
| 5290 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5291 | if (mKeyguardDelegate != null) { |
| 5292 | mKeyguardDelegate.onStartedGoingToSleep(why); |
| 5293 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | // Called on the PowerManager's Notifier thread. |
| 5297 | @Override |
| 5298 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5299 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5300 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5301 | |
| 5302 | // We must get this work done here because the power manager will drop |
| 5303 | // 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] | 5304 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5305 | mAwake = false; |
| 5306 | mKeyguardDrawComplete = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5307 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5308 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5309 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5310 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5311 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5312 | mKeyguardDelegate.onFinishedGoingToSleep(why); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5313 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5314 | } |
| 5315 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5316 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5317 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5318 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5319 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5320 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5321 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5322 | // Since goToSleep performs these functions synchronously, we must |
| 5323 | // do the same here. We cannot post this work to a handler because |
| 5324 | // that might cause it to become reordered with respect to what |
| 5325 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5326 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5327 | mAwake = true; |
| 5328 | mKeyguardDrawComplete = false; |
| 5329 | if (mKeyguardDelegate != null) { |
| 5330 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5331 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
| 5332 | } |
| 5333 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5334 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5335 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5336 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5337 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5338 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5339 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5340 | mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5341 | // ... eventually calls finishKeyguardDrawn |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5342 | } else { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5343 | if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5344 | finishKeyguardDrawn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5345 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5346 | } |
| 5347 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5348 | // Called on the PowerManager's Notifier thread. |
| 5349 | @Override |
| 5350 | public void finishedWakingUp() { |
| 5351 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
| 5352 | } |
| 5353 | |
| 5354 | private void wakeUpFromPowerKey(long eventTime) { |
| 5355 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey); |
| 5356 | } |
| 5357 | |
| 5358 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) { |
| 5359 | if (!wakeInTheaterMode && isTheaterModeEnabled()) { |
| 5360 | return false; |
| 5361 | } |
| 5362 | |
| 5363 | mPowerManager.wakeUp(wakeTime); |
| 5364 | return true; |
| 5365 | } |
| 5366 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5367 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5368 | synchronized (mLock) { |
| 5369 | if (!mAwake || mKeyguardDrawComplete) { |
| 5370 | return; // spurious |
| 5371 | } |
| 5372 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5373 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5374 | if (mKeyguardDelegate != null) { |
| 5375 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5376 | } |
| 5377 | } |
| 5378 | |
| 5379 | finishScreenTurningOn(); |
| 5380 | } |
| 5381 | |
| 5382 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5383 | @Override |
| 5384 | public void screenTurnedOff() { |
| 5385 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 5386 | |
| 5387 | synchronized (mLock) { |
| 5388 | mScreenOnEarly = false; |
| 5389 | mScreenOnFully = false; |
| 5390 | mWindowManagerDrawComplete = false; |
| 5391 | mScreenOnListener = null; |
| 5392 | updateOrientationListenerLp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5393 | } |
| 5394 | } |
| 5395 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5396 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5397 | @Override |
| 5398 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5399 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5400 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5401 | synchronized (mLock) { |
| 5402 | mScreenOnEarly = true; |
| 5403 | mScreenOnFully = false; |
| 5404 | mWindowManagerDrawComplete = false; |
| 5405 | mScreenOnListener = screenOnListener; |
| 5406 | updateOrientationListenerLp(); |
| 5407 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5408 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 5409 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 5410 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5411 | // ... eventually calls finishWindowsDrawn |
| 5412 | } |
| 5413 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5414 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5415 | synchronized (mLock) { |
| 5416 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
| 5417 | return; // spurious |
| 5418 | } |
| 5419 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5420 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5421 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5422 | |
| 5423 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5424 | } |
| 5425 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5426 | private void finishScreenTurningOn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5427 | final ScreenOnListener listener; |
| 5428 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5429 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5430 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5431 | "finishScreenTurningOn: mAwake=" + mAwake |
| 5432 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 5433 | + ", mScreenOnFully=" + mScreenOnFully |
| 5434 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 5435 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 5436 | |
| 5437 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 5438 | || (mAwake && !mKeyguardDrawComplete)) { |
| 5439 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5440 | } |
| 5441 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5442 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 5443 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 5444 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5445 | mScreenOnFully = true; |
| 5446 | |
| 5447 | // Remember the first time we draw the keyguard so we know when we're done with |
| 5448 | // the main part of booting and can enable the screen and hide boot messages. |
| 5449 | if (!mKeyguardDrawnOnce && mAwake) { |
| 5450 | mKeyguardDrawnOnce = true; |
| 5451 | enableScreen = true; |
| 5452 | if (mBootMessageNeedsHiding) { |
| 5453 | mBootMessageNeedsHiding = false; |
| 5454 | hideBootMessages(); |
| 5455 | } |
| 5456 | } else { |
| 5457 | enableScreen = false; |
| 5458 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5459 | } |
| 5460 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5461 | if (listener != null) { |
| 5462 | listener.onScreenOn(); |
| 5463 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 5464 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5465 | if (enableScreen) { |
| 5466 | try { |
| 5467 | mWindowManager.enableScreenIfNeeded(); |
| 5468 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5469 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5474 | synchronized (mLock) { |
| 5475 | if (!mKeyguardDrawnOnce) { |
| 5476 | mBootMessageNeedsHiding = true; |
| 5477 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 5478 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5479 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5480 | |
| 5481 | if (mBootMsgDialog != null) { |
| 5482 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 5483 | mBootMsgDialog.dismiss(); |
| 5484 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5485 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5486 | } |
| 5487 | |
| 5488 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5489 | public boolean isScreenOn() { |
| 5490 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5491 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5492 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5493 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5494 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5495 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5496 | if (mKeyguardDelegate != null) { |
| 5497 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5498 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5502 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5503 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5504 | if (mKeyguardDelegate != null) { |
| 5505 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5506 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5507 | } |
| 5508 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5509 | private boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5510 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5511 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5512 | } |
| 5513 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5514 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5515 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5516 | public boolean isKeyguardLocked() { |
| 5517 | return keyguardOn(); |
| 5518 | } |
| 5519 | |
| 5520 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5521 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5522 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5523 | if (mKeyguardDelegate == null) return false; |
| 5524 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5525 | } |
| 5526 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5527 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5528 | @Override |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 5529 | public boolean isKeyguardShowingOrOccluded() { |
| 5530 | return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing(); |
| 5531 | } |
| 5532 | |
| 5533 | /** {@inheritDoc} */ |
| 5534 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5535 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5536 | if (mKeyguardDelegate == null) return false; |
| 5537 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5538 | } |
| 5539 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5540 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5541 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5542 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5543 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5544 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5545 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5546 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 5547 | // ask the keyguard to prompt the user to authenticate if necessary |
| 5548 | mKeyguardDelegate.dismiss(); |
| 5549 | } |
| 5550 | }); |
| 5551 | } |
| 5552 | } |
| 5553 | |
| 5554 | public void notifyActivityDrawnForKeyguardLw() { |
| 5555 | if (mKeyguardDelegate != null) { |
| 5556 | mHandler.post(new Runnable() { |
| 5557 | @Override |
| 5558 | public void run() { |
| 5559 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5560 | } |
| 5561 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5562 | } |
| 5563 | } |
| 5564 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5565 | @Override |
| 5566 | public boolean isKeyguardDrawnLw() { |
| 5567 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5568 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5569 | } |
| 5570 | } |
| 5571 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5572 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5573 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5574 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5575 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5576 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5577 | } |
| 5578 | } |
| 5579 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5580 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5581 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5582 | } |
| 5583 | |
| 5584 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5585 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5586 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 5587 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5588 | @Override |
| 5589 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5590 | if (false) { |
| 5591 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 5592 | + orientation + ", last=" + lastRotation |
| 5593 | + "); user=" + mUserRotation + " " |
| 5594 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 5595 | ? "USER_ROTATION_LOCKED" : "") |
| 5596 | ); |
| 5597 | } |
| 5598 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 5599 | if (mForceDefaultOrientation) { |
| 5600 | return Surface.ROTATION_0; |
| 5601 | } |
| 5602 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5603 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5604 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 5605 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 5606 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5607 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5608 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5609 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5610 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5611 | // Ignore sensor when lid switch is open and rotation is forced. |
| 5612 | preferredRotation = mLidOpenRotation; |
| 5613 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5614 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5615 | // Ignore sensor when in car dock unless explicitly enabled. |
| 5616 | // This case can override the behavior of NOSENSOR, and can also |
| 5617 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5618 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5619 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 5620 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5621 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 5622 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5623 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5624 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 5625 | // This case can override the behavior of NOSENSOR, and can also |
| 5626 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5627 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5628 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5629 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 5630 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 5631 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5632 | preferredRotation = mDemoHdmiRotation; |
| 5633 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 5634 | && mUndockedHdmiRotation >= 0) { |
| 5635 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 5636 | // been specified in the configuration (only for legacy devices without |
| 5637 | // full multi-display support). |
| 5638 | // Note that the dock orientation overrides the HDMI orientation. |
| 5639 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 5640 | } else if (mDemoRotationLock) { |
| 5641 | // Ignore sensor when demo rotation lock is enabled. |
| 5642 | // Note that the dock orientation and HDMI rotation lock override this. |
| 5643 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5644 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 5645 | // Application just wants to remain locked in the last rotation. |
| 5646 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5647 | } else if (!mSupportAutoRotation) { |
| 5648 | // If we don't support auto-rotation then bail out here and ignore |
| 5649 | // the sensor and any rotation lock settings. |
| 5650 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5651 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5652 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5653 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 5654 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 5655 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 5656 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5657 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 5658 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5659 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 5660 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 5661 | // Otherwise, use sensor only if requested by the application or enabled |
| 5662 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5663 | if (mAllowAllRotations < 0) { |
| 5664 | // Can't read this during init() because the context doesn't |
| 5665 | // have display metrics at that time so we cannot determine |
| 5666 | // tablet vs. phone then. |
| 5667 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 5668 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 5669 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5670 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5671 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5672 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5673 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5674 | preferredRotation = sensorRotation; |
| 5675 | } else { |
| 5676 | preferredRotation = lastRotation; |
| 5677 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5678 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 5679 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 5680 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 5681 | // The idea is that the user rotation expresses a weak preference for the direction |
| 5682 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 5683 | // 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] | 5684 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5685 | } else { |
| 5686 | // No overriding preference. |
| 5687 | // We will do exactly what the application asked us to do. |
| 5688 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5689 | } |
| 5690 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5691 | switch (orientation) { |
| 5692 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5693 | // Return portrait unless overridden. |
| 5694 | if (isAnyPortrait(preferredRotation)) { |
| 5695 | return preferredRotation; |
| 5696 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5697 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5698 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5699 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5700 | // Return landscape unless overridden. |
| 5701 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5702 | return preferredRotation; |
| 5703 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5704 | return mLandscapeRotation; |
| 5705 | |
| 5706 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5707 | // Return reverse portrait unless overridden. |
| 5708 | if (isAnyPortrait(preferredRotation)) { |
| 5709 | return preferredRotation; |
| 5710 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5711 | return mUpsideDownRotation; |
| 5712 | |
| 5713 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5714 | // Return seascape unless overridden. |
| 5715 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5716 | return preferredRotation; |
| 5717 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5718 | return mSeascapeRotation; |
| 5719 | |
| 5720 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5721 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5722 | // Return either landscape rotation. |
| 5723 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5724 | return preferredRotation; |
| 5725 | } |
| 5726 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 5727 | return lastRotation; |
| 5728 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5729 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5730 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5731 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5732 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5733 | // Return either portrait rotation. |
| 5734 | if (isAnyPortrait(preferredRotation)) { |
| 5735 | return preferredRotation; |
| 5736 | } |
| 5737 | if (isAnyPortrait(lastRotation)) { |
| 5738 | return lastRotation; |
| 5739 | } |
| 5740 | return mPortraitRotation; |
| 5741 | |
| 5742 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5743 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 5744 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5745 | if (preferredRotation >= 0) { |
| 5746 | return preferredRotation; |
| 5747 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5748 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 5749 | } |
| 5750 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5751 | } |
| 5752 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5753 | @Override |
| 5754 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 5755 | switch (orientation) { |
| 5756 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 5757 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 5758 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 5759 | return isAnyPortrait(rotation); |
| 5760 | |
| 5761 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 5762 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 5763 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 5764 | return isLandscapeOrSeascape(rotation); |
| 5765 | |
| 5766 | default: |
| 5767 | return true; |
| 5768 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5769 | } |
| 5770 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5771 | @Override |
| 5772 | public void setRotationLw(int rotation) { |
| 5773 | mOrientationListener.setCurrentRotation(rotation); |
| 5774 | } |
| 5775 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5776 | private boolean isLandscapeOrSeascape(int rotation) { |
| 5777 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5778 | } |
| 5779 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5780 | private boolean isAnyPortrait(int rotation) { |
| 5781 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5784 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5785 | public int getUserRotationMode() { |
| 5786 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 5787 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 5788 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 5789 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5790 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5791 | |
| 5792 | // 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] | 5793 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5794 | public void setUserRotationMode(int mode, int rot) { |
| 5795 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5796 | |
| 5797 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5798 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5799 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5800 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5801 | rot, |
| 5802 | UserHandle.USER_CURRENT); |
| 5803 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5804 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5805 | 0, |
| 5806 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5807 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5808 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5809 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5810 | 1, |
| 5811 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5812 | } |
| 5813 | } |
| 5814 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5815 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5816 | public void setSafeMode(boolean safeMode) { |
| 5817 | mSafeMode = safeMode; |
| 5818 | performHapticFeedbackLw(null, safeMode |
| 5819 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 5820 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5821 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5822 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 5823 | static long[] getLongIntArray(Resources r, int resid) { |
| 5824 | int[] ar = r.getIntArray(resid); |
| 5825 | if (ar == null) { |
| 5826 | return null; |
| 5827 | } |
| 5828 | long[] out = new long[ar.length]; |
| 5829 | for (int i=0; i<ar.length; i++) { |
| 5830 | out[i] = ar[i]; |
| 5831 | } |
| 5832 | return out; |
| 5833 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5834 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5835 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5836 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5837 | public void systemReady() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5838 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 5839 | mKeyguardDelegate.onSystemReady(); |
| 5840 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5841 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5842 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5843 | synchronized (mLock) { |
| 5844 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5845 | mSystemReady = true; |
| 5846 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5847 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5848 | public void run() { |
| 5849 | updateSettings(); |
| 5850 | } |
| 5851 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5852 | } |
| 5853 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5854 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5855 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5856 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5857 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5858 | if (mKeyguardDelegate != null) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 5859 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5860 | mKeyguardDelegate.onBootCompleted(); |
| 5861 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5862 | synchronized (mLock) { |
| 5863 | mSystemBooted = true; |
| 5864 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5865 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5866 | screenTurningOn(null); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5867 | } |
| 5868 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5869 | ProgressDialog mBootMsgDialog = null; |
| 5870 | |
| 5871 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5872 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5873 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5874 | mHandler.post(new Runnable() { |
| 5875 | @Override public void run() { |
| 5876 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 5877 | int theme; |
| 5878 | if (mContext.getPackageManager().hasSystemFeature( |
| 5879 | PackageManager.FEATURE_WATCH)) { |
| 5880 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 5881 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 5882 | PackageManager.FEATURE_TELEVISION)) { |
| 5883 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 5884 | } else { |
| 5885 | theme = 0; |
| 5886 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 5887 | |
| 5888 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 5889 | // This dialog will consume all events coming in to |
| 5890 | // it, to avoid it trying to do things too early in boot. |
| 5891 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 5892 | return true; |
| 5893 | } |
| 5894 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5895 | return true; |
| 5896 | } |
| 5897 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 5898 | return true; |
| 5899 | } |
| 5900 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 5901 | return true; |
| 5902 | } |
| 5903 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 5904 | return true; |
| 5905 | } |
| 5906 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 5907 | AccessibilityEvent event) { |
| 5908 | return true; |
| 5909 | } |
| 5910 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 5911 | if (mContext.getPackageManager().isUpgrade()) { |
| 5912 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 5913 | } else { |
| 5914 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 5915 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5916 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 5917 | mBootMsgDialog.setIndeterminate(true); |
| 5918 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5919 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5920 | mBootMsgDialog.getWindow().addFlags( |
| 5921 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 5922 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 5923 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 5924 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 5925 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 5926 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5927 | mBootMsgDialog.setCancelable(false); |
| 5928 | mBootMsgDialog.show(); |
| 5929 | } |
| 5930 | mBootMsgDialog.setMessage(msg); |
| 5931 | } |
| 5932 | }); |
| 5933 | } |
| 5934 | |
| 5935 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5936 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5937 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5938 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5939 | } |
| 5940 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5941 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5942 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5943 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5944 | // *************************************** |
| 5945 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 5946 | // *************************************** |
| 5947 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 5948 | // WITH ITS LOCKS HELD. |
| 5949 | // |
| 5950 | // This code must be VERY careful about the locks |
| 5951 | // it acquires. |
| 5952 | // In fact, the current code acquires way too many, |
| 5953 | // and probably has lurking deadlocks. |
| 5954 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5955 | synchronized (mScreenLockTimeout) { |
| 5956 | if (mLockScreenTimerActive) { |
| 5957 | // reset the timer |
| 5958 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5959 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5960 | } |
| 5961 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5962 | } |
| 5963 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5964 | class ScreenLockTimeout implements Runnable { |
| 5965 | Bundle options; |
| 5966 | |
| 5967 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5968 | public void run() { |
| 5969 | synchronized (this) { |
| 5970 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5971 | if (mKeyguardDelegate != null) { |
| 5972 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5973 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5974 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5975 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5976 | } |
| 5977 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5978 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5979 | public void setLockOptions(Bundle options) { |
| 5980 | this.options = options; |
| 5981 | } |
| 5982 | } |
| 5983 | |
| 5984 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 5985 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5986 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5987 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5988 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 5989 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5990 | if (options != null) { |
| 5991 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 5992 | // until the runnable actually executes. |
| 5993 | mScreenLockTimeout.setLockOptions(options); |
| 5994 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 5995 | mHandler.post(mScreenLockTimeout); |
| 5996 | } |
| 5997 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5998 | private void updateLockScreenTimeout() { |
| 5999 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6000 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6001 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6002 | if (mLockScreenTimerActive != enable) { |
| 6003 | if (enable) { |
| 6004 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 6005 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6006 | } else { |
| 6007 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 6008 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6009 | } |
| 6010 | mLockScreenTimerActive = enable; |
| 6011 | } |
| 6012 | } |
| 6013 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6014 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6015 | private void updateDreamingSleepToken(boolean acquire) { |
| 6016 | if (acquire) { |
| 6017 | if (mDreamingSleepToken == null) { |
| 6018 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 6019 | } |
| 6020 | } else { |
| 6021 | if (mDreamingSleepToken != null) { |
| 6022 | mDreamingSleepToken.release(); |
| 6023 | } |
| 6024 | } |
| 6025 | } |
| 6026 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6027 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6028 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6029 | public void enableScreenAfterBoot() { |
| 6030 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6031 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6032 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6033 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 6034 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6035 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6036 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6037 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 6038 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6039 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6040 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6041 | |
| 6042 | synchronized (mLock) { |
| 6043 | updateWakeGestureListenerLp(); |
| 6044 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6045 | } |
| 6046 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6047 | void updateUiMode() { |
| 6048 | if (mUiModeManager == null) { |
| 6049 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 6050 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 6051 | } |
| 6052 | try { |
| 6053 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 6054 | } catch (RemoteException e) { |
| 6055 | } |
| 6056 | } |
| 6057 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6058 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6059 | try { |
| 6060 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 6061 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 6062 | } catch (RemoteException e) { |
| 6063 | // Ignore |
| 6064 | } |
| 6065 | } |
| 6066 | |
| 6067 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 6068 | try { |
| 6069 | //set orientation on WindowManager |
| 6070 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6071 | } catch (RemoteException e) { |
| 6072 | // Ignore |
| 6073 | } |
| 6074 | } |
| 6075 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6076 | /** |
| 6077 | * Return an Intent to launch the currently active dock app as home. Returns |
| 6078 | * null if the standard home should be launched, which is the case if any of the following is |
| 6079 | * true: |
| 6080 | * <ul> |
| 6081 | * <li>The device is not in either car mode or desk mode |
| 6082 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 6083 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 6084 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 6085 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 6086 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6087 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6088 | */ |
| 6089 | Intent createHomeDockIntent() { |
| 6090 | Intent intent = null; |
| 6091 | |
| 6092 | // What home does is based on the mode, not the dock state. That |
| 6093 | // is, when in car mode you should be taken to car home regardless |
| 6094 | // of whether we are actually in a car dock. |
| 6095 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 6096 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 6097 | intent = mCarDockIntent; |
| 6098 | } |
| 6099 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 6100 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 6101 | intent = mDeskDockIntent; |
| 6102 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6103 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 6104 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6105 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 6106 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 6107 | // Always launch dock home from home when watch is docked, if it exists. |
| 6108 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | if (intent == null) { |
| 6112 | return null; |
| 6113 | } |
| 6114 | |
| 6115 | ActivityInfo ai = null; |
| 6116 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 6117 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 6118 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6119 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6120 | if (info != null) { |
| 6121 | ai = info.activityInfo; |
| 6122 | } |
| 6123 | if (ai != null |
| 6124 | && ai.metaData != null |
| 6125 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 6126 | intent = new Intent(intent); |
| 6127 | intent.setClassName(ai.packageName, ai.name); |
| 6128 | return intent; |
| 6129 | } |
| 6130 | |
| 6131 | return null; |
| 6132 | } |
| 6133 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6134 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 6135 | if (awakenFromDreams) { |
| 6136 | awakenDreams(); |
| 6137 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6138 | |
| 6139 | Intent dock = createHomeDockIntent(); |
| 6140 | if (dock != null) { |
| 6141 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6142 | if (fromHomeKey) { |
| 6143 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6144 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6145 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6146 | return; |
| 6147 | } catch (ActivityNotFoundException e) { |
| 6148 | } |
| 6149 | } |
| 6150 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6151 | Intent intent; |
| 6152 | |
| 6153 | if (fromHomeKey) { |
| 6154 | intent = new Intent(mHomeIntent); |
| 6155 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6156 | } else { |
| 6157 | intent = mHomeIntent; |
| 6158 | } |
| 6159 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 6160 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6161 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6162 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6163 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6164 | * goes to the home screen |
| 6165 | * @return whether it did anything |
| 6166 | */ |
| 6167 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6168 | if (!isUserSetupComplete()) { |
| 6169 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 6170 | return false; |
| 6171 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6172 | if (false) { |
| 6173 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 6174 | try { |
| 6175 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6176 | } catch (RemoteException e) { |
| 6177 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 6178 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6179 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6180 | } else { |
| 6181 | // This code brings home to the front or, if it is already |
| 6182 | // at the front, puts the device to sleep. |
| 6183 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 6184 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 6185 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 6186 | Log.d(TAG, "UTS-TEST-MODE"); |
| 6187 | } else { |
| 6188 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6189 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6190 | Intent dock = createHomeDockIntent(); |
| 6191 | if (dock != null) { |
| 6192 | int result = ActivityManagerNative.getDefault() |
| 6193 | .startActivityAsUser(null, null, dock, |
| 6194 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6195 | null, null, 0, |
| 6196 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6197 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6198 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 6199 | return false; |
| 6200 | } |
| 6201 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6202 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6203 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6204 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6205 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6206 | null, null, 0, |
| 6207 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6208 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6209 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6210 | return false; |
| 6211 | } |
| 6212 | } catch (RemoteException ex) { |
| 6213 | // bummer, the activity manager, which is in this process, is dead |
| 6214 | } |
| 6215 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6216 | return true; |
| 6217 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6218 | |
| 6219 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6220 | public void setCurrentOrientationLw(int newOrientation) { |
| 6221 | synchronized (mLock) { |
| 6222 | if (newOrientation != mCurrentAppOrientation) { |
| 6223 | mCurrentAppOrientation = newOrientation; |
| 6224 | updateOrientationListenerLp(); |
| 6225 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6226 | } |
| 6227 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6228 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6229 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 6230 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 6231 | return; |
| 6232 | } |
| 6233 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 6234 | Context.AUDIO_SERVICE); |
| 6235 | if (audioManager.isSilentMode()) { |
| 6236 | return; |
| 6237 | } |
| 6238 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 6239 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 6240 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 6241 | ringTone.play(); |
| 6242 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6243 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6244 | private boolean isTheaterModeEnabled() { |
| 6245 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6246 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 6247 | } |
| 6248 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6249 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 6250 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6251 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 6252 | } |
| 6253 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6254 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6255 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 6256 | if (!mVibrator.hasVibrator()) { |
| 6257 | return false; |
| 6258 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6259 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 6260 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 6261 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6262 | return false; |
| 6263 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6264 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6265 | switch (effectId) { |
| 6266 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6267 | pattern = mLongPressVibePattern; |
| 6268 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6269 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6270 | pattern = mVirtualKeyVibePattern; |
| 6271 | break; |
| 6272 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 6273 | pattern = mKeyboardTapVibePattern; |
| 6274 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 6275 | case HapticFeedbackConstants.CLOCK_TICK: |
| 6276 | pattern = mClockTickVibePattern; |
| 6277 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 6278 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 6279 | pattern = mCalendarDateVibePattern; |
| 6280 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6281 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6282 | pattern = mSafeModeDisabledVibePattern; |
| 6283 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6284 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6285 | pattern = mSafeModeEnabledVibePattern; |
| 6286 | break; |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame^] | 6287 | case HapticFeedbackConstants.CONTEXT_CLICK: |
| 6288 | pattern = mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 6289 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6290 | default: |
| 6291 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6292 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6293 | int owningUid; |
| 6294 | String owningPackage; |
| 6295 | if (win != null) { |
| 6296 | owningUid = win.getOwningUid(); |
| 6297 | owningPackage = win.getOwningPackage(); |
| 6298 | } else { |
| 6299 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 6300 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6301 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6302 | if (pattern.length == 1) { |
| 6303 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6304 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6305 | } else { |
| 6306 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6307 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6308 | } |
| 6309 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6310 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6311 | |
| 6312 | @Override |
| 6313 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6314 | } |
| 6315 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6316 | @Override |
| 6317 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6318 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 6319 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6320 | } |
| 6321 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 6322 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6323 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6324 | // If there is no window focused, there will be nobody to handle the events |
| 6325 | // 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] | 6326 | final WindowState win = mFocusedWindow != null ? mFocusedWindow |
| 6327 | : mTopFullscreenOpaqueWindowState; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6328 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6329 | return 0; |
| 6330 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6331 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6332 | // We are updating at a point where the keyguard has gotten |
| 6333 | // focus, but we were last in a state where the top window is |
| 6334 | // hiding it. This is probably because the keyguard as been |
| 6335 | // shown while the top window was displayed, so we want to ignore |
| 6336 | // it here because this is just a very transient change and it |
| 6337 | // will quickly lose focus once it correctly gets hidden. |
| 6338 | return 0; |
| 6339 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6340 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 6341 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6342 | & ~mResettingSystemUiFlags |
| 6343 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6344 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6345 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6346 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6347 | tmpVisibility = updateLightStatusBarLw(tmpVisibility); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6348 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6349 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6350 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 6351 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6352 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6353 | return 0; |
| 6354 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6355 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6356 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6357 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6358 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6359 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6360 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6361 | try { |
| 6362 | IStatusBarService statusbar = getStatusBarService(); |
| 6363 | if (statusbar != null) { |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 6364 | statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString()); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6365 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6366 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6367 | } catch (RemoteException e) { |
| 6368 | // re-acquire status bar service next time it is needed. |
| 6369 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6370 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6371 | } |
| 6372 | }); |
| 6373 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6374 | } |
| 6375 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6376 | private int updateLightStatusBarLw(int vis) { |
| 6377 | WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6378 | ? mStatusBar |
| 6379 | : mTopFullscreenOpaqueOrDimmingWindowState; |
| 6380 | |
| 6381 | if (statusColorWin != null) { |
| 6382 | if (statusColorWin == mTopFullscreenOpaqueWindowState) { |
| 6383 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 6384 | // its light flag. |
| 6385 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6386 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 6387 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6388 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 6389 | // Otherwise if it's dimming, clear the light flag. |
| 6390 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6391 | } |
| 6392 | } |
| 6393 | return vis; |
| 6394 | } |
| 6395 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6396 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6397 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6398 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6399 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6400 | : mTopFullscreenOpaqueWindowState; |
| 6401 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6402 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6403 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6404 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 6405 | int type = win.getAttrs().type; |
| 6406 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6407 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6408 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 6409 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 6410 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 6411 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 6412 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6413 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6414 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 6415 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6416 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6417 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6418 | |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 6419 | if (!areTranslucentBarsAllowed() && transWin != mStatusBar) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 6420 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 6421 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6422 | } |
| 6423 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6424 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6425 | boolean immersiveSticky = |
| 6426 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6427 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6428 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6429 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6430 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 6431 | boolean hideStatusBarSysui = |
| 6432 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6433 | boolean hideNavBarSysui = |
| 6434 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6435 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6436 | boolean transientStatusBarAllowed = |
| 6437 | mStatusBar != null && ( |
| 6438 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6439 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6440 | || statusBarHasFocus); |
| 6441 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6442 | boolean transientNavBarAllowed = |
| 6443 | mNavigationBar != null && |
| 6444 | hideNavBarSysui && immersiveSticky; |
| 6445 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6446 | final long now = SystemClock.uptimeMillis(); |
| 6447 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 6448 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 6449 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 6450 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 6451 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 6452 | mPendingPanicGestureUptime = 0; |
| 6453 | mStatusBarController.showTransient(); |
| 6454 | mNavigationBarController.showTransient(); |
| 6455 | } |
| 6456 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6457 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6458 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6459 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6460 | && !transientNavBarAllowed; |
| 6461 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6462 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6463 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 6464 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6465 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6466 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6467 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 6468 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 6469 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 6470 | |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 6471 | if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType()) |
| 6472 | > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6473 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 6474 | // the input events. |
| 6475 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 6476 | } |
| 6477 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6478 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 6479 | |
| 6480 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6481 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 6482 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 6483 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6484 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6485 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 6486 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6487 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6488 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6489 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 6490 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6491 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6492 | } |
| 6493 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6494 | private void clearClearableFlagsLw() { |
| 6495 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6496 | if (newVal != mResettingSystemUiFlags) { |
| 6497 | mResettingSystemUiFlags = newVal; |
| 6498 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 6499 | } |
| 6500 | } |
| 6501 | |
| 6502 | private boolean isImmersiveMode(int vis) { |
| 6503 | 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] | 6504 | return mNavigationBar != null |
| 6505 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 6506 | && (vis & flags) != 0 |
| 6507 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6508 | } |
| 6509 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6510 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6511 | * @return whether the navigation or status bar can be made translucent |
| 6512 | * |
| 6513 | * This should return true unless touch exploration is not enabled or |
| 6514 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6515 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6516 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 6517 | return mTranslucentDecorEnabled |
| 6518 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6519 | } |
| 6520 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6521 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 6522 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6523 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6524 | public boolean hasNavigationBar() { |
| 6525 | return mHasNavigationBar; |
| 6526 | } |
| 6527 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 6528 | @Override |
| 6529 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 6530 | mLastInputMethodWindow = ime; |
| 6531 | mLastInputMethodTargetWindow = target; |
| 6532 | } |
| 6533 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6534 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 6535 | public int getInputMethodWindowVisibleHeightLw() { |
| 6536 | return mDockBottom - mCurBottom; |
| 6537 | } |
| 6538 | |
| 6539 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6540 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6541 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6542 | if (mKeyguardDelegate != null) { |
| 6543 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6544 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 6545 | if (mStatusBarService != null) { |
| 6546 | try { |
| 6547 | mStatusBarService.setCurrentUser(newUserId); |
| 6548 | } catch (RemoteException e) { |
| 6549 | // oh well |
| 6550 | } |
| 6551 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6552 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6553 | } |
| 6554 | |
| 6555 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 6556 | public boolean canMagnifyWindow(int windowType) { |
| 6557 | switch (windowType) { |
| 6558 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 6559 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 6560 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 6561 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 6562 | return false; |
| 6563 | } |
| 6564 | } |
| 6565 | return true; |
| 6566 | } |
| 6567 | |
| 6568 | @Override |
| 6569 | public boolean isTopLevelWindow(int windowType) { |
| 6570 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 6571 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 6572 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 6573 | } |
| 6574 | return true; |
| 6575 | } |
| 6576 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 6577 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 6578 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6579 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6580 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 6581 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6582 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6583 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6584 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6585 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6586 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 6587 | || mForceClearedSystemUiFlags != 0) { |
| 6588 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 6589 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 6590 | pw.print(" mResettingSystemUiFlags=0x"); |
| 6591 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 6592 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 6593 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6594 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6595 | if (mLastFocusNeedsMenu) { |
| 6596 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 6597 | pw.println(mLastFocusNeedsMenu); |
| 6598 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6599 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 6600 | pw.println(mWakeGestureEnabledSetting); |
| 6601 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6602 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6603 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 6604 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6605 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 6606 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 6607 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 6608 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6609 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6610 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6611 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 6612 | pw.print(mCarDockEnablesAccelerometer); |
| 6613 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 6614 | pw.println(mDeskDockEnablesAccelerometer); |
| 6615 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 6616 | pw.print(mLidKeyboardAccessibility); |
| 6617 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6618 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6619 | pw.print(prefix); |
| 6620 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 6621 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6622 | pw.print(prefix); |
| 6623 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 6624 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6625 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6626 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 6627 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 6628 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 6629 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 6630 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 6631 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 6632 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 6633 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 6634 | pw.print(","); pw.print(mOverscanScreenTop); |
| 6635 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 6636 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 6637 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 6638 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 6639 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 6640 | pw.print(" top="); pw.print(mOverscanTop); |
| 6641 | pw.print(" right="); pw.print(mOverscanRight); |
| 6642 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 6643 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 6644 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 6645 | pw.print(mRestrictedOverscanScreenLeft); |
| 6646 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 6647 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 6648 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6649 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 6650 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 6651 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 6652 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 6653 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 6654 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 6655 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 6656 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 6657 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 6658 | pw.print(","); pw.print(mStableFullscreenTop); |
| 6659 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 6660 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6661 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 6662 | pw.print(","); pw.print(mStableTop); |
| 6663 | pw.print(")-("); pw.print(mStableRight); |
| 6664 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6665 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 6666 | pw.print(","); pw.print(mSystemTop); |
| 6667 | pw.print(")-("); pw.print(mSystemRight); |
| 6668 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6669 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 6670 | pw.print(","); pw.print(mCurTop); |
| 6671 | pw.print(")-("); pw.print(mCurRight); |
| 6672 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 6673 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 6674 | pw.print(","); pw.print(mContentTop); |
| 6675 | pw.print(")-("); pw.print(mContentRight); |
| 6676 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 6677 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 6678 | pw.print(","); pw.print(mVoiceContentTop); |
| 6679 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 6680 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6681 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 6682 | pw.print(","); pw.print(mDockTop); |
| 6683 | pw.print(")-("); pw.print(mDockRight); |
| 6684 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6685 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 6686 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6687 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 6688 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6689 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 6690 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6691 | if (mLastInputMethodWindow != null) { |
| 6692 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 6693 | pw.println(mLastInputMethodWindow); |
| 6694 | } |
| 6695 | if (mLastInputMethodTargetWindow != null) { |
| 6696 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 6697 | pw.println(mLastInputMethodTargetWindow); |
| 6698 | } |
| 6699 | if (mStatusBar != null) { |
| 6700 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 6701 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 6702 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6703 | } |
| 6704 | if (mNavigationBar != null) { |
| 6705 | pw.print(prefix); pw.print("mNavigationBar="); |
| 6706 | pw.println(mNavigationBar); |
| 6707 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6708 | if (mFocusedWindow != null) { |
| 6709 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 6710 | pw.println(mFocusedWindow); |
| 6711 | } |
| 6712 | if (mFocusedApp != null) { |
| 6713 | pw.print(prefix); pw.print("mFocusedApp="); |
| 6714 | pw.println(mFocusedApp); |
| 6715 | } |
| 6716 | if (mWinDismissingKeyguard != null) { |
| 6717 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 6718 | pw.println(mWinDismissingKeyguard); |
| 6719 | } |
| 6720 | if (mTopFullscreenOpaqueWindowState != null) { |
| 6721 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 6722 | pw.println(mTopFullscreenOpaqueWindowState); |
| 6723 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6724 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 6725 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 6726 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 6727 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6728 | if (mForcingShowNavBar) { |
| 6729 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 6730 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 6731 | pw.println(mForcingShowNavBarLayer); |
| 6732 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6733 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6734 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6735 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 6736 | pw.print(" mForceStatusBarFromKeyguard="); |
| 6737 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6738 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 6739 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6740 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 6741 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 6742 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 6743 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 6744 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 6745 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 6746 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 6747 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 6748 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 6749 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 6750 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6751 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 6752 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 6753 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6754 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 6755 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6756 | mStatusBarController.dump(pw, prefix); |
| 6757 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6758 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6759 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6760 | if (mWakeGestureListener != null) { |
| 6761 | mWakeGestureListener.dump(pw, prefix); |
| 6762 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6763 | if (mOrientationListener != null) { |
| 6764 | mOrientationListener.dump(pw, prefix); |
| 6765 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 6766 | if (mBurnInProtectionHelper != null) { |
| 6767 | mBurnInProtectionHelper.dump(prefix, pw); |
| 6768 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6769 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6770 | } |