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; |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame^] | 59 | import android.os.IDeviceIdleController; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 60 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 61 | import android.os.Message; |
| 62 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 63 | import android.os.PowerManager; |
| 64 | import android.os.RemoteException; |
| 65 | import android.os.ServiceManager; |
| 66 | import android.os.SystemClock; |
| 67 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 68 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 69 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 71 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 72 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 73 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 74 | import android.service.dreams.DreamService; |
| 75 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 76 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 77 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 78 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 79 | import android.util.EventLog; |
| 80 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 81 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 82 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 83 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 84 | import android.view.Gravity; |
| 85 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 86 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 87 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 88 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 89 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 90 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 91 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 92 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 93 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 94 | import android.view.KeyEvent; |
| 95 | import android.view.MotionEvent; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 96 | import com.android.internal.policy.PhoneWindow; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 97 | import android.view.Surface; |
| 98 | import android.view.View; |
| 99 | import android.view.ViewConfiguration; |
| 100 | import android.view.Window; |
| 101 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 102 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 103 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 104 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 105 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 106 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 107 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 108 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 109 | import android.view.animation.AnimationUtils; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 110 | import com.android.internal.R; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 111 | import com.android.internal.statusbar.IStatusBarService; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 112 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 113 | import com.android.internal.widget.PointerLocationView; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 114 | import com.android.server.LocalServices; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 115 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
| 116 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 117 | |
| 118 | import java.io.File; |
| 119 | import java.io.FileReader; |
| 120 | import java.io.IOException; |
| 121 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 122 | import java.util.HashSet; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 123 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 124 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 125 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 126 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 127 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 128 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 129 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 130 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
| 131 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 132 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 133 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 134 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 135 | * introduces a new method suffix, Lp, for an internal lock of the |
| 136 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 137 | * can be acquired with either the Lw and Li lock held, so has the restrictions |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 138 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 139 | */ |
| 140 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 141 | static final String TAG = "WindowManager"; |
| 142 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 143 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 144 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 145 | static final boolean DEBUG_KEYGUARD = false; |
| 146 | static final boolean DEBUG_LAYOUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 147 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 148 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 149 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 150 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 151 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 152 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 153 | // No longer recommended for desk docks; still useful in car docks. |
| 154 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 155 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 156 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 157 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 158 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 159 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 160 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 161 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 162 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 163 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 164 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 165 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 166 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 167 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 168 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 169 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 170 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 171 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 172 | // These need to match the documentation/constant in |
| 173 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 174 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 175 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 176 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 177 | |
| 178 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 179 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 180 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 181 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 182 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 183 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 184 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 185 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 186 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 187 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 188 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 189 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 190 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 191 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 192 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 193 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 194 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 195 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 196 | /** |
| 197 | * These are the system UI flags that, when changing, can cause the layout |
| 198 | * of the screen to change. |
| 199 | */ |
| 200 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 201 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 202 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 203 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 204 | | View.NAVIGATION_BAR_TRANSLUCENT |
| 205 | | View.SYSTEM_UI_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 206 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 207 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 208 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 209 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 210 | .build(); |
| 211 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 212 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 213 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 214 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 215 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 216 | /** |
| 217 | * Keyguard stuff |
| 218 | */ |
| 219 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 220 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 221 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 222 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 223 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 224 | * |
| 225 | * These are special keys that are used to launch particular kinds of applications, |
| 226 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 227 | * usage page. We don't support quite that many yet... |
| 228 | */ |
| 229 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 230 | static { |
| 231 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 232 | sApplicationLaunchKeyCategories.append( |
| 233 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 234 | sApplicationLaunchKeyCategories.append( |
| 235 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 236 | sApplicationLaunchKeyCategories.append( |
| 237 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 238 | sApplicationLaunchKeyCategories.append( |
| 239 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 240 | sApplicationLaunchKeyCategories.append( |
| 241 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 242 | sApplicationLaunchKeyCategories.append( |
| 243 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 244 | } |
| 245 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 246 | /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 247 | static final int WAITING_FOR_DRAWN_TIMEOUT = 500; |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 248 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 249 | /** |
| 250 | * Lock protecting internal state. Must not call out into window |
| 251 | * manager with lock held. (This lock will be acquired in places |
| 252 | * where the window manager is calling in with its own lock held.) |
| 253 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 254 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 255 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 256 | Context mContext; |
| 257 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 258 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 259 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 260 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 261 | ActivityManagerInternal mActivityManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 262 | DreamManagerInternal mDreamManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 263 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 264 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 265 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 266 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 267 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 268 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 269 | BurnInProtectionHelper mBurnInProtectionHelper; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 270 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 271 | // Vibrator pattern for haptic feedback of a long press. |
| 272 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 273 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 274 | // Vibrator pattern for haptic feedback of virtual key press. |
| 275 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 276 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 277 | // Vibrator pattern for a short vibration. |
| 278 | long[] mKeyboardTapVibePattern; |
| 279 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 280 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 281 | long[] mClockTickVibePattern; |
| 282 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 283 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 284 | long[] mCalendarDateVibePattern; |
| 285 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 286 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 287 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 288 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 289 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 290 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 291 | |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 292 | // Vibrator pattern for haptic feedback of a context click. |
| 293 | long[] mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 294 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 295 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 296 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 297 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 298 | boolean mSafeMode; |
| 299 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 300 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 301 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 302 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 303 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 304 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 305 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 306 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 307 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 308 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 309 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 310 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 311 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 312 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 313 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 314 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 315 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 316 | } |
| 317 | }; |
| 318 | final ShowListener mKeyguardDelegateCallback = new ShowListener() { |
| 319 | @Override |
| 320 | public void onShown(IBinder windowToken) { |
| 321 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown."); |
| 322 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 323 | } |
| 324 | }; |
| 325 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 326 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 327 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 328 | WindowState mLastInputMethodWindow = null; |
| 329 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 330 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 331 | // FIXME This state is shared between the input reader and handler thread. |
| 332 | // Technically it's broken and buggy but it has been like this for many years |
| 333 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 334 | // so that only one thread is involved in handling input policy. Unfortunately |
| 335 | // it's on a critical path for power management so we can't just post the work to the |
| 336 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 337 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 338 | volatile boolean mPowerKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 339 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 340 | volatile int mPowerKeyPressCounter; |
| 341 | volatile boolean mEndCallKeyHandled; |
| 342 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 343 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 344 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 345 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 346 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 347 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 348 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 349 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 350 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 351 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 352 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 353 | boolean mHdmiPlugged; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 354 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 355 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 356 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 357 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 358 | int mCarDockRotation; |
| 359 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 360 | int mUndockedHdmiRotation; |
| 361 | int mDemoHdmiRotation; |
| 362 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 363 | int mDemoRotation; |
| 364 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 365 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 366 | boolean mWakeGestureEnabledSetting; |
| 367 | MyWakeGestureListener mWakeGestureListener; |
| 368 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 369 | // Default display does not rotate, apps that require non-default orientation will have to |
| 370 | // have the orientation emulated. |
| 371 | private boolean mForceDefaultOrientation = false; |
| 372 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 373 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 374 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 375 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 376 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 377 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 378 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 379 | boolean mCarDockEnablesAccelerometer; |
| 380 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 381 | int mLidKeyboardAccessibility; |
| 382 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 383 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 384 | int mShortPressOnPowerBehavior; |
| 385 | int mLongPressOnPowerBehavior; |
| 386 | int mDoublePressOnPowerBehavior; |
| 387 | int mTriplePressOnPowerBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 388 | int mShortPressOnSleepBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 389 | boolean mAwake; |
| 390 | boolean mScreenOnEarly; |
| 391 | boolean mScreenOnFully; |
| 392 | ScreenOnListener mScreenOnListener; |
| 393 | boolean mKeyguardDrawComplete; |
| 394 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 395 | boolean mOrientationSensorEnabled = false; |
| 396 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 397 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 398 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 399 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 400 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 401 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 402 | |
| 403 | // The last window we were told about in focusChanged. |
| 404 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 405 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 406 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 407 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 408 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 409 | // The current size of the screen; really; extends into the overscan area of |
| 410 | // the screen and doesn't account for any system elements like the status bar. |
| 411 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 412 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 413 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 414 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 415 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 416 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 417 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 418 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 419 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 420 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 421 | // if the status bar can't be hidden; in that case it effectively carves out |
| 422 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 423 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 424 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 425 | // During layout, the current screen borders accounting for any currently |
| 426 | // visible system UI elements. |
| 427 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 428 | // For applications requesting stable content insets, these are them. |
| 429 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 430 | // For applications requesting stable content insets but have also set the |
| 431 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 432 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 433 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 434 | // During layout, the current screen borders with all outer decoration |
| 435 | // (status bar, input method dock) accounted for. |
| 436 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 437 | // During layout, the frame in which content should be displayed |
| 438 | // to the user, accounting for all screen decoration except for any |
| 439 | // space they deem as available for other content. This is usually |
| 440 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 441 | // content insets. |
| 442 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 443 | // During layout, the frame in which voice content should be displayed |
| 444 | // to the user, accounting for all screen decoration except for any |
| 445 | // space they deem as available for other content. |
| 446 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 447 | // 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] | 448 | // windows are placed. |
| 449 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 450 | // During layout, the layer at which the doc window is placed. |
| 451 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 452 | // During layout, this is the layer of the status bar. |
| 453 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 454 | int mLastSystemUiFlags; |
| 455 | // Bits that we are in the process of clearing, so we want to prevent |
| 456 | // them from being set by applications until everything has been updated |
| 457 | // to have them clear. |
| 458 | int mResettingSystemUiFlags = 0; |
| 459 | // Bits that we are currently always keeping cleared. |
| 460 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 461 | // What we last reported to system UI about whether the compatibility |
| 462 | // menu needs to be displayed. |
| 463 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 464 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 465 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 466 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 467 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 468 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 469 | static final Rect mTmpParentFrame = new Rect(); |
| 470 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 471 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 472 | static final Rect mTmpContentFrame = new Rect(); |
| 473 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 474 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 475 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 476 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 477 | static final Rect mTmpOutsetFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 478 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 479 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 480 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 481 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 482 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 483 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 484 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 485 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 486 | private boolean mForceStatusBarTransparent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 487 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 488 | boolean mForcingShowNavBar; |
| 489 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 490 | |
| 491 | // States of keyguard dismiss. |
| 492 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 493 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 494 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 495 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 496 | |
| 497 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 498 | * be done once per window. */ |
| 499 | private WindowState mWinDismissingKeyguard; |
| 500 | |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 501 | /** When window is currently dismissing the keyguard, dismissing the keyguard must handle |
| 502 | * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN |
| 503 | * lock SIM card. This variable is used to record the previous keyguard secure state for |
| 504 | * monitoring secure state change on window dismissing keyguard. */ |
| 505 | private boolean mSecureDismissingKeyguard; |
| 506 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 507 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 508 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 509 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 510 | * the wallpaper. */ |
| 511 | private WindowState mWinShowWhenLocked; |
| 512 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 513 | boolean mShowingLockscreen; |
| 514 | boolean mShowingDream; |
| 515 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 516 | boolean mDreamingSleepTokenNeeded; |
| 517 | SleepToken mDreamingSleepToken; |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 518 | SleepToken mScreenOffSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 519 | boolean mKeyguardSecure; |
| 520 | boolean mKeyguardSecureIncludingHidden; |
| 521 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 522 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 523 | boolean mHomeConsumed; |
| 524 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 525 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 526 | Intent mCarDockIntent; |
| 527 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 528 | boolean mSearchKeyShortcutPending; |
| 529 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 530 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 531 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 532 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 533 | // support for activating the lock screen while the screen is on |
| 534 | boolean mAllowLockscreenWhenOn; |
| 535 | int mLockScreenTimeout; |
| 536 | boolean mLockScreenTimerActive; |
| 537 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 538 | // 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] | 539 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 540 | |
| 541 | // Behavior of POWER button while in-call and screen on. |
| 542 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 543 | int mIncallPowerBehavior; |
| 544 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 545 | Display mDisplay; |
| 546 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 547 | int mLandscapeRotation = 0; // default landscape rotation |
| 548 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 549 | int mPortraitRotation = 0; // default portrait rotation |
| 550 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 551 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 552 | int mOverscanLeft = 0; |
| 553 | int mOverscanTop = 0; |
| 554 | int mOverscanRight = 0; |
| 555 | int mOverscanBottom = 0; |
| 556 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 557 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 558 | private int mLongPressOnHomeBehavior; |
| 559 | |
| 560 | // What we do when the user double-taps on home |
| 561 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 562 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 563 | // Allowed theater mode wake actions |
| 564 | private boolean mAllowTheaterModeWakeFromKey; |
| 565 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 566 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 567 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 568 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 569 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 570 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 571 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 572 | // Whether to support long press from power button in non-interactive mode |
| 573 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 574 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 575 | // Whether to go to sleep entering theater mode from power button |
| 576 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 577 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 578 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 579 | // Time to volume and power must be pressed within this interval of each other. |
| 580 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 581 | // Increase the chord delay when taking a screenshot from the keyguard |
| 582 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 583 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 584 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 585 | private long mScreenshotChordVolumeDownKeyTime; |
| 586 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 587 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 588 | private boolean mScreenshotChordPowerKeyTriggered; |
| 589 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 590 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 591 | /* The number of steps between min and max brightness */ |
| 592 | private static final int BRIGHTNESS_STEPS = 10; |
| 593 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 594 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 595 | ShortcutManager mShortcutManager; |
| 596 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 597 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 598 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 599 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 600 | private int mCurrentUserId; |
| 601 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 602 | // Maps global key codes to the components that will handle them. |
| 603 | private GlobalKeyManager mGlobalKeyManager; |
| 604 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 605 | // Fallback actions by key code. |
| 606 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 607 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 608 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 609 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 610 | = new LogDecelerateInterpolator(100, 0); |
| 611 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 612 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 613 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 614 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 615 | 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] | 616 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 617 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 618 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 619 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 620 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 621 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 622 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 623 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 624 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 625 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 626 | |
| 627 | private class PolicyHandler extends Handler { |
| 628 | @Override |
| 629 | public void handleMessage(Message msg) { |
| 630 | switch (msg.what) { |
| 631 | case MSG_ENABLE_POINTER_LOCATION: |
| 632 | enablePointerLocation(); |
| 633 | break; |
| 634 | case MSG_DISABLE_POINTER_LOCATION: |
| 635 | disablePointerLocation(); |
| 636 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 637 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 638 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 639 | break; |
| 640 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 641 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 642 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 643 | case MSG_DISPATCH_SHOW_RECENTS: |
| 644 | showRecentApps(false); |
| 645 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 646 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 647 | showGlobalActionsInternal(); |
| 648 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 649 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 650 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 651 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 652 | break; |
| 653 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 654 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 655 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 656 | break; |
| 657 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 658 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 659 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 660 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 661 | case MSG_HIDE_BOOT_MESSAGE: |
| 662 | handleHideBootMessage(); |
| 663 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 664 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 665 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 666 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 667 | case MSG_POWER_DELAYED_PRESS: |
| 668 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 669 | finishPowerKeyPress(); |
| 670 | break; |
| 671 | case MSG_POWER_LONG_PRESS: |
| 672 | powerLongPress(); |
| 673 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 674 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 675 | updateDreamingSleepToken(msg.arg1 != 0); |
| 676 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 681 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 682 | @Override |
| 683 | public void onUEvent(UEventObserver.UEvent event) { |
| 684 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 685 | } |
| 686 | }; |
| 687 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 688 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 689 | SettingsObserver(Handler handler) { |
| 690 | super(handler); |
| 691 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 692 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 693 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 694 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 695 | ContentResolver resolver = mContext.getContentResolver(); |
| 696 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 697 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 698 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 699 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 700 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 701 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 702 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 703 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 704 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 705 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 706 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 707 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 708 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 709 | Settings.System.USER_ROTATION), false, this, |
| 710 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 711 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 712 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 713 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 714 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 715 | Settings.System.POINTER_LOCATION), false, this, |
| 716 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 717 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 718 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 719 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 720 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 721 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 722 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 723 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 724 | Settings.Global.POLICY_CONTROL), false, this, |
| 725 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 726 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 730 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 731 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 732 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 733 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 734 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 735 | class MyWakeGestureListener extends WakeGestureListener { |
| 736 | MyWakeGestureListener(Context context, Handler handler) { |
| 737 | super(context, handler); |
| 738 | } |
| 739 | |
| 740 | @Override |
| 741 | public void onWakeUp() { |
| 742 | synchronized (mLock) { |
| 743 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 744 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 745 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 751 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 752 | MyOrientationListener(Context context, Handler handler) { |
| 753 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 754 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 755 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 756 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 757 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 758 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 759 | updateRotation(false); |
| 760 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 761 | } |
| 762 | MyOrientationListener mOrientationListener; |
| 763 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 764 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 765 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 766 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 767 | View.NAVIGATION_BAR_TRANSIENT, |
| 768 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 769 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 770 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 771 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 772 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 773 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 774 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 775 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 776 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 777 | IStatusBarService getStatusBarService() { |
| 778 | synchronized (mServiceAquireLock) { |
| 779 | if (mStatusBarService == null) { |
| 780 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 781 | ServiceManager.getService("statusbar")); |
| 782 | } |
| 783 | return mStatusBarService; |
| 784 | } |
| 785 | } |
| 786 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 787 | /* |
| 788 | * We always let the sensor be switched on by default except when |
| 789 | * the user has explicitly disabled sensor based rotation or when the |
| 790 | * screen is switched off. |
| 791 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 792 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 793 | if (mSupportAutoRotation) { |
| 794 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 795 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 796 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 797 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 798 | // If the application has explicitly requested to follow the |
| 799 | // orientation, then we need to turn the sensor on. |
| 800 | return true; |
| 801 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 802 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 803 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 804 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 805 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 806 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 807 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 808 | // orientation management, |
| 809 | return true; |
| 810 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 811 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 812 | // If the setting for using the sensor by default is enabled, then |
| 813 | // we will always leave it on. Note that the user could go to |
| 814 | // a window that forces an orientation that does not use the |
| 815 | // sensor and in theory we could turn it off... however, when next |
| 816 | // turning it on we won't have a good value for the current |
| 817 | // orientation for a little bit, which can cause orientation |
| 818 | // changes to lag, so we'd like to keep it always on. (It will |
| 819 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 820 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 821 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 822 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 823 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 824 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 825 | /* |
| 826 | * Various use cases for invoking this function |
| 827 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 828 | * 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] | 829 | * if not already enabled |
| 830 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 831 | * already enabled |
| 832 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 833 | * screen turning on and current app has nosensor based orientation, do nothing |
| 834 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 835 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 836 | if (!mOrientationListener.canDetectOrientation()) { |
| 837 | // If sensor is turned off or nonexistent for some reason |
| 838 | return; |
| 839 | } |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 840 | // Could have been invoked due to screen turning on or off or |
| 841 | // change of the currently visible window's orientation. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 842 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 843 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 844 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled |
| 845 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 846 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 847 | boolean disable = true; |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 848 | // Note: We postpone the rotating of the screen until the keyguard as well as the |
| 849 | // window manager have reported a draw complete. |
| 850 | if (mScreenOnEarly && mAwake && |
| 851 | mKeyguardDrawComplete && mWindowManagerDrawComplete) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 852 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 853 | disable = false; |
| 854 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 855 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 856 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 857 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 858 | mOrientationSensorEnabled = true; |
| 859 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 860 | } |
| 861 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 862 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 863 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 864 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 865 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 866 | mOrientationSensorEnabled = false; |
| 867 | } |
| 868 | } |
| 869 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 870 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 871 | // Hold a wake lock until the power key is released. |
| 872 | if (!mPowerKeyWakeLock.isHeld()) { |
| 873 | mPowerKeyWakeLock.acquire(); |
| 874 | } |
| 875 | |
| 876 | // Cancel multi-press detection timeout. |
| 877 | if (mPowerKeyPressCounter != 0) { |
| 878 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 879 | } |
| 880 | |
| 881 | // Detect user pressing the power button in panic when an application has |
| 882 | // taken over the whole screen. |
| 883 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Craig Mautner | 0124980e9 | 2014-11-30 21:15:34 -0800 | [diff] [blame] | 884 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 885 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 886 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | // Latch power key state to detect screenshot chord. |
| 890 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 891 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 892 | mScreenshotChordPowerKeyTriggered = true; |
| 893 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 894 | interceptScreenshotChord(); |
| 895 | } |
| 896 | |
| 897 | // Stop ringing or end call if configured to do so when power is pressed. |
| 898 | TelecomManager telecomManager = getTelecommService(); |
| 899 | boolean hungUp = false; |
| 900 | if (telecomManager != null) { |
| 901 | if (telecomManager.isRinging()) { |
| 902 | // Pressing Power while there's a ringing incoming |
| 903 | // call should silence the ringer. |
| 904 | telecomManager.silenceRinger(); |
| 905 | } else if ((mIncallPowerBehavior |
| 906 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 907 | && telecomManager.isInCall() && interactive) { |
| 908 | // Otherwise, if "Power button ends call" is enabled, |
| 909 | // the Power button will hang up any current active call. |
| 910 | hungUp = telecomManager.endCall(); |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | // If the power key has still not yet been handled, then detect short |
| 915 | // press, long press, or multi press and decide what to do. |
| 916 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
| 917 | || mScreenshotChordVolumeUpKeyTriggered; |
| 918 | if (!mPowerKeyHandled) { |
| 919 | if (interactive) { |
| 920 | // When interactive, we're already awake. |
| 921 | // Wait for a long press or for the button to be released to decide what to do. |
| 922 | if (hasLongPressOnPowerBehavior()) { |
| 923 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 924 | msg.setAsynchronous(true); |
| 925 | mHandler.sendMessageDelayed(msg, |
| 926 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 927 | } |
| 928 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 929 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 930 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 931 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 932 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 933 | msg.setAsynchronous(true); |
| 934 | mHandler.sendMessageDelayed(msg, |
| 935 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 936 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 937 | } else { |
| 938 | final int maxCount = getMaxMultiPressPowerCount(); |
| 939 | |
| 940 | if (maxCount <= 1) { |
| 941 | mPowerKeyHandled = true; |
| 942 | } else { |
| 943 | mBeganFromNonInteractive = true; |
| 944 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 945 | } |
| 946 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 950 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 951 | final boolean handled = canceled || mPowerKeyHandled; |
| 952 | mScreenshotChordPowerKeyTriggered = false; |
| 953 | cancelPendingScreenshotChordAction(); |
| 954 | cancelPendingPowerKeyAction(); |
| 955 | |
| 956 | if (!handled) { |
| 957 | // Figure out how to handle the key now that it has been released. |
| 958 | mPowerKeyPressCounter += 1; |
| 959 | |
| 960 | final int maxCount = getMaxMultiPressPowerCount(); |
| 961 | final long eventTime = event.getDownTime(); |
| 962 | if (mPowerKeyPressCounter < maxCount) { |
| 963 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 964 | // Continue holding the wake lock. |
| 965 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 966 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 967 | msg.setAsynchronous(true); |
| 968 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 969 | return; |
| 970 | } |
| 971 | |
| 972 | // No other actions. Handle it immediately. |
| 973 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 974 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 975 | |
| 976 | // Done. Reset our state. |
| 977 | finishPowerKeyPress(); |
| 978 | } |
| 979 | |
| 980 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 981 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 982 | mPowerKeyPressCounter = 0; |
| 983 | if (mPowerKeyWakeLock.isHeld()) { |
| 984 | mPowerKeyWakeLock.release(); |
| 985 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | private void cancelPendingPowerKeyAction() { |
| 989 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 990 | mPowerKeyHandled = true; |
| 991 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 992 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 996 | if (mScreenOnEarly && !mScreenOnFully) { |
| 997 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 998 | + "already in the process of turning the screen on."); |
| 999 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 1000 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1001 | |
| 1002 | if (count == 2) { |
| 1003 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 1004 | } else if (count == 3) { |
| 1005 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1006 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1007 | switch (mShortPressOnPowerBehavior) { |
| 1008 | case SHORT_PRESS_POWER_NOTHING: |
| 1009 | break; |
| 1010 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 1011 | mPowerManager.goToSleep(eventTime, |
| 1012 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1013 | break; |
| 1014 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1015 | mPowerManager.goToSleep(eventTime, |
| 1016 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1017 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1018 | break; |
| 1019 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1020 | mPowerManager.goToSleep(eventTime, |
| 1021 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1022 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1023 | launchHomeFromHotKey(); |
| 1024 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1025 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1026 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1027 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1033 | switch (behavior) { |
| 1034 | case MULTI_PRESS_POWER_NOTHING: |
| 1035 | break; |
| 1036 | case MULTI_PRESS_POWER_THEATER_MODE: |
| 1037 | if (isTheaterModeEnabled()) { |
| 1038 | Slog.i(TAG, "Toggling theater mode off."); |
| 1039 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1040 | Settings.Global.THEATER_MODE_ON, 0); |
| 1041 | if (!interactive) { |
| 1042 | wakeUpFromPowerKey(eventTime); |
| 1043 | } |
| 1044 | } else { |
| 1045 | Slog.i(TAG, "Toggling theater mode on."); |
| 1046 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1047 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1048 | |
| 1049 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1050 | mPowerManager.goToSleep(eventTime, |
| 1051 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1052 | } |
| 1053 | } |
| 1054 | break; |
| 1055 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1056 | Slog.i(TAG, "Starting brightness boost."); |
| 1057 | if (!interactive) { |
| 1058 | wakeUpFromPowerKey(eventTime); |
| 1059 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1060 | mPowerManager.boostScreenBrightness(eventTime); |
| 1061 | break; |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | private int getMaxMultiPressPowerCount() { |
| 1066 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1067 | return 3; |
| 1068 | } |
| 1069 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1070 | return 2; |
| 1071 | } |
| 1072 | return 1; |
| 1073 | } |
| 1074 | |
| 1075 | private void powerLongPress() { |
| 1076 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1077 | switch (behavior) { |
| 1078 | case LONG_PRESS_POWER_NOTHING: |
| 1079 | break; |
| 1080 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1081 | mPowerKeyHandled = true; |
| 1082 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1083 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1084 | } |
| 1085 | showGlobalActionsInternal(); |
| 1086 | break; |
| 1087 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1088 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1089 | mPowerKeyHandled = true; |
| 1090 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1091 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1092 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1093 | break; |
| 1094 | } |
| 1095 | } |
| 1096 | |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1097 | private void sleepPress(long eventTime) { |
| 1098 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1099 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1104 | switch (mShortPressOnSleepBehavior) { |
| 1105 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1106 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1107 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
| 1108 | mPowerManager.goToSleep(eventTime, |
| 1109 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1110 | break; |
| 1111 | } |
| 1112 | } |
| 1113 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1114 | private int getResolvedLongPressOnPowerBehavior() { |
| 1115 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1116 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1117 | } |
| 1118 | return mLongPressOnPowerBehavior; |
| 1119 | } |
| 1120 | |
| 1121 | private boolean hasLongPressOnPowerBehavior() { |
| 1122 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1126 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1127 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1128 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1129 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1130 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1131 | && now <= mScreenshotChordPowerKeyTime |
| 1132 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1133 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1134 | cancelPendingPowerKeyAction(); |
| 1135 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1136 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1141 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1142 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1143 | // Double the time it takes to take a screenshot from the keyguard |
| 1144 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1145 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1146 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1147 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1150 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1151 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1154 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1155 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1156 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1157 | mEndCallKeyHandled = true; |
| 1158 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1159 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1160 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1161 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1162 | } |
| 1163 | }; |
| 1164 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1165 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1166 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1167 | public void run() { |
| 1168 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1169 | } |
| 1170 | }; |
| 1171 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1172 | @Override |
| 1173 | public void showGlobalActions() { |
| 1174 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1175 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1176 | } |
| 1177 | |
| 1178 | void showGlobalActionsInternal() { |
| 1179 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1180 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1181 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1182 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1183 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1184 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1185 | if (keyguardShowing) { |
| 1186 | // since it took two seconds of long press to bring this up, |
| 1187 | // 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] | 1188 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1193 | return Settings.Global.getInt( |
| 1194 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1197 | boolean isUserSetupComplete() { |
| 1198 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1199 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1200 | } |
| 1201 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1202 | private void handleShortPressOnHome() { |
| 1203 | // If there's a dream running then use home to escape the dream |
| 1204 | // but don't actually go home. |
| 1205 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1206 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1207 | return; |
| 1208 | } |
| 1209 | |
| 1210 | // Go home! |
| 1211 | launchHomeFromHotKey(); |
| 1212 | } |
| 1213 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1214 | private void handleLongPressOnHome(int deviceId) { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1215 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1216 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 1217 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1218 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1219 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 1220 | toggleRecentApps(); |
| 1221 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1222 | launchAssistAction(null, deviceId); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1223 | } |
| 1224 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1225 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1226 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1227 | private void handleDoubleTapOnHome() { |
| 1228 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1229 | mHomeConsumed = true; |
| 1230 | toggleRecentApps(); |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1235 | @Override |
| 1236 | public void run() { |
| 1237 | if (mHomeDoubleTapPending) { |
| 1238 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1239 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1240 | } |
| 1241 | } |
| 1242 | }; |
| 1243 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1244 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1245 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1246 | } |
| 1247 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1248 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1249 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1250 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1251 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1252 | mContext = context; |
| 1253 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1254 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1255 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1256 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1257 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1258 | |
| 1259 | // Init display burn-in protection |
| 1260 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1261 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1262 | // Allow a system property to override this. Used by developer settings. |
| 1263 | boolean burnInProtectionDevMode = |
| 1264 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1265 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1266 | final int minHorizontal; |
| 1267 | final int maxHorizontal; |
| 1268 | final int minVertical; |
| 1269 | final int maxVertical; |
| 1270 | final int maxRadius; |
| 1271 | if (burnInProtectionDevMode) { |
| 1272 | minHorizontal = -8; |
| 1273 | maxHorizontal = 8; |
| 1274 | minVertical = -8; |
| 1275 | maxVertical = -4; |
| 1276 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1277 | } else { |
| 1278 | Resources resources = context.getResources(); |
| 1279 | minHorizontal = resources.getInteger( |
| 1280 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1281 | maxHorizontal = resources.getInteger( |
| 1282 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1283 | minVertical = resources.getInteger( |
| 1284 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1285 | maxVertical = resources.getInteger( |
| 1286 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1287 | maxRadius = resources.getInteger( |
| 1288 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1289 | } |
| 1290 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1291 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1292 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1293 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1294 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1295 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1296 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1297 | try { |
| 1298 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1299 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1300 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1301 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1302 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1303 | mUiMode = context.getResources().getInteger( |
| 1304 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1305 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1306 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1307 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1308 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1309 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1310 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1311 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1312 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1313 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1314 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1315 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1316 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1317 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1318 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1319 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1320 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1321 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1322 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1323 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1324 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1325 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1326 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1327 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1328 | mCarDockRotation = readRotation( |
| 1329 | com.android.internal.R.integer.config_carDockRotation); |
| 1330 | mDeskDockRotation = readRotation( |
| 1331 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1332 | mUndockedHdmiRotation = readRotation( |
| 1333 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1334 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1335 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1336 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1337 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1338 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1339 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1340 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1341 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1342 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1343 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1344 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1345 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1346 | |
| 1347 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1348 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1349 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1350 | || mContext.getResources().getBoolean( |
| 1351 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1352 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1353 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1354 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1355 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1356 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1357 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1358 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1359 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1360 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1361 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1362 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1363 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1364 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1365 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1366 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1367 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1368 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1369 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1370 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1371 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1372 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1373 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1374 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1375 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1376 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1377 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1378 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1379 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1380 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1381 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1382 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1383 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1384 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1385 | Context.ACCESSIBILITY_SERVICE); |
| 1386 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1387 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1388 | IntentFilter filter = new IntentFilter(); |
| 1389 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1390 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1391 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1392 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1393 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1394 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1395 | if (intent != null) { |
| 1396 | // Retrieve current sticky dock event broadcast. |
| 1397 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1398 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1399 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1400 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1401 | // register for dream-related broadcasts |
| 1402 | filter = new IntentFilter(); |
| 1403 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1404 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1405 | context.registerReceiver(mDreamReceiver, filter); |
| 1406 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1407 | // register for multiuser-relevant broadcasts |
| 1408 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1409 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1410 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1411 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1412 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1413 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1414 | @Override |
| 1415 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1416 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1417 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1418 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1419 | } |
| 1420 | @Override |
| 1421 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1422 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1423 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1424 | } |
| 1425 | } |
| 1426 | @Override |
| 1427 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1428 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1429 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | @Override |
| 1433 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1434 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1435 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1436 | @Override |
| 1437 | public void onDown() { |
| 1438 | mOrientationListener.onTouchStart(); |
| 1439 | } |
| 1440 | @Override |
| 1441 | public void onUpOrCancel() { |
| 1442 | mOrientationListener.onTouchEnd(); |
| 1443 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1444 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1445 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1446 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1447 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1448 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1449 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1450 | com.android.internal.R.array.config_longPressVibePattern); |
| 1451 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1452 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1453 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1454 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1455 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1456 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1457 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1458 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1459 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1460 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1461 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1462 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 1463 | mContextClickVibePattern = getLongIntArray(mContext.getResources(), |
| 1464 | com.android.internal.R.array.config_contextClickVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1465 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1466 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1467 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1468 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1469 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1470 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1471 | // Controls rotation and the like. |
| 1472 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1473 | |
| 1474 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1475 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 1476 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 1477 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1478 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1479 | |
| 1480 | mWindowManagerInternal.registerAppTransitionListener( |
| 1481 | mStatusBarController.getAppTransitionListener()); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1484 | /** |
| 1485 | * Read values from config.xml that may be overridden depending on |
| 1486 | * the configuration of the device. |
| 1487 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1488 | */ |
| 1489 | private void readConfigurationDependentBehaviors() { |
| 1490 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1491 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1492 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1493 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1494 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1495 | } |
| 1496 | |
| 1497 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1498 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1499 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1500 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1501 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1502 | } |
| 1503 | } |
| 1504 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1505 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1506 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1507 | // This method might be called before the policy has been fully initialized |
| 1508 | // or for other displays we don't care about. |
| 1509 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1510 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1511 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1512 | mDisplay = display; |
| 1513 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1514 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1515 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1516 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1517 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1518 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1519 | mLandscapeRotation = Surface.ROTATION_0; |
| 1520 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1521 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1522 | mPortraitRotation = Surface.ROTATION_90; |
| 1523 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1524 | } else { |
| 1525 | mPortraitRotation = Surface.ROTATION_270; |
| 1526 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1527 | } |
| 1528 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1529 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1530 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1531 | mPortraitRotation = Surface.ROTATION_0; |
| 1532 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1533 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1534 | mLandscapeRotation = Surface.ROTATION_270; |
| 1535 | mSeascapeRotation = Surface.ROTATION_90; |
| 1536 | } else { |
| 1537 | mLandscapeRotation = Surface.ROTATION_90; |
| 1538 | mSeascapeRotation = Surface.ROTATION_270; |
| 1539 | } |
| 1540 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1541 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1542 | mStatusBarHeight = |
| 1543 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1544 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1545 | // Height of the navigation bar when presented horizontally at bottom |
| 1546 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1547 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1548 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1549 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1550 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1551 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1552 | |
| 1553 | // Width of the navigation bar when presented vertically along one side |
| 1554 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1555 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1556 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1557 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1558 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1559 | |
| 1560 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1561 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1562 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1563 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 1564 | // Allow the navigation bar to move on non-square small devices (phones). |
| 1565 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1566 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1567 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1568 | // Allow a system property to override this. Used by the emulator. |
| 1569 | // See also hasNavigationBar(). |
| 1570 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1571 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1572 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1573 | } else if ("0".equals(navBarOverride)) { |
| 1574 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1575 | } |
| 1576 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1577 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1578 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1579 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1580 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1581 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1582 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1583 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1584 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1585 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 1586 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 1587 | // By default, remote display locks rotation to landscape. |
| 1588 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 1589 | mDemoRotation = mPortraitRotation; |
| 1590 | } else { |
| 1591 | mDemoRotation = mLandscapeRotation; |
| 1592 | } |
| 1593 | mDemoRotationLock = SystemProperties.getBoolean( |
| 1594 | "persist.demo.rotationlock", false); |
| 1595 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1596 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1597 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1598 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1599 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1600 | // For debug purposes the next line turns this feature off with: |
| 1601 | // $ adb shell setprop config.override_forced_orient true |
| 1602 | // $ adb shell wm size reset |
| 1603 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1604 | } |
| 1605 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1606 | /** |
| 1607 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1608 | * navigation bar and touch exploration is not enabled |
| 1609 | */ |
| 1610 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1611 | return mHasNavigationBar |
| 1612 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1615 | @Override |
| 1616 | public boolean isDefaultOrientationForced() { |
| 1617 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1620 | @Override |
| 1621 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1622 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1623 | mOverscanLeft = left; |
| 1624 | mOverscanTop = top; |
| 1625 | mOverscanRight = right; |
| 1626 | mOverscanBottom = bottom; |
| 1627 | } |
| 1628 | } |
| 1629 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1630 | public void updateSettings() { |
| 1631 | ContentResolver resolver = mContext.getContentResolver(); |
| 1632 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1633 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1634 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1635 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1636 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1637 | UserHandle.USER_CURRENT); |
| 1638 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1639 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1640 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1641 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1642 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1643 | // Configure wake gesture. |
| 1644 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1645 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1646 | UserHandle.USER_CURRENT) != 0; |
| 1647 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1648 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1649 | updateWakeGestureListenerLp(); |
| 1650 | } |
| 1651 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1652 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1653 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1654 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1655 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1656 | if (mUserRotation != userRotation) { |
| 1657 | mUserRotation = userRotation; |
| 1658 | updateRotation = true; |
| 1659 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1660 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1661 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1662 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1663 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1664 | if (mUserRotationMode != userRotationMode) { |
| 1665 | mUserRotationMode = userRotationMode; |
| 1666 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1667 | updateOrientationListenerLp(); |
| 1668 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1669 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1670 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1671 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1672 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1673 | if (mPointerLocationMode != pointerLocation) { |
| 1674 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1675 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1676 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1680 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1681 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1682 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1683 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1684 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1685 | if (mHasSoftInput != hasSoftInput) { |
| 1686 | mHasSoftInput = hasSoftInput; |
| 1687 | updateRotation = true; |
| 1688 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1689 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1690 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1691 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1692 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1693 | } |
| 1694 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1695 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1696 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1699 | private void updateWakeGestureListenerLp() { |
| 1700 | if (shouldEnableWakeGestureLp()) { |
| 1701 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1702 | } else { |
| 1703 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1708 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1709 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1710 | && mWakeGestureListener.isSupported(); |
| 1711 | } |
| 1712 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1713 | private void enablePointerLocation() { |
| 1714 | if (mPointerLocationView == null) { |
| 1715 | mPointerLocationView = new PointerLocationView(mContext); |
| 1716 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1717 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1718 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1719 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1720 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1721 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1722 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1723 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1724 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1725 | if (ActivityManager.isHighEndGfx()) { |
| 1726 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1727 | lp.privateFlags |= |
| 1728 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1729 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1730 | lp.format = PixelFormat.TRANSLUCENT; |
| 1731 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1732 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1733 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1734 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1735 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1736 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1737 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1738 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1739 | |
| 1740 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1741 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1742 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1743 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1744 | wm.removeView(mPointerLocationView); |
| 1745 | mPointerLocationView = null; |
| 1746 | } |
| 1747 | } |
| 1748 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1749 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1750 | try { |
| 1751 | int rotation = mContext.getResources().getInteger(resID); |
| 1752 | switch (rotation) { |
| 1753 | case 0: |
| 1754 | return Surface.ROTATION_0; |
| 1755 | case 90: |
| 1756 | return Surface.ROTATION_90; |
| 1757 | case 180: |
| 1758 | return Surface.ROTATION_180; |
| 1759 | case 270: |
| 1760 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1761 | } |
| 1762 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1763 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1764 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1765 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1769 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1770 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1771 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1772 | |
| 1773 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1774 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 1775 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 1776 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 1777 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 1778 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 1779 | } |
| 1780 | |
| 1781 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 1782 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1783 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1784 | } |
| 1785 | String permission = null; |
| 1786 | switch (type) { |
| 1787 | case TYPE_TOAST: |
| 1788 | // XXX right now the app process has complete control over |
| 1789 | // this... should introduce a token to let the system |
| 1790 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1791 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1792 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1793 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1794 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1795 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1796 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1797 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1798 | case TYPE_ACCESSIBILITY_OVERLAY: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1799 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1800 | break; |
| 1801 | case TYPE_PHONE: |
| 1802 | case TYPE_PRIORITY_PHONE: |
| 1803 | case TYPE_SYSTEM_ALERT: |
| 1804 | case TYPE_SYSTEM_ERROR: |
| 1805 | case TYPE_SYSTEM_OVERLAY: |
| 1806 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1807 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1808 | break; |
| 1809 | default: |
| 1810 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1811 | } |
| 1812 | if (permission != null) { |
| 1813 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1814 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1815 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1816 | } |
| 1817 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1818 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1819 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1820 | |
| 1821 | @Override |
| 1822 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1823 | |
| 1824 | // If this switch statement is modified, modify the comment in the declarations of |
| 1825 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1826 | switch (attrs.type) { |
| 1827 | default: |
| 1828 | // These are the windows that by default are shown only to the user that created |
| 1829 | // them. If this needs to be overridden, set |
| 1830 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1831 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1832 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1833 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1834 | return true; |
| 1835 | } |
| 1836 | break; |
| 1837 | |
| 1838 | // These are the windows that by default are shown to all users. However, to |
| 1839 | // protect against spoofing, check permissions below. |
| 1840 | case TYPE_APPLICATION_STARTING: |
| 1841 | case TYPE_BOOT_PROGRESS: |
| 1842 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1843 | case TYPE_INPUT_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1844 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1845 | case TYPE_KEYGUARD_DIALOG: |
| 1846 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1847 | case TYPE_NAVIGATION_BAR: |
| 1848 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1849 | case TYPE_PHONE: |
| 1850 | case TYPE_POINTER: |
| 1851 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1852 | case TYPE_SEARCH_BAR: |
| 1853 | case TYPE_STATUS_BAR: |
| 1854 | case TYPE_STATUS_BAR_PANEL: |
| 1855 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1856 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1857 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1858 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1859 | break; |
| 1860 | } |
| 1861 | |
| 1862 | // Check if third party app has set window to system window type. |
| 1863 | return mContext.checkCallingOrSelfPermission( |
| 1864 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1865 | != PackageManager.PERMISSION_GRANTED; |
| 1866 | } |
| 1867 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1868 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1869 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1870 | switch (attrs.type) { |
| 1871 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1872 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1873 | // These types of windows can't receive input events. |
| 1874 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1875 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1876 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1877 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1878 | case TYPE_STATUS_BAR: |
| 1879 | |
| 1880 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 1881 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 1882 | // the keyguard as occluded wouldn't set these flags again. |
| 1883 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 1884 | if (mKeyguardHidden) { |
| 1885 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 1886 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1887 | } |
| 1888 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1889 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 1890 | |
| 1891 | if (attrs.type != TYPE_STATUS_BAR) { |
| 1892 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 1893 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1894 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1895 | |
| 1896 | if (ActivityManager.isHighEndGfx() |
| 1897 | && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
Adrian Roos | f5e9b5c | 2014-09-10 15:27:41 +0200 | [diff] [blame] | 1898 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 1899 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1900 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1901 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1902 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1903 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1904 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1905 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 1906 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 1907 | private void readCameraLensCoverState() { |
| 1908 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 1909 | } |
| 1910 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1911 | private boolean isHidden(int accessibilityMode) { |
| 1912 | switch (accessibilityMode) { |
| 1913 | case 1: |
| 1914 | return mLidState == LID_CLOSED; |
| 1915 | case 2: |
| 1916 | return mLidState == LID_OPEN; |
| 1917 | default: |
| 1918 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1919 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1920 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1921 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1922 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1923 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1924 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1925 | int navigationPresence) { |
| 1926 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1927 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1928 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1929 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1930 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1931 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1932 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1933 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1934 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1935 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1936 | if (!mHasSoftInput) { |
| 1937 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1938 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1939 | } |
| 1940 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1941 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1942 | || (navigationPresence == PRESENCE_INTERNAL |
| 1943 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1944 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1945 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1946 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1947 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1948 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1949 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1950 | public int windowTypeToLayerLw(int type) { |
| 1951 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1952 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1953 | } |
| 1954 | switch (type) { |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1955 | case TYPE_PRIVATE_PRESENTATION: |
| 1956 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1957 | case TYPE_WALLPAPER: |
| 1958 | // wallpaper is at the bottom, though the window manager may move it. |
| 1959 | return 2; |
| 1960 | case TYPE_PHONE: |
| 1961 | return 3; |
| 1962 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 1963 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1964 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1965 | case TYPE_VOICE_INTERACTION: |
| 1966 | // voice interaction layer is almost immediately above apps. |
| 1967 | return 5; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1968 | case TYPE_INPUT_CONSUMER: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1969 | return 6; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1970 | case TYPE_SYSTEM_DIALOG: |
| 1971 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1972 | case TYPE_TOAST: |
| 1973 | // toasts and the plugged-in battery thing |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1974 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1975 | case TYPE_PRIORITY_PHONE: |
| 1976 | // 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] | 1977 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1978 | case TYPE_DREAM: |
| 1979 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1980 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1981 | case TYPE_SYSTEM_ALERT: |
| 1982 | // like the ANR / app crashed dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1983 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1984 | case TYPE_INPUT_METHOD: |
| 1985 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1986 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1987 | case TYPE_INPUT_METHOD_DIALOG: |
| 1988 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1989 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1990 | case TYPE_KEYGUARD_SCRIM: |
| 1991 | // the safety window that shows behind keyguard while keyguard is starting |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1992 | return 14; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1993 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1994 | return 15; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1995 | case TYPE_STATUS_BAR: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1996 | return 16; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1997 | case TYPE_STATUS_BAR_PANEL: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1998 | return 17; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 1999 | case TYPE_KEYGUARD_DIALOG: |
| 2000 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2001 | case TYPE_VOLUME_OVERLAY: |
| 2002 | // the on-screen volume indicator and controller shown when the user |
| 2003 | // changes the device volume |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2004 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2005 | case TYPE_SYSTEM_OVERLAY: |
| 2006 | // the on-screen volume indicator and controller shown when the user |
| 2007 | // changes the device volume |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2008 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2009 | case TYPE_NAVIGATION_BAR: |
| 2010 | // the navigation bar, if available, shows atop most things |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2011 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2012 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2013 | // 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] | 2014 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2015 | case TYPE_SYSTEM_ERROR: |
| 2016 | // system-level error dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2017 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2018 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2019 | // used to highlight the magnified portion of a display |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2020 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2021 | case TYPE_DISPLAY_OVERLAY: |
| 2022 | // used to simulate secondary display devices |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2023 | return 25; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2024 | case TYPE_DRAG: |
| 2025 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2026 | // which sits above all other focusable windows |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2027 | return 26; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2028 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2029 | // overlay put by accessibility services to intercept user interaction |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2030 | return 27; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2031 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2032 | return 28; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2033 | case TYPE_BOOT_PROGRESS: |
| 2034 | return 29; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2035 | case TYPE_POINTER: |
| 2036 | // the (mouse) pointer layer |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2037 | return 30; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2038 | } |
| 2039 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2040 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2044 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2045 | public int subWindowTypeToLayerLw(int type) { |
| 2046 | switch (type) { |
| 2047 | case TYPE_APPLICATION_PANEL: |
| 2048 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2049 | return APPLICATION_PANEL_SUBLAYER; |
| 2050 | case TYPE_APPLICATION_MEDIA: |
| 2051 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2052 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2053 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2054 | case TYPE_APPLICATION_SUB_PANEL: |
| 2055 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2056 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2057 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2058 | } |
| 2059 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2060 | return 0; |
| 2061 | } |
| 2062 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2063 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2064 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2065 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2068 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2069 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2070 | if (mHasNavigationBar) { |
| 2071 | // For a basic navigation bar, when we are in landscape mode we place |
| 2072 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2073 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 2074 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2075 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2076 | } |
| 2077 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2078 | } |
| 2079 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2080 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2081 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2082 | if (mHasNavigationBar) { |
| 2083 | // For a basic navigation bar, when we are in portrait mode we place |
| 2084 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2085 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 2086 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2092 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2093 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 2094 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2097 | @Override |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2098 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2099 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2100 | // 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] | 2101 | // we do want to exclude it since applications can't generally use that part |
| 2102 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2103 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2104 | } |
| 2105 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2106 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 2107 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 2108 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2109 | (isKeyguardHostWindow(attrs) && |
| 2110 | (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 2111 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2112 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2113 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2114 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2115 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2116 | return attrs.type == TYPE_STATUS_BAR; |
| 2117 | } |
| 2118 | |
| 2119 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2120 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2121 | switch (attrs.type) { |
| 2122 | case TYPE_STATUS_BAR: |
| 2123 | case TYPE_NAVIGATION_BAR: |
| 2124 | case TYPE_WALLPAPER: |
| 2125 | case TYPE_DREAM: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2126 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2127 | return false; |
| 2128 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 2129 | // Hide only windows below the keyguard host window. |
| 2130 | return windowTypeToLayerLw(win.getBaseType()) |
| 2131 | < windowTypeToLayerLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2132 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2133 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2134 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2135 | @Override |
| 2136 | public WindowState getWinShowWhenLockedLw() { |
| 2137 | return mWinShowWhenLocked; |
| 2138 | } |
| 2139 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2140 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2141 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2142 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2143 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2144 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2145 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2146 | return null; |
| 2147 | } |
| 2148 | if (packageName == null) { |
| 2149 | return null; |
| 2150 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2151 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2152 | WindowManager wm = null; |
| 2153 | View view = null; |
| 2154 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2155 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2156 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2157 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2158 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2159 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2160 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2161 | try { |
| 2162 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2163 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2164 | } catch (PackageManager.NameNotFoundException e) { |
| 2165 | // Ignore |
| 2166 | } |
| 2167 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2168 | |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2169 | PhoneWindow win = new PhoneWindow(context); |
| 2170 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2171 | final TypedArray ta = win.getWindowStyle(); |
| 2172 | if (ta.getBoolean( |
| 2173 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 2174 | || ta.getBoolean( |
| 2175 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2176 | return null; |
| 2177 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2178 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2179 | Resources r = context.getResources(); |
| 2180 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2181 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2182 | win.setType( |
| 2183 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2184 | |
| 2185 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2186 | // Assumes it's safe to show starting windows of launched apps while |
| 2187 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2188 | // secret information. |
| 2189 | if (mKeyguardHidden) { |
| 2190 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2191 | } |
| 2192 | } |
| 2193 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2194 | // Force the window flags: this is a fake window, so it is not really |
| 2195 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2196 | // flag because we do know that the next window will take input |
| 2197 | // focus, so we want to get the IME window up on top of us right away. |
| 2198 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2199 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2200 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2201 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2202 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2203 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2204 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2205 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2206 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2207 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2208 | win.setDefaultIcon(icon); |
| 2209 | win.setDefaultLogo(logo); |
| 2210 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2211 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2212 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2213 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2214 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2215 | params.token = appToken; |
| 2216 | params.packageName = packageName; |
| 2217 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2218 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2219 | params.privateFlags |= |
| 2220 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2221 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2222 | |
| 2223 | if (!compatInfo.supportsScreen()) { |
| 2224 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2225 | } |
| 2226 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2227 | params.setTitle("Starting " + packageName); |
| 2228 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2229 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2230 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2231 | |
| 2232 | if (win.isFloating()) { |
| 2233 | // Whoops, there is no way to display an animation/preview |
| 2234 | // of such a thing! After all that work... let's skip it. |
| 2235 | // (Note that we must do this here because it is in |
| 2236 | // getDecorView() where the theme is evaluated... maybe |
| 2237 | // we should peek the floating attribute from the theme |
| 2238 | // earlier.) |
| 2239 | return null; |
| 2240 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2241 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2242 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2243 | TAG, "Adding starting window for " + packageName |
| 2244 | + " / " + appToken + ": " |
| 2245 | + (view.getParent() != null ? view : null)); |
| 2246 | |
| 2247 | wm.addView(view, params); |
| 2248 | |
| 2249 | // Only return the view if it was successfully added to the |
| 2250 | // window manager... which we can tell by it having a parent. |
| 2251 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2252 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2253 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2254 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2255 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2256 | } catch (RuntimeException e) { |
| 2257 | // don't crash if something else bad happens, for example a |
| 2258 | // failure loading resources because we are loading from an app |
| 2259 | // on external storage that has been unmounted. |
| 2260 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2261 | } finally { |
| 2262 | if (view != null && view.getParent() == null) { |
| 2263 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2264 | wm.removeViewImmediate(view); |
| 2265 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | return null; |
| 2269 | } |
| 2270 | |
| 2271 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2272 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2273 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2274 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2275 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2276 | |
| 2277 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2278 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2279 | wm.removeView(window); |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2285 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2286 | * Currently enforces that three window types are singletons: |
| 2287 | * <ul> |
| 2288 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2289 | * <li>KEYGUARD_TYPE</li> |
| 2290 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2291 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2292 | * @param win The window to be added |
| 2293 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2294 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2295 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2296 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2297 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2298 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2299 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2300 | switch (attrs.type) { |
| 2301 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2302 | mContext.enforceCallingOrSelfPermission( |
| 2303 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2304 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2305 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2306 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2307 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2308 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2309 | } |
| 2310 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2311 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2312 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2313 | case TYPE_NAVIGATION_BAR: |
| 2314 | mContext.enforceCallingOrSelfPermission( |
| 2315 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2316 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2317 | if (mNavigationBar != null) { |
| 2318 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2319 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2320 | } |
| 2321 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2322 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2323 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2324 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2325 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2326 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2327 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2328 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2329 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2330 | mContext.enforceCallingOrSelfPermission( |
| 2331 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2332 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2333 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2334 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2335 | if (mKeyguardScrim != null) { |
| 2336 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2337 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2338 | mKeyguardScrim = win; |
| 2339 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2340 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2341 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2345 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2346 | public void removeWindowLw(WindowState win) { |
| 2347 | if (mStatusBar == win) { |
| 2348 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2349 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2350 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2351 | } else if (mKeyguardScrim == win) { |
| 2352 | Log.v(TAG, "Removing keyguard scrim"); |
| 2353 | mKeyguardScrim = null; |
| 2354 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2355 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2356 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2361 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2362 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2363 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2364 | public int selectAnimationLw(WindowState win, int transit) { |
| 2365 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2366 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2367 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2368 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2369 | if (transit == TRANSIT_EXIT |
| 2370 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2371 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2372 | } else if (transit == TRANSIT_ENTER |
| 2373 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2374 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2375 | } |
| 2376 | } else if (win == mNavigationBar) { |
| 2377 | // This can be on either the bottom or the right. |
| 2378 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2379 | if (transit == TRANSIT_EXIT |
| 2380 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2381 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2382 | } else if (transit == TRANSIT_ENTER |
| 2383 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2384 | return R.anim.dock_bottom_enter; |
| 2385 | } |
| 2386 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2387 | if (transit == TRANSIT_EXIT |
| 2388 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2389 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2390 | } else if (transit == TRANSIT_ENTER |
| 2391 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2392 | return R.anim.dock_right_enter; |
| 2393 | } |
| 2394 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2398 | if (win.hasAppShownWindows()) { |
| 2399 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2400 | return com.android.internal.R.anim.app_starting_exit; |
| 2401 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2402 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2403 | && transit == TRANSIT_ENTER) { |
| 2404 | // Special case: we are animating in a dream, while the keyguard |
| 2405 | // is shown. We don't want an animation on the dream, because |
| 2406 | // we need it shown immediately with the keyguard animating away |
| 2407 | // to reveal it. |
| 2408 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | return 0; |
| 2412 | } |
| 2413 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2414 | @Override |
| 2415 | public void selectRotationAnimationLw(int anim[]) { |
| 2416 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2417 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2418 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2419 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2420 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2421 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2422 | case ROTATION_ANIMATION_CROSSFADE: |
| 2423 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2424 | anim[1] = R.anim.rotation_animation_enter; |
| 2425 | break; |
| 2426 | case ROTATION_ANIMATION_JUMPCUT: |
| 2427 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2428 | anim[1] = R.anim.rotation_animation_enter; |
| 2429 | break; |
| 2430 | case ROTATION_ANIMATION_ROTATE: |
| 2431 | default: |
| 2432 | anim[0] = anim[1] = 0; |
| 2433 | break; |
| 2434 | } |
| 2435 | } else { |
| 2436 | anim[0] = anim[1] = 0; |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | @Override |
| 2441 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2442 | boolean forceDefault) { |
| 2443 | switch (exitAnimId) { |
| 2444 | case R.anim.rotation_animation_xfade_exit: |
| 2445 | case R.anim.rotation_animation_jump_exit: |
| 2446 | // These are the only cases that matter. |
| 2447 | if (forceDefault) { |
| 2448 | return false; |
| 2449 | } |
| 2450 | int anim[] = new int[2]; |
| 2451 | selectRotationAnimationLw(anim); |
| 2452 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2453 | default: |
| 2454 | return true; |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2459 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2460 | boolean goingToNotificationShade) { |
| 2461 | if (goingToNotificationShade) { |
| 2462 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2463 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2464 | |
| 2465 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 2466 | R.anim.lock_screen_behind_enter_wallpaper : |
| 2467 | R.anim.lock_screen_behind_enter); |
| 2468 | |
| 2469 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2470 | final List<Animation> animations = set.getAnimations(); |
| 2471 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 2472 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 2473 | } |
| 2474 | |
| 2475 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | |
| 2479 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2480 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2481 | if (goingToNotificationShade) { |
| 2482 | return null; |
| 2483 | } else { |
| 2484 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2485 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2486 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2487 | |
| 2488 | private static void awakenDreams() { |
| 2489 | IDreamManager dreamManager = getDreamManager(); |
| 2490 | if (dreamManager != null) { |
| 2491 | try { |
| 2492 | dreamManager.awaken(); |
| 2493 | } catch (RemoteException e) { |
| 2494 | // fine, stay asleep then |
| 2495 | } |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | static IDreamManager getDreamManager() { |
| 2500 | return IDreamManager.Stub.asInterface( |
| 2501 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2502 | } |
| 2503 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2504 | TelecomManager getTelecommService() { |
| 2505 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2506 | } |
| 2507 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2508 | static IAudioService getAudioService() { |
| 2509 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2510 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2511 | if (audioService == null) { |
| 2512 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2513 | } |
| 2514 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2518 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2522 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2523 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2524 | }; |
| 2525 | |
| 2526 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2527 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2528 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2529 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2530 | final int keyCode = event.getKeyCode(); |
| 2531 | final int repeatCount = event.getRepeatCount(); |
| 2532 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2533 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2534 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2535 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2536 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2537 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2538 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2539 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2540 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2541 | } |
| 2542 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2543 | // If we think we might have a volume down & power key chord on the way |
| 2544 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2545 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2546 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2547 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2548 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2549 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2550 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2551 | if (now < timeoutTime) { |
| 2552 | return timeoutTime - now; |
| 2553 | } |
| 2554 | } |
| 2555 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2556 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2557 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2558 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2559 | } |
| 2560 | return -1; |
| 2561 | } |
| 2562 | } |
| 2563 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2564 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2565 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2566 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2567 | mPendingMetaAction = false; |
| 2568 | } |
| 2569 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2570 | // First we always handle the home key here, so applications |
| 2571 | // can never break it, although if keyguard is on, we do let |
| 2572 | // it handle it, because that gives us the correct 5 second |
| 2573 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2574 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2575 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2576 | // If we have released the home key, and didn't do anything else |
| 2577 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2578 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2579 | cancelPreloadRecentApps(); |
| 2580 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2581 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2582 | if (mHomeConsumed) { |
| 2583 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2584 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2585 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2586 | |
| 2587 | if (canceled) { |
| 2588 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2589 | return -1; |
| 2590 | } |
| 2591 | |
Yorke Lee | 4f80324 | 2014-12-15 23:22:06 +0000 | [diff] [blame] | 2592 | // If an incoming call is ringing, HOME is totally disabled. |
| 2593 | // (The user is already on the InCallUI at this point, |
| 2594 | // and his ONLY options are to answer or reject the call.) |
| 2595 | TelecomManager telecomManager = getTelecommService(); |
| 2596 | if (telecomManager != null && telecomManager.isRinging()) { |
| 2597 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2598 | return -1; |
| 2599 | } |
| 2600 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2601 | // Delay handling home if a double-tap is possible. |
| 2602 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2603 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2604 | mHomeDoubleTapPending = true; |
| 2605 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2606 | ViewConfiguration.getDoubleTapTimeout()); |
| 2607 | return -1; |
| 2608 | } |
| 2609 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2610 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2611 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2612 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2613 | |
| 2614 | // If a system window has focus, then it doesn't make sense |
| 2615 | // right now to interact with applications. |
| 2616 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2617 | if (attrs != null) { |
| 2618 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2619 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2620 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2621 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2622 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2623 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2624 | } |
| 2625 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2626 | for (int i=0; i<typeCount; i++) { |
| 2627 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2628 | // 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] | 2629 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2633 | |
| 2634 | // Remember that home is pressed and handle special actions. |
| 2635 | if (repeatCount == 0) { |
| 2636 | mHomePressed = true; |
| 2637 | if (mHomeDoubleTapPending) { |
| 2638 | mHomeDoubleTapPending = false; |
| 2639 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2640 | handleDoubleTapOnHome(); |
| 2641 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2642 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2643 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2644 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2645 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2646 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 2647 | handleLongPressOnHome(event.getDeviceId()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2648 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2649 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2650 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2651 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2652 | // Hijack modified menu keys for debugging features |
| 2653 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2654 | |
| 2655 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2656 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2657 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2658 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2659 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2660 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2661 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2662 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2663 | Intent service = new Intent(); |
| 2664 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2665 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2666 | boolean shown = Settings.Global.getInt( |
| 2667 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2668 | if (!shown) { |
| 2669 | mContext.startService(service); |
| 2670 | } else { |
| 2671 | mContext.stopService(service); |
| 2672 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2673 | Settings.Global.putInt( |
| 2674 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2675 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2676 | } |
| 2677 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2678 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2679 | if (down) { |
| 2680 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2681 | mSearchKeyShortcutPending = true; |
| 2682 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2683 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2684 | } else { |
| 2685 | mSearchKeyShortcutPending = false; |
| 2686 | if (mConsumeSearchKeyUp) { |
| 2687 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2688 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2689 | } |
| 2690 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2691 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2692 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2693 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2694 | if (down && repeatCount == 0) { |
| 2695 | preloadRecentApps(); |
| 2696 | } else if (!down) { |
| 2697 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2698 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2699 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2700 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 2701 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 2702 | if (down) { |
| 2703 | IStatusBarService service = getStatusBarService(); |
| 2704 | if (service != null) { |
| 2705 | try { |
| 2706 | service.expandNotificationsPanel(); |
| 2707 | } catch (RemoteException e) { |
| 2708 | // do nothing. |
| 2709 | } |
| 2710 | } |
| 2711 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2712 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2713 | if (down) { |
| 2714 | if (repeatCount == 0) { |
| 2715 | mAssistKeyLongPressed = false; |
| 2716 | } else if (repeatCount == 1) { |
| 2717 | mAssistKeyLongPressed = true; |
| 2718 | if (!keyguardOn) { |
| 2719 | launchAssistLongPressAction(); |
| 2720 | } |
| 2721 | } |
| 2722 | } else { |
| 2723 | if (mAssistKeyLongPressed) { |
| 2724 | mAssistKeyLongPressed = false; |
| 2725 | } else { |
| 2726 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 2727 | launchAssistAction(null, event.getDeviceId()); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2728 | } |
| 2729 | } |
| 2730 | } |
| 2731 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2732 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2733 | if (!down) { |
| 2734 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2735 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2736 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2737 | } else { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame^] | 2738 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 2739 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 2740 | if (dic != null) { |
| 2741 | try { |
| 2742 | dic.exitIdle("voice-search"); |
| 2743 | } catch (RemoteException e) { |
| 2744 | } |
| 2745 | } |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2746 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2747 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2748 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2749 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2750 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2751 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2752 | if (down && repeatCount == 0) { |
| 2753 | mHandler.post(mScreenshotRunnable); |
| 2754 | } |
| 2755 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2756 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2757 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2758 | if (down) { |
| 2759 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2760 | |
| 2761 | // Disable autobrightness if it's on |
| 2762 | int auto = Settings.System.getIntForUser( |
| 2763 | mContext.getContentResolver(), |
| 2764 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2765 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2766 | UserHandle.USER_CURRENT_OR_SELF); |
| 2767 | if (auto != 0) { |
| 2768 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2769 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2770 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2771 | UserHandle.USER_CURRENT_OR_SELF); |
| 2772 | } |
| 2773 | |
| 2774 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2775 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2776 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2777 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2778 | Settings.System.SCREEN_BRIGHTNESS, |
| 2779 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2780 | UserHandle.USER_CURRENT_OR_SELF); |
| 2781 | brightness += step; |
| 2782 | // Make sure we don't go beyond the limits. |
| 2783 | brightness = Math.min(max, brightness); |
| 2784 | brightness = Math.max(min, brightness); |
| 2785 | |
| 2786 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2787 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2788 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2789 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 2790 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2791 | } |
| 2792 | return -1; |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2793 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2794 | if (down) { |
| 2795 | mPendingMetaAction = true; |
| 2796 | } else if (mPendingMetaAction) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 2797 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2798 | } |
| 2799 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2800 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2801 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2802 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2803 | // Any printing key that is chorded with Search should be consumed |
| 2804 | // even if no shortcut was invoked. This prevents text from being |
| 2805 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2806 | // 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] | 2807 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2808 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2809 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2810 | mConsumeSearchKeyUp = true; |
| 2811 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2812 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2813 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2814 | if (shortcutIntent != null) { |
| 2815 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2816 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2817 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2818 | } catch (ActivityNotFoundException ex) { |
| 2819 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2820 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2821 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2822 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2823 | } else { |
| 2824 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2825 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2826 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2827 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2828 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2829 | } |
| 2830 | } |
| 2831 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2832 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2833 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2834 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2835 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2836 | if (kcm.isPrintingKey(keyCode)) { |
| 2837 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2838 | metaState & ~(KeyEvent.META_META_ON |
| 2839 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2840 | if (shortcutIntent != null) { |
| 2841 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2842 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2843 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2844 | } catch (ActivityNotFoundException ex) { |
| 2845 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2846 | + "the activity to which it is registered was not found: " |
| 2847 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2848 | } |
| 2849 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2850 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2851 | } |
| 2852 | } |
| 2853 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2854 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2855 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2856 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2857 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2858 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2859 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2860 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2861 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2862 | } catch (ActivityNotFoundException ex) { |
| 2863 | Slog.w(TAG, "Dropping application launch key because " |
| 2864 | + "the activity to which it is registered was not found: " |
| 2865 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2866 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2867 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2868 | } |
| 2869 | } |
| 2870 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2871 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2872 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2873 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2874 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 2875 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2876 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 2877 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2878 | return -1; |
| 2879 | } |
| 2880 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 2881 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 2882 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 2883 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 2884 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2885 | } |
| 2886 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2887 | // Handle keyboard language switching. |
| 2888 | if (down && repeatCount == 0 |
| 2889 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2890 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2891 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2892 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2893 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2894 | return -1; |
| 2895 | } |
| 2896 | if (mLanguageSwitchKeyPressed && !down |
| 2897 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2898 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2899 | mLanguageSwitchKeyPressed = false; |
| 2900 | return -1; |
| 2901 | } |
| 2902 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2903 | if (isValidGlobalKey(keyCode) |
| 2904 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2905 | return -1; |
| 2906 | } |
| 2907 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2908 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 2909 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2910 | return -1; |
| 2911 | } |
| 2912 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2913 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2914 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2915 | } |
| 2916 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2917 | /** {@inheritDoc} */ |
| 2918 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2919 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2920 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2921 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2922 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2923 | + ", flags=" + event.getFlags() |
| 2924 | + ", keyCode=" + event.getKeyCode() |
| 2925 | + ", scanCode=" + event.getScanCode() |
| 2926 | + ", metaState=" + event.getMetaState() |
| 2927 | + ", repeatCount=" + event.getRepeatCount() |
| 2928 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2929 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2930 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2931 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2932 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2933 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2934 | final int keyCode = event.getKeyCode(); |
| 2935 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2936 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2937 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2938 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2939 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2940 | final FallbackAction fallbackAction; |
| 2941 | if (initialDown) { |
| 2942 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2943 | } else { |
| 2944 | fallbackAction = mFallbackActions.get(keyCode); |
| 2945 | } |
| 2946 | |
| 2947 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2948 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2949 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2950 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2951 | } |
| 2952 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2953 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2954 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2955 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2956 | event.getAction(), fallbackAction.keyCode, |
| 2957 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2958 | event.getDeviceId(), event.getScanCode(), |
| 2959 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2960 | |
| 2961 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2962 | fallbackEvent.recycle(); |
| 2963 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2964 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2965 | |
| 2966 | if (initialDown) { |
| 2967 | mFallbackActions.put(keyCode, fallbackAction); |
| 2968 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2969 | mFallbackActions.remove(keyCode); |
| 2970 | fallbackAction.recycle(); |
| 2971 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2972 | } |
| 2973 | } |
| 2974 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2975 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2976 | if (fallbackEvent == null) { |
| 2977 | Slog.d(TAG, "No fallback."); |
| 2978 | } else { |
| 2979 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2980 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2981 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2982 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2983 | } |
| 2984 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2985 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2986 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2987 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2988 | long delayMillis = interceptKeyBeforeDispatching( |
| 2989 | win, fallbackEvent, policyFlags); |
| 2990 | if (delayMillis == 0) { |
| 2991 | return true; |
| 2992 | } |
| 2993 | } |
| 2994 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2995 | } |
| 2996 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2997 | private void launchAssistLongPressAction() { |
| 2998 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2999 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 3000 | |
| 3001 | // launch the search activity |
| 3002 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 3003 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3004 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3005 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3006 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3007 | SearchManager searchManager = getSearchManager(); |
| 3008 | if (searchManager != null) { |
| 3009 | searchManager.stopSearch(); |
| 3010 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3011 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3012 | } catch (ActivityNotFoundException e) { |
| 3013 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | private void launchAssistAction() { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3018 | launchAssistAction(null, Integer.MIN_VALUE); |
Michael Wright | 8ab940a | 2014-09-01 11:01:27 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | private void launchAssistAction(String hint) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3022 | launchAssistAction(hint, Integer.MIN_VALUE); |
| 3023 | } |
| 3024 | |
| 3025 | private void launchAssistAction(String hint, int deviceId) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3026 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3027 | Bundle args = null; |
| 3028 | if (deviceId > Integer.MIN_VALUE) { |
| 3029 | args = new Bundle(); |
| 3030 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3031 | } |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3032 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 3033 | .launchAssistAction(hint, UserHandle.myUserId(), args); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3036 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3037 | if (isUserSetupComplete()) { |
| 3038 | mContext.startActivityAsUser(intent, handle); |
| 3039 | } else { |
| 3040 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3041 | } |
| 3042 | } |
| 3043 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3044 | private SearchManager getSearchManager() { |
| 3045 | if (mSearchManager == null) { |
| 3046 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3047 | } |
| 3048 | return mSearchManager; |
| 3049 | } |
| 3050 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3051 | private void preloadRecentApps() { |
| 3052 | mPreloadedRecentApps = true; |
| 3053 | try { |
| 3054 | IStatusBarService statusbar = getStatusBarService(); |
| 3055 | if (statusbar != null) { |
| 3056 | statusbar.preloadRecentApps(); |
| 3057 | } |
| 3058 | } catch (RemoteException e) { |
| 3059 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 3060 | // re-acquire status bar service next time it is needed. |
| 3061 | mStatusBarService = null; |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | private void cancelPreloadRecentApps() { |
| 3066 | if (mPreloadedRecentApps) { |
| 3067 | mPreloadedRecentApps = false; |
| 3068 | try { |
| 3069 | IStatusBarService statusbar = getStatusBarService(); |
| 3070 | if (statusbar != null) { |
| 3071 | statusbar.cancelPreloadRecentApps(); |
| 3072 | } |
| 3073 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3074 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3075 | // re-acquire status bar service next time it is needed. |
| 3076 | mStatusBarService = null; |
| 3077 | } |
| 3078 | } |
| 3079 | } |
| 3080 | |
| 3081 | private void toggleRecentApps() { |
| 3082 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3083 | try { |
| 3084 | IStatusBarService statusbar = getStatusBarService(); |
| 3085 | if (statusbar != null) { |
| 3086 | statusbar.toggleRecentApps(); |
| 3087 | } |
| 3088 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3089 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 3090 | // re-acquire status bar service next time it is needed. |
| 3091 | mStatusBarService = null; |
| 3092 | } |
| 3093 | } |
| 3094 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3095 | @Override |
| 3096 | public void showRecentApps() { |
| 3097 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 3098 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 3099 | } |
| 3100 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3101 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 3102 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3103 | try { |
| 3104 | IStatusBarService statusbar = getStatusBarService(); |
| 3105 | if (statusbar != null) { |
| 3106 | statusbar.showRecentApps(triggeredFromAltTab); |
| 3107 | } |
| 3108 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3109 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 3110 | // re-acquire status bar service next time it is needed. |
| 3111 | mStatusBarService = null; |
| 3112 | } |
| 3113 | } |
| 3114 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3115 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3116 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3117 | try { |
| 3118 | IStatusBarService statusbar = getStatusBarService(); |
| 3119 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3120 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3121 | } |
| 3122 | } catch (RemoteException e) { |
| 3123 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 3124 | // re-acquire status bar service next time it is needed. |
| 3125 | mStatusBarService = null; |
| 3126 | } |
| 3127 | } |
| 3128 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3129 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3130 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3131 | } |
| 3132 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3133 | /** |
| 3134 | * A home key -> launch home action was detected. Take the appropriate action |
| 3135 | * given the situation with the keyguard. |
| 3136 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3137 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3138 | if (respectKeyguard) { |
| 3139 | if (isKeyguardShowingAndNotOccluded()) { |
| 3140 | // don't launch home if keyguard showing |
| 3141 | return; |
| 3142 | } |
| 3143 | |
| 3144 | if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
| 3145 | // when in keyguard restricted mode, must first verify unlock |
| 3146 | // before launching home |
| 3147 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3148 | @Override |
| 3149 | public void onKeyguardExitResult(boolean success) { |
| 3150 | if (success) { |
| 3151 | try { |
| 3152 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3153 | } catch (RemoteException e) { |
| 3154 | } |
| 3155 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3156 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3157 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3158 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3159 | }); |
| 3160 | return; |
| 3161 | } |
| 3162 | } |
| 3163 | |
| 3164 | // no keyguard stuff to worry about, just launch home! |
| 3165 | try { |
| 3166 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3167 | } catch (RemoteException e) { |
| 3168 | } |
| 3169 | if (mRecentsVisible) { |
| 3170 | // Hide Recents and notify it to launch Home |
| 3171 | if (awakenFromDreams) { |
| 3172 | awakenDreams(); |
| 3173 | } |
| 3174 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3175 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3176 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3177 | // Otherwise, just launch Home |
| 3178 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3179 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3183 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3184 | @Override |
| 3185 | public void run() { |
| 3186 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3187 | // Clear flags. |
| 3188 | mForceClearedSystemUiFlags &= |
| 3189 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3190 | } |
| 3191 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3192 | } |
| 3193 | }; |
| 3194 | |
| 3195 | /** |
| 3196 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3197 | * to determine when the nav bar should be shown and prevent applications from |
| 3198 | * receiving those touches. |
| 3199 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3200 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3201 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3202 | super(inputChannel, looper); |
| 3203 | } |
| 3204 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3205 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3206 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3207 | boolean handled = false; |
| 3208 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3209 | if (event instanceof MotionEvent |
| 3210 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3211 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3212 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3213 | // When the user taps down, we re-show the nav bar. |
| 3214 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3215 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3216 | // Any user activity always causes us to show the |
| 3217 | // navigation controls, if they had been hidden. |
| 3218 | // We also clear the low profile and only content |
| 3219 | // flags so that tapping on the screen will atomically |
| 3220 | // restore all currently hidden screen decorations. |
| 3221 | int newVal = mResettingSystemUiFlags | |
| 3222 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3223 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3224 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3225 | if (mResettingSystemUiFlags != newVal) { |
| 3226 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3227 | changed = true; |
| 3228 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3229 | // We don't allow the system's nav bar to be hidden |
| 3230 | // again for 1 second, to prevent applications from |
| 3231 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3232 | newVal = mForceClearedSystemUiFlags | |
| 3233 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3234 | if (mForceClearedSystemUiFlags != newVal) { |
| 3235 | mForceClearedSystemUiFlags = newVal; |
| 3236 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3237 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3238 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3239 | } |
| 3240 | if (changed) { |
| 3241 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3242 | } |
| 3243 | } |
| 3244 | } |
| 3245 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3246 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3247 | } |
| 3248 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3249 | } |
| 3250 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3251 | new InputEventReceiver.Factory() { |
| 3252 | @Override |
| 3253 | public InputEventReceiver createInputEventReceiver( |
| 3254 | InputChannel inputChannel, Looper looper) { |
| 3255 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3256 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3257 | }; |
| 3258 | |
| 3259 | @Override |
| 3260 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3261 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3262 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3263 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3264 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3265 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3266 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3267 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3268 | // Clear any bits in the new visibility that are currently being |
| 3269 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3270 | return visibility & ~mResettingSystemUiFlags |
| 3271 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3274 | @Override |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3275 | public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets, |
| 3276 | Rect outStableInsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3277 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3278 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3279 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3280 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3281 | 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] | 3282 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3283 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3284 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3285 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3286 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3287 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3288 | } else { |
| 3289 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3290 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3291 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3292 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3293 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3294 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3295 | availRight - mStableFullscreenRight, |
| 3296 | availBottom - mStableFullscreenBottom); |
| 3297 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3298 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3299 | availRight - mStableRight, availBottom - mStableBottom); |
| 3300 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3301 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3302 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3303 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3304 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3305 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3306 | availRight - mCurRight, availBottom - mCurBottom); |
| 3307 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3308 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3309 | availRight - mCurRight, availBottom - mCurBottom); |
| 3310 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3311 | |
| 3312 | outStableInsets.set(mStableLeft, mStableTop, |
| 3313 | availRight - mStableRight, availBottom - mStableBottom); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3314 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3315 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3316 | outContentInsets.setEmpty(); |
| 3317 | outStableInsets.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3318 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3319 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3320 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3321 | @Override |
| 3322 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 3323 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3324 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3325 | if (isDefaultDisplay) { |
| 3326 | switch (displayRotation) { |
| 3327 | case Surface.ROTATION_90: |
| 3328 | overscanLeft = mOverscanTop; |
| 3329 | overscanTop = mOverscanRight; |
| 3330 | overscanRight = mOverscanBottom; |
| 3331 | overscanBottom = mOverscanLeft; |
| 3332 | break; |
| 3333 | case Surface.ROTATION_180: |
| 3334 | overscanLeft = mOverscanRight; |
| 3335 | overscanTop = mOverscanBottom; |
| 3336 | overscanRight = mOverscanLeft; |
| 3337 | overscanBottom = mOverscanTop; |
| 3338 | break; |
| 3339 | case Surface.ROTATION_270: |
| 3340 | overscanLeft = mOverscanBottom; |
| 3341 | overscanTop = mOverscanLeft; |
| 3342 | overscanRight = mOverscanTop; |
| 3343 | overscanBottom = mOverscanRight; |
| 3344 | break; |
| 3345 | default: |
| 3346 | overscanLeft = mOverscanLeft; |
| 3347 | overscanTop = mOverscanTop; |
| 3348 | overscanRight = mOverscanRight; |
| 3349 | overscanBottom = mOverscanBottom; |
| 3350 | break; |
| 3351 | } |
| 3352 | } else { |
| 3353 | overscanLeft = 0; |
| 3354 | overscanTop = 0; |
| 3355 | overscanRight = 0; |
| 3356 | overscanBottom = 0; |
| 3357 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3358 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3359 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3360 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3361 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3362 | mSystemLeft = 0; |
| 3363 | mSystemTop = 0; |
| 3364 | mSystemRight = displayWidth; |
| 3365 | mSystemBottom = displayHeight; |
| 3366 | mUnrestrictedScreenLeft = overscanLeft; |
| 3367 | mUnrestrictedScreenTop = overscanTop; |
| 3368 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3369 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3370 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3371 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3372 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3373 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3374 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3375 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3376 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3377 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3378 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3379 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3380 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3381 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3382 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3383 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3384 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3385 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3386 | final Rect pf = mTmpParentFrame; |
| 3387 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3388 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3389 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3390 | final Rect dcf = mTmpDecorFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3391 | final Rect osf = mTmpOutsetFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3392 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3393 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3394 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3395 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3396 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3397 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3398 | if (isDefaultDisplay) { |
| 3399 | // For purposes of putting out fake window up to steal focus, we will |
| 3400 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3401 | final int sysui = mLastSystemUiFlags; |
| 3402 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3403 | boolean navTranslucent = (sysui |
| 3404 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3405 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3406 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3407 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3408 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3409 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3410 | if (!isKeyguardShowing) { |
| 3411 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3412 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3413 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3414 | // When the navigation bar isn't visible, we put up a fake |
| 3415 | // input window to catch all touch events. This way we can |
| 3416 | // detect when the user presses anywhere to bring back the nav |
| 3417 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3418 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3419 | if (mInputConsumer != null) { |
| 3420 | mInputConsumer.dismiss(); |
| 3421 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3422 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3423 | } else if (mInputConsumer == null) { |
| 3424 | mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(), |
| 3425 | mHideNavInputEventReceiverFactory); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3426 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3427 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3428 | // For purposes of positioning and showing the nav bar, if we have |
| 3429 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3430 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3431 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3432 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3433 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3434 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3435 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3436 | // Force the navigation bar to its appropriate place and |
| 3437 | // size. We need to do this directly, instead of relying on |
| 3438 | // it to bubble up from the nav bar, because this needs to |
| 3439 | // change atomically with screen rotations. |
| 3440 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 3441 | if (mNavigationBarOnBottom) { |
| 3442 | // 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] | 3443 | int top = displayHeight - overscanBottom |
| 3444 | - mNavigationBarHeightForRotation[displayRotation]; |
| 3445 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3446 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3447 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3448 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3449 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3450 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3451 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3452 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3453 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3454 | } else { |
| 3455 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3456 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3457 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3458 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3459 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3460 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3461 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3462 | // and not in the process of animating on or off, then |
| 3463 | // we can tell the app that it is covered by it. |
| 3464 | mSystemBottom = mTmpNavigationFrame.top; |
| 3465 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3466 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3467 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3468 | int left = displayWidth - overscanRight |
| 3469 | - mNavigationBarWidthForRotation[displayRotation]; |
| 3470 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3471 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3472 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3473 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3474 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3475 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3476 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3477 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3478 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3479 | } else { |
| 3480 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3481 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3482 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3483 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 3484 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3485 | // If the nav bar is currently requested to be visible, |
| 3486 | // and not in the process of animating on or off, then |
| 3487 | // we can tell the app that it is covered by it. |
| 3488 | mSystemRight = mTmpNavigationFrame.left; |
| 3489 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3490 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3491 | // Make sure the content and current rectangles are updated to |
| 3492 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3493 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3494 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3495 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3496 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3497 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3498 | // And compute the final frame. |
| 3499 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3500 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3501 | mTmpNavigationFrame, mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3502 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3503 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3504 | updateSysUiVisibility = true; |
| 3505 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3506 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3507 | 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] | 3508 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 3509 | |
| 3510 | // decide where the status bar goes ahead of time |
| 3511 | if (mStatusBar != null) { |
| 3512 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3513 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3514 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3515 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3516 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3517 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3518 | vf.left = mStableLeft; |
| 3519 | vf.top = mStableTop; |
| 3520 | vf.right = mStableRight; |
| 3521 | vf.bottom = mStableBottom; |
| 3522 | |
| 3523 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3524 | |
| 3525 | // Let the status bar determine its size. |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3526 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 3527 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
| 3528 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3529 | |
| 3530 | // For layout, the status bar is always at the top with our fixed height. |
| 3531 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3532 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3533 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3534 | boolean statusBarTranslucent = (sysui |
| 3535 | & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0; |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3536 | if (!isKeyguardShowing) { |
| 3537 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3538 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3539 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3540 | // If the status bar is hidden, we don't want to cause |
| 3541 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 3542 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3543 | // Status bar may go away, so the screen area it occupies |
| 3544 | // is available to apps but just covering them when the |
| 3545 | // status bar is visible. |
| 3546 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3547 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3548 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3549 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3550 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3551 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3552 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3553 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3554 | String.format( |
| 3555 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3556 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3557 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3558 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3559 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3560 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3561 | && !statusBarTransient && !statusBarTranslucent |
| 3562 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3563 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3564 | // and not in the process of animating on or off, then |
| 3565 | // we can tell the app that it is covered by it. |
| 3566 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3567 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3568 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3569 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3570 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3571 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3572 | if (updateSysUiVisibility) { |
| 3573 | updateSystemUiVisibilityLw(); |
| 3574 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3575 | } |
| 3576 | } |
| 3577 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3578 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3579 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3580 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 3581 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 3582 | return mStatusBar.getSurfaceLayer(); |
| 3583 | } |
| 3584 | |
| 3585 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 3586 | return mNavigationBar.getSurfaceLayer(); |
| 3587 | } |
| 3588 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3589 | return 0; |
| 3590 | } |
| 3591 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3592 | @Override |
| 3593 | public void getContentRectLw(Rect r) { |
| 3594 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3595 | } |
| 3596 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3597 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3598 | 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] | 3599 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3600 | // Here's a special case: if this attached window is a panel that is |
| 3601 | // above the dock window, and the window it is attached to is below |
| 3602 | // the dock window, then the frames we computed for the window it is |
| 3603 | // attached to can not be used because the dock is effectively part |
| 3604 | // of the underlying window and the attached window is floating on top |
| 3605 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3606 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3607 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3608 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3609 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3610 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3611 | } else { |
| 3612 | // The effective display frame of the attached window depends on |
| 3613 | // whether it is taking care of insetting its content. If not, |
| 3614 | // we need to use the parent's content frame so that the entire |
| 3615 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3616 | // 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] | 3617 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3618 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3619 | // Set the content frame of the attached window to the parent's decor frame |
| 3620 | // (same as content frame when IME isn't present) if specifically requested by |
| 3621 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 3622 | // Otherwise, use the overscan frame. |
| 3623 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 3624 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3625 | } else { |
| 3626 | // If the window is resizing, then we want to base the content |
| 3627 | // frame on our attached content frame to resize... however, |
| 3628 | // things can be tricky if the attached window is NOT in resize |
| 3629 | // mode, in which case its content frame will be larger. |
| 3630 | // Ungh. So to deal with that, make sure the content frame |
| 3631 | // we end up using is not covering the IM dock. |
| 3632 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3633 | if (attached.isVoiceInteraction()) { |
| 3634 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3635 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3636 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3637 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3638 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3639 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3640 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3641 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3642 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3643 | } |
| 3644 | } |
| 3645 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3646 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3647 | vf.set(attached.getVisibleFrameLw()); |
| 3648 | } |
| 3649 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3650 | // window should be positioned relative to its parent or the entire |
| 3651 | // screen. |
| 3652 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3653 | ? attached.getFrameLw() : df); |
| 3654 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3655 | |
| 3656 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3657 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3658 | // If app is requesting a stable layout, don't let the |
| 3659 | // content insets go below the stable values. |
| 3660 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3661 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3662 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3663 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3664 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3665 | } else { |
| 3666 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3667 | if (r.top < mStableTop) r.top = mStableTop; |
| 3668 | if (r.right > mStableRight) r.right = mStableRight; |
| 3669 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3670 | } |
| 3671 | } |
| 3672 | } |
| 3673 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3674 | private boolean canReceiveInput(WindowState win) { |
| 3675 | boolean notFocusable = |
| 3676 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 3677 | boolean altFocusableIm = |
| 3678 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 3679 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 3680 | return !notFocusableForIm; |
| 3681 | } |
| 3682 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3683 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3684 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 3685 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3686 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 3687 | // input, we need to layout it again to accomodate for the IME window. |
| 3688 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3689 | return; |
| 3690 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3691 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3692 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 3693 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3694 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 3695 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3696 | 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] | 3697 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 3698 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3699 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3700 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3701 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3702 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3703 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3704 | final Rect pf = mTmpParentFrame; |
| 3705 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3706 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3707 | final Rect cf = mTmpContentFrame; |
| 3708 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3709 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3710 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3711 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3712 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3713 | |
| 3714 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3715 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3716 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 3717 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 3718 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3719 | if (isDefaultDisplay) { |
| 3720 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 3721 | } else { |
| 3722 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 3723 | } |
| 3724 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3725 | if (!isDefaultDisplay) { |
| 3726 | if (attached != null) { |
| 3727 | // If this window is attached to another, our display |
| 3728 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3729 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3730 | } else { |
| 3731 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3732 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3733 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3734 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3735 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3736 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3737 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3738 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3739 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3740 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3741 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3742 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3743 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3744 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3745 | // ...with content insets above the nav bar |
| 3746 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3747 | // IM dock windows always go to the bottom of the screen. |
| 3748 | attrs.gravity = Gravity.BOTTOM; |
| 3749 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 3750 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
| 3751 | pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft; |
| 3752 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3753 | pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft |
| 3754 | + mUnrestrictedScreenWidth; |
| 3755 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3756 | + mUnrestrictedScreenHeight; |
| 3757 | cf.bottom = vf.bottom = mStableBottom; |
| 3758 | cf.top = vf.top = mStableTop; |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3759 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 3760 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3761 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3762 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3763 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 3764 | cf.left = vf.left = mStableLeft; |
| 3765 | cf.top = vf.top = mStableTop; |
| 3766 | cf.right = vf.right = mStableRight; |
| 3767 | vf.bottom = mStableBottom; |
| 3768 | cf.bottom = mContentBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3769 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3770 | |
| 3771 | // Default policy decor for the default display |
| 3772 | dcf.left = mSystemLeft; |
| 3773 | dcf.top = mSystemTop; |
| 3774 | dcf.right = mSystemRight; |
| 3775 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3776 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3777 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3778 | final boolean isAppWindow = |
| 3779 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3780 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3781 | final boolean topAtRest = |
| 3782 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3783 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3784 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3785 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3786 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 3787 | && (fl & WindowManager.LayoutParams. |
| 3788 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3789 | // Ensure policy decor includes status bar |
| 3790 | dcf.top = mStableTop; |
| 3791 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3792 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3793 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 3794 | && (fl & WindowManager.LayoutParams. |
| 3795 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3796 | // Ensure policy decor includes navigation bar |
| 3797 | dcf.bottom = mStableBottom; |
| 3798 | dcf.right = mStableRight; |
| 3799 | } |
| 3800 | } |
| 3801 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3802 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3803 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3804 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3805 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3806 | // This is the case for a normal activity window: we want it |
| 3807 | // to cover all of the screen space, and it can take care of |
| 3808 | // moving its contents to account for screen decorations that |
| 3809 | // intrude into that space. |
| 3810 | if (attached != null) { |
| 3811 | // If this window is attached to another, our display |
| 3812 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3813 | 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] | 3814 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3815 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3816 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3817 | // Status bar panels are the only windows who can go on top of |
| 3818 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3819 | // permission, so they have the same privileges as the status |
| 3820 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3821 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3822 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3823 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3824 | pf.left = df.left = of.left = hasNavBar |
| 3825 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3826 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3827 | pf.right = df.right = of.right = hasNavBar |
| 3828 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3829 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3830 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3831 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3832 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3833 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3834 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3835 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3836 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3837 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3838 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3839 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3840 | // Asking to layout into the overscan region, so give it that pure |
| 3841 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3842 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3843 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3844 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3845 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3846 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3847 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3848 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3849 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3850 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3851 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3852 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3853 | // only do this for application windows to ensure no window that |
| 3854 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3855 | pf.left = df.left = mOverscanScreenLeft; |
| 3856 | pf.top = df.top = mOverscanScreenTop; |
| 3857 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3858 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3859 | // We need to tell the app about where the frame inside the overscan |
| 3860 | // is, so it can inset its content by that amount -- it didn't ask |
| 3861 | // to actually extend itself into the overscan region. |
| 3862 | of.left = mUnrestrictedScreenLeft; |
| 3863 | of.top = mUnrestrictedScreenTop; |
| 3864 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3865 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3866 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3867 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3868 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3869 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3870 | + mRestrictedOverscanScreenWidth; |
| 3871 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3872 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3873 | // We need to tell the app about where the frame inside the overscan |
| 3874 | // is, so it can inset its content by that amount -- it didn't ask |
| 3875 | // to actually extend itself into the overscan region. |
| 3876 | of.left = mUnrestrictedScreenLeft; |
| 3877 | of.top = mUnrestrictedScreenTop; |
| 3878 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3879 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3880 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3881 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3882 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3883 | if (win.isVoiceInteraction()) { |
| 3884 | cf.left = mVoiceContentLeft; |
| 3885 | cf.top = mVoiceContentTop; |
| 3886 | cf.right = mVoiceContentRight; |
| 3887 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3888 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3889 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3890 | cf.left = mDockLeft; |
| 3891 | cf.top = mDockTop; |
| 3892 | cf.right = mDockRight; |
| 3893 | cf.bottom = mDockBottom; |
| 3894 | } else { |
| 3895 | cf.left = mContentLeft; |
| 3896 | cf.top = mContentTop; |
| 3897 | cf.right = mContentRight; |
| 3898 | cf.bottom = mContentBottom; |
| 3899 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3900 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3901 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3902 | // Full screen windows are always given a layout that is as if the |
| 3903 | // status bar and other transient decors are gone. This is to avoid |
| 3904 | // bad states when moving from a window that is not hding the |
| 3905 | // status bar to one that is. |
| 3906 | cf.left = mRestrictedScreenLeft; |
| 3907 | cf.top = mRestrictedScreenTop; |
| 3908 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3909 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3910 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3911 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3912 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3913 | vf.left = mCurLeft; |
| 3914 | vf.top = mCurTop; |
| 3915 | vf.right = mCurRight; |
| 3916 | vf.bottom = mCurBottom; |
| 3917 | } else { |
| 3918 | vf.set(cf); |
| 3919 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3920 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3921 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3922 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3923 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3924 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3925 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3926 | // A window that has requested to fill the entire screen just |
| 3927 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3928 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3929 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3930 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3931 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3932 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3933 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3934 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3935 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3936 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3937 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3938 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3939 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3940 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3941 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3942 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3943 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3944 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3945 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3946 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3947 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3948 | + mUnrestrictedScreenWidth; |
| 3949 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3950 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3951 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3952 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3953 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3954 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3955 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3956 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3957 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3958 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3959 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3960 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3961 | + mOverscanScreenWidth; |
| 3962 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3963 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 3964 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3965 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3966 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3967 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3968 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3969 | + mOverscanScreenWidth; |
| 3970 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3971 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3972 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3973 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 3974 | // it about the overscan area. |
| 3975 | pf.left = df.left = mOverscanScreenLeft; |
| 3976 | pf.top = df.top = mOverscanScreenTop; |
| 3977 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3978 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 3979 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 3980 | of.top = cf.top = mUnrestrictedScreenTop; |
| 3981 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3982 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3983 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3984 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3985 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3986 | // Asking to layout into the overscan region, so give it that pure |
| 3987 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3988 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3989 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3990 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3991 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3992 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3993 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3994 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3995 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 3996 | && (attrs.type == TYPE_STATUS_BAR |
| 3997 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 3998 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3999 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4000 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4001 | // Asking for layout as if the nav bar is hidden, lets the |
| 4002 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4003 | // 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] | 4004 | // can be above the nav bar can do this. |
| 4005 | // XXX This assumes that an app asking for this will also |
| 4006 | // ask for layout in only content. We can't currently figure out |
| 4007 | // 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] | 4008 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 4009 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4010 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 4011 | + mUnrestrictedScreenWidth; |
| 4012 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 4013 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4014 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4015 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4016 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4017 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4018 | + mRestrictedScreenWidth; |
| 4019 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4020 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4021 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4022 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4023 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4024 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4025 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4026 | vf.left = mCurLeft; |
| 4027 | vf.top = mCurTop; |
| 4028 | vf.right = mCurRight; |
| 4029 | vf.bottom = mCurBottom; |
| 4030 | } else { |
| 4031 | vf.set(cf); |
| 4032 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4033 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4034 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4035 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4036 | // A child window should be placed inside of the same visible |
| 4037 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4038 | 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] | 4039 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4040 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4041 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4042 | // Otherwise, a normal window must be placed inside the content |
| 4043 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4044 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 4045 | // Status bar panels are the only windows who can go on top of |
| 4046 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4047 | // permission, so they have the same privileges as the status |
| 4048 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4049 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4050 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4051 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4052 | + mRestrictedScreenWidth; |
| 4053 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4054 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4055 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 4056 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 4057 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4058 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 4059 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 4060 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 4061 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4062 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4063 | pf.left = mContentLeft; |
| 4064 | pf.top = mContentTop; |
| 4065 | pf.right = mContentRight; |
| 4066 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 4067 | if (win.isVoiceInteraction()) { |
| 4068 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 4069 | df.top = of.top = cf.top = mVoiceContentTop; |
| 4070 | df.right = of.right = cf.right = mVoiceContentRight; |
| 4071 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 4072 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4073 | df.left = of.left = cf.left = mDockLeft; |
| 4074 | df.top = of.top = cf.top = mDockTop; |
| 4075 | df.right = of.right = cf.right = mDockRight; |
| 4076 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4077 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4078 | df.left = of.left = cf.left = mContentLeft; |
| 4079 | df.top = of.top = cf.top = mContentTop; |
| 4080 | df.right = of.right = cf.right = mContentRight; |
| 4081 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4082 | } |
| 4083 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4084 | vf.left = mCurLeft; |
| 4085 | vf.top = mCurTop; |
| 4086 | vf.right = mCurRight; |
| 4087 | vf.bottom = mCurBottom; |
| 4088 | } else { |
| 4089 | vf.set(cf); |
| 4090 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4091 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4092 | } |
| 4093 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4094 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 4095 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 4096 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4097 | df.left = df.top = -10000; |
| 4098 | df.right = df.bottom = 10000; |
| 4099 | if (attrs.type != TYPE_WALLPAPER) { |
| 4100 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 4101 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 4102 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4103 | } |
| 4104 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4105 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 4106 | // need to provide information to the clients that want to pretend that you can draw there. |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 4107 | // We only want to apply outsets to certain types of windows. For example, we never want to |
| 4108 | // apply the outsets to floating dialogs, because they wouldn't make sense there. |
| 4109 | final boolean useOutsets = attrs.type == TYPE_WALLPAPER |
| 4110 | || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 4111 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; |
| 4112 | if (isDefaultDisplay && useOutsets) { |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4113 | osf = mTmpOutsetFrame; |
| 4114 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 4115 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4116 | if (outset > 0) { |
| 4117 | int rotation = Surface.ROTATION_0; |
| 4118 | try { |
| 4119 | rotation = mWindowManager.getRotation(); |
| 4120 | } catch (RemoteException e) { |
| 4121 | } |
| 4122 | if (rotation == Surface.ROTATION_0) { |
| 4123 | osf.bottom += outset; |
| 4124 | } else if (rotation == Surface.ROTATION_90) { |
| 4125 | osf.right += outset; |
| 4126 | } else if (rotation == Surface.ROTATION_180) { |
| 4127 | osf.top -= outset; |
| 4128 | } else if (rotation == Surface.ROTATION_270) { |
| 4129 | osf.left -= outset; |
| 4130 | } |
| 4131 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 4132 | + " with rotation " + rotation + ", result: " + osf); |
| 4133 | } |
| 4134 | } |
| 4135 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4136 | 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] | 4137 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4138 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4139 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 4140 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4141 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4142 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4143 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4144 | + " sf=" + sf.toShortString() |
| 4145 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4146 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4147 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4148 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4149 | // Dock windows carve out the bottom of the screen, so normal windows |
| 4150 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 4151 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 4152 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4153 | setLastInputMethodWindowLw(null, null); |
| 4154 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4155 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4156 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 4157 | && !win.getGivenInsetsPendingLw()) { |
| 4158 | offsetVoiceInputWindowLw(win); |
| 4159 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4160 | } |
| 4161 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4162 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4163 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4164 | top += win.getGivenContentInsetsLw().top; |
| 4165 | if (mContentBottom > top) { |
| 4166 | mContentBottom = top; |
| 4167 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4168 | if (mVoiceContentBottom > top) { |
| 4169 | mVoiceContentBottom = top; |
| 4170 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4171 | top = win.getVisibleFrameLw().top; |
| 4172 | top += win.getGivenVisibleInsetsLw().top; |
| 4173 | if (mCurBottom > top) { |
| 4174 | mCurBottom = top; |
| 4175 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4176 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4177 | + mDockBottom + " mContentBottom=" |
| 4178 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 4179 | } |
| 4180 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4181 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4182 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 4183 | top += win.getGivenContentInsetsLw().top; |
| 4184 | if (mVoiceContentBottom > top) { |
| 4185 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4186 | } |
| 4187 | } |
| 4188 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4189 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 4190 | @Override |
| 4191 | public void finishLayoutLw() { |
| 4192 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4193 | } |
| 4194 | |
| 4195 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4196 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4197 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4198 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4199 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4200 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4201 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4202 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4203 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4204 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4205 | mForcingShowNavBar = false; |
| 4206 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4207 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4208 | mHideLockScreen = false; |
| 4209 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4210 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4211 | mShowingLockscreen = false; |
| 4212 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4213 | mWinShowWhenLocked = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4214 | mKeyguardSecure = isKeyguardSecure(); |
| 4215 | mKeyguardSecureIncludingHidden = mKeyguardSecure |
| 4216 | && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4217 | } |
| 4218 | |
| 4219 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4220 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4221 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4222 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 4223 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4224 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4225 | if (mTopFullscreenOpaqueWindowState == null |
| 4226 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 4227 | mForcingShowNavBar = true; |
| 4228 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4229 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4230 | if (attrs.type == TYPE_STATUS_BAR) { |
| 4231 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 4232 | mForceStatusBarFromKeyguard = true; |
| 4233 | } |
| 4234 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 4235 | mForceStatusBarTransparent = true; |
| 4236 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4237 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4238 | |
| 4239 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 4240 | && attrs.type < FIRST_SYSTEM_WINDOW; |
| 4241 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 4242 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
| 4243 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4244 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 4245 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4246 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4247 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4248 | mForceStatusBarFromKeyguard = true; |
| 4249 | } else { |
| 4250 | mForceStatusBar = true; |
| 4251 | } |
| 4252 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4253 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4254 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4255 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4256 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4257 | // If the lockscreen was showing when the dream started then wait |
| 4258 | // for the dream to draw before hiding the lockscreen. |
| 4259 | if (!mDreamingLockscreen |
| 4260 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4261 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4262 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4263 | } |
| 4264 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4265 | |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4266 | if (appWindow) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4267 | final IApplicationToken appToken = win.getAppToken(); |
| 4268 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4269 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4270 | mAppsToBeHidden.remove(appToken); |
| 4271 | mAppsThatDismissKeyguard.remove(appToken); |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4272 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | 192d604 | 2014-12-02 23:24:48 -0800 | [diff] [blame] | 4273 | if (dismissKeyguard && !mKeyguardSecure) { |
| 4274 | mAppsThatDismissKeyguard.add(appToken); |
| 4275 | } else { |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4276 | mWinShowWhenLocked = win; |
| 4277 | mHideLockScreen = true; |
| 4278 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4279 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4280 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4281 | } else if (dismissKeyguard) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4282 | if (mKeyguardSecure) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4283 | mAppsToBeHidden.add(appToken); |
| 4284 | } else { |
| 4285 | mAppsToBeHidden.remove(appToken); |
| 4286 | } |
| 4287 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4288 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4289 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4290 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4291 | if (attrs.x == 0 && attrs.y == 0 |
| 4292 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4293 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 4294 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4295 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4296 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 4297 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4298 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4299 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4300 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4301 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4302 | "Setting mDismissKeyguard true by win " + win); |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4303 | mDismissKeyguard = (mWinDismissingKeyguard == win |
| 4304 | && mSecureDismissingKeyguard == mKeyguardSecure) |
| 4305 | ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4306 | mWinDismissingKeyguard = win; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4307 | mSecureDismissingKeyguard = mKeyguardSecure; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4308 | mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4309 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) { |
| 4310 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4311 | "Setting mHideLockScreen to true by win " + win); |
| 4312 | mHideLockScreen = true; |
| 4313 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4314 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4315 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4316 | mAllowLockscreenWhenOn = true; |
| 4317 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4318 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4319 | |
| 4320 | if (mWinShowWhenLocked != null && |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4321 | mWinShowWhenLocked.getAppToken() != win.getAppToken() && |
| 4322 | (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4323 | win.hideLw(false); |
| 4324 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4325 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4326 | } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) { |
| 4327 | // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window |
| 4328 | // that is being hidden in an animation - keep the |
| 4329 | // keyguard hidden until the new window shows up and |
| 4330 | // we know whether to show the keyguard or not. |
Adrian Roos | b85e1ec | 2015-05-29 15:23:18 -0700 | [diff] [blame] | 4331 | if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4332 | mHideLockScreen = true; |
| 4333 | mWinShowWhenLocked = win; |
| 4334 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4335 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4336 | if (mTopFullscreenOpaqueOrDimmingWindowState == null |
| 4337 | && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw() |
| 4338 | && win.isDimming()) { |
| 4339 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4340 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4344 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4345 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c5e73bf | 2015-04-21 15:41:26 +0000 | [diff] [blame] | 4346 | if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null && |
| 4347 | mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken() |
| 4348 | && isKeyguardLocked()) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4349 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4350 | // fullscreen window. |
| 4351 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4352 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4353 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4354 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4355 | } |
| 4356 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4357 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4358 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4359 | |
| 4360 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4361 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4362 | : null; |
| 4363 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4364 | // If we are not currently showing a dream then remember the current |
| 4365 | // lockscreen state. We will use this to determine whether the dream |
| 4366 | // started while the lockscreen was showing and remember this state |
| 4367 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4368 | if (!mShowingDream) { |
| 4369 | mDreamingLockscreen = mShowingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 4370 | if (mDreamingSleepTokenNeeded) { |
| 4371 | mDreamingSleepTokenNeeded = false; |
| 4372 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 4373 | } |
| 4374 | } else { |
| 4375 | if (!mDreamingSleepTokenNeeded) { |
| 4376 | mDreamingSleepTokenNeeded = true; |
| 4377 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 4378 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4379 | } |
| 4380 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4381 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4382 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4383 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 4384 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4385 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 4386 | && !mForceStatusBar |
| 4387 | && !mForceStatusBarFromKeyguard; |
| 4388 | if (!shouldBeTransparent) { |
| 4389 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 4390 | } else if (!mStatusBar.isVisibleLw()) { |
| 4391 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 4392 | } |
| 4393 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4394 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4395 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4396 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4397 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4398 | // Maintain fullscreen layout until incoming animation is complete. |
| 4399 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 4400 | // Transient status bar on the lockscreen is not allowed |
| 4401 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 4402 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 4403 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 4404 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4405 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4406 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4407 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4408 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4409 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4410 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4411 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4412 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4413 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4414 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4415 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 4416 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4417 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 4418 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4419 | if (mStatusBarController.isTransientShowing()) { |
| 4420 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4421 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4422 | } |
| 4423 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4424 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4425 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4426 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4427 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 4428 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 4429 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4430 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4431 | 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] | 4432 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4433 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4434 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4435 | } |
| 4436 | } |
| 4437 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4438 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4439 | if (mTopIsFullscreen != topIsFullscreen) { |
| 4440 | if (!topIsFullscreen) { |
| 4441 | // Force another layout when status bar becomes fully shown. |
| 4442 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4443 | } |
| 4444 | mTopIsFullscreen = topIsFullscreen; |
| 4445 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4446 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4447 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 4448 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4449 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 4450 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 4451 | + mHideLockScreen); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4452 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4453 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4454 | if (setKeyguardOccludedLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4455 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4456 | | FINISH_LAYOUT_REDO_CONFIG |
| 4457 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4458 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4459 | if (mKeyguardDelegate.isShowing()) { |
| 4460 | mHandler.post(new Runnable() { |
| 4461 | @Override |
| 4462 | public void run() { |
| 4463 | mKeyguardDelegate.keyguardDone(false, false); |
| 4464 | } |
| 4465 | }); |
| 4466 | } |
| 4467 | } else if (mHideLockScreen) { |
| 4468 | mKeyguardHidden = true; |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4469 | mWinDismissingKeyguard = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4470 | if (setKeyguardOccludedLw(true)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4471 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4472 | | FINISH_LAYOUT_REDO_CONFIG |
| 4473 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4474 | } |
| 4475 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4476 | mKeyguardHidden = false; |
| 4477 | if (setKeyguardOccludedLw(false)) { |
| 4478 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4479 | | FINISH_LAYOUT_REDO_CONFIG |
| 4480 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4481 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4482 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 4483 | // Only launch the next keyguard unlock window once per window. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4484 | mHandler.post(new Runnable() { |
| 4485 | @Override |
| 4486 | public void run() { |
| 4487 | mKeyguardDelegate.dismiss(); |
| 4488 | } |
| 4489 | }); |
| 4490 | } |
| 4491 | } else { |
| 4492 | mWinDismissingKeyguard = null; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4493 | mSecureDismissingKeyguard = false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4494 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4495 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4496 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4497 | | FINISH_LAYOUT_REDO_CONFIG |
| 4498 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4499 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 4500 | } |
| 4501 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4502 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4503 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4504 | // If the navigation bar has been hidden or shown, we need to do another |
| 4505 | // layout pass to update that window. |
| 4506 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4507 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4508 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4509 | // update since mAllowLockscreenWhenOn might have changed |
| 4510 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4511 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4512 | } |
| 4513 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4514 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4515 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4516 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4517 | * @return Whether the flags have changed and we have to redo the layout. |
| 4518 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4519 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
| 4520 | boolean wasOccluded = mKeyguardOccluded; |
| 4521 | boolean showing = mKeyguardDelegate.isShowing(); |
| 4522 | if (wasOccluded && !isOccluded && showing) { |
| 4523 | mKeyguardOccluded = false; |
| 4524 | mKeyguardDelegate.setOccluded(false); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4525 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4526 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4527 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4528 | } else if (!wasOccluded && isOccluded && showing) { |
| 4529 | mKeyguardOccluded = true; |
| 4530 | mKeyguardDelegate.setOccluded(true); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4531 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4532 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4533 | return true; |
| 4534 | } else { |
| 4535 | return false; |
| 4536 | } |
| 4537 | } |
| 4538 | |
| 4539 | private boolean isStatusBarKeyguard() { |
| 4540 | return mStatusBar != null |
| 4541 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4542 | } |
| 4543 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4544 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4545 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4546 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4547 | // 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] | 4548 | return false; |
| 4549 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4550 | return true; |
| 4551 | } |
| 4552 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4553 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4554 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4555 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4556 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4557 | // If the navigation bar has been hidden or shown, we need to do another |
| 4558 | // layout pass to update that window. |
| 4559 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4560 | } |
| 4561 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4562 | } |
| 4563 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4564 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4565 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4566 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4567 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4568 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4569 | if (newLidState == mLidState) { |
| 4570 | return; |
| 4571 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4572 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4573 | mLidState = newLidState; |
| 4574 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4575 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4576 | |
| 4577 | if (lidOpen) { |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4578 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4579 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4580 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4581 | } |
| 4582 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4583 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4584 | @Override |
| 4585 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 4586 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 4587 | if (mCameraLensCoverState == lensCoverState) { |
| 4588 | return; |
| 4589 | } |
| 4590 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 4591 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 4592 | Intent intent; |
| 4593 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 4594 | mKeyguardDelegate.isShowing(); |
| 4595 | if (keyguardActive) { |
| 4596 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 4597 | } else { |
| 4598 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 4599 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 4600 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4601 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4602 | } |
| 4603 | mCameraLensCoverState = lensCoverState; |
| 4604 | } |
| 4605 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4606 | void setHdmiPlugged(boolean plugged) { |
| 4607 | if (mHdmiPlugged != plugged) { |
| 4608 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4609 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4610 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4611 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4612 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4613 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4614 | } |
| 4615 | } |
| 4616 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4617 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4618 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4619 | // watch for HDMI plug messages if the hdmi switch exists |
| 4620 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4621 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4622 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4623 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4624 | FileReader reader = null; |
| 4625 | try { |
| 4626 | reader = new FileReader(filename); |
| 4627 | char[] buf = new char[15]; |
| 4628 | int n = reader.read(buf); |
| 4629 | if (n > 1) { |
| 4630 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4631 | } |
| 4632 | } catch (IOException ex) { |
| 4633 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4634 | } catch (NumberFormatException ex) { |
| 4635 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4636 | } finally { |
| 4637 | if (reader != null) { |
| 4638 | try { |
| 4639 | reader.close(); |
| 4640 | } catch (IOException ex) { |
| 4641 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4642 | } |
| 4643 | } |
| 4644 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4645 | // This dance forces the code in setHdmiPlugged to run. |
| 4646 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4647 | mHdmiPlugged = !plugged; |
| 4648 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4649 | } |
| 4650 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4651 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4652 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4653 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4654 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4655 | @Override public void run() { |
| 4656 | synchronized (mScreenshotLock) { |
| 4657 | if (mScreenshotConnection != null) { |
| 4658 | mContext.unbindService(mScreenshotConnection); |
| 4659 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4660 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4661 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4662 | } |
| 4663 | }; |
| 4664 | |
| 4665 | // Assume this is called from the Handler thread. |
| 4666 | private void takeScreenshot() { |
| 4667 | synchronized (mScreenshotLock) { |
| 4668 | if (mScreenshotConnection != null) { |
| 4669 | return; |
| 4670 | } |
| 4671 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4672 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 4673 | Intent intent = new Intent(); |
| 4674 | intent.setComponent(cn); |
| 4675 | ServiceConnection conn = new ServiceConnection() { |
| 4676 | @Override |
| 4677 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 4678 | synchronized (mScreenshotLock) { |
| 4679 | if (mScreenshotConnection != this) { |
| 4680 | return; |
| 4681 | } |
| 4682 | Messenger messenger = new Messenger(service); |
| 4683 | Message msg = Message.obtain(null, 1); |
| 4684 | final ServiceConnection myConn = this; |
| 4685 | Handler h = new Handler(mHandler.getLooper()) { |
| 4686 | @Override |
| 4687 | public void handleMessage(Message msg) { |
| 4688 | synchronized (mScreenshotLock) { |
| 4689 | if (mScreenshotConnection == myConn) { |
| 4690 | mContext.unbindService(mScreenshotConnection); |
| 4691 | mScreenshotConnection = null; |
| 4692 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 4693 | } |
| 4694 | } |
| 4695 | } |
| 4696 | }; |
| 4697 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 4698 | msg.arg1 = msg.arg2 = 0; |
| 4699 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 4700 | msg.arg1 = 1; |
| 4701 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 4702 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4703 | try { |
| 4704 | messenger.send(msg); |
| 4705 | } catch (RemoteException e) { |
| 4706 | } |
| 4707 | } |
| 4708 | } |
| 4709 | @Override |
| 4710 | public void onServiceDisconnected(ComponentName name) {} |
| 4711 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 4712 | if (mContext.bindServiceAsUser( |
| 4713 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4714 | mScreenshotConnection = conn; |
| 4715 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 4716 | } |
| 4717 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4718 | } |
| 4719 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4720 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4721 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4722 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4723 | if (!mSystemBooted) { |
| 4724 | // If we have not yet booted, don't let key events do anything. |
| 4725 | return 0; |
| 4726 | } |
| 4727 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4728 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 4729 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 4730 | final boolean canceled = event.isCanceled(); |
| 4731 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 4732 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4733 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4734 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 4735 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 4736 | // the same as if it were open and in front. |
| 4737 | // This will prevent any keys other than the power button from waking the screen |
| 4738 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4739 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4740 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4741 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4742 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4743 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4744 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4745 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4746 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4747 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4748 | } |
| 4749 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4750 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4751 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 4752 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 4753 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4754 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4755 | // When the device is interactive or the key is injected pass the |
| 4756 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4757 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4758 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 4759 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 4760 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 4761 | // to the application but preserve its wake key status to make sure we still move |
| 4762 | // from dozing to fully interactive if we would normally go from off to fully |
| 4763 | // interactive. |
| 4764 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4765 | } else { |
| 4766 | // When the screen is off and the key is not injected, determine whether |
| 4767 | // to wake the device but don't pass the key to the application. |
| 4768 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4769 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 4770 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4771 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4772 | } |
| 4773 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4774 | // If the key would be handled globally, just return the result, don't worry about special |
| 4775 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4776 | if (isValidGlobalKey(keyCode) |
| 4777 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4778 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4779 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 4780 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 4781 | return result; |
| 4782 | } |
| 4783 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4784 | boolean useHapticFeedback = down |
| 4785 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 4786 | && event.getRepeatCount() == 0; |
| 4787 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4788 | // Handle special keys. |
| 4789 | switch (keyCode) { |
| 4790 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 4791 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4792 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4793 | if (mUseTvRouting) { |
| 4794 | // On TVs volume keys never go to the foreground app |
| 4795 | result &= ~ACTION_PASS_TO_USER; |
| 4796 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4797 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 4798 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4799 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4800 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4801 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 4802 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 4803 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4804 | cancelPendingPowerKeyAction(); |
| 4805 | interceptScreenshotChord(); |
| 4806 | } |
| 4807 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4808 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4809 | cancelPendingScreenshotChordAction(); |
| 4810 | } |
| 4811 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 4812 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4813 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4814 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4815 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4816 | cancelPendingPowerKeyAction(); |
| 4817 | cancelPendingScreenshotChordAction(); |
| 4818 | } |
| 4819 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4820 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4821 | cancelPendingScreenshotChordAction(); |
| 4822 | } |
| 4823 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4824 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4825 | TelecomManager telecomManager = getTelecommService(); |
| 4826 | if (telecomManager != null) { |
| 4827 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4828 | // If an incoming call is ringing, either VOLUME key means |
| 4829 | // "silence ringer". We handle these keys here, rather than |
| 4830 | // in the InCallScreen, to make sure we'll respond to them |
| 4831 | // even if the InCallScreen hasn't come to the foreground yet. |
| 4832 | // Look for the DOWN event here, to agree with the "fallback" |
| 4833 | // behavior in the InCallScreen. |
| 4834 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4835 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4836 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4837 | // Silence the ringer. (It's safe to call this |
| 4838 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4839 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4840 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4841 | // And *don't* pass this key thru to the current activity |
| 4842 | // (which is probably the InCallScreen.) |
| 4843 | result &= ~ACTION_PASS_TO_USER; |
| 4844 | break; |
| 4845 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4846 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4847 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 4848 | // 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] | 4849 | // the application, just pass it to the session service. |
| 4850 | |
| 4851 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 4852 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4853 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 4857 | if ((result & ACTION_PASS_TO_USER) == 0) { |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 4858 | if (mUseTvRouting) { |
| 4859 | dispatchDirectAudioEvent(event); |
| 4860 | } else { |
| 4861 | // If we aren't passing to the user and no one else |
| 4862 | // handled it send it to the session manager to |
| 4863 | // figure out. |
| 4864 | MediaSessionLegacyHelper.getHelper(mContext) |
| 4865 | .sendVolumeKeyEvent(event, true); |
| 4866 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4867 | break; |
| 4868 | } |
| 4869 | } |
| 4870 | break; |
| 4871 | } |
| 4872 | |
| 4873 | case KeyEvent.KEYCODE_ENDCALL: { |
| 4874 | result &= ~ACTION_PASS_TO_USER; |
| 4875 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4876 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4877 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4878 | if (telecomManager != null) { |
| 4879 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4880 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4881 | if (interactive && !hungUp) { |
| 4882 | mEndCallKeyHandled = false; |
| 4883 | mHandler.postDelayed(mEndCallLongPress, |
| 4884 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 4885 | } else { |
| 4886 | mEndCallKeyHandled = true; |
| 4887 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4888 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4889 | if (!mEndCallKeyHandled) { |
| 4890 | mHandler.removeCallbacks(mEndCallLongPress); |
| 4891 | if (!canceled) { |
| 4892 | if ((mEndcallBehavior |
| 4893 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 4894 | if (goHome()) { |
| 4895 | break; |
| 4896 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 4897 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4898 | if ((mEndcallBehavior |
| 4899 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 4900 | mPowerManager.goToSleep(event.getEventTime(), |
| 4901 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 4902 | isWakeKey = false; |
| 4903 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4904 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4905 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4906 | } |
| 4907 | break; |
| 4908 | } |
| 4909 | |
| 4910 | case KeyEvent.KEYCODE_POWER: { |
| 4911 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4912 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4913 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4914 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4915 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 4916 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4917 | } |
| 4918 | break; |
| 4919 | } |
| 4920 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4921 | case KeyEvent.KEYCODE_SLEEP: { |
| 4922 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 4923 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 4924 | if (!mPowerManager.isInteractive()) { |
| 4925 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 4926 | } |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 4927 | if (down) { |
| 4928 | sleepPress(event.getEventTime()); |
| 4929 | } else { |
| 4930 | sleepRelease(event.getEventTime()); |
| 4931 | } |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4932 | break; |
| 4933 | } |
| 4934 | |
| 4935 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4936 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4937 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4938 | break; |
| 4939 | } |
| 4940 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4941 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4942 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4943 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4944 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4945 | case KeyEvent.KEYCODE_MUTE: |
| 4946 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4947 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4948 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4949 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4950 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4951 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4952 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 4953 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 4954 | // If the global session is active pass all media keys to it |
| 4955 | // instead of the active window. |
| 4956 | result &= ~ACTION_PASS_TO_USER; |
| 4957 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4958 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4959 | // Only do this if we would otherwise not pass it to the user. In that |
| 4960 | // case, the PhoneWindow class will do the same thing, except it will |
| 4961 | // 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] | 4962 | // Note that we need to make a copy of the key event here because the |
| 4963 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4964 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4965 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4966 | new KeyEvent(event)); |
| 4967 | msg.setAsynchronous(true); |
| 4968 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4969 | } |
| 4970 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4971 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4972 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4973 | case KeyEvent.KEYCODE_CALL: { |
| 4974 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4975 | TelecomManager telecomManager = getTelecommService(); |
| 4976 | if (telecomManager != null) { |
| 4977 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4978 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4979 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 4980 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4981 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 4982 | // And *don't* pass this key thru to the current activity |
| 4983 | // (which is presumably the InCallScreen.) |
| 4984 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4985 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4986 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4987 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4988 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4989 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 4990 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 4991 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 4992 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 4993 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 4994 | // key event here because the original key event will be recycled when we return. |
| 4995 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 4996 | mBroadcastWakeLock.acquire(); |
| 4997 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 4998 | keyguardActive ? 1 : 0, 0); |
| 4999 | msg.setAsynchronous(true); |
| 5000 | msg.sendToTarget(); |
| 5001 | } |
| 5002 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5003 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5004 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5005 | if (useHapticFeedback) { |
| 5006 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5007 | } |
| 5008 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5009 | if (isWakeKey) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5010 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5011 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5012 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5013 | return result; |
| 5014 | } |
| 5015 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5016 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5017 | * Returns true if the key can have global actions attached to it. |
| 5018 | * We reserve all power management keys for the system since they require |
| 5019 | * very careful handling. |
| 5020 | */ |
| 5021 | private static boolean isValidGlobalKey(int keyCode) { |
| 5022 | switch (keyCode) { |
| 5023 | case KeyEvent.KEYCODE_POWER: |
| 5024 | case KeyEvent.KEYCODE_WAKEUP: |
| 5025 | case KeyEvent.KEYCODE_SLEEP: |
| 5026 | return false; |
| 5027 | default: |
| 5028 | return true; |
| 5029 | } |
| 5030 | } |
| 5031 | |
| 5032 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5033 | * When the screen is off we ignore some keys that might otherwise typically |
| 5034 | * be considered wake keys. We filter them out here. |
| 5035 | * |
| 5036 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 5037 | * is always considered a wake key. |
| 5038 | */ |
| 5039 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 5040 | switch (keyCode) { |
| 5041 | // ignore volume keys unless docked |
| 5042 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5043 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5044 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5045 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 5046 | |
| 5047 | // ignore media and camera keys |
| 5048 | case KeyEvent.KEYCODE_MUTE: |
| 5049 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5050 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5051 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5052 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 5053 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5054 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5055 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5056 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5057 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 5058 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5059 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5060 | case KeyEvent.KEYCODE_CAMERA: |
| 5061 | return false; |
| 5062 | } |
| 5063 | return true; |
| 5064 | } |
| 5065 | |
| 5066 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5067 | /** {@inheritDoc} */ |
| 5068 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5069 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 5070 | if ((policyFlags & FLAG_WAKE) != 0) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5071 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) { |
| 5072 | return 0; |
| 5073 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5074 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5075 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5076 | if (shouldDispatchInputWhenNonInteractive()) { |
| 5077 | return ACTION_PASS_TO_USER; |
| 5078 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5079 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5080 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 5081 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 5082 | // wake up in this case. |
| 5083 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
| 5084 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming); |
| 5085 | } |
| 5086 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5087 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5088 | } |
| 5089 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5090 | private boolean shouldDispatchInputWhenNonInteractive() { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5091 | // Send events to keyguard while the screen is on. |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5092 | if (isKeyguardShowingAndNotOccluded() && mDisplay != null |
| 5093 | && mDisplay.getState() != Display.STATE_OFF) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5094 | return true; |
| 5095 | } |
| 5096 | |
| 5097 | // Send events to a dozing dream even if the screen is off since the dream |
| 5098 | // is in control of the state of the screen. |
| 5099 | IDreamManager dreamManager = getDreamManager(); |
| 5100 | |
| 5101 | try { |
| 5102 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 5103 | return true; |
| 5104 | } |
| 5105 | } catch (RemoteException e) { |
| 5106 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 5107 | } |
| 5108 | |
| 5109 | // Otherwise, consume events since the user can't see what is being |
| 5110 | // interacted with. |
| 5111 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5112 | } |
| 5113 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5114 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 5115 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 5116 | return; |
| 5117 | } |
| 5118 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 5119 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 5120 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5121 | String pkgName = mContext.getOpPackageName(); |
| 5122 | switch (keyCode) { |
| 5123 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5124 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5125 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5126 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5127 | } catch (RemoteException e) { |
| 5128 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 5129 | } |
| 5130 | break; |
| 5131 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5132 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5133 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5134 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5135 | } catch (RemoteException e) { |
| 5136 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 5137 | } |
| 5138 | break; |
| 5139 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5140 | try { |
| 5141 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5142 | getAudioService().adjustSuggestedStreamVolume( |
| 5143 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5144 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5145 | } |
| 5146 | } catch (RemoteException e) { |
| 5147 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 5148 | } |
| 5149 | break; |
| 5150 | } |
| 5151 | } |
| 5152 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5153 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 5154 | if (DEBUG_INPUT) { |
| 5155 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5156 | } |
| 5157 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5158 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 5159 | if (DEBUG_INPUT) { |
| 5160 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 5161 | } |
| 5162 | |
| 5163 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 5164 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5165 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 5166 | } |
| 5167 | |
| 5168 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 5169 | |
| 5170 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5171 | && event.getRepeatCount() == 0) { |
| 5172 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 5173 | |
| 5174 | Message msg = mHandler.obtainMessage( |
| 5175 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 5176 | msg.setAsynchronous(true); |
| 5177 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 5178 | } else { |
| 5179 | mBroadcastWakeLock.release(); |
| 5180 | } |
| 5181 | } |
| 5182 | |
| 5183 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 5184 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5185 | |
| 5186 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 5187 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 5188 | if (DEBUG_INPUT) { |
| 5189 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 5190 | } |
| 5191 | |
| 5192 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 5193 | mBroadcastWakeLock.release(); |
| 5194 | } |
| 5195 | |
| 5196 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 5197 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5198 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5199 | } |
| 5200 | } |
| 5201 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5202 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame^] | 5203 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 5204 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 5205 | if (dic != null) { |
| 5206 | try { |
| 5207 | dic.exitIdle("voice-search"); |
| 5208 | } catch (RemoteException e) { |
| 5209 | } |
| 5210 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5211 | Intent voiceIntent = |
| 5212 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 5213 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5214 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5215 | mBroadcastWakeLock.release(); |
| 5216 | } |
| 5217 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5218 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5219 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5220 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 5221 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 5222 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 5223 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5224 | } else { |
| 5225 | try { |
| 5226 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 5227 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5228 | mUiMode = uiModeService.getCurrentModeType(); |
| 5229 | } catch (RemoteException e) { |
| 5230 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 5231 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5232 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5233 | synchronized (mLock) { |
| 5234 | updateOrientationListenerLp(); |
| 5235 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5236 | } |
| 5237 | }; |
| 5238 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5239 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 5240 | @Override |
| 5241 | public void onReceive(Context context, Intent intent) { |
| 5242 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5243 | if (mKeyguardDelegate != null) { |
| 5244 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5245 | } |
| 5246 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5247 | if (mKeyguardDelegate != null) { |
| 5248 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5249 | } |
| 5250 | } |
| 5251 | } |
| 5252 | }; |
| 5253 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5254 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 5255 | @Override |
| 5256 | public void onReceive(Context context, Intent intent) { |
| 5257 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 5258 | // tickle the settings observer: this first ensures that we're |
| 5259 | // observing the relevant settings for the newly-active user, |
| 5260 | // and then updates our own bookkeeping based on the now- |
| 5261 | // current user. |
| 5262 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5263 | |
| 5264 | // force a re-application of focused window sysui visibility. |
| 5265 | // the window may never have been shown for this user |
| 5266 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5267 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5268 | mLastSystemUiFlags = 0; |
| 5269 | updateSystemUiVisibilityLw(); |
| 5270 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5271 | } |
| 5272 | } |
| 5273 | }; |
| 5274 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5275 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5276 | @Override |
| 5277 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5278 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 5279 | if (!isUserSetupComplete()) { |
| 5280 | // Swipe-up for navigation bar is disabled during setup |
| 5281 | return; |
| 5282 | } |
| 5283 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
| 5284 | mNavigationBarController.showTransient(); |
| 5285 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5286 | } |
| 5287 | }; |
| 5288 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5289 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5290 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5291 | if (!isUserSetupComplete()) { |
| 5292 | // Swipe-up for navigation bar is disabled during setup |
| 5293 | return; |
| 5294 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5295 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 5296 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5297 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 5298 | // Don't show status bar when swiping on already visible navigation bar |
| 5299 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5300 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5301 | return; |
| 5302 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5303 | if (sb) mStatusBarController.showTransient(); |
| 5304 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5305 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5306 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5307 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5308 | } |
| 5309 | } |
| 5310 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5311 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5312 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5313 | public void startedGoingToSleep(int why) { |
| 5314 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5315 | if (mKeyguardDelegate != null) { |
| 5316 | mKeyguardDelegate.onStartedGoingToSleep(why); |
| 5317 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | // Called on the PowerManager's Notifier thread. |
| 5321 | @Override |
| 5322 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5323 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5324 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5325 | |
| 5326 | // We must get this work done here because the power manager will drop |
| 5327 | // 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] | 5328 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5329 | mAwake = false; |
| 5330 | mKeyguardDrawComplete = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5331 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5332 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5333 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5334 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5335 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5336 | mKeyguardDelegate.onFinishedGoingToSleep(why); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5337 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5338 | } |
| 5339 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5340 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5341 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5342 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5343 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5344 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5345 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5346 | // Since goToSleep performs these functions synchronously, we must |
| 5347 | // do the same here. We cannot post this work to a handler because |
| 5348 | // that might cause it to become reordered with respect to what |
| 5349 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5350 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5351 | mAwake = true; |
| 5352 | mKeyguardDrawComplete = false; |
| 5353 | if (mKeyguardDelegate != null) { |
| 5354 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5355 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
| 5356 | } |
| 5357 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5358 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5359 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5360 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5361 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5362 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5363 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5364 | mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5365 | // ... eventually calls finishKeyguardDrawn |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5366 | } else { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5367 | if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5368 | finishKeyguardDrawn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5369 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5370 | } |
| 5371 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5372 | // Called on the PowerManager's Notifier thread. |
| 5373 | @Override |
| 5374 | public void finishedWakingUp() { |
| 5375 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
| 5376 | } |
| 5377 | |
| 5378 | private void wakeUpFromPowerKey(long eventTime) { |
| 5379 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey); |
| 5380 | } |
| 5381 | |
| 5382 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) { |
| 5383 | if (!wakeInTheaterMode && isTheaterModeEnabled()) { |
| 5384 | return false; |
| 5385 | } |
| 5386 | |
| 5387 | mPowerManager.wakeUp(wakeTime); |
| 5388 | return true; |
| 5389 | } |
| 5390 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5391 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5392 | synchronized (mLock) { |
| 5393 | if (!mAwake || mKeyguardDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5394 | return; // We are not awake yet or we have already informed of this event. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5395 | } |
| 5396 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5397 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5398 | if (mKeyguardDelegate != null) { |
| 5399 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5400 | } |
| 5401 | } |
| 5402 | |
| 5403 | finishScreenTurningOn(); |
| 5404 | } |
| 5405 | |
| 5406 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5407 | @Override |
| 5408 | public void screenTurnedOff() { |
| 5409 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 5410 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 5411 | updateScreenOffSleepToken(true); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5412 | synchronized (mLock) { |
| 5413 | mScreenOnEarly = false; |
| 5414 | mScreenOnFully = false; |
| 5415 | mWindowManagerDrawComplete = false; |
| 5416 | mScreenOnListener = null; |
| 5417 | updateOrientationListenerLp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5418 | } |
| 5419 | } |
| 5420 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5421 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5422 | @Override |
| 5423 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5424 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5425 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 5426 | updateScreenOffSleepToken(false); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5427 | synchronized (mLock) { |
| 5428 | mScreenOnEarly = true; |
| 5429 | mScreenOnFully = false; |
| 5430 | mWindowManagerDrawComplete = false; |
| 5431 | mScreenOnListener = screenOnListener; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5432 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5433 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 5434 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 5435 | WAITING_FOR_DRAWN_TIMEOUT); |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5436 | // ... eventually calls finishWindowsDrawn which will finalize our screen turn on |
| 5437 | // as well as enabling the orientation change logic/sensor. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5438 | } |
| 5439 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5440 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5441 | synchronized (mLock) { |
| 5442 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5443 | return; // Screen is not turned on or we did already handle this case earlier. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5444 | } |
| 5445 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5446 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5447 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5448 | |
| 5449 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5450 | } |
| 5451 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5452 | private void finishScreenTurningOn() { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5453 | synchronized (mLock) { |
| 5454 | // We have just finished drawing screen content. Since the orientation listener |
| 5455 | // gets only installed when all windows are drawn, we try to install it again. |
| 5456 | updateOrientationListenerLp(); |
| 5457 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5458 | final ScreenOnListener listener; |
| 5459 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5460 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5461 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5462 | "finishScreenTurningOn: mAwake=" + mAwake |
| 5463 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 5464 | + ", mScreenOnFully=" + mScreenOnFully |
| 5465 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 5466 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 5467 | |
| 5468 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 5469 | || (mAwake && !mKeyguardDrawComplete)) { |
| 5470 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5471 | } |
| 5472 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5473 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 5474 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 5475 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5476 | mScreenOnFully = true; |
| 5477 | |
| 5478 | // Remember the first time we draw the keyguard so we know when we're done with |
| 5479 | // the main part of booting and can enable the screen and hide boot messages. |
| 5480 | if (!mKeyguardDrawnOnce && mAwake) { |
| 5481 | mKeyguardDrawnOnce = true; |
| 5482 | enableScreen = true; |
| 5483 | if (mBootMessageNeedsHiding) { |
| 5484 | mBootMessageNeedsHiding = false; |
| 5485 | hideBootMessages(); |
| 5486 | } |
| 5487 | } else { |
| 5488 | enableScreen = false; |
| 5489 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5490 | } |
| 5491 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5492 | if (listener != null) { |
| 5493 | listener.onScreenOn(); |
| 5494 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 5495 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5496 | if (enableScreen) { |
| 5497 | try { |
| 5498 | mWindowManager.enableScreenIfNeeded(); |
| 5499 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5500 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5501 | } |
| 5502 | } |
| 5503 | |
| 5504 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5505 | synchronized (mLock) { |
| 5506 | if (!mKeyguardDrawnOnce) { |
| 5507 | mBootMessageNeedsHiding = true; |
| 5508 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 5509 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5510 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5511 | |
| 5512 | if (mBootMsgDialog != null) { |
| 5513 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 5514 | mBootMsgDialog.dismiss(); |
| 5515 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5516 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5520 | public boolean isScreenOn() { |
| 5521 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5522 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5523 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5524 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5525 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5526 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5527 | if (mKeyguardDelegate != null) { |
| 5528 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5529 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5533 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5534 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5535 | if (mKeyguardDelegate != null) { |
| 5536 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5537 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5538 | } |
| 5539 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5540 | private boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5541 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5542 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5543 | } |
| 5544 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5545 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5546 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5547 | public boolean isKeyguardLocked() { |
| 5548 | return keyguardOn(); |
| 5549 | } |
| 5550 | |
| 5551 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5552 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5553 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5554 | if (mKeyguardDelegate == null) return false; |
| 5555 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5556 | } |
| 5557 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5558 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5559 | @Override |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 5560 | public boolean isKeyguardShowingOrOccluded() { |
| 5561 | return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing(); |
| 5562 | } |
| 5563 | |
| 5564 | /** {@inheritDoc} */ |
| 5565 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5566 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5567 | if (mKeyguardDelegate == null) return false; |
| 5568 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5569 | } |
| 5570 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5571 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5572 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5573 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5574 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5575 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5576 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5577 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 5578 | // ask the keyguard to prompt the user to authenticate if necessary |
| 5579 | mKeyguardDelegate.dismiss(); |
| 5580 | } |
| 5581 | }); |
| 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | public void notifyActivityDrawnForKeyguardLw() { |
| 5586 | if (mKeyguardDelegate != null) { |
| 5587 | mHandler.post(new Runnable() { |
| 5588 | @Override |
| 5589 | public void run() { |
| 5590 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5591 | } |
| 5592 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5593 | } |
| 5594 | } |
| 5595 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5596 | @Override |
| 5597 | public boolean isKeyguardDrawnLw() { |
| 5598 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5599 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5600 | } |
| 5601 | } |
| 5602 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5603 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5604 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5605 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5606 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5607 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5608 | } |
| 5609 | } |
| 5610 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5611 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5612 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5613 | } |
| 5614 | |
| 5615 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5616 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5617 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 5618 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5619 | @Override |
| 5620 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5621 | if (false) { |
| 5622 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 5623 | + orientation + ", last=" + lastRotation |
| 5624 | + "); user=" + mUserRotation + " " |
| 5625 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 5626 | ? "USER_ROTATION_LOCKED" : "") |
| 5627 | ); |
| 5628 | } |
| 5629 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 5630 | if (mForceDefaultOrientation) { |
| 5631 | return Surface.ROTATION_0; |
| 5632 | } |
| 5633 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5634 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5635 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 5636 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 5637 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5638 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5639 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5640 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5641 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5642 | // Ignore sensor when lid switch is open and rotation is forced. |
| 5643 | preferredRotation = mLidOpenRotation; |
| 5644 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5645 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5646 | // Ignore sensor when in car dock unless explicitly enabled. |
| 5647 | // This case can override the behavior of NOSENSOR, and can also |
| 5648 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5649 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5650 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 5651 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 5652 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 5653 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5654 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5655 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 5656 | // This case can override the behavior of NOSENSOR, and can also |
| 5657 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5658 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5659 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5660 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 5661 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 5662 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5663 | preferredRotation = mDemoHdmiRotation; |
| 5664 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 5665 | && mUndockedHdmiRotation >= 0) { |
| 5666 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 5667 | // been specified in the configuration (only for legacy devices without |
| 5668 | // full multi-display support). |
| 5669 | // Note that the dock orientation overrides the HDMI orientation. |
| 5670 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 5671 | } else if (mDemoRotationLock) { |
| 5672 | // Ignore sensor when demo rotation lock is enabled. |
| 5673 | // Note that the dock orientation and HDMI rotation lock override this. |
| 5674 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5675 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 5676 | // Application just wants to remain locked in the last rotation. |
| 5677 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5678 | } else if (!mSupportAutoRotation) { |
| 5679 | // If we don't support auto-rotation then bail out here and ignore |
| 5680 | // the sensor and any rotation lock settings. |
| 5681 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5682 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5683 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5684 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 5685 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 5686 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 5687 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5688 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 5689 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5690 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 5691 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 5692 | // Otherwise, use sensor only if requested by the application or enabled |
| 5693 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5694 | if (mAllowAllRotations < 0) { |
| 5695 | // Can't read this during init() because the context doesn't |
| 5696 | // have display metrics at that time so we cannot determine |
| 5697 | // tablet vs. phone then. |
| 5698 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 5699 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 5700 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5701 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 5702 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5703 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 5704 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5705 | preferredRotation = sensorRotation; |
| 5706 | } else { |
| 5707 | preferredRotation = lastRotation; |
| 5708 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 5709 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 5710 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 5711 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 5712 | // The idea is that the user rotation expresses a weak preference for the direction |
| 5713 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 5714 | // 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] | 5715 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5716 | } else { |
| 5717 | // No overriding preference. |
| 5718 | // We will do exactly what the application asked us to do. |
| 5719 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5720 | } |
| 5721 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5722 | switch (orientation) { |
| 5723 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5724 | // Return portrait unless overridden. |
| 5725 | if (isAnyPortrait(preferredRotation)) { |
| 5726 | return preferredRotation; |
| 5727 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5728 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5729 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5730 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5731 | // Return landscape unless overridden. |
| 5732 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5733 | return preferredRotation; |
| 5734 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5735 | return mLandscapeRotation; |
| 5736 | |
| 5737 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5738 | // Return reverse portrait unless overridden. |
| 5739 | if (isAnyPortrait(preferredRotation)) { |
| 5740 | return preferredRotation; |
| 5741 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5742 | return mUpsideDownRotation; |
| 5743 | |
| 5744 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 5745 | // Return seascape unless overridden. |
| 5746 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5747 | return preferredRotation; |
| 5748 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5749 | return mSeascapeRotation; |
| 5750 | |
| 5751 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5752 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5753 | // Return either landscape rotation. |
| 5754 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 5755 | return preferredRotation; |
| 5756 | } |
| 5757 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 5758 | return lastRotation; |
| 5759 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5760 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5761 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5762 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 5763 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5764 | // Return either portrait rotation. |
| 5765 | if (isAnyPortrait(preferredRotation)) { |
| 5766 | return preferredRotation; |
| 5767 | } |
| 5768 | if (isAnyPortrait(lastRotation)) { |
| 5769 | return lastRotation; |
| 5770 | } |
| 5771 | return mPortraitRotation; |
| 5772 | |
| 5773 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 5774 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 5775 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5776 | if (preferredRotation >= 0) { |
| 5777 | return preferredRotation; |
| 5778 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 5779 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 5780 | } |
| 5781 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5784 | @Override |
| 5785 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 5786 | switch (orientation) { |
| 5787 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 5788 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 5789 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 5790 | return isAnyPortrait(rotation); |
| 5791 | |
| 5792 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 5793 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 5794 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 5795 | return isLandscapeOrSeascape(rotation); |
| 5796 | |
| 5797 | default: |
| 5798 | return true; |
| 5799 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 5800 | } |
| 5801 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 5802 | @Override |
| 5803 | public void setRotationLw(int rotation) { |
| 5804 | mOrientationListener.setCurrentRotation(rotation); |
| 5805 | } |
| 5806 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5807 | private boolean isLandscapeOrSeascape(int rotation) { |
| 5808 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5809 | } |
| 5810 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5811 | private boolean isAnyPortrait(int rotation) { |
| 5812 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 5813 | } |
| 5814 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5815 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5816 | public int getUserRotationMode() { |
| 5817 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 5818 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 5819 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 5820 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5821 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5822 | |
| 5823 | // 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] | 5824 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5825 | public void setUserRotationMode(int mode, int rot) { |
| 5826 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5827 | |
| 5828 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5829 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5830 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5831 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5832 | rot, |
| 5833 | UserHandle.USER_CURRENT); |
| 5834 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5835 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5836 | 0, |
| 5837 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5838 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5839 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5840 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5841 | 1, |
| 5842 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5843 | } |
| 5844 | } |
| 5845 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5846 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 5847 | public void setSafeMode(boolean safeMode) { |
| 5848 | mSafeMode = safeMode; |
| 5849 | performHapticFeedbackLw(null, safeMode |
| 5850 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 5851 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5852 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5853 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 5854 | static long[] getLongIntArray(Resources r, int resid) { |
| 5855 | int[] ar = r.getIntArray(resid); |
| 5856 | if (ar == null) { |
| 5857 | return null; |
| 5858 | } |
| 5859 | long[] out = new long[ar.length]; |
| 5860 | for (int i=0; i<ar.length; i++) { |
| 5861 | out[i] = ar[i]; |
| 5862 | } |
| 5863 | return out; |
| 5864 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5865 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5866 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5867 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5868 | public void systemReady() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5869 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 5870 | mKeyguardDelegate.onSystemReady(); |
| 5871 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5872 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 5873 | updateUiMode(); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5874 | synchronized (mLock) { |
| 5875 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5876 | mSystemReady = true; |
| 5877 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5878 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 5879 | public void run() { |
| 5880 | updateSettings(); |
| 5881 | } |
| 5882 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5883 | } |
| 5884 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5885 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5886 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5887 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5888 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5889 | if (mKeyguardDelegate != null) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 5890 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 5891 | mKeyguardDelegate.onBootCompleted(); |
| 5892 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5893 | synchronized (mLock) { |
| 5894 | mSystemBooted = true; |
| 5895 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5896 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5897 | screenTurningOn(null); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5898 | } |
| 5899 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5900 | ProgressDialog mBootMsgDialog = null; |
| 5901 | |
| 5902 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5903 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5904 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 5905 | mHandler.post(new Runnable() { |
| 5906 | @Override public void run() { |
| 5907 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 5908 | int theme; |
| 5909 | if (mContext.getPackageManager().hasSystemFeature( |
| 5910 | PackageManager.FEATURE_WATCH)) { |
| 5911 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 5912 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 5913 | PackageManager.FEATURE_TELEVISION)) { |
| 5914 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 5915 | } else { |
| 5916 | theme = 0; |
| 5917 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 5918 | |
| 5919 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 5920 | // This dialog will consume all events coming in to |
| 5921 | // it, to avoid it trying to do things too early in boot. |
| 5922 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 5923 | return true; |
| 5924 | } |
| 5925 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5926 | return true; |
| 5927 | } |
| 5928 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 5929 | return true; |
| 5930 | } |
| 5931 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 5932 | return true; |
| 5933 | } |
| 5934 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 5935 | return true; |
| 5936 | } |
| 5937 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 5938 | AccessibilityEvent event) { |
| 5939 | return true; |
| 5940 | } |
| 5941 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 5942 | if (mContext.getPackageManager().isUpgrade()) { |
| 5943 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 5944 | } else { |
| 5945 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 5946 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5947 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 5948 | mBootMsgDialog.setIndeterminate(true); |
| 5949 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 5950 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5951 | mBootMsgDialog.getWindow().addFlags( |
| 5952 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 5953 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 5954 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 5955 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 5956 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 5957 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5958 | mBootMsgDialog.setCancelable(false); |
| 5959 | mBootMsgDialog.show(); |
| 5960 | } |
| 5961 | mBootMsgDialog.setMessage(msg); |
| 5962 | } |
| 5963 | }); |
| 5964 | } |
| 5965 | |
| 5966 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5967 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5968 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5969 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 5970 | } |
| 5971 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5972 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5973 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5974 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5975 | // *************************************** |
| 5976 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 5977 | // *************************************** |
| 5978 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 5979 | // WITH ITS LOCKS HELD. |
| 5980 | // |
| 5981 | // This code must be VERY careful about the locks |
| 5982 | // it acquires. |
| 5983 | // In fact, the current code acquires way too many, |
| 5984 | // and probably has lurking deadlocks. |
| 5985 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5986 | synchronized (mScreenLockTimeout) { |
| 5987 | if (mLockScreenTimerActive) { |
| 5988 | // reset the timer |
| 5989 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 5990 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 5991 | } |
| 5992 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5993 | } |
| 5994 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 5995 | class ScreenLockTimeout implements Runnable { |
| 5996 | Bundle options; |
| 5997 | |
| 5998 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5999 | public void run() { |
| 6000 | synchronized (this) { |
| 6001 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6002 | if (mKeyguardDelegate != null) { |
| 6003 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6004 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6005 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6006 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6007 | } |
| 6008 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6009 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6010 | public void setLockOptions(Bundle options) { |
| 6011 | this.options = options; |
| 6012 | } |
| 6013 | } |
| 6014 | |
| 6015 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 6016 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6017 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6018 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6019 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 6020 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6021 | if (options != null) { |
| 6022 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 6023 | // until the runnable actually executes. |
| 6024 | mScreenLockTimeout.setLockOptions(options); |
| 6025 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6026 | mHandler.post(mScreenLockTimeout); |
| 6027 | } |
| 6028 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6029 | private void updateLockScreenTimeout() { |
| 6030 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6031 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6032 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6033 | if (mLockScreenTimerActive != enable) { |
| 6034 | if (enable) { |
| 6035 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 6036 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6037 | } else { |
| 6038 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 6039 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6040 | } |
| 6041 | mLockScreenTimerActive = enable; |
| 6042 | } |
| 6043 | } |
| 6044 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6045 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6046 | private void updateDreamingSleepToken(boolean acquire) { |
| 6047 | if (acquire) { |
| 6048 | if (mDreamingSleepToken == null) { |
| 6049 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 6050 | } |
| 6051 | } else { |
| 6052 | if (mDreamingSleepToken != null) { |
| 6053 | mDreamingSleepToken.release(); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6054 | mDreamingSleepToken = null; |
| 6055 | } |
| 6056 | } |
| 6057 | } |
| 6058 | |
| 6059 | private void updateScreenOffSleepToken(boolean acquire) { |
| 6060 | if (acquire) { |
| 6061 | if (mScreenOffSleepToken == null) { |
| 6062 | mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff"); |
| 6063 | } |
| 6064 | } else { |
| 6065 | if (mScreenOffSleepToken != null) { |
| 6066 | mScreenOffSleepToken.release(); |
| 6067 | mScreenOffSleepToken = null; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6068 | } |
| 6069 | } |
| 6070 | } |
| 6071 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6072 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6073 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6074 | public void enableScreenAfterBoot() { |
| 6075 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6076 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6077 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6078 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 6079 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6080 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6081 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6082 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 6083 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6084 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6085 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6086 | |
| 6087 | synchronized (mLock) { |
| 6088 | updateWakeGestureListenerLp(); |
| 6089 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6090 | } |
| 6091 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6092 | void updateUiMode() { |
| 6093 | if (mUiModeManager == null) { |
| 6094 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 6095 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 6096 | } |
| 6097 | try { |
| 6098 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 6099 | } catch (RemoteException e) { |
| 6100 | } |
| 6101 | } |
| 6102 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6103 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6104 | try { |
| 6105 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 6106 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 6107 | } catch (RemoteException e) { |
| 6108 | // Ignore |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 6113 | try { |
| 6114 | //set orientation on WindowManager |
| 6115 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6116 | } catch (RemoteException e) { |
| 6117 | // Ignore |
| 6118 | } |
| 6119 | } |
| 6120 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6121 | /** |
| 6122 | * Return an Intent to launch the currently active dock app as home. Returns |
| 6123 | * null if the standard home should be launched, which is the case if any of the following is |
| 6124 | * true: |
| 6125 | * <ul> |
| 6126 | * <li>The device is not in either car mode or desk mode |
| 6127 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 6128 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 6129 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 6130 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 6131 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6132 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6133 | */ |
| 6134 | Intent createHomeDockIntent() { |
| 6135 | Intent intent = null; |
| 6136 | |
| 6137 | // What home does is based on the mode, not the dock state. That |
| 6138 | // is, when in car mode you should be taken to car home regardless |
| 6139 | // of whether we are actually in a car dock. |
| 6140 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 6141 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 6142 | intent = mCarDockIntent; |
| 6143 | } |
| 6144 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 6145 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 6146 | intent = mDeskDockIntent; |
| 6147 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6148 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 6149 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6150 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 6151 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 6152 | // Always launch dock home from home when watch is docked, if it exists. |
| 6153 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6154 | } |
| 6155 | |
| 6156 | if (intent == null) { |
| 6157 | return null; |
| 6158 | } |
| 6159 | |
| 6160 | ActivityInfo ai = null; |
| 6161 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 6162 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 6163 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6164 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6165 | if (info != null) { |
| 6166 | ai = info.activityInfo; |
| 6167 | } |
| 6168 | if (ai != null |
| 6169 | && ai.metaData != null |
| 6170 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 6171 | intent = new Intent(intent); |
| 6172 | intent.setClassName(ai.packageName, ai.name); |
| 6173 | return intent; |
| 6174 | } |
| 6175 | |
| 6176 | return null; |
| 6177 | } |
| 6178 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6179 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 6180 | if (awakenFromDreams) { |
| 6181 | awakenDreams(); |
| 6182 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6183 | |
| 6184 | Intent dock = createHomeDockIntent(); |
| 6185 | if (dock != null) { |
| 6186 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6187 | if (fromHomeKey) { |
| 6188 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6189 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6190 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6191 | return; |
| 6192 | } catch (ActivityNotFoundException e) { |
| 6193 | } |
| 6194 | } |
| 6195 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6196 | Intent intent; |
| 6197 | |
| 6198 | if (fromHomeKey) { |
| 6199 | intent = new Intent(mHomeIntent); |
| 6200 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6201 | } else { |
| 6202 | intent = mHomeIntent; |
| 6203 | } |
| 6204 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 6205 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6206 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6207 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6208 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6209 | * goes to the home screen |
| 6210 | * @return whether it did anything |
| 6211 | */ |
| 6212 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6213 | if (!isUserSetupComplete()) { |
| 6214 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 6215 | return false; |
| 6216 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6217 | if (false) { |
| 6218 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 6219 | try { |
| 6220 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6221 | } catch (RemoteException e) { |
| 6222 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 6223 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6224 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6225 | } else { |
| 6226 | // This code brings home to the front or, if it is already |
| 6227 | // at the front, puts the device to sleep. |
| 6228 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 6229 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 6230 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 6231 | Log.d(TAG, "UTS-TEST-MODE"); |
| 6232 | } else { |
| 6233 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6234 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6235 | Intent dock = createHomeDockIntent(); |
| 6236 | if (dock != null) { |
| 6237 | int result = ActivityManagerNative.getDefault() |
| 6238 | .startActivityAsUser(null, null, dock, |
| 6239 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6240 | null, null, 0, |
| 6241 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6242 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6243 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 6244 | return false; |
| 6245 | } |
| 6246 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6247 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6248 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6249 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6250 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6251 | null, null, 0, |
| 6252 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6253 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6254 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6255 | return false; |
| 6256 | } |
| 6257 | } catch (RemoteException ex) { |
| 6258 | // bummer, the activity manager, which is in this process, is dead |
| 6259 | } |
| 6260 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6261 | return true; |
| 6262 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6263 | |
| 6264 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6265 | public void setCurrentOrientationLw(int newOrientation) { |
| 6266 | synchronized (mLock) { |
| 6267 | if (newOrientation != mCurrentAppOrientation) { |
| 6268 | mCurrentAppOrientation = newOrientation; |
| 6269 | updateOrientationListenerLp(); |
| 6270 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6271 | } |
| 6272 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6273 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6274 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 6275 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 6276 | return; |
| 6277 | } |
| 6278 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 6279 | Context.AUDIO_SERVICE); |
| 6280 | if (audioManager.isSilentMode()) { |
| 6281 | return; |
| 6282 | } |
| 6283 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 6284 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 6285 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 6286 | ringTone.play(); |
| 6287 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6288 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6289 | private boolean isTheaterModeEnabled() { |
| 6290 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6291 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 6292 | } |
| 6293 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6294 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 6295 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6296 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 6297 | } |
| 6298 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6299 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6300 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 6301 | if (!mVibrator.hasVibrator()) { |
| 6302 | return false; |
| 6303 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6304 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 6305 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 6306 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6307 | return false; |
| 6308 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6309 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6310 | switch (effectId) { |
| 6311 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6312 | pattern = mLongPressVibePattern; |
| 6313 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6314 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6315 | pattern = mVirtualKeyVibePattern; |
| 6316 | break; |
| 6317 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 6318 | pattern = mKeyboardTapVibePattern; |
| 6319 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 6320 | case HapticFeedbackConstants.CLOCK_TICK: |
| 6321 | pattern = mClockTickVibePattern; |
| 6322 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 6323 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 6324 | pattern = mCalendarDateVibePattern; |
| 6325 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6326 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6327 | pattern = mSafeModeDisabledVibePattern; |
| 6328 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6329 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6330 | pattern = mSafeModeEnabledVibePattern; |
| 6331 | break; |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 6332 | case HapticFeedbackConstants.CONTEXT_CLICK: |
| 6333 | pattern = mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 6334 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6335 | default: |
| 6336 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6337 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6338 | int owningUid; |
| 6339 | String owningPackage; |
| 6340 | if (win != null) { |
| 6341 | owningUid = win.getOwningUid(); |
| 6342 | owningPackage = win.getOwningPackage(); |
| 6343 | } else { |
| 6344 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 6345 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6346 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6347 | if (pattern.length == 1) { |
| 6348 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6349 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6350 | } else { |
| 6351 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6352 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6353 | } |
| 6354 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6355 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6356 | |
| 6357 | @Override |
| 6358 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6359 | } |
| 6360 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6361 | @Override |
| 6362 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6363 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 6364 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6365 | } |
| 6366 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 6367 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6368 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6369 | // If there is no window focused, there will be nobody to handle the events |
| 6370 | // 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] | 6371 | final WindowState win = mFocusedWindow != null ? mFocusedWindow |
| 6372 | : mTopFullscreenOpaqueWindowState; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6373 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6374 | return 0; |
| 6375 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6376 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6377 | // We are updating at a point where the keyguard has gotten |
| 6378 | // focus, but we were last in a state where the top window is |
| 6379 | // hiding it. This is probably because the keyguard as been |
| 6380 | // shown while the top window was displayed, so we want to ignore |
| 6381 | // it here because this is just a very transient change and it |
| 6382 | // will quickly lose focus once it correctly gets hidden. |
| 6383 | return 0; |
| 6384 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6385 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 6386 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6387 | & ~mResettingSystemUiFlags |
| 6388 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6389 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6390 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6391 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6392 | tmpVisibility = updateLightStatusBarLw(tmpVisibility); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6393 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6394 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6395 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 6396 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6397 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6398 | return 0; |
| 6399 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6400 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6401 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6402 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6403 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6404 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6405 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6406 | try { |
| 6407 | IStatusBarService statusbar = getStatusBarService(); |
| 6408 | if (statusbar != null) { |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 6409 | statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString()); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6410 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6411 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6412 | } catch (RemoteException e) { |
| 6413 | // re-acquire status bar service next time it is needed. |
| 6414 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6415 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6416 | } |
| 6417 | }); |
| 6418 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6419 | } |
| 6420 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6421 | private int updateLightStatusBarLw(int vis) { |
| 6422 | WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6423 | ? mStatusBar |
| 6424 | : mTopFullscreenOpaqueOrDimmingWindowState; |
| 6425 | |
| 6426 | if (statusColorWin != null) { |
| 6427 | if (statusColorWin == mTopFullscreenOpaqueWindowState) { |
| 6428 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 6429 | // its light flag. |
| 6430 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6431 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 6432 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6433 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 6434 | // Otherwise if it's dimming, clear the light flag. |
| 6435 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6436 | } |
| 6437 | } |
| 6438 | return vis; |
| 6439 | } |
| 6440 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6441 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6442 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6443 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6444 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6445 | : mTopFullscreenOpaqueWindowState; |
| 6446 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6447 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6448 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6449 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 6450 | int type = win.getAttrs().type; |
| 6451 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6452 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6453 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 6454 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 6455 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 6456 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 6457 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6458 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6459 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 6460 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6461 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6462 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6463 | |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 6464 | if (!areTranslucentBarsAllowed() && transWin != mStatusBar) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 6465 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 6466 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6467 | } |
| 6468 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6469 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6470 | boolean immersiveSticky = |
| 6471 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6472 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6473 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6474 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6475 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 6476 | boolean hideStatusBarSysui = |
| 6477 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6478 | boolean hideNavBarSysui = |
| 6479 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6480 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6481 | boolean transientStatusBarAllowed = |
| 6482 | mStatusBar != null && ( |
| 6483 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6484 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6485 | || statusBarHasFocus); |
| 6486 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6487 | boolean transientNavBarAllowed = |
| 6488 | mNavigationBar != null && |
| 6489 | hideNavBarSysui && immersiveSticky; |
| 6490 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6491 | final long now = SystemClock.uptimeMillis(); |
| 6492 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 6493 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 6494 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 6495 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 6496 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 6497 | mPendingPanicGestureUptime = 0; |
| 6498 | mStatusBarController.showTransient(); |
| 6499 | mNavigationBarController.showTransient(); |
| 6500 | } |
| 6501 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6502 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6503 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 6504 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6505 | && !transientNavBarAllowed; |
| 6506 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6507 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6508 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 6509 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6510 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6511 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6512 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 6513 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 6514 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 6515 | |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 6516 | if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType()) |
| 6517 | > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6518 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 6519 | // the input events. |
| 6520 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 6521 | } |
| 6522 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6523 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 6524 | |
| 6525 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6526 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 6527 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 6528 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6529 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6530 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 6531 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6532 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6533 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6534 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 6535 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6536 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6537 | } |
| 6538 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6539 | private void clearClearableFlagsLw() { |
| 6540 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6541 | if (newVal != mResettingSystemUiFlags) { |
| 6542 | mResettingSystemUiFlags = newVal; |
| 6543 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | private boolean isImmersiveMode(int vis) { |
| 6548 | 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] | 6549 | return mNavigationBar != null |
| 6550 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 6551 | && (vis & flags) != 0 |
| 6552 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6553 | } |
| 6554 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6555 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6556 | * @return whether the navigation or status bar can be made translucent |
| 6557 | * |
| 6558 | * This should return true unless touch exploration is not enabled or |
| 6559 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6560 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6561 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 6562 | return mTranslucentDecorEnabled |
| 6563 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6564 | } |
| 6565 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6566 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 6567 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6568 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6569 | public boolean hasNavigationBar() { |
| 6570 | return mHasNavigationBar; |
| 6571 | } |
| 6572 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 6573 | @Override |
| 6574 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 6575 | mLastInputMethodWindow = ime; |
| 6576 | mLastInputMethodTargetWindow = target; |
| 6577 | } |
| 6578 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6579 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 6580 | public int getInputMethodWindowVisibleHeightLw() { |
| 6581 | return mDockBottom - mCurBottom; |
| 6582 | } |
| 6583 | |
| 6584 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6585 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6586 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6587 | if (mKeyguardDelegate != null) { |
| 6588 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6589 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 6590 | if (mStatusBarService != null) { |
| 6591 | try { |
| 6592 | mStatusBarService.setCurrentUser(newUserId); |
| 6593 | } catch (RemoteException e) { |
| 6594 | // oh well |
| 6595 | } |
| 6596 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6597 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 6601 | public boolean canMagnifyWindow(int windowType) { |
| 6602 | switch (windowType) { |
| 6603 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 6604 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 6605 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 6606 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 6607 | return false; |
| 6608 | } |
| 6609 | } |
| 6610 | return true; |
| 6611 | } |
| 6612 | |
| 6613 | @Override |
| 6614 | public boolean isTopLevelWindow(int windowType) { |
| 6615 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 6616 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 6617 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 6618 | } |
| 6619 | return true; |
| 6620 | } |
| 6621 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 6622 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 6623 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6624 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6625 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 6626 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6627 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6628 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6629 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6630 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6631 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 6632 | || mForceClearedSystemUiFlags != 0) { |
| 6633 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 6634 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 6635 | pw.print(" mResettingSystemUiFlags=0x"); |
| 6636 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 6637 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 6638 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6639 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6640 | if (mLastFocusNeedsMenu) { |
| 6641 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 6642 | pw.println(mLastFocusNeedsMenu); |
| 6643 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6644 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 6645 | pw.println(mWakeGestureEnabledSetting); |
| 6646 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6647 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6648 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 6649 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6650 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 6651 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 6652 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 6653 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6654 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6655 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6656 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 6657 | pw.print(mCarDockEnablesAccelerometer); |
| 6658 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 6659 | pw.println(mDeskDockEnablesAccelerometer); |
| 6660 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 6661 | pw.print(mLidKeyboardAccessibility); |
| 6662 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 6663 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6664 | pw.print(prefix); |
| 6665 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 6666 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 6667 | pw.print(prefix); |
| 6668 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 6669 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6670 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6671 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 6672 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 6673 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 6674 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 6675 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 6676 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 6677 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 6678 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 6679 | pw.print(","); pw.print(mOverscanScreenTop); |
| 6680 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 6681 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 6682 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 6683 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 6684 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 6685 | pw.print(" top="); pw.print(mOverscanTop); |
| 6686 | pw.print(" right="); pw.print(mOverscanRight); |
| 6687 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 6688 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 6689 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 6690 | pw.print(mRestrictedOverscanScreenLeft); |
| 6691 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 6692 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 6693 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6694 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 6695 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 6696 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 6697 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 6698 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 6699 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 6700 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 6701 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 6702 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 6703 | pw.print(","); pw.print(mStableFullscreenTop); |
| 6704 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 6705 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6706 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 6707 | pw.print(","); pw.print(mStableTop); |
| 6708 | pw.print(")-("); pw.print(mStableRight); |
| 6709 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6710 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 6711 | pw.print(","); pw.print(mSystemTop); |
| 6712 | pw.print(")-("); pw.print(mSystemRight); |
| 6713 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6714 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 6715 | pw.print(","); pw.print(mCurTop); |
| 6716 | pw.print(")-("); pw.print(mCurRight); |
| 6717 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 6718 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 6719 | pw.print(","); pw.print(mContentTop); |
| 6720 | pw.print(")-("); pw.print(mContentRight); |
| 6721 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 6722 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 6723 | pw.print(","); pw.print(mVoiceContentTop); |
| 6724 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 6725 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6726 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 6727 | pw.print(","); pw.print(mDockTop); |
| 6728 | pw.print(")-("); pw.print(mDockRight); |
| 6729 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 6730 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 6731 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6732 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 6733 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6734 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 6735 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6736 | if (mLastInputMethodWindow != null) { |
| 6737 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 6738 | pw.println(mLastInputMethodWindow); |
| 6739 | } |
| 6740 | if (mLastInputMethodTargetWindow != null) { |
| 6741 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 6742 | pw.println(mLastInputMethodTargetWindow); |
| 6743 | } |
| 6744 | if (mStatusBar != null) { |
| 6745 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 6746 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 6747 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6748 | } |
| 6749 | if (mNavigationBar != null) { |
| 6750 | pw.print(prefix); pw.print("mNavigationBar="); |
| 6751 | pw.println(mNavigationBar); |
| 6752 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 6753 | if (mFocusedWindow != null) { |
| 6754 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 6755 | pw.println(mFocusedWindow); |
| 6756 | } |
| 6757 | if (mFocusedApp != null) { |
| 6758 | pw.print(prefix); pw.print("mFocusedApp="); |
| 6759 | pw.println(mFocusedApp); |
| 6760 | } |
| 6761 | if (mWinDismissingKeyguard != null) { |
| 6762 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 6763 | pw.println(mWinDismissingKeyguard); |
| 6764 | } |
| 6765 | if (mTopFullscreenOpaqueWindowState != null) { |
| 6766 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 6767 | pw.println(mTopFullscreenOpaqueWindowState); |
| 6768 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6769 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 6770 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 6771 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 6772 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6773 | if (mForcingShowNavBar) { |
| 6774 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 6775 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 6776 | pw.println(mForcingShowNavBarLayer); |
| 6777 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 6778 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6779 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6780 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 6781 | pw.print(" mForceStatusBarFromKeyguard="); |
| 6782 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6783 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 6784 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6785 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 6786 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 6787 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 6788 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 6789 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 6790 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 6791 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 6792 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 6793 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 6794 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 6795 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6796 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 6797 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 6798 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6799 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 6800 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6801 | mStatusBarController.dump(pw, prefix); |
| 6802 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6803 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6804 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6805 | if (mWakeGestureListener != null) { |
| 6806 | mWakeGestureListener.dump(pw, prefix); |
| 6807 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 6808 | if (mOrientationListener != null) { |
| 6809 | mOrientationListener.dump(pw, prefix); |
| 6810 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 6811 | if (mBurnInProtectionHelper != null) { |
| 6812 | mBurnInProtectionHelper.dump(prefix, pw); |
| 6813 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6814 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6815 | } |