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 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 21 | import static android.content.res.Configuration.UI_MODE_TYPE_CAR; |
| 22 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.*; |
| 24 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 25 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 26 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
| 27 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 28 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
| 29 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
| 30 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 31 | import android.app.ActivityManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 32 | import android.app.ActivityManagerInternal; |
| 33 | import android.app.ActivityManagerInternal.SleepToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 34 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 35 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 36 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 37 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 38 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 39 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 40 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 41 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 42 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 43 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 44 | import android.content.ContentResolver; |
| 45 | import android.content.Context; |
| 46 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 47 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 48 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 49 | import android.content.pm.ActivityInfo; |
| 50 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 51 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 52 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 53 | import android.content.res.Configuration; |
| 54 | import android.content.res.Resources; |
| 55 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 56 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 57 | import android.graphics.Rect; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 58 | import android.hardware.hdmi.HdmiControlManager; |
| 59 | import android.hardware.hdmi.HdmiPlaybackClient; |
| 60 | import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 61 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 62 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 63 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 64 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 65 | import android.media.Ringtone; |
| 66 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 67 | import android.media.session.MediaSessionLegacyHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 68 | import android.os.Binder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 69 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 70 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 71 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 72 | import android.os.Handler; |
| 73 | import android.os.IBinder; |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 74 | import android.os.IDeviceIdleController; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 75 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 76 | import android.os.Message; |
| 77 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 78 | import android.os.PowerManager; |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 79 | import android.os.PowerManagerInternal; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 80 | import android.os.Process; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 81 | import android.os.RemoteException; |
| 82 | import android.os.ServiceManager; |
| 83 | import android.os.SystemClock; |
| 84 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 85 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 86 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 87 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 88 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 89 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 90 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 91 | import android.service.dreams.DreamService; |
| 92 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 93 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 94 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 95 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 96 | import android.util.EventLog; |
| 97 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 98 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 99 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 100 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 101 | import android.view.Gravity; |
| 102 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 103 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 104 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 105 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 106 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 107 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 108 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 109 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 110 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 111 | import android.view.KeyEvent; |
| 112 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 113 | import android.view.Surface; |
| 114 | import android.view.View; |
| 115 | import android.view.ViewConfiguration; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 116 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 117 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 118 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 119 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 120 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 121 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 122 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 123 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 124 | import android.view.animation.AnimationUtils; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 125 | import com.android.internal.R; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 126 | import com.android.internal.logging.MetricsLogger; |
| 127 | import com.android.internal.policy.PhoneWindow; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 128 | import com.android.internal.statusbar.IStatusBarService; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 129 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 130 | import com.android.internal.widget.PointerLocationView; |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 131 | import com.android.server.GestureLauncherService; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 132 | import com.android.server.LocalServices; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 133 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 134 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 135 | |
| 136 | import java.io.File; |
| 137 | import java.io.FileReader; |
| 138 | import java.io.IOException; |
| 139 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 140 | import java.util.HashSet; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 141 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 142 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 143 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 144 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 145 | * introduces a new method suffix, Lp, for an internal lock of the |
| 146 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 147 | * 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] | 148 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 149 | */ |
| 150 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 151 | static final String TAG = "WindowManager"; |
| 152 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 153 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 154 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 155 | static final boolean DEBUG_KEYGUARD = false; |
| 156 | static final boolean DEBUG_LAYOUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 157 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 158 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 159 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 160 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 161 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 162 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 163 | // No longer recommended for desk docks; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 164 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 165 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 166 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 167 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 168 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 169 | 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] | 170 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 171 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 172 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 173 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 174 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 175 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 176 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 177 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 178 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 179 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 180 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 181 | // These need to match the documentation/constant in |
| 182 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 183 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 184 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 185 | static final int LONG_PRESS_HOME_ASSIST = 2; |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame^] | 186 | static final int LONG_PRESS_HOME_PICTURE_IN_PICTURE = 3; |
| 187 | static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_PICTURE_IN_PICTURE; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 188 | |
| 189 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 190 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 191 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 192 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 193 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 194 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 195 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 196 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 197 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 198 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 199 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 200 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 201 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 202 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 203 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 204 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 205 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 206 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 207 | /** |
| 208 | * These are the system UI flags that, when changing, can cause the layout |
| 209 | * of the screen to change. |
| 210 | */ |
| 211 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 212 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 213 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 214 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 215 | | View.NAVIGATION_BAR_TRANSLUCENT |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 216 | | View.STATUS_BAR_TRANSPARENT |
| 217 | | View.NAVIGATION_BAR_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 218 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 219 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 220 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 221 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 222 | .build(); |
| 223 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 224 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 225 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 226 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 227 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 228 | /** |
| 229 | * Keyguard stuff |
| 230 | */ |
| 231 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 232 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 233 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 234 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 235 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 236 | * |
| 237 | * These are special keys that are used to launch particular kinds of applications, |
| 238 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 239 | * usage page. We don't support quite that many yet... |
| 240 | */ |
| 241 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 242 | static { |
| 243 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 244 | sApplicationLaunchKeyCategories.append( |
| 245 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 246 | sApplicationLaunchKeyCategories.append( |
| 247 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 248 | sApplicationLaunchKeyCategories.append( |
| 249 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 250 | sApplicationLaunchKeyCategories.append( |
| 251 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 252 | sApplicationLaunchKeyCategories.append( |
| 253 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 254 | sApplicationLaunchKeyCategories.append( |
| 255 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 256 | } |
| 257 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 258 | /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */ |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 259 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 260 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 261 | /** |
| 262 | * Lock protecting internal state. Must not call out into window |
| 263 | * manager with lock held. (This lock will be acquired in places |
| 264 | * where the window manager is calling in with its own lock held.) |
| 265 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 266 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 267 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 268 | Context mContext; |
| 269 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 270 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 271 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 272 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 273 | ActivityManagerInternal mActivityManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 274 | DreamManagerInternal mDreamManagerInternal; |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 275 | PowerManagerInternal mPowerManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 276 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 277 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 278 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 279 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 280 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 281 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 282 | BurnInProtectionHelper mBurnInProtectionHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 283 | AppOpsManager mAppOpsManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 284 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 285 | // Vibrator pattern for haptic feedback of a long press. |
| 286 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 287 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 288 | // Vibrator pattern for haptic feedback of virtual key press. |
| 289 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 290 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 291 | // Vibrator pattern for a short vibration. |
| 292 | long[] mKeyboardTapVibePattern; |
| 293 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 294 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 295 | long[] mClockTickVibePattern; |
| 296 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 297 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 298 | long[] mCalendarDateVibePattern; |
| 299 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 300 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 301 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 302 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 303 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 304 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 305 | |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 306 | // Vibrator pattern for haptic feedback of a context click. |
| 307 | long[] mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 308 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 309 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 310 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 311 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 312 | boolean mSafeMode; |
| 313 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 314 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 315 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 316 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 317 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 318 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 319 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 320 | int[] mNavigationBarHeightForRotationDefault = new int[4]; |
| 321 | int[] mNavigationBarWidthForRotationDefault = new int[4]; |
| 322 | int[] mNavigationBarHeightForRotationInCarMode = new int[4]; |
| 323 | int[] mNavigationBarWidthForRotationInCarMode = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 324 | |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 325 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 326 | // This is for car dock and this is updated from resource. |
| 327 | private boolean mEnableCarDockHomeCapture = true; |
| 328 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 329 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 330 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 331 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 332 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 333 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 334 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 335 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 336 | } |
| 337 | }; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 338 | final DrawnListener mKeyguardDrawnCallback = new DrawnListener() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 339 | @Override |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 340 | public void onDrawn() { |
| 341 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 342 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 343 | } |
| 344 | }; |
| 345 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 346 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 347 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 348 | WindowState mLastInputMethodWindow = null; |
| 349 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 350 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 351 | // FIXME This state is shared between the input reader and handler thread. |
| 352 | // Technically it's broken and buggy but it has been like this for many years |
| 353 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 354 | // so that only one thread is involved in handling input policy. Unfortunately |
| 355 | // it's on a critical path for power management so we can't just post the work to the |
| 356 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 357 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 358 | volatile boolean mPowerKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 359 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 360 | volatile int mPowerKeyPressCounter; |
| 361 | volatile boolean mEndCallKeyHandled; |
| 362 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 363 | boolean mRecentsVisible; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 364 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 365 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 366 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 367 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 368 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 369 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 370 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 371 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 372 | boolean mSystemBooted; |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 373 | private boolean mDeferBindKeyguard; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 374 | boolean mHdmiPlugged; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 375 | HdmiControl mHdmiControl; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 376 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 377 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 378 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 379 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 380 | int mCarDockRotation; |
| 381 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 382 | int mUndockedHdmiRotation; |
| 383 | int mDemoHdmiRotation; |
| 384 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 385 | int mDemoRotation; |
| 386 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 387 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 388 | boolean mWakeGestureEnabledSetting; |
| 389 | MyWakeGestureListener mWakeGestureListener; |
| 390 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 391 | // Default display does not rotate, apps that require non-default orientation will have to |
| 392 | // have the orientation emulated. |
| 393 | private boolean mForceDefaultOrientation = false; |
| 394 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 395 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 396 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 397 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 398 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 399 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 400 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 401 | boolean mCarDockEnablesAccelerometer; |
| 402 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 403 | int mLidKeyboardAccessibility; |
| 404 | int mLidNavigationAccessibility; |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 405 | boolean mLidControlsScreenLock; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 406 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 407 | int mShortPressOnPowerBehavior; |
| 408 | int mLongPressOnPowerBehavior; |
| 409 | int mDoublePressOnPowerBehavior; |
| 410 | int mTriplePressOnPowerBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 411 | int mShortPressOnSleepBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 412 | boolean mAwake; |
| 413 | boolean mScreenOnEarly; |
| 414 | boolean mScreenOnFully; |
| 415 | ScreenOnListener mScreenOnListener; |
| 416 | boolean mKeyguardDrawComplete; |
| 417 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 418 | boolean mOrientationSensorEnabled = false; |
| 419 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 420 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 421 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 422 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 423 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 424 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 425 | |
| 426 | // The last window we were told about in focusChanged. |
| 427 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 428 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 429 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 430 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 431 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 432 | // The current size of the screen; really; extends into the overscan area of |
| 433 | // the screen and doesn't account for any system elements like the status bar. |
| 434 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 435 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 436 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 437 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 438 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 439 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 440 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 441 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 442 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 443 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 444 | // if the status bar can't be hidden; in that case it effectively carves out |
| 445 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 446 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 447 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 448 | // During layout, the current screen borders accounting for any currently |
| 449 | // visible system UI elements. |
| 450 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 451 | // For applications requesting stable content insets, these are them. |
| 452 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 453 | // For applications requesting stable content insets but have also set the |
| 454 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 455 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 456 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 457 | // During layout, the current screen borders with all outer decoration |
| 458 | // (status bar, input method dock) accounted for. |
| 459 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 460 | // During layout, the frame in which content should be displayed |
| 461 | // to the user, accounting for all screen decoration except for any |
| 462 | // space they deem as available for other content. This is usually |
| 463 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 464 | // content insets. |
| 465 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 466 | // During layout, the frame in which voice content should be displayed |
| 467 | // to the user, accounting for all screen decoration except for any |
| 468 | // space they deem as available for other content. |
| 469 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 470 | // 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] | 471 | // windows are placed. |
| 472 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 473 | // During layout, the layer at which the doc window is placed. |
| 474 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 475 | // During layout, this is the layer of the status bar. |
| 476 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 477 | int mLastSystemUiFlags; |
| 478 | // Bits that we are in the process of clearing, so we want to prevent |
| 479 | // them from being set by applications until everything has been updated |
| 480 | // to have them clear. |
| 481 | int mResettingSystemUiFlags = 0; |
| 482 | // Bits that we are currently always keeping cleared. |
| 483 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 484 | // What we last reported to system UI about whether the compatibility |
| 485 | // menu needs to be displayed. |
| 486 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 487 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 488 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 489 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 490 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 491 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 492 | static final Rect mTmpParentFrame = new Rect(); |
| 493 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 494 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 495 | static final Rect mTmpContentFrame = new Rect(); |
| 496 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 497 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 498 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 499 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 500 | static final Rect mTmpOutsetFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 501 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 502 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 503 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 504 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 505 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 506 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 507 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 508 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 509 | private boolean mForceStatusBarTransparent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 510 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 511 | boolean mForcingShowNavBar; |
| 512 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 513 | |
| 514 | // States of keyguard dismiss. |
| 515 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 516 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 517 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 518 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 519 | |
| 520 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 521 | * be done once per window. */ |
| 522 | private WindowState mWinDismissingKeyguard; |
| 523 | |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 524 | /** When window is currently dismissing the keyguard, dismissing the keyguard must handle |
| 525 | * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN |
| 526 | * lock SIM card. This variable is used to record the previous keyguard secure state for |
| 527 | * monitoring secure state change on window dismissing keyguard. */ |
| 528 | private boolean mSecureDismissingKeyguard; |
| 529 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 530 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 531 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 532 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 533 | * the wallpaper. */ |
| 534 | private WindowState mWinShowWhenLocked; |
| 535 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 536 | boolean mShowingLockscreen; |
| 537 | boolean mShowingDream; |
| 538 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 539 | boolean mDreamingSleepTokenNeeded; |
| 540 | SleepToken mDreamingSleepToken; |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 541 | SleepToken mScreenOffSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 542 | boolean mKeyguardSecure; |
| 543 | boolean mKeyguardSecureIncludingHidden; |
| 544 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 545 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 546 | boolean mHomeConsumed; |
| 547 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 548 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 549 | Intent mCarDockIntent; |
| 550 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 551 | boolean mSearchKeyShortcutPending; |
| 552 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 553 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 554 | boolean mPendingMetaAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 555 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 556 | // support for activating the lock screen while the screen is on |
| 557 | boolean mAllowLockscreenWhenOn; |
| 558 | int mLockScreenTimeout; |
| 559 | boolean mLockScreenTimerActive; |
| 560 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 561 | // 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] | 562 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 563 | |
| 564 | // Behavior of POWER button while in-call and screen on. |
| 565 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 566 | int mIncallPowerBehavior; |
| 567 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 568 | Display mDisplay; |
| 569 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 570 | private int mDisplayRotation; |
| 571 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 572 | int mLandscapeRotation = 0; // default landscape rotation |
| 573 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 574 | int mPortraitRotation = 0; // default portrait rotation |
| 575 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 576 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 577 | int mOverscanLeft = 0; |
| 578 | int mOverscanTop = 0; |
| 579 | int mOverscanRight = 0; |
| 580 | int mOverscanBottom = 0; |
| 581 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 582 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 583 | private int mLongPressOnHomeBehavior; |
| 584 | |
| 585 | // What we do when the user double-taps on home |
| 586 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 587 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 588 | // Allowed theater mode wake actions |
| 589 | private boolean mAllowTheaterModeWakeFromKey; |
| 590 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 591 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 592 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 593 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 594 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 595 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 596 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 597 | // Whether to support long press from power button in non-interactive mode |
| 598 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 599 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 600 | // Whether to go to sleep entering theater mode from power button |
| 601 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 602 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 603 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 604 | // Time to volume and power must be pressed within this interval of each other. |
| 605 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 606 | // Increase the chord delay when taking a screenshot from the keyguard |
| 607 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 608 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 609 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 610 | private long mScreenshotChordVolumeDownKeyTime; |
| 611 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 612 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 613 | private boolean mScreenshotChordPowerKeyTriggered; |
| 614 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 615 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 616 | /* The number of steps between min and max brightness */ |
| 617 | private static final int BRIGHTNESS_STEPS = 10; |
| 618 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 619 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 620 | ShortcutManager mShortcutManager; |
| 621 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 622 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 623 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 624 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 625 | private int mCurrentUserId; |
| 626 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 627 | // Maps global key codes to the components that will handle them. |
| 628 | private GlobalKeyManager mGlobalKeyManager; |
| 629 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 630 | // Fallback actions by key code. |
| 631 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 632 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 633 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 634 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 635 | = new LogDecelerateInterpolator(100, 0); |
| 636 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 637 | private boolean mForceWindowDrawsStatusBarBackground; |
| 638 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 639 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 640 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 641 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 642 | 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] | 643 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 644 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 645 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 646 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 647 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 648 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 649 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 650 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 651 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 652 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 653 | private static final int MSG_REQUEST_TRANSIENT_BARS = 16; |
| 654 | |
| 655 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; |
| 656 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 657 | |
| 658 | private class PolicyHandler extends Handler { |
| 659 | @Override |
| 660 | public void handleMessage(Message msg) { |
| 661 | switch (msg.what) { |
| 662 | case MSG_ENABLE_POINTER_LOCATION: |
| 663 | enablePointerLocation(); |
| 664 | break; |
| 665 | case MSG_DISABLE_POINTER_LOCATION: |
| 666 | disablePointerLocation(); |
| 667 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 668 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 669 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 670 | break; |
| 671 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 672 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 673 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 674 | case MSG_DISPATCH_SHOW_RECENTS: |
| 675 | showRecentApps(false); |
| 676 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 677 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 678 | showGlobalActionsInternal(); |
| 679 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 680 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 681 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 682 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 683 | break; |
| 684 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 685 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 686 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 687 | break; |
| 688 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 689 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 690 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 691 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 692 | case MSG_HIDE_BOOT_MESSAGE: |
| 693 | handleHideBootMessage(); |
| 694 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 695 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 696 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 697 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 698 | case MSG_POWER_DELAYED_PRESS: |
| 699 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 700 | finishPowerKeyPress(); |
| 701 | break; |
| 702 | case MSG_POWER_LONG_PRESS: |
| 703 | powerLongPress(); |
| 704 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 705 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 706 | updateDreamingSleepToken(msg.arg1 != 0); |
| 707 | break; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 708 | case MSG_REQUEST_TRANSIENT_BARS: |
| 709 | WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ? |
| 710 | mStatusBar : mNavigationBar; |
| 711 | if (targetBar != null) { |
| 712 | requestTransientBars(targetBar); |
| 713 | } |
| 714 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | } |
| 718 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 719 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 720 | @Override |
| 721 | public void onUEvent(UEventObserver.UEvent event) { |
| 722 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 723 | } |
| 724 | }; |
| 725 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 726 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 727 | SettingsObserver(Handler handler) { |
| 728 | super(handler); |
| 729 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 730 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 731 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 732 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 733 | ContentResolver resolver = mContext.getContentResolver(); |
| 734 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 735 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 736 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 737 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 738 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 739 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 740 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 741 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 742 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 743 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 744 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 745 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 746 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 747 | Settings.System.USER_ROTATION), false, this, |
| 748 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 749 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 750 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 751 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 752 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 753 | Settings.System.POINTER_LOCATION), false, this, |
| 754 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 755 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 756 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 757 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 758 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 759 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 760 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 761 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 762 | Settings.Global.POLICY_CONTROL), false, this, |
| 763 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 764 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 768 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 769 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 770 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 771 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 772 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 773 | class MyWakeGestureListener extends WakeGestureListener { |
| 774 | MyWakeGestureListener(Context context, Handler handler) { |
| 775 | super(context, handler); |
| 776 | } |
| 777 | |
| 778 | @Override |
| 779 | public void onWakeUp() { |
| 780 | synchronized (mLock) { |
| 781 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 782 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 783 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture, |
| 784 | "android.policy:GESTURE"); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | } |
| 788 | } |
| 789 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 790 | class MyOrientationListener extends WindowOrientationListener { |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 791 | private final Runnable mUpdateRotationRunnable = new Runnable() { |
| 792 | @Override |
| 793 | public void run() { |
Tim Murray | 1f40764 | 2015-10-01 17:07:12 -0700 | [diff] [blame] | 794 | // send interaction hint to improve redraw performance |
| 795 | mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 796 | updateRotation(false); |
| 797 | } |
| 798 | }; |
| 799 | |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 800 | MyOrientationListener(Context context, Handler handler) { |
| 801 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 802 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 803 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 804 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 805 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 806 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 807 | mHandler.post(mUpdateRotationRunnable); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 808 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 809 | } |
| 810 | MyOrientationListener mOrientationListener; |
| 811 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 812 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 813 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 814 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 815 | View.NAVIGATION_BAR_TRANSIENT, |
| 816 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 817 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 818 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 819 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, |
| 820 | View.NAVIGATION_BAR_TRANSPARENT); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 821 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 822 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 823 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 824 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 825 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 826 | IStatusBarService getStatusBarService() { |
| 827 | synchronized (mServiceAquireLock) { |
| 828 | if (mStatusBarService == null) { |
| 829 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 830 | ServiceManager.getService("statusbar")); |
| 831 | } |
| 832 | return mStatusBarService; |
| 833 | } |
| 834 | } |
| 835 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 836 | /* |
| 837 | * We always let the sensor be switched on by default except when |
| 838 | * the user has explicitly disabled sensor based rotation or when the |
| 839 | * screen is switched off. |
| 840 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 841 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 842 | if (mSupportAutoRotation) { |
| 843 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 844 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 845 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 846 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 847 | // If the application has explicitly requested to follow the |
| 848 | // orientation, then we need to turn the sensor on. |
| 849 | return true; |
| 850 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 851 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 852 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 853 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 854 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 855 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 856 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 857 | // orientation management, |
| 858 | return true; |
| 859 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 860 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 861 | // If the setting for using the sensor by default is enabled, then |
| 862 | // we will always leave it on. Note that the user could go to |
| 863 | // a window that forces an orientation that does not use the |
| 864 | // sensor and in theory we could turn it off... however, when next |
| 865 | // turning it on we won't have a good value for the current |
| 866 | // orientation for a little bit, which can cause orientation |
| 867 | // changes to lag, so we'd like to keep it always on. (It will |
| 868 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 869 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 870 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 871 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 872 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 873 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 874 | /* |
| 875 | * Various use cases for invoking this function |
| 876 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 877 | * 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] | 878 | * if not already enabled |
| 879 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 880 | * already enabled |
| 881 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 882 | * screen turning on and current app has nosensor based orientation, do nothing |
| 883 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 884 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 885 | if (!mOrientationListener.canDetectOrientation()) { |
| 886 | // If sensor is turned off or nonexistent for some reason |
| 887 | return; |
| 888 | } |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 889 | // Could have been invoked due to screen turning on or off or |
| 890 | // change of the currently visible window's orientation. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 891 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 892 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 893 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled |
| 894 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 895 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 896 | boolean disable = true; |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 897 | // Note: We postpone the rotating of the screen until the keyguard as well as the |
| 898 | // window manager have reported a draw complete. |
| 899 | if (mScreenOnEarly && mAwake && |
| 900 | mKeyguardDrawComplete && mWindowManagerDrawComplete) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 901 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 902 | disable = false; |
| 903 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 904 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 905 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 906 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 907 | mOrientationSensorEnabled = true; |
| 908 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 909 | } |
| 910 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 911 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 912 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 913 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 914 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 915 | mOrientationSensorEnabled = false; |
| 916 | } |
| 917 | } |
| 918 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 919 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 920 | // Hold a wake lock until the power key is released. |
| 921 | if (!mPowerKeyWakeLock.isHeld()) { |
| 922 | mPowerKeyWakeLock.acquire(); |
| 923 | } |
| 924 | |
| 925 | // Cancel multi-press detection timeout. |
| 926 | if (mPowerKeyPressCounter != 0) { |
| 927 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 928 | } |
| 929 | |
| 930 | // Detect user pressing the power button in panic when an application has |
| 931 | // taken over the whole screen. |
| 932 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Craig Mautner | 0124980e9 | 2014-11-30 21:15:34 -0800 | [diff] [blame] | 933 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 934 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 935 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | // Latch power key state to detect screenshot chord. |
| 939 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 940 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 941 | mScreenshotChordPowerKeyTriggered = true; |
| 942 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 943 | interceptScreenshotChord(); |
| 944 | } |
| 945 | |
| 946 | // Stop ringing or end call if configured to do so when power is pressed. |
| 947 | TelecomManager telecomManager = getTelecommService(); |
| 948 | boolean hungUp = false; |
| 949 | if (telecomManager != null) { |
| 950 | if (telecomManager.isRinging()) { |
| 951 | // Pressing Power while there's a ringing incoming |
| 952 | // call should silence the ringer. |
| 953 | telecomManager.silenceRinger(); |
| 954 | } else if ((mIncallPowerBehavior |
| 955 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 956 | && telecomManager.isInCall() && interactive) { |
| 957 | // Otherwise, if "Power button ends call" is enabled, |
| 958 | // the Power button will hang up any current active call. |
| 959 | hungUp = telecomManager.endCall(); |
| 960 | } |
| 961 | } |
| 962 | |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 963 | GestureLauncherService gestureService = LocalServices.getService( |
| 964 | GestureLauncherService.class); |
| 965 | boolean gesturedServiceIntercepted = false; |
| 966 | if (gestureService != null) { |
| 967 | gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive); |
| 968 | } |
| 969 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 970 | // If the power key has still not yet been handled, then detect short |
| 971 | // press, long press, or multi press and decide what to do. |
| 972 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 973 | || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 974 | if (!mPowerKeyHandled) { |
| 975 | if (interactive) { |
| 976 | // When interactive, we're already awake. |
| 977 | // Wait for a long press or for the button to be released to decide what to do. |
| 978 | if (hasLongPressOnPowerBehavior()) { |
| 979 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 980 | msg.setAsynchronous(true); |
| 981 | mHandler.sendMessageDelayed(msg, |
| 982 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 983 | } |
| 984 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 985 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 986 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 987 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 988 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 989 | msg.setAsynchronous(true); |
| 990 | mHandler.sendMessageDelayed(msg, |
| 991 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 992 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 993 | } else { |
| 994 | final int maxCount = getMaxMultiPressPowerCount(); |
| 995 | |
| 996 | if (maxCount <= 1) { |
| 997 | mPowerKeyHandled = true; |
| 998 | } else { |
| 999 | mBeganFromNonInteractive = true; |
| 1000 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1001 | } |
| 1002 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1006 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 1007 | final boolean handled = canceled || mPowerKeyHandled; |
| 1008 | mScreenshotChordPowerKeyTriggered = false; |
| 1009 | cancelPendingScreenshotChordAction(); |
| 1010 | cancelPendingPowerKeyAction(); |
| 1011 | |
| 1012 | if (!handled) { |
| 1013 | // Figure out how to handle the key now that it has been released. |
| 1014 | mPowerKeyPressCounter += 1; |
| 1015 | |
| 1016 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1017 | final long eventTime = event.getDownTime(); |
| 1018 | if (mPowerKeyPressCounter < maxCount) { |
| 1019 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1020 | // Continue holding the wake lock. |
| 1021 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 1022 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 1023 | msg.setAsynchronous(true); |
| 1024 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 1025 | return; |
| 1026 | } |
| 1027 | |
| 1028 | // No other actions. Handle it immediately. |
| 1029 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1030 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1031 | |
| 1032 | // Done. Reset our state. |
| 1033 | finishPowerKeyPress(); |
| 1034 | } |
| 1035 | |
| 1036 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1037 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1038 | mPowerKeyPressCounter = 0; |
| 1039 | if (mPowerKeyWakeLock.isHeld()) { |
| 1040 | mPowerKeyWakeLock.release(); |
| 1041 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | private void cancelPendingPowerKeyAction() { |
| 1045 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1046 | mPowerKeyHandled = true; |
| 1047 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1048 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 1052 | if (mScreenOnEarly && !mScreenOnFully) { |
| 1053 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 1054 | + "already in the process of turning the screen on."); |
| 1055 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 1056 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1057 | |
| 1058 | if (count == 2) { |
| 1059 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 1060 | } else if (count == 3) { |
| 1061 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1062 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1063 | switch (mShortPressOnPowerBehavior) { |
| 1064 | case SHORT_PRESS_POWER_NOTHING: |
| 1065 | break; |
| 1066 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 1067 | mPowerManager.goToSleep(eventTime, |
| 1068 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1069 | break; |
| 1070 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1071 | mPowerManager.goToSleep(eventTime, |
| 1072 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1073 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1074 | break; |
| 1075 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1076 | mPowerManager.goToSleep(eventTime, |
| 1077 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1078 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1079 | launchHomeFromHotKey(); |
| 1080 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1081 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1082 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1083 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1089 | switch (behavior) { |
| 1090 | case MULTI_PRESS_POWER_NOTHING: |
| 1091 | break; |
| 1092 | case MULTI_PRESS_POWER_THEATER_MODE: |
Bryce Lee | 3ae447e | 2015-06-30 12:31:41 -0700 | [diff] [blame] | 1093 | if (!isUserSetupComplete()) { |
| 1094 | Slog.i(TAG, "Ignoring toggling theater mode - device not setup."); |
| 1095 | break; |
| 1096 | } |
| 1097 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1098 | if (isTheaterModeEnabled()) { |
| 1099 | Slog.i(TAG, "Toggling theater mode off."); |
| 1100 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1101 | Settings.Global.THEATER_MODE_ON, 0); |
| 1102 | if (!interactive) { |
| 1103 | wakeUpFromPowerKey(eventTime); |
| 1104 | } |
| 1105 | } else { |
| 1106 | Slog.i(TAG, "Toggling theater mode on."); |
| 1107 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1108 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1109 | |
| 1110 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1111 | mPowerManager.goToSleep(eventTime, |
| 1112 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1113 | } |
| 1114 | } |
| 1115 | break; |
| 1116 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1117 | Slog.i(TAG, "Starting brightness boost."); |
| 1118 | if (!interactive) { |
| 1119 | wakeUpFromPowerKey(eventTime); |
| 1120 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1121 | mPowerManager.boostScreenBrightness(eventTime); |
| 1122 | break; |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | private int getMaxMultiPressPowerCount() { |
| 1127 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1128 | return 3; |
| 1129 | } |
| 1130 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1131 | return 2; |
| 1132 | } |
| 1133 | return 1; |
| 1134 | } |
| 1135 | |
| 1136 | private void powerLongPress() { |
| 1137 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1138 | switch (behavior) { |
| 1139 | case LONG_PRESS_POWER_NOTHING: |
| 1140 | break; |
| 1141 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1142 | mPowerKeyHandled = true; |
| 1143 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1144 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1145 | } |
| 1146 | showGlobalActionsInternal(); |
| 1147 | break; |
| 1148 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1149 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1150 | mPowerKeyHandled = true; |
| 1151 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1152 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1153 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1154 | break; |
| 1155 | } |
| 1156 | } |
| 1157 | |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1158 | private void sleepPress(long eventTime) { |
| 1159 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1160 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1165 | switch (mShortPressOnSleepBehavior) { |
| 1166 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1167 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1168 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
| 1169 | mPowerManager.goToSleep(eventTime, |
| 1170 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1171 | break; |
| 1172 | } |
| 1173 | } |
| 1174 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1175 | private int getResolvedLongPressOnPowerBehavior() { |
| 1176 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1177 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1178 | } |
| 1179 | return mLongPressOnPowerBehavior; |
| 1180 | } |
| 1181 | |
| 1182 | private boolean hasLongPressOnPowerBehavior() { |
| 1183 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1187 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1188 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1189 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1190 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1191 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1192 | && now <= mScreenshotChordPowerKeyTime |
| 1193 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1194 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1195 | cancelPendingPowerKeyAction(); |
| 1196 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1197 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | } |
| 1201 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1202 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1203 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1204 | // Double the time it takes to take a screenshot from the keyguard |
| 1205 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1206 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1207 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1208 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1211 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1212 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1215 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1216 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1217 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1218 | mEndCallKeyHandled = true; |
| 1219 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1220 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1221 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1222 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1223 | } |
| 1224 | }; |
| 1225 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1226 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1227 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1228 | public void run() { |
| 1229 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1230 | } |
| 1231 | }; |
| 1232 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1233 | @Override |
| 1234 | public void showGlobalActions() { |
| 1235 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1236 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1237 | } |
| 1238 | |
| 1239 | void showGlobalActionsInternal() { |
| 1240 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1241 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1242 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1243 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1244 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1245 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1246 | if (keyguardShowing) { |
| 1247 | // since it took two seconds of long press to bring this up, |
| 1248 | // 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] | 1249 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1254 | return Settings.Global.getInt( |
| 1255 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1256 | } |
| 1257 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1258 | boolean isUserSetupComplete() { |
| 1259 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1260 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1261 | } |
| 1262 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1263 | private void handleShortPressOnHome() { |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1264 | // Turn on the connected TV and switch HDMI input if we're a HDMI playback device. |
| 1265 | getHdmiControl().turnOnTv(); |
| 1266 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1267 | // If there's a dream running then use home to escape the dream |
| 1268 | // but don't actually go home. |
| 1269 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1270 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1271 | return; |
| 1272 | } |
| 1273 | |
| 1274 | // Go home! |
| 1275 | launchHomeFromHotKey(); |
| 1276 | } |
| 1277 | |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1278 | /** |
| 1279 | * Creates an accessor to HDMI control service that performs the operation of |
| 1280 | * turning on TV (optional) and switching input to us. If HDMI control service |
| 1281 | * is not available or we're not a HDMI playback device, the operation is no-op. |
| 1282 | */ |
| 1283 | private HdmiControl getHdmiControl() { |
| 1284 | if (null == mHdmiControl) { |
| 1285 | HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService( |
| 1286 | Context.HDMI_CONTROL_SERVICE); |
| 1287 | HdmiPlaybackClient client = null; |
| 1288 | if (manager != null) { |
| 1289 | client = manager.getPlaybackClient(); |
| 1290 | } |
| 1291 | mHdmiControl = new HdmiControl(client); |
| 1292 | } |
| 1293 | return mHdmiControl; |
| 1294 | } |
| 1295 | |
| 1296 | private static class HdmiControl { |
| 1297 | private final HdmiPlaybackClient mClient; |
| 1298 | |
| 1299 | private HdmiControl(HdmiPlaybackClient client) { |
| 1300 | mClient = client; |
| 1301 | } |
| 1302 | |
| 1303 | public void turnOnTv() { |
| 1304 | if (mClient == null) { |
| 1305 | return; |
| 1306 | } |
| 1307 | mClient.oneTouchPlay(new OneTouchPlayCallback() { |
| 1308 | @Override |
| 1309 | public void onComplete(int result) { |
| 1310 | if (result != HdmiControlManager.RESULT_SUCCESS) { |
| 1311 | Log.w(TAG, "One touch play failed: " + result); |
| 1312 | } |
| 1313 | } |
| 1314 | }); |
| 1315 | } |
| 1316 | } |
| 1317 | |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame^] | 1318 | private void handleLongPressOnHome(int deviceId, KeyEvent event) { |
| 1319 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) { |
| 1320 | return; |
| 1321 | } |
| 1322 | mHomeConsumed = true; |
| 1323 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1324 | |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame^] | 1325 | switch (mLongPressOnHomeBehavior) { |
| 1326 | case LONG_PRESS_HOME_RECENT_SYSTEM_UI: |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1327 | toggleRecentApps(); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame^] | 1328 | break; |
| 1329 | case LONG_PRESS_HOME_ASSIST: |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1330 | launchAssistAction(null, deviceId); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame^] | 1331 | break; |
| 1332 | case LONG_PRESS_HOME_PICTURE_IN_PICTURE: |
| 1333 | handlePipKey(event); |
| 1334 | break; |
| 1335 | default: |
| 1336 | Log.w(TAG, "Not defined home long press behavior: " + mLongPressOnHomeBehavior); |
| 1337 | break; |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1338 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1339 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1340 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1341 | private void handleDoubleTapOnHome() { |
| 1342 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1343 | mHomeConsumed = true; |
| 1344 | toggleRecentApps(); |
| 1345 | } |
| 1346 | } |
| 1347 | |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame^] | 1348 | private void handlePipKey(KeyEvent event) { |
| 1349 | if (DEBUG_INPUT) Log.d(TAG, "handlePipKey event=" + event); |
| 1350 | Intent intent = new Intent(Intent.ACTION_PICTURE_IN_PICTURE_BUTTON); |
| 1351 | intent.putExtra(Intent.EXTRA_KEY_EVENT, event); |
| 1352 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
| 1353 | } |
| 1354 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1355 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1356 | @Override |
| 1357 | public void run() { |
| 1358 | if (mHomeDoubleTapPending) { |
| 1359 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1360 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1361 | } |
| 1362 | } |
| 1363 | }; |
| 1364 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1365 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1366 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1367 | } |
| 1368 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1369 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1370 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1371 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1372 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1373 | mContext = context; |
| 1374 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1375 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1376 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1377 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1378 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1379 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1380 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1381 | |
| 1382 | // Init display burn-in protection |
| 1383 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1384 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1385 | // Allow a system property to override this. Used by developer settings. |
| 1386 | boolean burnInProtectionDevMode = |
| 1387 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1388 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1389 | final int minHorizontal; |
| 1390 | final int maxHorizontal; |
| 1391 | final int minVertical; |
| 1392 | final int maxVertical; |
| 1393 | final int maxRadius; |
| 1394 | if (burnInProtectionDevMode) { |
| 1395 | minHorizontal = -8; |
| 1396 | maxHorizontal = 8; |
| 1397 | minVertical = -8; |
| 1398 | maxVertical = -4; |
| 1399 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1400 | } else { |
| 1401 | Resources resources = context.getResources(); |
| 1402 | minHorizontal = resources.getInteger( |
| 1403 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1404 | maxHorizontal = resources.getInteger( |
| 1405 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1406 | minVertical = resources.getInteger( |
| 1407 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1408 | maxVertical = resources.getInteger( |
| 1409 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1410 | maxRadius = resources.getInteger( |
| 1411 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1412 | } |
| 1413 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1414 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1415 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1416 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1417 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1418 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1419 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1420 | try { |
| 1421 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1422 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1423 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1424 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1425 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1426 | mUiMode = context.getResources().getInteger( |
| 1427 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1428 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1429 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1430 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1431 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 1432 | mEnableCarDockHomeCapture = context.getResources().getBoolean( |
| 1433 | com.android.internal.R.bool.config_enableCarDockHomeLaunch); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1434 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1435 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1436 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1437 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1438 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1439 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1440 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1441 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1442 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1443 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1444 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1445 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1446 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1447 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1448 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1449 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1450 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1451 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1452 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1453 | mCarDockRotation = readRotation( |
| 1454 | com.android.internal.R.integer.config_carDockRotation); |
| 1455 | mDeskDockRotation = readRotation( |
| 1456 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1457 | mUndockedHdmiRotation = readRotation( |
| 1458 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1459 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1460 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1461 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1462 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1463 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1464 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1465 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1466 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 1467 | mLidControlsScreenLock = mContext.getResources().getBoolean( |
| 1468 | com.android.internal.R.bool.config_lidControlsScreenLock); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1469 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1470 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1471 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1472 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1473 | |
| 1474 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1475 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1476 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1477 | || mContext.getResources().getBoolean( |
| 1478 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1479 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1480 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1481 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1482 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1483 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1484 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1485 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1486 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1487 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1488 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1489 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1490 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1491 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1492 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1493 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1494 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1495 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1496 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1497 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1498 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1499 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1500 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1501 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1502 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1503 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1504 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1505 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1506 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1507 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1508 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1509 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1510 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1511 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1512 | Context.ACCESSIBILITY_SERVICE); |
| 1513 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1514 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1515 | IntentFilter filter = new IntentFilter(); |
| 1516 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1517 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1518 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1519 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1520 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1521 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1522 | if (intent != null) { |
| 1523 | // Retrieve current sticky dock event broadcast. |
| 1524 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1525 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1526 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1527 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1528 | // register for dream-related broadcasts |
| 1529 | filter = new IntentFilter(); |
| 1530 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1531 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1532 | context.registerReceiver(mDreamReceiver, filter); |
| 1533 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1534 | // register for multiuser-relevant broadcasts |
| 1535 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1536 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1537 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1538 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1539 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1540 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1541 | @Override |
| 1542 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1543 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1544 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1545 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1546 | } |
| 1547 | @Override |
| 1548 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1549 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1550 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | @Override |
| 1554 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1555 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1556 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1557 | } |
| 1558 | } |
| 1559 | @Override |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1560 | public void onFling(int duration) { |
| 1561 | if (mPowerManagerInternal != null) { |
| 1562 | mPowerManagerInternal.powerHint( |
| 1563 | PowerManagerInternal.POWER_HINT_INTERACTION, duration); |
| 1564 | } |
| 1565 | } |
| 1566 | @Override |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1567 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1568 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1569 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1570 | @Override |
| 1571 | public void onDown() { |
| 1572 | mOrientationListener.onTouchStart(); |
| 1573 | } |
| 1574 | @Override |
| 1575 | public void onUpOrCancel() { |
| 1576 | mOrientationListener.onTouchEnd(); |
| 1577 | } |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 1578 | @Override |
| 1579 | public void onMouseHoverAtTop() { |
| 1580 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1581 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1582 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; |
| 1583 | mHandler.sendMessageDelayed(msg, 500); |
| 1584 | } |
| 1585 | @Override |
| 1586 | public void onMouseHoverAtBottom() { |
| 1587 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1588 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1589 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; |
| 1590 | mHandler.sendMessageDelayed(msg, 500); |
| 1591 | } |
| 1592 | @Override |
| 1593 | public void onMouseLeaveFromEdge() { |
| 1594 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1595 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1596 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1597 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1598 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1599 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1600 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1601 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1602 | com.android.internal.R.array.config_longPressVibePattern); |
| 1603 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1604 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1605 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1606 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1607 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1608 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1609 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1610 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1611 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1612 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1613 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1614 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 1615 | mContextClickVibePattern = getLongIntArray(mContext.getResources(), |
| 1616 | com.android.internal.R.array.config_contextClickVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1617 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1618 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1619 | com.android.internal.R.bool.config_enableScreenshotChord); |
Jorim Jaggi | 406585a | 2015-12-21 10:58:56 +0100 | [diff] [blame] | 1620 | mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean( |
| 1621 | R.bool.config_forceWindowDrawsStatusBarBackground); |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1622 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1623 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1624 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1625 | // Controls rotation and the like. |
| 1626 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1627 | |
| 1628 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1629 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 1630 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 1631 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1632 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1633 | |
| 1634 | mWindowManagerInternal.registerAppTransitionListener( |
| 1635 | mStatusBarController.getAppTransitionListener()); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1638 | /** |
| 1639 | * Read values from config.xml that may be overridden depending on |
| 1640 | * the configuration of the device. |
| 1641 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1642 | */ |
| 1643 | private void readConfigurationDependentBehaviors() { |
| 1644 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1645 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1646 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame^] | 1647 | mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) { |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1648 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1649 | } |
| 1650 | |
| 1651 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1652 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1653 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1654 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1655 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1656 | } |
| 1657 | } |
| 1658 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1659 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1660 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1661 | // This method might be called before the policy has been fully initialized |
| 1662 | // or for other displays we don't care about. |
| 1663 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1664 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1665 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1666 | mDisplay = display; |
| 1667 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1668 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1669 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1670 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1671 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1672 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1673 | mLandscapeRotation = Surface.ROTATION_0; |
| 1674 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1675 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1676 | mPortraitRotation = Surface.ROTATION_90; |
| 1677 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1678 | } else { |
| 1679 | mPortraitRotation = Surface.ROTATION_270; |
| 1680 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1681 | } |
| 1682 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1683 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1684 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1685 | mPortraitRotation = Surface.ROTATION_0; |
| 1686 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1687 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1688 | mLandscapeRotation = Surface.ROTATION_270; |
| 1689 | mSeascapeRotation = Surface.ROTATION_90; |
| 1690 | } else { |
| 1691 | mLandscapeRotation = Surface.ROTATION_90; |
| 1692 | mSeascapeRotation = Surface.ROTATION_270; |
| 1693 | } |
| 1694 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1695 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1696 | mStatusBarHeight = |
| 1697 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1698 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1699 | // Height of the navigation bar when presented horizontally at bottom |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1700 | mNavigationBarHeightForRotationDefault[mPortraitRotation] = |
| 1701 | mNavigationBarHeightForRotationDefault[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1702 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1703 | mNavigationBarHeightForRotationDefault[mLandscapeRotation] = |
| 1704 | mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize( |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1705 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1706 | |
| 1707 | // Width of the navigation bar when presented vertically along one side |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1708 | mNavigationBarWidthForRotationDefault[mPortraitRotation] = |
| 1709 | mNavigationBarWidthForRotationDefault[mUpsideDownRotation] = |
| 1710 | mNavigationBarWidthForRotationDefault[mLandscapeRotation] = |
| 1711 | mNavigationBarWidthForRotationDefault[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1712 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1713 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 1714 | // Height of the navigation bar when presented horizontally at bottom |
| 1715 | mNavigationBarHeightForRotationInCarMode[mPortraitRotation] = |
| 1716 | mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] = |
| 1717 | res.getDimensionPixelSize( |
| 1718 | com.android.internal.R.dimen.navigation_bar_height_car_mode); |
| 1719 | mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] = |
| 1720 | mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1721 | com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode); |
| 1722 | |
| 1723 | // Width of the navigation bar when presented vertically along one side |
| 1724 | mNavigationBarWidthForRotationInCarMode[mPortraitRotation] = |
| 1725 | mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] = |
| 1726 | mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] = |
| 1727 | mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] = |
| 1728 | res.getDimensionPixelSize( |
| 1729 | com.android.internal.R.dimen.navigation_bar_width_car_mode); |
| 1730 | |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1731 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1732 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1733 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1734 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 1735 | // Allow the navigation bar to move on non-square small devices (phones). |
| 1736 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1737 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1738 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1739 | // Allow a system property to override this. Used by the emulator. |
| 1740 | // See also hasNavigationBar(). |
| 1741 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1742 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1743 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1744 | } else if ("0".equals(navBarOverride)) { |
| 1745 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1746 | } |
| 1747 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1748 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1749 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1750 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1751 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1752 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1753 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1754 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1755 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1756 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 1757 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 1758 | // By default, remote display locks rotation to landscape. |
| 1759 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 1760 | mDemoRotation = mPortraitRotation; |
| 1761 | } else { |
| 1762 | mDemoRotation = mLandscapeRotation; |
| 1763 | } |
| 1764 | mDemoRotationLock = SystemProperties.getBoolean( |
| 1765 | "persist.demo.rotationlock", false); |
| 1766 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1767 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1768 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1769 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1770 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1771 | // For debug purposes the next line turns this feature off with: |
| 1772 | // $ adb shell setprop config.override_forced_orient true |
| 1773 | // $ adb shell wm size reset |
| 1774 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1775 | } |
| 1776 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1777 | /** |
| 1778 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1779 | * navigation bar and touch exploration is not enabled |
| 1780 | */ |
| 1781 | private boolean canHideNavigationBar() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 1782 | return mHasNavigationBar; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1785 | @Override |
| 1786 | public boolean isDefaultOrientationForced() { |
| 1787 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1790 | @Override |
| 1791 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1792 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1793 | mOverscanLeft = left; |
| 1794 | mOverscanTop = top; |
| 1795 | mOverscanRight = right; |
| 1796 | mOverscanBottom = bottom; |
| 1797 | } |
| 1798 | } |
| 1799 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1800 | public void updateSettings() { |
| 1801 | ContentResolver resolver = mContext.getContentResolver(); |
| 1802 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1803 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1804 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1805 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1806 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1807 | UserHandle.USER_CURRENT); |
| 1808 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1809 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1810 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1811 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1812 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1813 | // Configure wake gesture. |
| 1814 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1815 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1816 | UserHandle.USER_CURRENT) != 0; |
| 1817 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1818 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1819 | updateWakeGestureListenerLp(); |
| 1820 | } |
| 1821 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1822 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1823 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1824 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1825 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1826 | if (mUserRotation != userRotation) { |
| 1827 | mUserRotation = userRotation; |
| 1828 | updateRotation = true; |
| 1829 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1830 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1831 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1832 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1833 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1834 | if (mUserRotationMode != userRotationMode) { |
| 1835 | mUserRotationMode = userRotationMode; |
| 1836 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1837 | updateOrientationListenerLp(); |
| 1838 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1839 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1840 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1841 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1842 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1843 | if (mPointerLocationMode != pointerLocation) { |
| 1844 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1845 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1846 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1847 | } |
| 1848 | } |
| 1849 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1850 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1851 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1852 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1853 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1854 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1855 | if (mHasSoftInput != hasSoftInput) { |
| 1856 | mHasSoftInput = hasSoftInput; |
| 1857 | updateRotation = true; |
| 1858 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1859 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1860 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1861 | } |
tiger_huang | cc6366d | 2015-06-29 17:17:30 +0800 | [diff] [blame] | 1862 | } |
| 1863 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1864 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1865 | } |
| 1866 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1867 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1868 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1871 | private void updateWakeGestureListenerLp() { |
| 1872 | if (shouldEnableWakeGestureLp()) { |
| 1873 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1874 | } else { |
| 1875 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1880 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1881 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1882 | && mWakeGestureListener.isSupported(); |
| 1883 | } |
| 1884 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1885 | private void enablePointerLocation() { |
| 1886 | if (mPointerLocationView == null) { |
| 1887 | mPointerLocationView = new PointerLocationView(mContext); |
| 1888 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1889 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1890 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1891 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1892 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1893 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1894 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1895 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1896 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1897 | if (ActivityManager.isHighEndGfx()) { |
| 1898 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1899 | lp.privateFlags |= |
| 1900 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1901 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1902 | lp.format = PixelFormat.TRANSLUCENT; |
| 1903 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1904 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1905 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1906 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1907 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1908 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1909 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1910 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1911 | |
| 1912 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1913 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1914 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1915 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1916 | wm.removeView(mPointerLocationView); |
| 1917 | mPointerLocationView = null; |
| 1918 | } |
| 1919 | } |
| 1920 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1921 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1922 | try { |
| 1923 | int rotation = mContext.getResources().getInteger(resID); |
| 1924 | switch (rotation) { |
| 1925 | case 0: |
| 1926 | return Surface.ROTATION_0; |
| 1927 | case 90: |
| 1928 | return Surface.ROTATION_90; |
| 1929 | case 180: |
| 1930 | return Surface.ROTATION_180; |
| 1931 | case 270: |
| 1932 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1933 | } |
| 1934 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1935 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1936 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1937 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1941 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1942 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1943 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1944 | |
| 1945 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1946 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 1947 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 1948 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 1949 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 1950 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 1951 | } |
| 1952 | |
| 1953 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 1954 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1955 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1956 | } |
| 1957 | String permission = null; |
| 1958 | switch (type) { |
| 1959 | case TYPE_TOAST: |
| 1960 | // XXX right now the app process has complete control over |
| 1961 | // this... should introduce a token to let the system |
| 1962 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1963 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1964 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1965 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1966 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1967 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1968 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1969 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 1970 | case TYPE_ACCESSIBILITY_OVERLAY: |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 1971 | case TYPE_QS_DIALOG: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1972 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1973 | break; |
| 1974 | case TYPE_PHONE: |
| 1975 | case TYPE_PRIORITY_PHONE: |
| 1976 | case TYPE_SYSTEM_ALERT: |
| 1977 | case TYPE_SYSTEM_ERROR: |
| 1978 | case TYPE_SYSTEM_OVERLAY: |
| 1979 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1980 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1981 | break; |
| 1982 | default: |
| 1983 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1984 | } |
| 1985 | if (permission != null) { |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1986 | if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) { |
| 1987 | final int callingUid = Binder.getCallingUid(); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 1988 | // system processes will be automatically allowed privilege to draw |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1989 | if (callingUid == Process.SYSTEM_UID) { |
| 1990 | return WindowManagerGlobal.ADD_OKAY; |
| 1991 | } |
| 1992 | |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 1993 | // check if user has enabled this operation. SecurityException will be thrown if |
| 1994 | // this app has not been allowed by the user |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1995 | final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid, |
| 1996 | attrs.packageName); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 1997 | switch (mode) { |
| 1998 | case AppOpsManager.MODE_ALLOWED: |
| 1999 | case AppOpsManager.MODE_IGNORED: |
| 2000 | // although we return ADD_OKAY for MODE_IGNORED, the added window will |
| 2001 | // actually be hidden in WindowManagerService |
| 2002 | return WindowManagerGlobal.ADD_OKAY; |
| 2003 | case AppOpsManager.MODE_ERRORED: |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2004 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2005 | default: |
| 2006 | // in the default mode, we will make a decision here based on |
| 2007 | // checkCallingPermission() |
| 2008 | if (mContext.checkCallingPermission(permission) != |
| 2009 | PackageManager.PERMISSION_GRANTED) { |
| 2010 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
| 2011 | } else { |
| 2012 | return WindowManagerGlobal.ADD_OKAY; |
| 2013 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2014 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2015 | } |
| 2016 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2017 | if (mContext.checkCallingOrSelfPermission(permission) |
| 2018 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2019 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2020 | } |
| 2021 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2022 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2023 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2024 | |
| 2025 | @Override |
| 2026 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 2027 | |
| 2028 | // If this switch statement is modified, modify the comment in the declarations of |
| 2029 | // the type in {@link WindowManager.LayoutParams} as well. |
| 2030 | switch (attrs.type) { |
| 2031 | default: |
| 2032 | // These are the windows that by default are shown only to the user that created |
| 2033 | // them. If this needs to be overridden, set |
| 2034 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 2035 | // {@link WindowManager.LayoutParams}. Note that permission |
| 2036 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 2037 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 2038 | return true; |
| 2039 | } |
| 2040 | break; |
| 2041 | |
| 2042 | // These are the windows that by default are shown to all users. However, to |
| 2043 | // protect against spoofing, check permissions below. |
| 2044 | case TYPE_APPLICATION_STARTING: |
| 2045 | case TYPE_BOOT_PROGRESS: |
| 2046 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2047 | case TYPE_INPUT_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2048 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2049 | case TYPE_KEYGUARD_DIALOG: |
| 2050 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2051 | case TYPE_NAVIGATION_BAR: |
| 2052 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2053 | case TYPE_PHONE: |
| 2054 | case TYPE_POINTER: |
| 2055 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2056 | case TYPE_SEARCH_BAR: |
| 2057 | case TYPE_STATUS_BAR: |
| 2058 | case TYPE_STATUS_BAR_PANEL: |
| 2059 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 2060 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2061 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2062 | case TYPE_PRIVATE_PRESENTATION: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2063 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2064 | break; |
| 2065 | } |
| 2066 | |
| 2067 | // Check if third party app has set window to system window type. |
| 2068 | return mContext.checkCallingOrSelfPermission( |
| 2069 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 2070 | != PackageManager.PERMISSION_GRANTED; |
| 2071 | } |
| 2072 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2073 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2074 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 2075 | switch (attrs.type) { |
| 2076 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2077 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2078 | // These types of windows can't receive input events. |
| 2079 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2080 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2081 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2082 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2083 | case TYPE_STATUS_BAR: |
| 2084 | |
| 2085 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 2086 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 2087 | // the keyguard as occluded wouldn't set these flags again. |
| 2088 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 2089 | if (mKeyguardHidden) { |
| 2090 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2091 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2092 | } |
| 2093 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2094 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 2095 | |
| 2096 | if (attrs.type != TYPE_STATUS_BAR) { |
| 2097 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 2098 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2099 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2100 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2101 | if (ActivityManager.isHighEndGfx()) { |
| 2102 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
| 2103 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 2104 | } |
| 2105 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 |
Jorim Jaggi | 406585a | 2015-12-21 10:58:56 +0100 | [diff] [blame] | 2106 | || (mForceWindowDrawsStatusBarBackground |
| 2107 | && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) { |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2108 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 2109 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2110 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2111 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2112 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2113 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 2114 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2115 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2116 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 2117 | private void readCameraLensCoverState() { |
| 2118 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 2119 | } |
| 2120 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2121 | private boolean isHidden(int accessibilityMode) { |
| 2122 | switch (accessibilityMode) { |
| 2123 | case 1: |
| 2124 | return mLidState == LID_CLOSED; |
| 2125 | case 2: |
| 2126 | return mLidState == LID_OPEN; |
| 2127 | default: |
| 2128 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2129 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2130 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2131 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2132 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2133 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2134 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 2135 | int navigationPresence) { |
| 2136 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 2137 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2138 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2139 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 2140 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2141 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2142 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 2143 | || (keyboardPresence == PRESENCE_INTERNAL |
| 2144 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2145 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2146 | if (!mHasSoftInput) { |
| 2147 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 2148 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2149 | } |
| 2150 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2151 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 2152 | || (navigationPresence == PRESENCE_INTERNAL |
| 2153 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2154 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2155 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2156 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2157 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2158 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2159 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2160 | public int windowTypeToLayerLw(int type) { |
| 2161 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2162 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2163 | } |
| 2164 | switch (type) { |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2165 | case TYPE_PRIVATE_PRESENTATION: |
| 2166 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2167 | case TYPE_WALLPAPER: |
| 2168 | // wallpaper is at the bottom, though the window manager may move it. |
| 2169 | return 2; |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2170 | case TYPE_DOCK_DIVIDER: |
| 2171 | return 2; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 2172 | case TYPE_QS_DIALOG: |
| 2173 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2174 | case TYPE_PHONE: |
| 2175 | return 3; |
| 2176 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2177 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2178 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2179 | case TYPE_VOICE_INTERACTION: |
| 2180 | // voice interaction layer is almost immediately above apps. |
| 2181 | return 5; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2182 | case TYPE_INPUT_CONSUMER: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2183 | return 6; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2184 | case TYPE_SYSTEM_DIALOG: |
| 2185 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2186 | case TYPE_TOAST: |
| 2187 | // toasts and the plugged-in battery thing |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2188 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2189 | case TYPE_PRIORITY_PHONE: |
| 2190 | // 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] | 2191 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2192 | case TYPE_DREAM: |
| 2193 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2194 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2195 | case TYPE_SYSTEM_ALERT: |
| 2196 | // like the ANR / app crashed dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2197 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2198 | case TYPE_INPUT_METHOD: |
| 2199 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2200 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2201 | case TYPE_INPUT_METHOD_DIALOG: |
| 2202 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2203 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2204 | case TYPE_KEYGUARD_SCRIM: |
| 2205 | // the safety window that shows behind keyguard while keyguard is starting |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2206 | return 14; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2207 | case TYPE_STATUS_BAR_SUB_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2208 | return 15; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2209 | case TYPE_STATUS_BAR: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2210 | return 16; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2211 | case TYPE_STATUS_BAR_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2212 | return 17; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2213 | case TYPE_KEYGUARD_DIALOG: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2214 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2215 | case TYPE_VOLUME_OVERLAY: |
| 2216 | // the on-screen volume indicator and controller shown when the user |
| 2217 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2218 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2219 | case TYPE_SYSTEM_OVERLAY: |
| 2220 | // the on-screen volume indicator and controller shown when the user |
| 2221 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2222 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2223 | case TYPE_NAVIGATION_BAR: |
| 2224 | // the navigation bar, if available, shows atop most things |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2225 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2226 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2227 | // some panels (e.g. search) need to show on top of the navigation bar |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2228 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2229 | case TYPE_SYSTEM_ERROR: |
| 2230 | // system-level error dialogs |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2231 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2232 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2233 | // used to highlight the magnified portion of a display |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2234 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2235 | case TYPE_DISPLAY_OVERLAY: |
| 2236 | // used to simulate secondary display devices |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2237 | return 25; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2238 | case TYPE_DRAG: |
| 2239 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2240 | // which sits above all other focusable windows |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2241 | return 26; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2242 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2243 | // overlay put by accessibility services to intercept user interaction |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2244 | return 27; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2245 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2246 | return 28; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2247 | case TYPE_BOOT_PROGRESS: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2248 | return 29; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2249 | case TYPE_POINTER: |
| 2250 | // the (mouse) pointer layer |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2251 | return 30; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2252 | } |
| 2253 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2254 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2258 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2259 | public int subWindowTypeToLayerLw(int type) { |
| 2260 | switch (type) { |
| 2261 | case TYPE_APPLICATION_PANEL: |
| 2262 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2263 | return APPLICATION_PANEL_SUBLAYER; |
| 2264 | case TYPE_APPLICATION_MEDIA: |
| 2265 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2266 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2267 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2268 | case TYPE_APPLICATION_SUB_PANEL: |
| 2269 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2270 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2271 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2272 | } |
| 2273 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2274 | return 0; |
| 2275 | } |
| 2276 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2277 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2278 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2279 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2282 | private int getNavigationBarWidth(int rotation, int uiMode) { |
| 2283 | if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
| 2284 | return mNavigationBarWidthForRotationInCarMode[rotation]; |
| 2285 | } else { |
| 2286 | return mNavigationBarWidthForRotationDefault[rotation]; |
| 2287 | } |
| 2288 | } |
| 2289 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2290 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2291 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, |
| 2292 | int uiMode) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2293 | if (mHasNavigationBar) { |
| 2294 | // For a basic navigation bar, when we are in landscape mode we place |
| 2295 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2296 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2297 | return fullWidth - getNavigationBarWidth(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2298 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2299 | } |
| 2300 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2301 | } |
| 2302 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2303 | private int getNavigationBarHeight(int rotation, int uiMode) { |
| 2304 | if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
| 2305 | return mNavigationBarHeightForRotationInCarMode[rotation]; |
| 2306 | } else { |
| 2307 | return mNavigationBarHeightForRotationDefault[rotation]; |
| 2308 | } |
| 2309 | } |
| 2310 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2311 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2312 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, |
| 2313 | int uiMode) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2314 | if (mHasNavigationBar) { |
| 2315 | // For a basic navigation bar, when we are in portrait mode we place |
| 2316 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2317 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2318 | return fullHeight - getNavigationBarHeight(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2319 | } |
| 2320 | } |
| 2321 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2322 | } |
| 2323 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2324 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2325 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) { |
| 2326 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2329 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2330 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2331 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2332 | // 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] | 2333 | // we do want to exclude it since applications can't generally use that part |
| 2334 | // of the screen. |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2335 | return getNonDecorDisplayHeight( |
| 2336 | fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2337 | } |
| 2338 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2339 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 2340 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 2341 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2342 | (isKeyguardHostWindow(attrs) && |
| 2343 | (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 2344 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2345 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2346 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2347 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2348 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2349 | return attrs.type == TYPE_STATUS_BAR; |
| 2350 | } |
| 2351 | |
| 2352 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2353 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2354 | switch (attrs.type) { |
| 2355 | case TYPE_STATUS_BAR: |
| 2356 | case TYPE_NAVIGATION_BAR: |
| 2357 | case TYPE_WALLPAPER: |
| 2358 | case TYPE_DREAM: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2359 | case TYPE_KEYGUARD_SCRIM: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2360 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2361 | return false; |
| 2362 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 2363 | // Hide only windows below the keyguard host window. |
| 2364 | return windowTypeToLayerLw(win.getBaseType()) |
| 2365 | < windowTypeToLayerLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2366 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2367 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2368 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2369 | @Override |
| 2370 | public WindowState getWinShowWhenLockedLw() { |
| 2371 | return mWinShowWhenLocked; |
| 2372 | } |
| 2373 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2374 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2375 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2376 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2377 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2378 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2379 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2380 | return null; |
| 2381 | } |
| 2382 | if (packageName == null) { |
| 2383 | return null; |
| 2384 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2385 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2386 | WindowManager wm = null; |
| 2387 | View view = null; |
| 2388 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2389 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2390 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2391 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2392 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2393 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2394 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2395 | try { |
| 2396 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2397 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2398 | } catch (PackageManager.NameNotFoundException e) { |
| 2399 | // Ignore |
| 2400 | } |
| 2401 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2402 | |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2403 | PhoneWindow win = new PhoneWindow(context); |
| 2404 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2405 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2406 | Resources r = context.getResources(); |
| 2407 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2408 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2409 | win.setType( |
| 2410 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2411 | |
| 2412 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2413 | // Assumes it's safe to show starting windows of launched apps while |
| 2414 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2415 | // secret information. |
| 2416 | if (mKeyguardHidden) { |
| 2417 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2418 | } |
| 2419 | } |
| 2420 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2421 | // Force the window flags: this is a fake window, so it is not really |
| 2422 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2423 | // flag because we do know that the next window will take input |
| 2424 | // focus, so we want to get the IME window up on top of us right away. |
| 2425 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2426 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2427 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2428 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2429 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2430 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2431 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2432 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2433 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2434 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2435 | win.setDefaultIcon(icon); |
| 2436 | win.setDefaultLogo(logo); |
| 2437 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2438 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2439 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2440 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2441 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2442 | params.token = appToken; |
| 2443 | params.packageName = packageName; |
| 2444 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2445 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2446 | params.privateFlags |= |
| 2447 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2448 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2449 | |
| 2450 | if (!compatInfo.supportsScreen()) { |
| 2451 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2452 | } |
| 2453 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2454 | params.setTitle("Starting " + packageName); |
| 2455 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2456 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2457 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2458 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2459 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2460 | TAG, "Adding starting window for " + packageName |
| 2461 | + " / " + appToken + ": " |
| 2462 | + (view.getParent() != null ? view : null)); |
| 2463 | |
| 2464 | wm.addView(view, params); |
| 2465 | |
| 2466 | // Only return the view if it was successfully added to the |
| 2467 | // window manager... which we can tell by it having a parent. |
| 2468 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2469 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2470 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2471 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2472 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2473 | } catch (RuntimeException e) { |
| 2474 | // don't crash if something else bad happens, for example a |
| 2475 | // failure loading resources because we are loading from an app |
| 2476 | // on external storage that has been unmounted. |
| 2477 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2478 | } finally { |
| 2479 | if (view != null && view.getParent() == null) { |
| 2480 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2481 | wm.removeViewImmediate(view); |
| 2482 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | return null; |
| 2486 | } |
| 2487 | |
| 2488 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2489 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2490 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2491 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2492 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2493 | |
| 2494 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2495 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2496 | wm.removeView(window); |
| 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | /** |
| 2501 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2502 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2503 | * Currently enforces that three window types are singletons: |
| 2504 | * <ul> |
| 2505 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2506 | * <li>KEYGUARD_TYPE</li> |
| 2507 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2508 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2509 | * @param win The window to be added |
| 2510 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2511 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2512 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2513 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2514 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2515 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2516 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2517 | switch (attrs.type) { |
| 2518 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2519 | mContext.enforceCallingOrSelfPermission( |
| 2520 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2521 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2522 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2523 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2524 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2525 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2526 | } |
| 2527 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2528 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2529 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2530 | case TYPE_NAVIGATION_BAR: |
| 2531 | mContext.enforceCallingOrSelfPermission( |
| 2532 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2533 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2534 | if (mNavigationBar != null) { |
| 2535 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2536 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2537 | } |
| 2538 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2539 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2540 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2541 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2542 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2543 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2544 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2545 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2546 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2547 | mContext.enforceCallingOrSelfPermission( |
| 2548 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2549 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2550 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2551 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2552 | if (mKeyguardScrim != null) { |
| 2553 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2554 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2555 | mKeyguardScrim = win; |
| 2556 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2557 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2558 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2562 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2563 | public void removeWindowLw(WindowState win) { |
| 2564 | if (mStatusBar == win) { |
| 2565 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2566 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2567 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2568 | } else if (mKeyguardScrim == win) { |
| 2569 | Log.v(TAG, "Removing keyguard scrim"); |
| 2570 | mKeyguardScrim = null; |
| 2571 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2572 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2573 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2578 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2579 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2580 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2581 | public int selectAnimationLw(WindowState win, int transit) { |
| 2582 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2583 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2584 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2585 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2586 | if (transit == TRANSIT_EXIT |
| 2587 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2588 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2589 | } else if (transit == TRANSIT_ENTER |
| 2590 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2591 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2592 | } |
| 2593 | } else if (win == mNavigationBar) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2594 | if (win.getAttrs().windowAnimations != 0) { |
| 2595 | return 0; |
| 2596 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2597 | // This can be on either the bottom or the right. |
| 2598 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2599 | if (transit == TRANSIT_EXIT |
| 2600 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2601 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2602 | } else if (transit == TRANSIT_ENTER |
| 2603 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2604 | return R.anim.dock_bottom_enter; |
| 2605 | } |
| 2606 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2607 | if (transit == TRANSIT_EXIT |
| 2608 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2609 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2610 | } else if (transit == TRANSIT_ENTER |
| 2611 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2612 | return R.anim.dock_right_enter; |
| 2613 | } |
| 2614 | } |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 2615 | } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) { |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 2616 | if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) { |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 2617 | return R.anim.fade_in; |
| 2618 | } else if (transit == TRANSIT_EXIT) { |
| 2619 | return R.anim.fade_out; |
| 2620 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2624 | if (win.hasAppShownWindows()) { |
| 2625 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2626 | return com.android.internal.R.anim.app_starting_exit; |
| 2627 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2628 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2629 | && transit == TRANSIT_ENTER) { |
| 2630 | // Special case: we are animating in a dream, while the keyguard |
| 2631 | // is shown. We don't want an animation on the dream, because |
| 2632 | // we need it shown immediately with the keyguard animating away |
| 2633 | // to reveal it. |
| 2634 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | return 0; |
| 2638 | } |
| 2639 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2640 | @Override |
| 2641 | public void selectRotationAnimationLw(int anim[]) { |
| 2642 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2643 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2644 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2645 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2646 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2647 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2648 | case ROTATION_ANIMATION_CROSSFADE: |
| 2649 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2650 | anim[1] = R.anim.rotation_animation_enter; |
| 2651 | break; |
| 2652 | case ROTATION_ANIMATION_JUMPCUT: |
| 2653 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2654 | anim[1] = R.anim.rotation_animation_enter; |
| 2655 | break; |
| 2656 | case ROTATION_ANIMATION_ROTATE: |
| 2657 | default: |
| 2658 | anim[0] = anim[1] = 0; |
| 2659 | break; |
| 2660 | } |
| 2661 | } else { |
| 2662 | anim[0] = anim[1] = 0; |
| 2663 | } |
| 2664 | } |
| 2665 | |
| 2666 | @Override |
| 2667 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2668 | boolean forceDefault) { |
| 2669 | switch (exitAnimId) { |
| 2670 | case R.anim.rotation_animation_xfade_exit: |
| 2671 | case R.anim.rotation_animation_jump_exit: |
| 2672 | // These are the only cases that matter. |
| 2673 | if (forceDefault) { |
| 2674 | return false; |
| 2675 | } |
| 2676 | int anim[] = new int[2]; |
| 2677 | selectRotationAnimationLw(anim); |
| 2678 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2679 | default: |
| 2680 | return true; |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2685 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2686 | boolean goingToNotificationShade) { |
| 2687 | if (goingToNotificationShade) { |
| 2688 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2689 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2690 | |
| 2691 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 2692 | R.anim.lock_screen_behind_enter_wallpaper : |
| 2693 | R.anim.lock_screen_behind_enter); |
| 2694 | |
| 2695 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2696 | final List<Animation> animations = set.getAnimations(); |
| 2697 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 2698 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 2699 | } |
| 2700 | |
| 2701 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | |
| 2705 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2706 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2707 | if (goingToNotificationShade) { |
| 2708 | return null; |
| 2709 | } else { |
| 2710 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2711 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2712 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2713 | |
| 2714 | private static void awakenDreams() { |
| 2715 | IDreamManager dreamManager = getDreamManager(); |
| 2716 | if (dreamManager != null) { |
| 2717 | try { |
| 2718 | dreamManager.awaken(); |
| 2719 | } catch (RemoteException e) { |
| 2720 | // fine, stay asleep then |
| 2721 | } |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | static IDreamManager getDreamManager() { |
| 2726 | return IDreamManager.Stub.asInterface( |
| 2727 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2728 | } |
| 2729 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2730 | TelecomManager getTelecommService() { |
| 2731 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2732 | } |
| 2733 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2734 | static IAudioService getAudioService() { |
| 2735 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2736 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2737 | if (audioService == null) { |
| 2738 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2739 | } |
| 2740 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2744 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2748 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2749 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2750 | }; |
| 2751 | |
| 2752 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2753 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2754 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2755 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2756 | final int keyCode = event.getKeyCode(); |
| 2757 | final int repeatCount = event.getRepeatCount(); |
| 2758 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2759 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2760 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2761 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2762 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2763 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2764 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2765 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2766 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2767 | } |
| 2768 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2769 | // If we think we might have a volume down & power key chord on the way |
| 2770 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2771 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2772 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2773 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2774 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2775 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2776 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2777 | if (now < timeoutTime) { |
| 2778 | return timeoutTime - now; |
| 2779 | } |
| 2780 | } |
| 2781 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2782 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2783 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2784 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2785 | } |
| 2786 | return -1; |
| 2787 | } |
| 2788 | } |
| 2789 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2790 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2791 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2792 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2793 | mPendingMetaAction = false; |
| 2794 | } |
| 2795 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2796 | // First we always handle the home key here, so applications |
| 2797 | // can never break it, although if keyguard is on, we do let |
| 2798 | // it handle it, because that gives us the correct 5 second |
| 2799 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2800 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2801 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2802 | // If we have released the home key, and didn't do anything else |
| 2803 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2804 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2805 | cancelPreloadRecentApps(); |
| 2806 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2807 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2808 | if (mHomeConsumed) { |
| 2809 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2810 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2811 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2812 | |
| 2813 | if (canceled) { |
| 2814 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2815 | return -1; |
| 2816 | } |
| 2817 | |
Yorke Lee | 4f80324 | 2014-12-15 23:22:06 +0000 | [diff] [blame] | 2818 | // If an incoming call is ringing, HOME is totally disabled. |
| 2819 | // (The user is already on the InCallUI at this point, |
| 2820 | // and his ONLY options are to answer or reject the call.) |
| 2821 | TelecomManager telecomManager = getTelecommService(); |
| 2822 | if (telecomManager != null && telecomManager.isRinging()) { |
| 2823 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2824 | return -1; |
| 2825 | } |
| 2826 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2827 | // Delay handling home if a double-tap is possible. |
| 2828 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2829 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2830 | mHomeDoubleTapPending = true; |
| 2831 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2832 | ViewConfiguration.getDoubleTapTimeout()); |
| 2833 | return -1; |
| 2834 | } |
| 2835 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2836 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2837 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2838 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2839 | |
| 2840 | // If a system window has focus, then it doesn't make sense |
| 2841 | // right now to interact with applications. |
| 2842 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2843 | if (attrs != null) { |
| 2844 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2845 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2846 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2847 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2848 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2849 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2850 | } |
| 2851 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2852 | for (int i=0; i<typeCount; i++) { |
| 2853 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2854 | // 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] | 2855 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2856 | } |
| 2857 | } |
| 2858 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2859 | |
| 2860 | // Remember that home is pressed and handle special actions. |
| 2861 | if (repeatCount == 0) { |
| 2862 | mHomePressed = true; |
| 2863 | if (mHomeDoubleTapPending) { |
| 2864 | mHomeDoubleTapPending = false; |
| 2865 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2866 | handleDoubleTapOnHome(); |
| 2867 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2868 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2869 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2870 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2871 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2872 | if (!keyguardOn) { |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame^] | 2873 | handleLongPressOnHome(event.getDeviceId(), event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2874 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2875 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2876 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2877 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2878 | // Hijack modified menu keys for debugging features |
| 2879 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2880 | |
| 2881 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2882 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2883 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2884 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2885 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2886 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2887 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2888 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2889 | Intent service = new Intent(); |
| 2890 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2891 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2892 | boolean shown = Settings.Global.getInt( |
| 2893 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2894 | if (!shown) { |
| 2895 | mContext.startService(service); |
| 2896 | } else { |
| 2897 | mContext.stopService(service); |
| 2898 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2899 | Settings.Global.putInt( |
| 2900 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2901 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2902 | } |
| 2903 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2904 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2905 | if (down) { |
| 2906 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2907 | mSearchKeyShortcutPending = true; |
| 2908 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2909 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2910 | } else { |
| 2911 | mSearchKeyShortcutPending = false; |
| 2912 | if (mConsumeSearchKeyUp) { |
| 2913 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2914 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2915 | } |
| 2916 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2917 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2918 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2919 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2920 | if (down && repeatCount == 0) { |
| 2921 | preloadRecentApps(); |
| 2922 | } else if (!down) { |
| 2923 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2924 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2925 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2926 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 2927 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 2928 | if (down) { |
| 2929 | IStatusBarService service = getStatusBarService(); |
| 2930 | if (service != null) { |
| 2931 | try { |
| 2932 | service.expandNotificationsPanel(); |
| 2933 | } catch (RemoteException e) { |
| 2934 | // do nothing. |
| 2935 | } |
| 2936 | } |
| 2937 | } |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 2938 | } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) { |
| 2939 | if (down) { |
| 2940 | if (repeatCount == 0) { |
Andrei Stingaceanu | c22ab79 | 2016-01-07 12:39:38 +0000 | [diff] [blame] | 2941 | toggleKeyboardShortcutsMenu(); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 2942 | } |
| 2943 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2944 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2945 | if (down) { |
| 2946 | if (repeatCount == 0) { |
| 2947 | mAssistKeyLongPressed = false; |
| 2948 | } else if (repeatCount == 1) { |
| 2949 | mAssistKeyLongPressed = true; |
| 2950 | if (!keyguardOn) { |
| 2951 | launchAssistLongPressAction(); |
| 2952 | } |
| 2953 | } |
| 2954 | } else { |
| 2955 | if (mAssistKeyLongPressed) { |
| 2956 | mAssistKeyLongPressed = false; |
| 2957 | } else { |
| 2958 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 2959 | launchAssistAction(null, event.getDeviceId()); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2960 | } |
| 2961 | } |
| 2962 | } |
| 2963 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2964 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 2965 | if (!down) { |
| 2966 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2967 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2968 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 2969 | } else { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 2970 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 2971 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 2972 | if (dic != null) { |
| 2973 | try { |
| 2974 | dic.exitIdle("voice-search"); |
| 2975 | } catch (RemoteException e) { |
| 2976 | } |
| 2977 | } |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2978 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 2979 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2980 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 2981 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 2982 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2983 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2984 | if (down && repeatCount == 0) { |
| 2985 | mHandler.post(mScreenshotRunnable); |
| 2986 | } |
| 2987 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2988 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2989 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2990 | if (down) { |
| 2991 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2992 | |
| 2993 | // Disable autobrightness if it's on |
| 2994 | int auto = Settings.System.getIntForUser( |
| 2995 | mContext.getContentResolver(), |
| 2996 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2997 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2998 | UserHandle.USER_CURRENT_OR_SELF); |
| 2999 | if (auto != 0) { |
| 3000 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3001 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3002 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3003 | UserHandle.USER_CURRENT_OR_SELF); |
| 3004 | } |
| 3005 | |
| 3006 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 3007 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 3008 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 3009 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 3010 | Settings.System.SCREEN_BRIGHTNESS, |
| 3011 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 3012 | UserHandle.USER_CURRENT_OR_SELF); |
| 3013 | brightness += step; |
| 3014 | // Make sure we don't go beyond the limits. |
| 3015 | brightness = Math.min(max, brightness); |
| 3016 | brightness = Math.max(min, brightness); |
| 3017 | |
| 3018 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3019 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 3020 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3021 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 3022 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3023 | } |
| 3024 | return -1; |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 3025 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 3026 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 3027 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { |
| 3028 | if (mUseTvRouting) { |
| 3029 | // On TVs volume keys never go to the foreground app. |
| 3030 | dispatchDirectAudioEvent(event); |
| 3031 | return -1; |
| 3032 | } |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 3033 | } else if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3034 | if (down) { |
| 3035 | mPendingMetaAction = true; |
| 3036 | } else if (mPendingMetaAction) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3037 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3038 | } |
| 3039 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3040 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3041 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3042 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3043 | // Any printing key that is chorded with Search should be consumed |
| 3044 | // even if no shortcut was invoked. This prevents text from being |
| 3045 | // inadvertently inserted when using a keyboard that has built-in macro |
| 3046 | // 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] | 3047 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3048 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 3049 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3050 | mConsumeSearchKeyUp = true; |
| 3051 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3052 | if (down && repeatCount == 0 && !keyguardOn) { |
| 3053 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 3054 | if (shortcutIntent != null) { |
| 3055 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3056 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3057 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3058 | } catch (ActivityNotFoundException ex) { |
| 3059 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3060 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3061 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3062 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3063 | } else { |
| 3064 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3065 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3066 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3067 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3068 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3069 | } |
| 3070 | } |
| 3071 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3072 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3073 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3074 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 3075 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3076 | if (kcm.isPrintingKey(keyCode)) { |
| 3077 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 3078 | metaState & ~(KeyEvent.META_META_ON |
| 3079 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 3080 | if (shortcutIntent != null) { |
| 3081 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3082 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3083 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3084 | } catch (ActivityNotFoundException ex) { |
| 3085 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3086 | + "the activity to which it is registered was not found: " |
| 3087 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 3088 | } |
| 3089 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3090 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3094 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3095 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3096 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 3097 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 3098 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3099 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3100 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3101 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3102 | } catch (ActivityNotFoundException ex) { |
| 3103 | Slog.w(TAG, "Dropping application launch key because " |
| 3104 | + "the activity to which it is registered was not found: " |
| 3105 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 3106 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3107 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3108 | } |
| 3109 | } |
| 3110 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3111 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3112 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Michael Wright | d847ad5 | 2015-10-24 13:24:15 +0100 | [diff] [blame] | 3113 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3114 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3115 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3116 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 3117 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3118 | return -1; |
| 3119 | } |
| 3120 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3121 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 3122 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 3123 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3124 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3125 | } |
| 3126 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3127 | // Handle keyboard layout switching. |
| 3128 | // TODO: Deprecate this behavior when we fully migrate to IME subtype-based layout rotation. |
| 3129 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_SPACE |
| 3130 | && ((metaState & KeyEvent.META_CTRL_MASK) != 0)) { |
| 3131 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 3132 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 3133 | return -1; |
| 3134 | } |
| 3135 | |
| 3136 | // Handle input method switching. |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3137 | if (down && repeatCount == 0 |
| 3138 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3139 | || (keyCode == KeyEvent.KEYCODE_SPACE |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3140 | && (metaState & KeyEvent.META_META_MASK) != 0))) { |
| 3141 | final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0; |
| 3142 | mWindowManagerFuncs.switchInputMethod(forwardDirection); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3143 | return -1; |
| 3144 | } |
| 3145 | if (mLanguageSwitchKeyPressed && !down |
| 3146 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3147 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 3148 | mLanguageSwitchKeyPressed = false; |
| 3149 | return -1; |
| 3150 | } |
| 3151 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3152 | if (isValidGlobalKey(keyCode) |
| 3153 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3154 | return -1; |
| 3155 | } |
| 3156 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3157 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 3158 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3159 | return -1; |
| 3160 | } |
| 3161 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3162 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3163 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3164 | } |
| 3165 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3166 | /** {@inheritDoc} */ |
| 3167 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3168 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3169 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3170 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3171 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 3172 | + ", flags=" + event.getFlags() |
| 3173 | + ", keyCode=" + event.getKeyCode() |
| 3174 | + ", scanCode=" + event.getScanCode() |
| 3175 | + ", metaState=" + event.getMetaState() |
| 3176 | + ", repeatCount=" + event.getRepeatCount() |
| 3177 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3178 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3179 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3180 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3181 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3182 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3183 | final int keyCode = event.getKeyCode(); |
| 3184 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3185 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 3186 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3187 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3188 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3189 | final FallbackAction fallbackAction; |
| 3190 | if (initialDown) { |
| 3191 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 3192 | } else { |
| 3193 | fallbackAction = mFallbackActions.get(keyCode); |
| 3194 | } |
| 3195 | |
| 3196 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3197 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3198 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 3199 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3200 | } |
| 3201 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3202 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 3203 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3204 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3205 | event.getAction(), fallbackAction.keyCode, |
| 3206 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3207 | event.getDeviceId(), event.getScanCode(), |
| 3208 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3209 | |
| 3210 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 3211 | fallbackEvent.recycle(); |
| 3212 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3213 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3214 | |
| 3215 | if (initialDown) { |
| 3216 | mFallbackActions.put(keyCode, fallbackAction); |
| 3217 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3218 | mFallbackActions.remove(keyCode); |
| 3219 | fallbackAction.recycle(); |
| 3220 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3221 | } |
| 3222 | } |
| 3223 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3224 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3225 | if (fallbackEvent == null) { |
| 3226 | Slog.d(TAG, "No fallback."); |
| 3227 | } else { |
| 3228 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 3229 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3230 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3231 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3232 | } |
| 3233 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3234 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3235 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3236 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 3237 | long delayMillis = interceptKeyBeforeDispatching( |
| 3238 | win, fallbackEvent, policyFlags); |
| 3239 | if (delayMillis == 0) { |
| 3240 | return true; |
| 3241 | } |
| 3242 | } |
| 3243 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3244 | } |
| 3245 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3246 | private void launchAssistLongPressAction() { |
| 3247 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 3248 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 3249 | |
| 3250 | // launch the search activity |
| 3251 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 3252 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3253 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3254 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3255 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3256 | SearchManager searchManager = getSearchManager(); |
| 3257 | if (searchManager != null) { |
| 3258 | searchManager.stopSearch(); |
| 3259 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3260 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3261 | } catch (ActivityNotFoundException e) { |
| 3262 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 3263 | } |
| 3264 | } |
| 3265 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3266 | private void launchAssistAction(String hint, int deviceId) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3267 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Maurice Lam | 39d1381 | 2015-07-23 20:49:20 -0700 | [diff] [blame] | 3268 | if (!isUserSetupComplete()) { |
| 3269 | // Disable opening assist window during setup |
| 3270 | return; |
| 3271 | } |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3272 | Bundle args = null; |
| 3273 | if (deviceId > Integer.MIN_VALUE) { |
| 3274 | args = new Bundle(); |
| 3275 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3276 | } |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3277 | if ((mContext.getResources().getConfiguration().uiMode |
| 3278 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3279 | // On TV, use legacy handling until assistants are implemented in the proper way. |
| 3280 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 3281 | .launchLegacyAssist(hint, UserHandle.myUserId(), args); |
| 3282 | } else { |
| 3283 | try { |
| 3284 | if (hint != null) { |
| 3285 | if (args == null) { |
| 3286 | args = new Bundle(); |
| 3287 | } |
| 3288 | args.putBoolean(hint, true); |
| 3289 | } |
| 3290 | IStatusBarService statusbar = getStatusBarService(); |
| 3291 | if (statusbar != null) { |
| 3292 | statusbar.startAssist(args); |
| 3293 | } |
| 3294 | } catch (RemoteException e) { |
| 3295 | Slog.e(TAG, "RemoteException when starting assist", e); |
| 3296 | // re-acquire status bar service next time it is needed. |
| 3297 | mStatusBarService = null; |
| 3298 | } |
| 3299 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3302 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3303 | if (isUserSetupComplete()) { |
| 3304 | mContext.startActivityAsUser(intent, handle); |
| 3305 | } else { |
| 3306 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3307 | } |
| 3308 | } |
| 3309 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3310 | private SearchManager getSearchManager() { |
| 3311 | if (mSearchManager == null) { |
| 3312 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3313 | } |
| 3314 | return mSearchManager; |
| 3315 | } |
| 3316 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3317 | private void preloadRecentApps() { |
| 3318 | mPreloadedRecentApps = true; |
| 3319 | try { |
| 3320 | IStatusBarService statusbar = getStatusBarService(); |
| 3321 | if (statusbar != null) { |
| 3322 | statusbar.preloadRecentApps(); |
| 3323 | } |
| 3324 | } catch (RemoteException e) { |
| 3325 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 3326 | // re-acquire status bar service next time it is needed. |
| 3327 | mStatusBarService = null; |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | private void cancelPreloadRecentApps() { |
| 3332 | if (mPreloadedRecentApps) { |
| 3333 | mPreloadedRecentApps = false; |
| 3334 | try { |
| 3335 | IStatusBarService statusbar = getStatusBarService(); |
| 3336 | if (statusbar != null) { |
| 3337 | statusbar.cancelPreloadRecentApps(); |
| 3338 | } |
| 3339 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3340 | Slog.e(TAG, "RemoteException when cancelling recent apps preload", e); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3341 | // re-acquire status bar service next time it is needed. |
| 3342 | mStatusBarService = null; |
| 3343 | } |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | private void toggleRecentApps() { |
| 3348 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3349 | try { |
| 3350 | IStatusBarService statusbar = getStatusBarService(); |
| 3351 | if (statusbar != null) { |
| 3352 | statusbar.toggleRecentApps(); |
| 3353 | } |
| 3354 | } catch (RemoteException e) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3355 | Slog.e(TAG, "RemoteException when toggling recent apps", e); |
| 3356 | // re-acquire status bar service next time it is needed. |
| 3357 | mStatusBarService = null; |
| 3358 | } |
| 3359 | } |
| 3360 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3361 | @Override |
| 3362 | public void showRecentApps() { |
| 3363 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
| 3364 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS); |
| 3365 | } |
| 3366 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3367 | private void showRecentApps(boolean triggeredFromAltTab) { |
| 3368 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3369 | try { |
| 3370 | IStatusBarService statusbar = getStatusBarService(); |
| 3371 | if (statusbar != null) { |
| 3372 | statusbar.showRecentApps(triggeredFromAltTab); |
| 3373 | } |
| 3374 | } catch (RemoteException e) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3375 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 3376 | // re-acquire status bar service next time it is needed. |
| 3377 | mStatusBarService = null; |
| 3378 | } |
| 3379 | } |
| 3380 | |
Andrei Stingaceanu | c22ab79 | 2016-01-07 12:39:38 +0000 | [diff] [blame] | 3381 | private void toggleKeyboardShortcutsMenu() { |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3382 | try { |
| 3383 | IStatusBarService statusbar = getStatusBarService(); |
| 3384 | if (statusbar != null) { |
Andrei Stingaceanu | c22ab79 | 2016-01-07 12:39:38 +0000 | [diff] [blame] | 3385 | statusbar.toggleKeyboardShortcutsMenu(); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3386 | } |
| 3387 | } catch (RemoteException e) { |
| 3388 | Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e); |
| 3389 | } |
| 3390 | } |
| 3391 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3392 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3393 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 3394 | try { |
| 3395 | IStatusBarService statusbar = getStatusBarService(); |
| 3396 | if (statusbar != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3397 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3398 | } |
| 3399 | } catch (RemoteException e) { |
| 3400 | Slog.e(TAG, "RemoteException when closing recent apps", e); |
| 3401 | // re-acquire status bar service next time it is needed. |
| 3402 | mStatusBarService = null; |
| 3403 | } |
| 3404 | } |
| 3405 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3406 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3407 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3408 | } |
| 3409 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3410 | /** |
| 3411 | * A home key -> launch home action was detected. Take the appropriate action |
| 3412 | * given the situation with the keyguard. |
| 3413 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3414 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3415 | if (respectKeyguard) { |
| 3416 | if (isKeyguardShowingAndNotOccluded()) { |
| 3417 | // don't launch home if keyguard showing |
| 3418 | return; |
| 3419 | } |
| 3420 | |
| 3421 | if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
| 3422 | // when in keyguard restricted mode, must first verify unlock |
| 3423 | // before launching home |
| 3424 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3425 | @Override |
| 3426 | public void onKeyguardExitResult(boolean success) { |
| 3427 | if (success) { |
| 3428 | try { |
| 3429 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3430 | } catch (RemoteException e) { |
| 3431 | } |
| 3432 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3433 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3434 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3435 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3436 | }); |
| 3437 | return; |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | // no keyguard stuff to worry about, just launch home! |
| 3442 | try { |
| 3443 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3444 | } catch (RemoteException e) { |
| 3445 | } |
| 3446 | if (mRecentsVisible) { |
| 3447 | // Hide Recents and notify it to launch Home |
| 3448 | if (awakenFromDreams) { |
| 3449 | awakenDreams(); |
| 3450 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3451 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3452 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3453 | // Otherwise, just launch Home |
| 3454 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3455 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3456 | } |
| 3457 | } |
| 3458 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3459 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3460 | @Override |
| 3461 | public void run() { |
| 3462 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3463 | // Clear flags. |
| 3464 | mForceClearedSystemUiFlags &= |
| 3465 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3466 | } |
| 3467 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3468 | } |
| 3469 | }; |
| 3470 | |
| 3471 | /** |
| 3472 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3473 | * to determine when the nav bar should be shown and prevent applications from |
| 3474 | * receiving those touches. |
| 3475 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3476 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3477 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3478 | super(inputChannel, looper); |
| 3479 | } |
| 3480 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3481 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3482 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3483 | boolean handled = false; |
| 3484 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3485 | if (event instanceof MotionEvent |
| 3486 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3487 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3488 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3489 | // When the user taps down, we re-show the nav bar. |
| 3490 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3491 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3492 | // Any user activity always causes us to show the |
| 3493 | // navigation controls, if they had been hidden. |
| 3494 | // We also clear the low profile and only content |
| 3495 | // flags so that tapping on the screen will atomically |
| 3496 | // restore all currently hidden screen decorations. |
| 3497 | int newVal = mResettingSystemUiFlags | |
| 3498 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3499 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3500 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3501 | if (mResettingSystemUiFlags != newVal) { |
| 3502 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3503 | changed = true; |
| 3504 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3505 | // We don't allow the system's nav bar to be hidden |
| 3506 | // again for 1 second, to prevent applications from |
| 3507 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3508 | newVal = mForceClearedSystemUiFlags | |
| 3509 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3510 | if (mForceClearedSystemUiFlags != newVal) { |
| 3511 | mForceClearedSystemUiFlags = newVal; |
| 3512 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3513 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3514 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3515 | } |
| 3516 | if (changed) { |
| 3517 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3518 | } |
| 3519 | } |
| 3520 | } |
| 3521 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3522 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3523 | } |
| 3524 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3525 | } |
| 3526 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3527 | new InputEventReceiver.Factory() { |
| 3528 | @Override |
| 3529 | public InputEventReceiver createInputEventReceiver( |
| 3530 | InputChannel inputChannel, Looper looper) { |
| 3531 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3532 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3533 | }; |
| 3534 | |
| 3535 | @Override |
| 3536 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3537 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3538 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3539 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3540 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3541 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3542 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3543 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3544 | // Clear any bits in the new visibility that are currently being |
| 3545 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3546 | return visibility & ~mResettingSystemUiFlags |
| 3547 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3550 | @Override |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3551 | public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation, |
| 3552 | Rect outContentInsets, Rect outStableInsets, Rect outOutsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3553 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3554 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3555 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3556 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3557 | final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl); |
| 3558 | if (useOutsets) { |
| 3559 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 3560 | if (outset > 0) { |
| 3561 | if (displayRotation == Surface.ROTATION_0) { |
| 3562 | outOutsets.bottom += outset; |
| 3563 | } else if (displayRotation == Surface.ROTATION_90) { |
| 3564 | outOutsets.right += outset; |
| 3565 | } else if (displayRotation == Surface.ROTATION_180) { |
| 3566 | outOutsets.top += outset; |
| 3567 | } else if (displayRotation == Surface.ROTATION_270) { |
| 3568 | outOutsets.left += outset; |
| 3569 | } |
| 3570 | } |
| 3571 | } |
| 3572 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3573 | 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] | 3574 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3575 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3576 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3577 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3578 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3579 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3580 | } else { |
| 3581 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3582 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3583 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3584 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3585 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3586 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3587 | availRight - mStableFullscreenRight, |
| 3588 | availBottom - mStableFullscreenBottom); |
| 3589 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3590 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3591 | availRight - mStableRight, availBottom - mStableBottom); |
| 3592 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3593 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3594 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3595 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3596 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3597 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3598 | availRight - mCurRight, availBottom - mCurBottom); |
| 3599 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3600 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3601 | availRight - mCurRight, availBottom - mCurBottom); |
| 3602 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3603 | |
| 3604 | outStableInsets.set(mStableLeft, mStableTop, |
| 3605 | availRight - mStableRight, availBottom - mStableBottom); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3606 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3607 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3608 | outContentInsets.setEmpty(); |
| 3609 | outStableInsets.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3610 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3611 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3612 | private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) { |
| 3613 | return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 3614 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; |
| 3615 | } |
| 3616 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3617 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3618 | @Override |
| 3619 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3620 | int displayRotation, int uiMode) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3621 | mDisplayRotation = displayRotation; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3622 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3623 | if (isDefaultDisplay) { |
| 3624 | switch (displayRotation) { |
| 3625 | case Surface.ROTATION_90: |
| 3626 | overscanLeft = mOverscanTop; |
| 3627 | overscanTop = mOverscanRight; |
| 3628 | overscanRight = mOverscanBottom; |
| 3629 | overscanBottom = mOverscanLeft; |
| 3630 | break; |
| 3631 | case Surface.ROTATION_180: |
| 3632 | overscanLeft = mOverscanRight; |
| 3633 | overscanTop = mOverscanBottom; |
| 3634 | overscanRight = mOverscanLeft; |
| 3635 | overscanBottom = mOverscanTop; |
| 3636 | break; |
| 3637 | case Surface.ROTATION_270: |
| 3638 | overscanLeft = mOverscanBottom; |
| 3639 | overscanTop = mOverscanLeft; |
| 3640 | overscanRight = mOverscanTop; |
| 3641 | overscanBottom = mOverscanRight; |
| 3642 | break; |
| 3643 | default: |
| 3644 | overscanLeft = mOverscanLeft; |
| 3645 | overscanTop = mOverscanTop; |
| 3646 | overscanRight = mOverscanRight; |
| 3647 | overscanBottom = mOverscanBottom; |
| 3648 | break; |
| 3649 | } |
| 3650 | } else { |
| 3651 | overscanLeft = 0; |
| 3652 | overscanTop = 0; |
| 3653 | overscanRight = 0; |
| 3654 | overscanBottom = 0; |
| 3655 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3656 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3657 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3658 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3659 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3660 | mSystemLeft = 0; |
| 3661 | mSystemTop = 0; |
| 3662 | mSystemRight = displayWidth; |
| 3663 | mSystemBottom = displayHeight; |
| 3664 | mUnrestrictedScreenLeft = overscanLeft; |
| 3665 | mUnrestrictedScreenTop = overscanTop; |
| 3666 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3667 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3668 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3669 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3670 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3671 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3672 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3673 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3674 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3675 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3676 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3677 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3678 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3679 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3680 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3681 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3682 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3683 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3684 | final Rect pf = mTmpParentFrame; |
| 3685 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3686 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3687 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3688 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3689 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3690 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3691 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3692 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3693 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3694 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3695 | if (isDefaultDisplay) { |
| 3696 | // For purposes of putting out fake window up to steal focus, we will |
| 3697 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3698 | final int sysui = mLastSystemUiFlags; |
| 3699 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3700 | boolean navTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 3701 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3702 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3703 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3704 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3705 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3706 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3707 | if (!isKeyguardShowing) { |
| 3708 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3709 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3710 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3711 | // When the navigation bar isn't visible, we put up a fake |
| 3712 | // input window to catch all touch events. This way we can |
| 3713 | // detect when the user presses anywhere to bring back the nav |
| 3714 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3715 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3716 | if (mInputConsumer != null) { |
| 3717 | mInputConsumer.dismiss(); |
| 3718 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3719 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3720 | } else if (mInputConsumer == null) { |
| 3721 | mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(), |
| 3722 | mHideNavInputEventReceiverFactory); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3723 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3724 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3725 | // For purposes of positioning and showing the nav bar, if we have |
| 3726 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3727 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3728 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3729 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3730 | boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3731 | displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent, |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3732 | navAllowedHidden); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3733 | 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] | 3734 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3735 | updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3736 | if (updateSysUiVisibility) { |
| 3737 | updateSystemUiVisibilityLw(); |
| 3738 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3739 | } |
| 3740 | } |
| 3741 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3742 | private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui, |
| 3743 | boolean isKeyguardShowing) { |
| 3744 | // decide where the status bar goes ahead of time |
| 3745 | if (mStatusBar != null) { |
| 3746 | // apply any navigation bar insets |
| 3747 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3748 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3749 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3750 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 3751 | + mUnrestrictedScreenTop; |
| 3752 | vf.left = mStableLeft; |
| 3753 | vf.top = mStableTop; |
| 3754 | vf.right = mStableRight; |
| 3755 | vf.bottom = mStableBottom; |
| 3756 | |
| 3757 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 3758 | |
| 3759 | // Let the status bar determine its size. |
| 3760 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 3761 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
| 3762 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */); |
| 3763 | |
| 3764 | // For layout, the status bar is always at the top with our fixed height. |
| 3765 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3766 | |
| 3767 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
| 3768 | boolean statusBarTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 3769 | & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0; |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3770 | if (!isKeyguardShowing) { |
| 3771 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 3772 | } |
| 3773 | |
| 3774 | // If the status bar is hidden, we don't want to cause |
| 3775 | // windows behind it to scroll. |
| 3776 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
| 3777 | // Status bar may go away, so the screen area it occupies |
| 3778 | // is available to apps but just covering them when the |
| 3779 | // status bar is visible. |
| 3780 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3781 | |
| 3782 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3783 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3784 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3785 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 3786 | |
| 3787 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
| 3788 | String.format( |
| 3789 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 3790 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 3791 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 3792 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 3793 | } |
| 3794 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
| 3795 | && !statusBarTransient && !statusBarTranslucent |
| 3796 | && !mStatusBarController.wasRecentlyTranslucent()) { |
| 3797 | // If the opaque status bar is currently requested to be visible, |
| 3798 | // and not in the process of animating on or off, then |
| 3799 | // we can tell the app that it is covered by it. |
| 3800 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 3801 | } |
| 3802 | if (mStatusBarController.checkHiddenLw()) { |
| 3803 | return true; |
| 3804 | } |
| 3805 | } |
| 3806 | return false; |
| 3807 | } |
| 3808 | |
| 3809 | private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3810 | int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible, |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3811 | boolean navTranslucent, boolean navAllowedHidden) { |
| 3812 | if (mNavigationBar != null) { |
| 3813 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
| 3814 | // Force the navigation bar to its appropriate place and |
| 3815 | // size. We need to do this directly, instead of relying on |
| 3816 | // it to bubble up from the nav bar, because this needs to |
| 3817 | // change atomically with screen rotations. |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 3818 | mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3819 | if (mNavigationBarOnBottom) { |
| 3820 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
| 3821 | int top = displayHeight - overscanBottom |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3822 | - getNavigationBarHeight(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3823 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
| 3824 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
| 3825 | if (transientNavBarShowing) { |
| 3826 | mNavigationBarController.setBarShowingLw(true); |
| 3827 | } else if (navVisible) { |
| 3828 | mNavigationBarController.setBarShowingLw(true); |
| 3829 | mDockBottom = mTmpNavigationFrame.top; |
| 3830 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 3831 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
| 3832 | } else { |
| 3833 | // We currently want to hide the navigation UI. |
| 3834 | mNavigationBarController.setBarShowingLw(false); |
| 3835 | } |
| 3836 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3837 | && !mNavigationBar.isAnimatingLw() |
| 3838 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 3839 | // If the opaque nav bar is currently requested to be visible, |
| 3840 | // and not in the process of animating on or off, then |
| 3841 | // we can tell the app that it is covered by it. |
| 3842 | mSystemBottom = mTmpNavigationFrame.top; |
| 3843 | } |
| 3844 | } else { |
| 3845 | // Landscape screen; nav bar goes to the right. |
| 3846 | int left = displayWidth - overscanRight |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3847 | - getNavigationBarWidth(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3848 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
| 3849 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
| 3850 | if (transientNavBarShowing) { |
| 3851 | mNavigationBarController.setBarShowingLw(true); |
| 3852 | } else if (navVisible) { |
| 3853 | mNavigationBarController.setBarShowingLw(true); |
| 3854 | mDockRight = mTmpNavigationFrame.left; |
| 3855 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 3856 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 3857 | } else { |
| 3858 | // We currently want to hide the navigation UI. |
| 3859 | mNavigationBarController.setBarShowingLw(false); |
| 3860 | } |
| 3861 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 3862 | && !mNavigationBar.isAnimatingLw() |
| 3863 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 3864 | // If the nav bar is currently requested to be visible, |
| 3865 | // and not in the process of animating on or off, then |
| 3866 | // we can tell the app that it is covered by it. |
| 3867 | mSystemRight = mTmpNavigationFrame.left; |
| 3868 | } |
| 3869 | } |
| 3870 | // Make sure the content and current rectangles are updated to |
| 3871 | // account for the restrictions from the navigation bar. |
| 3872 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 3873 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 3874 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 3875 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 3876 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 3877 | // And compute the final frame. |
| 3878 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
| 3879 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 3880 | mTmpNavigationFrame, mTmpNavigationFrame); |
| 3881 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
| 3882 | if (mNavigationBarController.checkHiddenLw()) { |
| 3883 | return true; |
| 3884 | } |
| 3885 | } |
| 3886 | return false; |
| 3887 | } |
| 3888 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 3889 | private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) { |
| 3890 | return !mNavigationBarCanMove || displayWidth < displayHeight; |
| 3891 | } |
| 3892 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3893 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3894 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3895 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 3896 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 3897 | return mStatusBar.getSurfaceLayer(); |
| 3898 | } |
| 3899 | |
| 3900 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 3901 | return mNavigationBar.getSurfaceLayer(); |
| 3902 | } |
| 3903 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3904 | return 0; |
| 3905 | } |
| 3906 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 3907 | @Override |
| 3908 | public void getContentRectLw(Rect r) { |
| 3909 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 3910 | } |
| 3911 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3912 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 3913 | 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] | 3914 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 3915 | // Here's a special case: if this attached window is a panel that is |
| 3916 | // above the dock window, and the window it is attached to is below |
| 3917 | // the dock window, then the frames we computed for the window it is |
| 3918 | // attached to can not be used because the dock is effectively part |
| 3919 | // of the underlying window and the attached window is floating on top |
| 3920 | // of the whole thing. So, we ignore the attached window and explicitly |
| 3921 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3922 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3923 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 3924 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 3925 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3926 | } else { |
| 3927 | // The effective display frame of the attached window depends on |
| 3928 | // whether it is taking care of insetting its content. If not, |
| 3929 | // we need to use the parent's content frame so that the entire |
| 3930 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3931 | // 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] | 3932 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3933 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 3934 | // Set the content frame of the attached window to the parent's decor frame |
| 3935 | // (same as content frame when IME isn't present) if specifically requested by |
| 3936 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 3937 | // Otherwise, use the overscan frame. |
| 3938 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 3939 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3940 | } else { |
| 3941 | // If the window is resizing, then we want to base the content |
| 3942 | // frame on our attached content frame to resize... however, |
| 3943 | // things can be tricky if the attached window is NOT in resize |
| 3944 | // mode, in which case its content frame will be larger. |
| 3945 | // Ungh. So to deal with that, make sure the content frame |
| 3946 | // we end up using is not covering the IM dock. |
| 3947 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3948 | if (attached.isVoiceInteraction()) { |
| 3949 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 3950 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 3951 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 3952 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 3953 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3954 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 3955 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 3956 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 3957 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 3958 | } |
| 3959 | } |
| 3960 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3961 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3962 | vf.set(attached.getVisibleFrameLw()); |
| 3963 | } |
| 3964 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 3965 | // window should be positioned relative to its parent or the entire |
| 3966 | // screen. |
| 3967 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 3968 | ? attached.getFrameLw() : df); |
| 3969 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3970 | |
| 3971 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 3972 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3973 | // If app is requesting a stable layout, don't let the |
| 3974 | // content insets go below the stable values. |
| 3975 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 3976 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 3977 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 3978 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 3979 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 3980 | } else { |
| 3981 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 3982 | if (r.top < mStableTop) r.top = mStableTop; |
| 3983 | if (r.right > mStableRight) r.right = mStableRight; |
| 3984 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 3985 | } |
| 3986 | } |
| 3987 | } |
| 3988 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 3989 | private boolean canReceiveInput(WindowState win) { |
| 3990 | boolean notFocusable = |
| 3991 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 3992 | boolean altFocusableIm = |
| 3993 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 3994 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 3995 | return !notFocusableForIm; |
| 3996 | } |
| 3997 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3998 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3999 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4000 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4001 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 4002 | // input, we need to layout it again to accomodate for the IME window. |
| 4003 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4004 | return; |
| 4005 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4006 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4007 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 4008 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4009 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 4010 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4011 | 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] | 4012 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 4013 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4014 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4015 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4016 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 4017 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4018 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4019 | final Rect pf = mTmpParentFrame; |
| 4020 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4021 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4022 | final Rect cf = mTmpContentFrame; |
| 4023 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4024 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4025 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4026 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4027 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4028 | |
| 4029 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4030 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4031 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 4032 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 4033 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4034 | if (isDefaultDisplay) { |
| 4035 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 4036 | } else { |
| 4037 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 4038 | } |
| 4039 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4040 | if (!isDefaultDisplay) { |
| 4041 | if (attached != null) { |
| 4042 | // If this window is attached to another, our display |
| 4043 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4044 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4045 | } else { |
| 4046 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4047 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4048 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4049 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4050 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4051 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4052 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4053 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4054 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4055 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4056 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 4057 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4058 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 4059 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4060 | // ...with content insets above the nav bar |
| 4061 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4062 | // IM dock windows always go to the bottom of the screen. |
| 4063 | attrs.gravity = Gravity.BOTTOM; |
| 4064 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4065 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4066 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4067 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4068 | pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4069 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4070 | cf.bottom = vf.bottom = mStableBottom; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4071 | // Note: In Phone landscape mode, the button bar should also be excluded. |
| 4072 | cf.right = vf.right = mStableRight; |
| 4073 | cf.left = vf.left = mStableLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4074 | cf.top = vf.top = mStableTop; |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4075 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 4076 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4077 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4078 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 4079 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 4080 | cf.left = vf.left = mStableLeft; |
| 4081 | cf.top = vf.top = mStableTop; |
| 4082 | cf.right = vf.right = mStableRight; |
| 4083 | vf.bottom = mStableBottom; |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 4084 | |
| 4085 | if (adjust == SOFT_INPUT_ADJUST_RESIZE) { |
| 4086 | cf.bottom = mContentBottom; |
| 4087 | } else { |
| 4088 | cf.bottom = mDockBottom; |
| 4089 | vf.bottom = mContentBottom; |
| 4090 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4091 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4092 | |
| 4093 | // Default policy decor for the default display |
| 4094 | dcf.left = mSystemLeft; |
| 4095 | dcf.top = mSystemTop; |
| 4096 | dcf.right = mSystemRight; |
| 4097 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4098 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 4099 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 4100 | final boolean isAppWindow = |
| 4101 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 4102 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 4103 | final boolean topAtRest = |
| 4104 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 4105 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4106 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 4107 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4108 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 4109 | && (fl & WindowManager.LayoutParams. |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4110 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
| 4111 | && !mForceWindowDrawsStatusBarBackground) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4112 | // Ensure policy decor includes status bar |
| 4113 | dcf.top = mStableTop; |
| 4114 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4115 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4116 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 4117 | && (fl & WindowManager.LayoutParams. |
| 4118 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4119 | // Ensure policy decor includes navigation bar |
| 4120 | dcf.bottom = mStableBottom; |
| 4121 | dcf.right = mStableRight; |
| 4122 | } |
| 4123 | } |
| 4124 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4125 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 4126 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4127 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4128 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4129 | // This is the case for a normal activity window: we want it |
| 4130 | // to cover all of the screen space, and it can take care of |
| 4131 | // moving its contents to account for screen decorations that |
| 4132 | // intrude into that space. |
| 4133 | if (attached != null) { |
| 4134 | // If this window is attached to another, our display |
| 4135 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4136 | 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] | 4137 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4138 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 4139 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4140 | // Status bar panels are the only windows who can go on top of |
| 4141 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4142 | // permission, so they have the same privileges as the status |
| 4143 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4144 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4145 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4146 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4147 | pf.left = df.left = of.left = hasNavBar |
| 4148 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4149 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4150 | pf.right = df.right = of.right = hasNavBar |
| 4151 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 4152 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4153 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 4154 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 4155 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4156 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4157 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4158 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 4159 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4160 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4161 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4162 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4163 | // Asking to layout into the overscan region, so give it that pure |
| 4164 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4165 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 4166 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 4167 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4168 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 4169 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4170 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4171 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4172 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4173 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4174 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4175 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4176 | // only do this for application windows to ensure no window that |
| 4177 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4178 | pf.left = df.left = mOverscanScreenLeft; |
| 4179 | pf.top = df.top = mOverscanScreenTop; |
| 4180 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4181 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4182 | // We need to tell the app about where the frame inside the overscan |
| 4183 | // is, so it can inset its content by that amount -- it didn't ask |
| 4184 | // to actually extend itself into the overscan region. |
| 4185 | of.left = mUnrestrictedScreenLeft; |
| 4186 | of.top = mUnrestrictedScreenTop; |
| 4187 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4188 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4189 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4190 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 4191 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 4192 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 4193 | + mRestrictedOverscanScreenWidth; |
| 4194 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 4195 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4196 | // We need to tell the app about where the frame inside the overscan |
| 4197 | // is, so it can inset its content by that amount -- it didn't ask |
| 4198 | // to actually extend itself into the overscan region. |
| 4199 | of.left = mUnrestrictedScreenLeft; |
| 4200 | of.top = mUnrestrictedScreenTop; |
| 4201 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4202 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4203 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4204 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4205 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4206 | if (win.isVoiceInteraction()) { |
| 4207 | cf.left = mVoiceContentLeft; |
| 4208 | cf.top = mVoiceContentTop; |
| 4209 | cf.right = mVoiceContentRight; |
| 4210 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4211 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4212 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4213 | cf.left = mDockLeft; |
| 4214 | cf.top = mDockTop; |
| 4215 | cf.right = mDockRight; |
| 4216 | cf.bottom = mDockBottom; |
| 4217 | } else { |
| 4218 | cf.left = mContentLeft; |
| 4219 | cf.top = mContentTop; |
| 4220 | cf.right = mContentRight; |
| 4221 | cf.bottom = mContentBottom; |
| 4222 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4223 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4224 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4225 | // Full screen windows are always given a layout that is as if the |
| 4226 | // status bar and other transient decors are gone. This is to avoid |
| 4227 | // bad states when moving from a window that is not hding the |
| 4228 | // status bar to one that is. |
| 4229 | cf.left = mRestrictedScreenLeft; |
| 4230 | cf.top = mRestrictedScreenTop; |
| 4231 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4232 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4233 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4234 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4235 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4236 | vf.left = mCurLeft; |
| 4237 | vf.top = mCurTop; |
| 4238 | vf.right = mCurRight; |
| 4239 | vf.bottom = mCurBottom; |
| 4240 | } else { |
| 4241 | vf.set(cf); |
| 4242 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4243 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4244 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 4245 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 4246 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4247 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4248 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4249 | // A window that has requested to fill the entire screen just |
| 4250 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4251 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4252 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL |
| 4253 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4254 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 4255 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4256 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4257 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4258 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4259 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4260 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4261 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4262 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4263 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4264 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 4265 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 4266 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 4267 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4268 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4269 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4270 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4271 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 4272 | + mUnrestrictedScreenWidth; |
| 4273 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 4274 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4275 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4276 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 4277 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4278 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 4279 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 4280 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 4281 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4282 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4283 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4284 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4285 | + mOverscanScreenWidth; |
| 4286 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4287 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 4288 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4289 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4290 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4291 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4292 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4293 | + mOverscanScreenWidth; |
| 4294 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4295 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 4296 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4297 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 4298 | // it about the overscan area. |
| 4299 | pf.left = df.left = mOverscanScreenLeft; |
| 4300 | pf.top = df.top = mOverscanScreenTop; |
| 4301 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4302 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 4303 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 4304 | of.top = cf.top = mUnrestrictedScreenTop; |
| 4305 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4306 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4307 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4308 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4309 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4310 | // Asking to layout into the overscan region, so give it that pure |
| 4311 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4312 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4313 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4314 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4315 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4316 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4317 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4318 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4319 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 4320 | && (attrs.type == TYPE_STATUS_BAR |
| 4321 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 4322 | || attrs.type == TYPE_DOCK_DIVIDER |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 4323 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4324 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4325 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4326 | // Asking for layout as if the nav bar is hidden, lets the |
| 4327 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4328 | // 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] | 4329 | // can be above the nav bar can do this. |
| 4330 | // XXX This assumes that an app asking for this will also |
| 4331 | // ask for layout in only content. We can't currently figure out |
| 4332 | // 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] | 4333 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 4334 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4335 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 4336 | + mUnrestrictedScreenWidth; |
| 4337 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 4338 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4339 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4340 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4341 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4342 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4343 | + mRestrictedScreenWidth; |
| 4344 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4345 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4346 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4347 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4348 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4349 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4350 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4351 | vf.left = mCurLeft; |
| 4352 | vf.top = mCurTop; |
| 4353 | vf.right = mCurRight; |
| 4354 | vf.bottom = mCurBottom; |
| 4355 | } else { |
| 4356 | vf.set(cf); |
| 4357 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4358 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4359 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4360 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4361 | // A child window should be placed inside of the same visible |
| 4362 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4363 | 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] | 4364 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4365 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4366 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4367 | // Otherwise, a normal window must be placed inside the content |
| 4368 | // of all screen decorations. |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4369 | if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 4370 | // Status bar panels and the volume dialog are the only windows who can go on |
| 4371 | // top of the status bar. They are protected by the STATUS_BAR_SERVICE |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4372 | // permission, so they have the same privileges as the status |
| 4373 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4374 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4375 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4376 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4377 | + mRestrictedScreenWidth; |
| 4378 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4379 | + mRestrictedScreenHeight; |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4380 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4381 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4382 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 4383 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 4384 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 4385 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4386 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4387 | pf.left = mContentLeft; |
| 4388 | pf.top = mContentTop; |
| 4389 | pf.right = mContentRight; |
| 4390 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 4391 | if (win.isVoiceInteraction()) { |
| 4392 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 4393 | df.top = of.top = cf.top = mVoiceContentTop; |
| 4394 | df.right = of.right = cf.right = mVoiceContentRight; |
| 4395 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 4396 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4397 | df.left = of.left = cf.left = mDockLeft; |
| 4398 | df.top = of.top = cf.top = mDockTop; |
| 4399 | df.right = of.right = cf.right = mDockRight; |
| 4400 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4401 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4402 | df.left = of.left = cf.left = mContentLeft; |
| 4403 | df.top = of.top = cf.top = mContentTop; |
| 4404 | df.right = of.right = cf.right = mContentRight; |
| 4405 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4406 | } |
| 4407 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4408 | vf.left = mCurLeft; |
| 4409 | vf.top = mCurTop; |
| 4410 | vf.right = mCurRight; |
| 4411 | vf.bottom = mCurBottom; |
| 4412 | } else { |
| 4413 | vf.set(cf); |
| 4414 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4415 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4416 | } |
| 4417 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4418 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 4419 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 4420 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4421 | df.left = df.top = -10000; |
| 4422 | df.right = df.bottom = 10000; |
| 4423 | if (attrs.type != TYPE_WALLPAPER) { |
| 4424 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 4425 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 4426 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4427 | } |
| 4428 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4429 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 4430 | // 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] | 4431 | // We only want to apply outsets to certain types of windows. For example, we never want to |
| 4432 | // apply the outsets to floating dialogs, because they wouldn't make sense there. |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4433 | final boolean useOutsets = shouldUseOutsets(attrs, fl); |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 4434 | if (isDefaultDisplay && useOutsets) { |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4435 | osf = mTmpOutsetFrame; |
| 4436 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 4437 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4438 | if (outset > 0) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4439 | int rotation = mDisplayRotation; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4440 | if (rotation == Surface.ROTATION_0) { |
| 4441 | osf.bottom += outset; |
| 4442 | } else if (rotation == Surface.ROTATION_90) { |
| 4443 | osf.right += outset; |
| 4444 | } else if (rotation == Surface.ROTATION_180) { |
| 4445 | osf.top -= outset; |
| 4446 | } else if (rotation == Surface.ROTATION_270) { |
| 4447 | osf.left -= outset; |
| 4448 | } |
| 4449 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 4450 | + " with rotation " + rotation + ", result: " + osf); |
| 4451 | } |
| 4452 | } |
| 4453 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4454 | 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] | 4455 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4456 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4457 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 4458 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4459 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4460 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4461 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4462 | + " sf=" + sf.toShortString() |
| 4463 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4464 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4465 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4466 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4467 | // Dock windows carve out the bottom of the screen, so normal windows |
| 4468 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 4469 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 4470 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4471 | setLastInputMethodWindowLw(null, null); |
| 4472 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4473 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4474 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 4475 | && !win.getGivenInsetsPendingLw()) { |
| 4476 | offsetVoiceInputWindowLw(win); |
| 4477 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4478 | } |
| 4479 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4480 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4481 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4482 | top += win.getGivenContentInsetsLw().top; |
| 4483 | if (mContentBottom > top) { |
| 4484 | mContentBottom = top; |
| 4485 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4486 | if (mVoiceContentBottom > top) { |
| 4487 | mVoiceContentBottom = top; |
| 4488 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4489 | top = win.getVisibleFrameLw().top; |
| 4490 | top += win.getGivenVisibleInsetsLw().top; |
| 4491 | if (mCurBottom > top) { |
| 4492 | mCurBottom = top; |
| 4493 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4494 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4495 | + mDockBottom + " mContentBottom=" |
| 4496 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 4497 | } |
| 4498 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4499 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4500 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 4501 | top += win.getGivenContentInsetsLw().top; |
| 4502 | if (mVoiceContentBottom > top) { |
| 4503 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4504 | } |
| 4505 | } |
| 4506 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4507 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 4508 | @Override |
| 4509 | public void finishLayoutLw() { |
| 4510 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4514 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4515 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4516 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4517 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4518 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4519 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4520 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4521 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4522 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4523 | mForcingShowNavBar = false; |
| 4524 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4525 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4526 | mHideLockScreen = false; |
| 4527 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4528 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4529 | mShowingLockscreen = false; |
| 4530 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4531 | mWinShowWhenLocked = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4532 | mKeyguardSecure = isKeyguardSecure(); |
| 4533 | mKeyguardSecureIncludingHidden = mKeyguardSecure |
| 4534 | && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4535 | } |
| 4536 | |
| 4537 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4538 | @Override |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 4539 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, |
| 4540 | WindowState attached) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4541 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 4542 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4543 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4544 | if (mTopFullscreenOpaqueWindowState == null |
| 4545 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 4546 | mForcingShowNavBar = true; |
| 4547 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4548 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4549 | if (attrs.type == TYPE_STATUS_BAR) { |
| 4550 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 4551 | mForceStatusBarFromKeyguard = true; |
Jorim Jaggi | e1de9f6 | 2015-09-23 14:59:50 -0700 | [diff] [blame] | 4552 | mShowingLockscreen = true; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4553 | } |
| 4554 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 4555 | mForceStatusBarTransparent = true; |
| 4556 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4557 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4558 | |
| 4559 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 4560 | && attrs.type < FIRST_SYSTEM_WINDOW; |
| 4561 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 4562 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
| 4563 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4564 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 4565 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4566 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4567 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4568 | mForceStatusBarFromKeyguard = true; |
| 4569 | } else { |
| 4570 | mForceStatusBar = true; |
| 4571 | } |
| 4572 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4573 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4574 | // If the lockscreen was showing when the dream started then wait |
| 4575 | // for the dream to draw before hiding the lockscreen. |
| 4576 | if (!mDreamingLockscreen |
| 4577 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4578 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4579 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4580 | } |
| 4581 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4582 | |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 4583 | final IApplicationToken appToken = win.getAppToken(); |
| 4584 | |
| 4585 | // For app windows that are not attached, we decide if all windows in the app they |
| 4586 | // represent should be hidden or if we should hide the lockscreen. For attached app |
| 4587 | // windows we defer the decision to the window it is attached to. |
| 4588 | if (appWindow && attached == null) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4589 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4590 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4591 | mAppsToBeHidden.remove(appToken); |
| 4592 | mAppsThatDismissKeyguard.remove(appToken); |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4593 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | 192d604 | 2014-12-02 23:24:48 -0800 | [diff] [blame] | 4594 | if (dismissKeyguard && !mKeyguardSecure) { |
| 4595 | mAppsThatDismissKeyguard.add(appToken); |
Selim Cinek | 90b5e07 | 2015-08-28 17:05:56 -0700 | [diff] [blame] | 4596 | } else if (win.isDrawnLw() || win.hasAppShownWindows()) { |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4597 | mWinShowWhenLocked = win; |
| 4598 | mHideLockScreen = true; |
| 4599 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4600 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4601 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4602 | } else if (dismissKeyguard) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4603 | if (mKeyguardSecure) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4604 | mAppsToBeHidden.add(appToken); |
| 4605 | } else { |
| 4606 | mAppsToBeHidden.remove(appToken); |
| 4607 | } |
| 4608 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4609 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4610 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4611 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4612 | if (attrs.x == 0 && attrs.y == 0 |
| 4613 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4614 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 4615 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4616 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4617 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 4618 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4619 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4620 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4621 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4622 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4623 | "Setting mDismissKeyguard true by win " + win); |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4624 | mDismissKeyguard = (mWinDismissingKeyguard == win |
| 4625 | && mSecureDismissingKeyguard == mKeyguardSecure) |
| 4626 | ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4627 | mWinDismissingKeyguard = win; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4628 | mSecureDismissingKeyguard = mKeyguardSecure; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4629 | mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; |
Selim Cinek | 90b5e07 | 2015-08-28 17:05:56 -0700 | [diff] [blame] | 4630 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked |
| 4631 | && (win.isDrawnLw() || win.hasAppShownWindows())) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4632 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4633 | "Setting mHideLockScreen to true by win " + win); |
| 4634 | mHideLockScreen = true; |
| 4635 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4636 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4637 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4638 | mAllowLockscreenWhenOn = true; |
| 4639 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4640 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4641 | |
| 4642 | if (mWinShowWhenLocked != null && |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4643 | mWinShowWhenLocked.getAppToken() != win.getAppToken() && |
| 4644 | (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4645 | win.hideLw(false); |
| 4646 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4647 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4648 | } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) { |
| 4649 | // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window |
| 4650 | // that is being hidden in an animation - keep the |
| 4651 | // keyguard hidden until the new window shows up and |
| 4652 | // we know whether to show the keyguard or not. |
Adrian Roos | b85e1ec | 2015-05-29 15:23:18 -0700 | [diff] [blame] | 4653 | if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4654 | mHideLockScreen = true; |
| 4655 | mWinShowWhenLocked = win; |
| 4656 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4657 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4658 | if (mTopFullscreenOpaqueOrDimmingWindowState == null |
| 4659 | && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw() |
| 4660 | && win.isDimming()) { |
| 4661 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4662 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4666 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4667 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c5e73bf | 2015-04-21 15:41:26 +0000 | [diff] [blame] | 4668 | if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null && |
| 4669 | mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken() |
| 4670 | && isKeyguardLocked()) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4671 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4672 | // fullscreen window. |
| 4673 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4674 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4675 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4676 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4677 | } |
| 4678 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4679 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4680 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4681 | |
| 4682 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4683 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4684 | : null; |
| 4685 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4686 | // If we are not currently showing a dream then remember the current |
| 4687 | // lockscreen state. We will use this to determine whether the dream |
| 4688 | // started while the lockscreen was showing and remember this state |
| 4689 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4690 | if (!mShowingDream) { |
| 4691 | mDreamingLockscreen = mShowingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 4692 | if (mDreamingSleepTokenNeeded) { |
| 4693 | mDreamingSleepTokenNeeded = false; |
| 4694 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 4695 | } |
| 4696 | } else { |
| 4697 | if (!mDreamingSleepTokenNeeded) { |
| 4698 | mDreamingSleepTokenNeeded = true; |
| 4699 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 4700 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4701 | } |
| 4702 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4703 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4704 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4705 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 4706 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4707 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 4708 | && !mForceStatusBar |
| 4709 | && !mForceStatusBarFromKeyguard; |
| 4710 | if (!shouldBeTransparent) { |
| 4711 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 4712 | } else if (!mStatusBar.isVisibleLw()) { |
| 4713 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 4714 | } |
| 4715 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4716 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4717 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4718 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4719 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4720 | // Maintain fullscreen layout until incoming animation is complete. |
| 4721 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 4722 | // Transient status bar on the lockscreen is not allowed |
| 4723 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 4724 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 4725 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 4726 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4727 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4728 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4729 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4730 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 4731 | + " shown position: " |
| 4732 | + mTopFullscreenOpaqueWindowState.getShownPositionLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4733 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4734 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4735 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4736 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4737 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4738 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 4739 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4740 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 4741 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4742 | if (mStatusBarController.isTransientShowing()) { |
| 4743 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4744 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4745 | } |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 4746 | } else if (topIsFullscreen |
| 4747 | && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID) |
| 4748 | && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4749 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4750 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4751 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4752 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 4753 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 4754 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4755 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4756 | 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] | 4757 | if (mStatusBarController.setBarShowingLw(true)) { |
| 4758 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4759 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4760 | } |
| 4761 | } |
| 4762 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4763 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 4764 | if (mTopIsFullscreen != topIsFullscreen) { |
| 4765 | if (!topIsFullscreen) { |
| 4766 | // Force another layout when status bar becomes fully shown. |
| 4767 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4768 | } |
| 4769 | mTopIsFullscreen = topIsFullscreen; |
| 4770 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4771 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4772 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 4773 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4774 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 4775 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 4776 | + mHideLockScreen); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4777 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4778 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4779 | if (setKeyguardOccludedLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4780 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4781 | | FINISH_LAYOUT_REDO_CONFIG |
| 4782 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4783 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4784 | if (mKeyguardDelegate.isShowing()) { |
| 4785 | mHandler.post(new Runnable() { |
| 4786 | @Override |
| 4787 | public void run() { |
| 4788 | mKeyguardDelegate.keyguardDone(false, false); |
| 4789 | } |
| 4790 | }); |
| 4791 | } |
| 4792 | } else if (mHideLockScreen) { |
| 4793 | mKeyguardHidden = true; |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4794 | mWinDismissingKeyguard = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4795 | if (setKeyguardOccludedLw(true)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4796 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4797 | | FINISH_LAYOUT_REDO_CONFIG |
| 4798 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4799 | } |
| 4800 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 4801 | mKeyguardHidden = false; |
| 4802 | if (setKeyguardOccludedLw(false)) { |
| 4803 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4804 | | FINISH_LAYOUT_REDO_CONFIG |
| 4805 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4806 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4807 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 4808 | // Only launch the next keyguard unlock window once per window. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4809 | mHandler.post(new Runnable() { |
| 4810 | @Override |
| 4811 | public void run() { |
| 4812 | mKeyguardDelegate.dismiss(); |
| 4813 | } |
| 4814 | }); |
| 4815 | } |
| 4816 | } else { |
| 4817 | mWinDismissingKeyguard = null; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4818 | mSecureDismissingKeyguard = false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4819 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4820 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4821 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 4822 | | FINISH_LAYOUT_REDO_CONFIG |
| 4823 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 4824 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 4825 | } |
| 4826 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4827 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4828 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4829 | // If the navigation bar has been hidden or shown, we need to do another |
| 4830 | // layout pass to update that window. |
| 4831 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 4832 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4833 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4834 | // update since mAllowLockscreenWhenOn might have changed |
| 4835 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4836 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4837 | } |
| 4838 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4839 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4840 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4841 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4842 | * @return Whether the flags have changed and we have to redo the layout. |
| 4843 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4844 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
| 4845 | boolean wasOccluded = mKeyguardOccluded; |
| 4846 | boolean showing = mKeyguardDelegate.isShowing(); |
| 4847 | if (wasOccluded && !isOccluded && showing) { |
| 4848 | mKeyguardOccluded = false; |
| 4849 | mKeyguardDelegate.setOccluded(false); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4850 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 4851 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4852 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4853 | } else if (!wasOccluded && isOccluded && showing) { |
| 4854 | mKeyguardOccluded = true; |
| 4855 | mKeyguardDelegate.setOccluded(true); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4856 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 4857 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 4858 | return true; |
| 4859 | } else { |
| 4860 | return false; |
| 4861 | } |
| 4862 | } |
| 4863 | |
| 4864 | private boolean isStatusBarKeyguard() { |
| 4865 | return mStatusBar != null |
| 4866 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 4867 | } |
| 4868 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4869 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4870 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4871 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 4872 | // 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] | 4873 | return false; |
| 4874 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4875 | return true; |
| 4876 | } |
| 4877 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4878 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4879 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4880 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4881 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4882 | // If the navigation bar has been hidden or shown, we need to do another |
| 4883 | // layout pass to update that window. |
| 4884 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 4885 | } |
| 4886 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 4887 | } |
| 4888 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 4889 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 4890 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4891 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 4892 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4893 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 4894 | if (newLidState == mLidState) { |
| 4895 | return; |
| 4896 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4897 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4898 | mLidState = newLidState; |
| 4899 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4900 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4901 | |
| 4902 | if (lidOpen) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4903 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch, |
| 4904 | "android.policy:LID"); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4905 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 4906 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4907 | } |
| 4908 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4909 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4910 | @Override |
| 4911 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 4912 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 4913 | if (mCameraLensCoverState == lensCoverState) { |
| 4914 | return; |
| 4915 | } |
| 4916 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 4917 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 4918 | Intent intent; |
| 4919 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 4920 | mKeyguardDelegate.isShowing(); |
| 4921 | if (keyguardActive) { |
| 4922 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 4923 | } else { |
| 4924 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 4925 | } |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4926 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens, |
| 4927 | "android.policy:CAMERA_COVER"); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 4928 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 4929 | } |
| 4930 | mCameraLensCoverState = lensCoverState; |
| 4931 | } |
| 4932 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4933 | void setHdmiPlugged(boolean plugged) { |
| 4934 | if (mHdmiPlugged != plugged) { |
| 4935 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4936 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4937 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4938 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4939 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 4940 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 4941 | } |
| 4942 | } |
| 4943 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4944 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4945 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4946 | // watch for HDMI plug messages if the hdmi switch exists |
| 4947 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 4948 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 4949 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 4950 | final String filename = "/sys/class/switch/hdmi/state"; |
| 4951 | FileReader reader = null; |
| 4952 | try { |
| 4953 | reader = new FileReader(filename); |
| 4954 | char[] buf = new char[15]; |
| 4955 | int n = reader.read(buf); |
| 4956 | if (n > 1) { |
| 4957 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 4958 | } |
| 4959 | } catch (IOException ex) { |
| 4960 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4961 | } catch (NumberFormatException ex) { |
| 4962 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 4963 | } finally { |
| 4964 | if (reader != null) { |
| 4965 | try { |
| 4966 | reader.close(); |
| 4967 | } catch (IOException ex) { |
| 4968 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4969 | } |
| 4970 | } |
| 4971 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 4972 | // This dance forces the code in setHdmiPlugged to run. |
| 4973 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 4974 | mHdmiPlugged = !plugged; |
| 4975 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 4976 | } |
| 4977 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 4978 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4979 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4980 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4981 | final Runnable mScreenshotTimeout = new Runnable() { |
| 4982 | @Override public void run() { |
| 4983 | synchronized (mScreenshotLock) { |
| 4984 | if (mScreenshotConnection != null) { |
| 4985 | mContext.unbindService(mScreenshotConnection); |
| 4986 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 4987 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4988 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4989 | } |
| 4990 | }; |
| 4991 | |
| 4992 | // Assume this is called from the Handler thread. |
| 4993 | private void takeScreenshot() { |
| 4994 | synchronized (mScreenshotLock) { |
| 4995 | if (mScreenshotConnection != null) { |
| 4996 | return; |
| 4997 | } |
| 4998 | ComponentName cn = new ComponentName("com.android.systemui", |
| 4999 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 5000 | Intent intent = new Intent(); |
| 5001 | intent.setComponent(cn); |
| 5002 | ServiceConnection conn = new ServiceConnection() { |
| 5003 | @Override |
| 5004 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 5005 | synchronized (mScreenshotLock) { |
| 5006 | if (mScreenshotConnection != this) { |
| 5007 | return; |
| 5008 | } |
| 5009 | Messenger messenger = new Messenger(service); |
| 5010 | Message msg = Message.obtain(null, 1); |
| 5011 | final ServiceConnection myConn = this; |
| 5012 | Handler h = new Handler(mHandler.getLooper()) { |
| 5013 | @Override |
| 5014 | public void handleMessage(Message msg) { |
| 5015 | synchronized (mScreenshotLock) { |
| 5016 | if (mScreenshotConnection == myConn) { |
| 5017 | mContext.unbindService(mScreenshotConnection); |
| 5018 | mScreenshotConnection = null; |
| 5019 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 5020 | } |
| 5021 | } |
| 5022 | } |
| 5023 | }; |
| 5024 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 5025 | msg.arg1 = msg.arg2 = 0; |
| 5026 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 5027 | msg.arg1 = 1; |
| 5028 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 5029 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5030 | try { |
| 5031 | messenger.send(msg); |
| 5032 | } catch (RemoteException e) { |
| 5033 | } |
| 5034 | } |
| 5035 | } |
| 5036 | @Override |
| 5037 | public void onServiceDisconnected(ComponentName name) {} |
| 5038 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 5039 | if (mContext.bindServiceAsUser( |
| 5040 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5041 | mScreenshotConnection = conn; |
| 5042 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 5043 | } |
| 5044 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 5045 | } |
| 5046 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5047 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5048 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5049 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5050 | if (!mSystemBooted) { |
| 5051 | // If we have not yet booted, don't let key events do anything. |
| 5052 | return 0; |
| 5053 | } |
| 5054 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5055 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5056 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 5057 | final boolean canceled = event.isCanceled(); |
| 5058 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 5059 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5060 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5061 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 5062 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 5063 | // the same as if it were open and in front. |
| 5064 | // This will prevent any keys other than the power button from waking the screen |
| 5065 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5066 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5067 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5068 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5069 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5070 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5071 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5072 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5073 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5074 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5075 | } |
| 5076 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5077 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5078 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 5079 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 5080 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5081 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5082 | // When the device is interactive or the key is injected pass the |
| 5083 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5084 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5085 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5086 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 5087 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 5088 | // to the application but preserve its wake key status to make sure we still move |
| 5089 | // from dozing to fully interactive if we would normally go from off to fully |
| 5090 | // interactive. |
| 5091 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5092 | } else { |
| 5093 | // When the screen is off and the key is not injected, determine whether |
| 5094 | // to wake the device but don't pass the key to the application. |
| 5095 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5096 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 5097 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5098 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5099 | } |
| 5100 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5101 | // If the key would be handled globally, just return the result, don't worry about special |
| 5102 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5103 | if (isValidGlobalKey(keyCode) |
| 5104 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5105 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5106 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5107 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5108 | return result; |
| 5109 | } |
| 5110 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5111 | boolean useHapticFeedback = down |
| 5112 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 5113 | && event.getRepeatCount() == 0; |
| 5114 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5115 | // Handle special keys. |
| 5116 | switch (keyCode) { |
| 5117 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 5118 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5119 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5120 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 5121 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5122 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5123 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5124 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 5125 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 5126 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5127 | cancelPendingPowerKeyAction(); |
| 5128 | interceptScreenshotChord(); |
| 5129 | } |
| 5130 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5131 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5132 | cancelPendingScreenshotChordAction(); |
| 5133 | } |
| 5134 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 5135 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5136 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5137 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5138 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5139 | cancelPendingPowerKeyAction(); |
| 5140 | cancelPendingScreenshotChordAction(); |
| 5141 | } |
| 5142 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5143 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5144 | cancelPendingScreenshotChordAction(); |
| 5145 | } |
| 5146 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5147 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5148 | TelecomManager telecomManager = getTelecommService(); |
| 5149 | if (telecomManager != null) { |
| 5150 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5151 | // If an incoming call is ringing, either VOLUME key means |
| 5152 | // "silence ringer". We handle these keys here, rather than |
| 5153 | // in the InCallScreen, to make sure we'll respond to them |
| 5154 | // even if the InCallScreen hasn't come to the foreground yet. |
| 5155 | // Look for the DOWN event here, to agree with the "fallback" |
| 5156 | // behavior in the InCallScreen. |
| 5157 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5158 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5159 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5160 | // Silence the ringer. (It's safe to call this |
| 5161 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5162 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5163 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5164 | // And *don't* pass this key thru to the current activity |
| 5165 | // (which is probably the InCallScreen.) |
| 5166 | result &= ~ACTION_PASS_TO_USER; |
| 5167 | break; |
| 5168 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5169 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5170 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 5171 | // 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] | 5172 | // the application, just pass it to the session service. |
| 5173 | |
| 5174 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 5175 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5176 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5177 | } |
| 5178 | } |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 5179 | } |
| 5180 | if (mUseTvRouting) { |
| 5181 | // On TVs, defer special key handlings to |
| 5182 | // {@link interceptKeyBeforeDispatching()}. |
| 5183 | result |= ACTION_PASS_TO_USER; |
| 5184 | } else if ((result & ACTION_PASS_TO_USER) == 0) { |
| 5185 | // If we aren't passing to the user and no one else |
| 5186 | // handled it send it to the session manager to |
| 5187 | // figure out. |
| 5188 | MediaSessionLegacyHelper.getHelper(mContext) |
| 5189 | .sendVolumeKeyEvent(event, true); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5190 | } |
| 5191 | break; |
| 5192 | } |
| 5193 | |
| 5194 | case KeyEvent.KEYCODE_ENDCALL: { |
| 5195 | result &= ~ACTION_PASS_TO_USER; |
| 5196 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5197 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5198 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5199 | if (telecomManager != null) { |
| 5200 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5201 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5202 | if (interactive && !hungUp) { |
| 5203 | mEndCallKeyHandled = false; |
| 5204 | mHandler.postDelayed(mEndCallLongPress, |
| 5205 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 5206 | } else { |
| 5207 | mEndCallKeyHandled = true; |
| 5208 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5209 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5210 | if (!mEndCallKeyHandled) { |
| 5211 | mHandler.removeCallbacks(mEndCallLongPress); |
| 5212 | if (!canceled) { |
| 5213 | if ((mEndcallBehavior |
| 5214 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 5215 | if (goHome()) { |
| 5216 | break; |
| 5217 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 5218 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5219 | if ((mEndcallBehavior |
| 5220 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 5221 | mPowerManager.goToSleep(event.getEventTime(), |
| 5222 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 5223 | isWakeKey = false; |
| 5224 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5225 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5226 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5227 | } |
| 5228 | break; |
| 5229 | } |
| 5230 | |
| 5231 | case KeyEvent.KEYCODE_POWER: { |
| 5232 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5233 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5234 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5235 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5236 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5237 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5238 | } |
| 5239 | break; |
| 5240 | } |
| 5241 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5242 | case KeyEvent.KEYCODE_SLEEP: { |
| 5243 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 5244 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5245 | if (!mPowerManager.isInteractive()) { |
| 5246 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 5247 | } |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 5248 | if (down) { |
| 5249 | sleepPress(event.getEventTime()); |
| 5250 | } else { |
| 5251 | sleepRelease(event.getEventTime()); |
| 5252 | } |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5253 | break; |
| 5254 | } |
| 5255 | |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 5256 | case KeyEvent.KEYCODE_SOFT_SLEEP: { |
| 5257 | result &= ~ACTION_PASS_TO_USER; |
| 5258 | isWakeKey = false; |
| 5259 | if (!down) { |
| 5260 | mPowerManagerInternal.setUserInactiveOverrideFromWindowManager(); |
| 5261 | } |
| 5262 | break; |
| 5263 | } |
| 5264 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5265 | case KeyEvent.KEYCODE_WAKEUP: { |
| 5266 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5267 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5268 | break; |
| 5269 | } |
| 5270 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5271 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5272 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5273 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5274 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5275 | case KeyEvent.KEYCODE_MUTE: |
| 5276 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5277 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5278 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5279 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5280 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5281 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 5282 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5283 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 5284 | // If the global session is active pass all media keys to it |
| 5285 | // instead of the active window. |
| 5286 | result &= ~ACTION_PASS_TO_USER; |
| 5287 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5288 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 5289 | // Only do this if we would otherwise not pass it to the user. In that |
| 5290 | // case, the PhoneWindow class will do the same thing, except it will |
| 5291 | // 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] | 5292 | // Note that we need to make a copy of the key event here because the |
| 5293 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5294 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5295 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 5296 | new KeyEvent(event)); |
| 5297 | msg.setAsynchronous(true); |
| 5298 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5299 | } |
| 5300 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5301 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5302 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5303 | case KeyEvent.KEYCODE_CALL: { |
| 5304 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5305 | TelecomManager telecomManager = getTelecommService(); |
| 5306 | if (telecomManager != null) { |
| 5307 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5308 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5309 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5310 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5311 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5312 | // And *don't* pass this key thru to the current activity |
| 5313 | // (which is presumably the InCallScreen.) |
| 5314 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5315 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5316 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5317 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5318 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5319 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5320 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 5321 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 5322 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 5323 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 5324 | // key event here because the original key event will be recycled when we return. |
| 5325 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 5326 | mBroadcastWakeLock.acquire(); |
| 5327 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 5328 | keyguardActive ? 1 : 0, 0); |
| 5329 | msg.setAsynchronous(true); |
| 5330 | msg.sendToTarget(); |
| 5331 | } |
| 5332 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5333 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5334 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5335 | if (useHapticFeedback) { |
| 5336 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5337 | } |
| 5338 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5339 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5340 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5341 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5342 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5343 | return result; |
| 5344 | } |
| 5345 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5346 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5347 | * Returns true if the key can have global actions attached to it. |
| 5348 | * We reserve all power management keys for the system since they require |
| 5349 | * very careful handling. |
| 5350 | */ |
| 5351 | private static boolean isValidGlobalKey(int keyCode) { |
| 5352 | switch (keyCode) { |
| 5353 | case KeyEvent.KEYCODE_POWER: |
| 5354 | case KeyEvent.KEYCODE_WAKEUP: |
| 5355 | case KeyEvent.KEYCODE_SLEEP: |
| 5356 | return false; |
| 5357 | default: |
| 5358 | return true; |
| 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5363 | * When the screen is off we ignore some keys that might otherwise typically |
| 5364 | * be considered wake keys. We filter them out here. |
| 5365 | * |
| 5366 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 5367 | * is always considered a wake key. |
| 5368 | */ |
| 5369 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 5370 | switch (keyCode) { |
| 5371 | // ignore volume keys unless docked |
| 5372 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5373 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5374 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5375 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 5376 | |
| 5377 | // ignore media and camera keys |
| 5378 | case KeyEvent.KEYCODE_MUTE: |
| 5379 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5380 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5381 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5382 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 5383 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5384 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5385 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5386 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5387 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 5388 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5389 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5390 | case KeyEvent.KEYCODE_CAMERA: |
| 5391 | return false; |
| 5392 | } |
| 5393 | return true; |
| 5394 | } |
| 5395 | |
| 5396 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5397 | /** {@inheritDoc} */ |
| 5398 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5399 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 5400 | if ((policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5401 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion, |
| 5402 | "android.policy:MOTION")) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5403 | return 0; |
| 5404 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5405 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5406 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5407 | if (shouldDispatchInputWhenNonInteractive()) { |
| 5408 | return ACTION_PASS_TO_USER; |
| 5409 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5410 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5411 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 5412 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 5413 | // wake up in this case. |
| 5414 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5415 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming, |
| 5416 | "android.policy:MOTION"); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5417 | } |
| 5418 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5419 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5420 | } |
| 5421 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5422 | private boolean shouldDispatchInputWhenNonInteractive() { |
Joe LaPenna | f2b9b2d | 2015-11-17 22:22:37 +0000 | [diff] [blame] | 5423 | // Send events to keyguard while the screen is on. |
| 5424 | if (isKeyguardShowingAndNotOccluded() && mDisplay != null |
| 5425 | && mDisplay.getState() != Display.STATE_OFF) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5426 | return true; |
| 5427 | } |
| 5428 | |
| 5429 | // Send events to a dozing dream even if the screen is off since the dream |
| 5430 | // is in control of the state of the screen. |
| 5431 | IDreamManager dreamManager = getDreamManager(); |
| 5432 | |
| 5433 | try { |
| 5434 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 5435 | return true; |
| 5436 | } |
| 5437 | } catch (RemoteException e) { |
| 5438 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 5439 | } |
| 5440 | |
| 5441 | // Otherwise, consume events since the user can't see what is being |
| 5442 | // interacted with. |
| 5443 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5444 | } |
| 5445 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5446 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 5447 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 5448 | return; |
| 5449 | } |
| 5450 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 5451 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 5452 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5453 | String pkgName = mContext.getOpPackageName(); |
| 5454 | switch (keyCode) { |
| 5455 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5456 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5457 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5458 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5459 | } catch (RemoteException e) { |
| 5460 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 5461 | } |
| 5462 | break; |
| 5463 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5464 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5465 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5466 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5467 | } catch (RemoteException e) { |
| 5468 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 5469 | } |
| 5470 | break; |
| 5471 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5472 | try { |
| 5473 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5474 | getAudioService().adjustSuggestedStreamVolume( |
| 5475 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5476 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5477 | } |
| 5478 | } catch (RemoteException e) { |
| 5479 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 5480 | } |
| 5481 | break; |
| 5482 | } |
| 5483 | } |
| 5484 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5485 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 5486 | if (DEBUG_INPUT) { |
| 5487 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5488 | } |
| 5489 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5490 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 5491 | if (DEBUG_INPUT) { |
| 5492 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 5493 | } |
| 5494 | |
| 5495 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 5496 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5497 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 5498 | } |
| 5499 | |
| 5500 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 5501 | |
| 5502 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5503 | && event.getRepeatCount() == 0) { |
| 5504 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 5505 | |
| 5506 | Message msg = mHandler.obtainMessage( |
| 5507 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 5508 | msg.setAsynchronous(true); |
| 5509 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 5510 | } else { |
| 5511 | mBroadcastWakeLock.release(); |
| 5512 | } |
| 5513 | } |
| 5514 | |
| 5515 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 5516 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5517 | |
| 5518 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 5519 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 5520 | if (DEBUG_INPUT) { |
| 5521 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 5522 | } |
| 5523 | |
| 5524 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 5525 | mBroadcastWakeLock.release(); |
| 5526 | } |
| 5527 | |
| 5528 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 5529 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5530 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5531 | } |
| 5532 | } |
| 5533 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5534 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 5535 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 5536 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 5537 | if (dic != null) { |
| 5538 | try { |
| 5539 | dic.exitIdle("voice-search"); |
| 5540 | } catch (RemoteException e) { |
| 5541 | } |
| 5542 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5543 | Intent voiceIntent = |
| 5544 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 5545 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5546 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5547 | mBroadcastWakeLock.release(); |
| 5548 | } |
| 5549 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5550 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5551 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5552 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 5553 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 5554 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 5555 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5556 | } else { |
| 5557 | try { |
| 5558 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 5559 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5560 | mUiMode = uiModeService.getCurrentModeType(); |
| 5561 | } catch (RemoteException e) { |
| 5562 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 5563 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5564 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5565 | synchronized (mLock) { |
| 5566 | updateOrientationListenerLp(); |
| 5567 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5568 | } |
| 5569 | }; |
| 5570 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5571 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 5572 | @Override |
| 5573 | public void onReceive(Context context, Intent intent) { |
| 5574 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5575 | if (mKeyguardDelegate != null) { |
| 5576 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5577 | } |
| 5578 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5579 | if (mKeyguardDelegate != null) { |
| 5580 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5581 | } |
| 5582 | } |
| 5583 | } |
| 5584 | }; |
| 5585 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5586 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 5587 | @Override |
| 5588 | public void onReceive(Context context, Intent intent) { |
| 5589 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 5590 | // tickle the settings observer: this first ensures that we're |
| 5591 | // observing the relevant settings for the newly-active user, |
| 5592 | // and then updates our own bookkeeping based on the now- |
| 5593 | // current user. |
| 5594 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5595 | |
| 5596 | // force a re-application of focused window sysui visibility. |
| 5597 | // the window may never have been shown for this user |
| 5598 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5599 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5600 | mLastSystemUiFlags = 0; |
| 5601 | updateSystemUiVisibilityLw(); |
| 5602 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5603 | } |
| 5604 | } |
| 5605 | }; |
| 5606 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5607 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5608 | @Override |
| 5609 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5610 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 5611 | if (!isUserSetupComplete()) { |
| 5612 | // Swipe-up for navigation bar is disabled during setup |
| 5613 | return; |
| 5614 | } |
| 5615 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
| 5616 | mNavigationBarController.showTransient(); |
| 5617 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5618 | } |
| 5619 | }; |
| 5620 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5621 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5622 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5623 | if (!isUserSetupComplete()) { |
| 5624 | // Swipe-up for navigation bar is disabled during setup |
| 5625 | return; |
| 5626 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5627 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 5628 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5629 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 5630 | // Don't show status bar when swiping on already visible navigation bar |
| 5631 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5632 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5633 | return; |
| 5634 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5635 | if (sb) mStatusBarController.showTransient(); |
| 5636 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5637 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5638 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5639 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5640 | } |
| 5641 | } |
| 5642 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5643 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5644 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5645 | public void startedGoingToSleep(int why) { |
| 5646 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5647 | if (mKeyguardDelegate != null) { |
| 5648 | mKeyguardDelegate.onStartedGoingToSleep(why); |
| 5649 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | // Called on the PowerManager's Notifier thread. |
| 5653 | @Override |
| 5654 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5655 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5656 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Chris Wren | 9bb290b | 2015-06-29 12:02:13 -0400 | [diff] [blame] | 5657 | MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5658 | |
| 5659 | // We must get this work done here because the power manager will drop |
| 5660 | // 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] | 5661 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5662 | mAwake = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5663 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5664 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5665 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5666 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5667 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 5668 | mKeyguardDelegate.onFinishedGoingToSleep(why); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5669 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5670 | } |
| 5671 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5672 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5673 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5674 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 5675 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5676 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5677 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5678 | // Since goToSleep performs these functions synchronously, we must |
| 5679 | // do the same here. We cannot post this work to a handler because |
| 5680 | // that might cause it to become reordered with respect to what |
| 5681 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5682 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5683 | mAwake = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5684 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 5685 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5686 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5687 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5688 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5689 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5690 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5691 | mKeyguardDelegate.onStartedWakingUp(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5692 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5693 | } |
| 5694 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5695 | // Called on the PowerManager's Notifier thread. |
| 5696 | @Override |
| 5697 | public void finishedWakingUp() { |
| 5698 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
| 5699 | } |
| 5700 | |
| 5701 | private void wakeUpFromPowerKey(long eventTime) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5702 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER"); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5703 | } |
| 5704 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5705 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) { |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 5706 | final boolean theaterModeEnabled = isTheaterModeEnabled(); |
| 5707 | if (!wakeInTheaterMode && theaterModeEnabled) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5708 | return false; |
| 5709 | } |
| 5710 | |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 5711 | if (theaterModeEnabled) { |
| 5712 | Settings.Global.putInt(mContext.getContentResolver(), |
| 5713 | Settings.Global.THEATER_MODE_ON, 0); |
| 5714 | } |
| 5715 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5716 | mPowerManager.wakeUp(wakeTime, reason); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 5717 | return true; |
| 5718 | } |
| 5719 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5720 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5721 | synchronized (mLock) { |
Jorim Jaggi | f325548 | 2015-07-24 12:32:42 -0700 | [diff] [blame] | 5722 | if (!mScreenOnEarly || mKeyguardDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5723 | 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] | 5724 | } |
| 5725 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5726 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5727 | if (mKeyguardDelegate != null) { |
| 5728 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5729 | } |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5730 | mWindowManagerDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5731 | } |
| 5732 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5733 | // ... eventually calls finishWindowsDrawn which will finalize our screen turn on |
| 5734 | // as well as enabling the orientation change logic/sensor. |
| 5735 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 5736 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5740 | @Override |
| 5741 | public void screenTurnedOff() { |
| 5742 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 5743 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 5744 | updateScreenOffSleepToken(true); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5745 | synchronized (mLock) { |
| 5746 | mScreenOnEarly = false; |
| 5747 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 5748 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5749 | mWindowManagerDrawComplete = false; |
| 5750 | mScreenOnListener = null; |
| 5751 | updateOrientationListenerLp(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 5752 | |
| 5753 | if (mKeyguardDelegate != null) { |
| 5754 | mKeyguardDelegate.onScreenTurnedOff(); |
| 5755 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5756 | } |
| 5757 | } |
| 5758 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5759 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5760 | @Override |
| 5761 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5762 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5763 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 5764 | updateScreenOffSleepToken(false); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5765 | synchronized (mLock) { |
| 5766 | mScreenOnEarly = true; |
| 5767 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 5768 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5769 | mWindowManagerDrawComplete = false; |
| 5770 | mScreenOnListener = screenOnListener; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5771 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5772 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | a4b51bc | 2015-08-10 18:20:43 -0700 | [diff] [blame] | 5773 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 5774 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 5775 | mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback); |
| 5776 | } else { |
| 5777 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5778 | "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 5779 | finishKeyguardDrawn(); |
| 5780 | } |
| 5781 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 5784 | // Called on the DisplayManager's DisplayPowerController thread. |
| 5785 | @Override |
| 5786 | public void screenTurnedOn() { |
| 5787 | synchronized (mLock) { |
| 5788 | if (mKeyguardDelegate != null) { |
| 5789 | mKeyguardDelegate.onScreenTurnedOn(); |
| 5790 | } |
| 5791 | } |
| 5792 | } |
| 5793 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5794 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5795 | synchronized (mLock) { |
| 5796 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5797 | 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] | 5798 | } |
| 5799 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5800 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5801 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5802 | |
| 5803 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5804 | } |
| 5805 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 5806 | private void finishScreenTurningOn() { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 5807 | synchronized (mLock) { |
| 5808 | // We have just finished drawing screen content. Since the orientation listener |
| 5809 | // gets only installed when all windows are drawn, we try to install it again. |
| 5810 | updateOrientationListenerLp(); |
| 5811 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5812 | final ScreenOnListener listener; |
| 5813 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5814 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5815 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 5816 | "finishScreenTurningOn: mAwake=" + mAwake |
| 5817 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 5818 | + ", mScreenOnFully=" + mScreenOnFully |
| 5819 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 5820 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 5821 | |
| 5822 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 5823 | || (mAwake && !mKeyguardDrawComplete)) { |
| 5824 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5825 | } |
| 5826 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5827 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 5828 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 5829 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5830 | mScreenOnFully = true; |
| 5831 | |
| 5832 | // Remember the first time we draw the keyguard so we know when we're done with |
| 5833 | // the main part of booting and can enable the screen and hide boot messages. |
| 5834 | if (!mKeyguardDrawnOnce && mAwake) { |
| 5835 | mKeyguardDrawnOnce = true; |
| 5836 | enableScreen = true; |
| 5837 | if (mBootMessageNeedsHiding) { |
| 5838 | mBootMessageNeedsHiding = false; |
| 5839 | hideBootMessages(); |
| 5840 | } |
| 5841 | } else { |
| 5842 | enableScreen = false; |
| 5843 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5844 | } |
| 5845 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5846 | if (listener != null) { |
| 5847 | listener.onScreenOn(); |
| 5848 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 5849 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5850 | if (enableScreen) { |
| 5851 | try { |
| 5852 | mWindowManager.enableScreenIfNeeded(); |
| 5853 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 5854 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5855 | } |
| 5856 | } |
| 5857 | |
| 5858 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5859 | synchronized (mLock) { |
| 5860 | if (!mKeyguardDrawnOnce) { |
| 5861 | mBootMessageNeedsHiding = true; |
| 5862 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 5863 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5864 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5865 | |
| 5866 | if (mBootMsgDialog != null) { |
| 5867 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 5868 | mBootMsgDialog.dismiss(); |
| 5869 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 5870 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5871 | } |
| 5872 | |
| 5873 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5874 | public boolean isScreenOn() { |
| 5875 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5876 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5877 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5878 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5879 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5880 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5881 | if (mKeyguardDelegate != null) { |
| 5882 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5883 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5884 | } |
| 5885 | |
| 5886 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5887 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5888 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5889 | if (mKeyguardDelegate != null) { |
| 5890 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 5891 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5892 | } |
| 5893 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5894 | private boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5895 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5896 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5897 | } |
| 5898 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5899 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5900 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5901 | public boolean isKeyguardLocked() { |
| 5902 | return keyguardOn(); |
| 5903 | } |
| 5904 | |
| 5905 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5906 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5907 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5908 | if (mKeyguardDelegate == null) return false; |
| 5909 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 5910 | } |
| 5911 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5912 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5913 | @Override |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 5914 | public boolean isKeyguardShowingOrOccluded() { |
| 5915 | return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing(); |
| 5916 | } |
| 5917 | |
| 5918 | /** {@inheritDoc} */ |
| 5919 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5920 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5921 | if (mKeyguardDelegate == null) return false; |
| 5922 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5923 | } |
| 5924 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5925 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5926 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 5927 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5928 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5929 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5930 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5931 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 5932 | // ask the keyguard to prompt the user to authenticate if necessary |
| 5933 | mKeyguardDelegate.dismiss(); |
| 5934 | } |
| 5935 | }); |
| 5936 | } |
| 5937 | } |
| 5938 | |
| 5939 | public void notifyActivityDrawnForKeyguardLw() { |
| 5940 | if (mKeyguardDelegate != null) { |
| 5941 | mHandler.post(new Runnable() { |
| 5942 | @Override |
| 5943 | public void run() { |
| 5944 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 5945 | } |
| 5946 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 5947 | } |
| 5948 | } |
| 5949 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5950 | @Override |
| 5951 | public boolean isKeyguardDrawnLw() { |
| 5952 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 5953 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 5954 | } |
| 5955 | } |
| 5956 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5957 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5958 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5959 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 5960 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 5961 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 5962 | } |
| 5963 | } |
| 5964 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 5965 | @Override |
| 5966 | public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 5967 | Rect outInsets) { |
| 5968 | outInsets.setEmpty(); |
| 5969 | if (mStatusBar != null) { |
| 5970 | outInsets.top = mStatusBarHeight; |
| 5971 | } |
| 5972 | if (mNavigationBar != null) { |
| 5973 | if (isNavigationBarOnBottom(displayWidth, displayHeight)) { |
| 5974 | outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode); |
| 5975 | } else { |
| 5976 | outInsets.right = getNavigationBarWidth(displayRotation, mUiMode); |
| 5977 | } |
| 5978 | } |
| 5979 | } |
| 5980 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5981 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5982 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 5986 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5987 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 5988 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5989 | @Override |
| 5990 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5991 | if (false) { |
| 5992 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 5993 | + orientation + ", last=" + lastRotation |
| 5994 | + "); user=" + mUserRotation + " " |
| 5995 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 5996 | ? "USER_ROTATION_LOCKED" : "") |
| 5997 | ); |
| 5998 | } |
| 5999 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 6000 | if (mForceDefaultOrientation) { |
| 6001 | return Surface.ROTATION_0; |
| 6002 | } |
| 6003 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6004 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6005 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 6006 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 6007 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6008 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6009 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6010 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6011 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6012 | // Ignore sensor when lid switch is open and rotation is forced. |
| 6013 | preferredRotation = mLidOpenRotation; |
| 6014 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6015 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6016 | // Ignore sensor when in car dock unless explicitly enabled. |
| 6017 | // This case can override the behavior of NOSENSOR, and can also |
| 6018 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6019 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6020 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 6021 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6022 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 6023 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6024 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6025 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 6026 | // This case can override the behavior of NOSENSOR, and can also |
| 6027 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6028 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6029 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6030 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 6031 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 6032 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6033 | preferredRotation = mDemoHdmiRotation; |
| 6034 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 6035 | && mUndockedHdmiRotation >= 0) { |
| 6036 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 6037 | // been specified in the configuration (only for legacy devices without |
| 6038 | // full multi-display support). |
| 6039 | // Note that the dock orientation overrides the HDMI orientation. |
| 6040 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 6041 | } else if (mDemoRotationLock) { |
| 6042 | // Ignore sensor when demo rotation lock is enabled. |
| 6043 | // Note that the dock orientation and HDMI rotation lock override this. |
| 6044 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6045 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 6046 | // Application just wants to remain locked in the last rotation. |
| 6047 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6048 | } else if (!mSupportAutoRotation) { |
| 6049 | // If we don't support auto-rotation then bail out here and ignore |
| 6050 | // the sensor and any rotation lock settings. |
| 6051 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6052 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6053 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6054 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 6055 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 6056 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 6057 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6058 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 6059 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6060 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 6061 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 6062 | // Otherwise, use sensor only if requested by the application or enabled |
| 6063 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6064 | if (mAllowAllRotations < 0) { |
| 6065 | // Can't read this during init() because the context doesn't |
| 6066 | // have display metrics at that time so we cannot determine |
| 6067 | // tablet vs. phone then. |
| 6068 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 6069 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 6070 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6071 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6072 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6073 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6074 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6075 | preferredRotation = sensorRotation; |
| 6076 | } else { |
| 6077 | preferredRotation = lastRotation; |
| 6078 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6079 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 6080 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 6081 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 6082 | // The idea is that the user rotation expresses a weak preference for the direction |
| 6083 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 6084 | // 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] | 6085 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6086 | } else { |
| 6087 | // No overriding preference. |
| 6088 | // We will do exactly what the application asked us to do. |
| 6089 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6090 | } |
| 6091 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6092 | switch (orientation) { |
| 6093 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6094 | // Return portrait unless overridden. |
| 6095 | if (isAnyPortrait(preferredRotation)) { |
| 6096 | return preferredRotation; |
| 6097 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6098 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6099 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6100 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6101 | // Return landscape unless overridden. |
| 6102 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6103 | return preferredRotation; |
| 6104 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6105 | return mLandscapeRotation; |
| 6106 | |
| 6107 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6108 | // Return reverse portrait unless overridden. |
| 6109 | if (isAnyPortrait(preferredRotation)) { |
| 6110 | return preferredRotation; |
| 6111 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6112 | return mUpsideDownRotation; |
| 6113 | |
| 6114 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6115 | // Return seascape unless overridden. |
| 6116 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6117 | return preferredRotation; |
| 6118 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6119 | return mSeascapeRotation; |
| 6120 | |
| 6121 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6122 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6123 | // Return either landscape rotation. |
| 6124 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6125 | return preferredRotation; |
| 6126 | } |
| 6127 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 6128 | return lastRotation; |
| 6129 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6130 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6131 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6132 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6133 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6134 | // Return either portrait rotation. |
| 6135 | if (isAnyPortrait(preferredRotation)) { |
| 6136 | return preferredRotation; |
| 6137 | } |
| 6138 | if (isAnyPortrait(lastRotation)) { |
| 6139 | return lastRotation; |
| 6140 | } |
| 6141 | return mPortraitRotation; |
| 6142 | |
| 6143 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 6144 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 6145 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6146 | if (preferredRotation >= 0) { |
| 6147 | return preferredRotation; |
| 6148 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6149 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 6150 | } |
| 6151 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6152 | } |
| 6153 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6154 | @Override |
| 6155 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 6156 | switch (orientation) { |
| 6157 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 6158 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 6159 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 6160 | return isAnyPortrait(rotation); |
| 6161 | |
| 6162 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 6163 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 6164 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 6165 | return isLandscapeOrSeascape(rotation); |
| 6166 | |
| 6167 | default: |
| 6168 | return true; |
| 6169 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6170 | } |
| 6171 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6172 | @Override |
| 6173 | public void setRotationLw(int rotation) { |
| 6174 | mOrientationListener.setCurrentRotation(rotation); |
| 6175 | } |
| 6176 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6177 | private boolean isLandscapeOrSeascape(int rotation) { |
| 6178 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6179 | } |
| 6180 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6181 | private boolean isAnyPortrait(int rotation) { |
| 6182 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6183 | } |
| 6184 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6185 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6186 | public int getUserRotationMode() { |
| 6187 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 6188 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 6189 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 6190 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6191 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6192 | |
| 6193 | // 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] | 6194 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6195 | public void setUserRotationMode(int mode, int rot) { |
| 6196 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6197 | |
| 6198 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6199 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6200 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6201 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6202 | rot, |
| 6203 | UserHandle.USER_CURRENT); |
| 6204 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6205 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6206 | 0, |
| 6207 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6208 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6209 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6210 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6211 | 1, |
| 6212 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6213 | } |
| 6214 | } |
| 6215 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6216 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6217 | public void setSafeMode(boolean safeMode) { |
| 6218 | mSafeMode = safeMode; |
| 6219 | performHapticFeedbackLw(null, safeMode |
| 6220 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 6221 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6222 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6223 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 6224 | static long[] getLongIntArray(Resources r, int resid) { |
| 6225 | int[] ar = r.getIntArray(resid); |
| 6226 | if (ar == null) { |
| 6227 | return null; |
| 6228 | } |
| 6229 | long[] out = new long[ar.length]; |
| 6230 | for (int i=0; i<ar.length; i++) { |
| 6231 | out[i] = ar[i]; |
| 6232 | } |
| 6233 | return out; |
| 6234 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6235 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6236 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6237 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6238 | public void systemReady() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6239 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 6240 | mKeyguardDelegate.onSystemReady(); |
| 6241 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6242 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6243 | updateUiMode(); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6244 | boolean bindKeyguardNow; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6245 | synchronized (mLock) { |
| 6246 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6247 | mSystemReady = true; |
| 6248 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6249 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6250 | public void run() { |
| 6251 | updateSettings(); |
| 6252 | } |
| 6253 | }); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6254 | |
| 6255 | bindKeyguardNow = mDeferBindKeyguard; |
| 6256 | if (bindKeyguardNow) { |
| 6257 | // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now. |
| 6258 | mDeferBindKeyguard = false; |
| 6259 | } |
| 6260 | } |
| 6261 | |
| 6262 | if (bindKeyguardNow) { |
| 6263 | mKeyguardDelegate.bindService(mContext); |
| 6264 | mKeyguardDelegate.onBootCompleted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6265 | } |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 6266 | mSystemGestures.systemReady(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6267 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6268 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6269 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6270 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6271 | public void systemBooted() { |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6272 | boolean bindKeyguardNow = false; |
| 6273 | synchronized (mLock) { |
| 6274 | // Time to bind Keyguard; take care to only bind it once, either here if ready or |
| 6275 | // in systemReady if not. |
| 6276 | if (mKeyguardDelegate != null) { |
| 6277 | bindKeyguardNow = true; |
| 6278 | } else { |
| 6279 | // Because mKeyguardDelegate is null, we know that the synchronized block in |
| 6280 | // systemReady didn't run yet and setting this will actually have an effect. |
| 6281 | mDeferBindKeyguard = true; |
| 6282 | } |
| 6283 | } |
| 6284 | if (bindKeyguardNow) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 6285 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 6286 | mKeyguardDelegate.onBootCompleted(); |
| 6287 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6288 | synchronized (mLock) { |
| 6289 | mSystemBooted = true; |
| 6290 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6291 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6292 | screenTurningOn(null); |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 6293 | screenTurnedOn(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6294 | } |
| 6295 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6296 | ProgressDialog mBootMsgDialog = null; |
| 6297 | |
| 6298 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6299 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6300 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 6301 | mHandler.post(new Runnable() { |
| 6302 | @Override public void run() { |
| 6303 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 6304 | int theme; |
| 6305 | if (mContext.getPackageManager().hasSystemFeature( |
| 6306 | PackageManager.FEATURE_WATCH)) { |
| 6307 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
| 6308 | } else if (mContext.getPackageManager().hasSystemFeature( |
| 6309 | PackageManager.FEATURE_TELEVISION)) { |
| 6310 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 6311 | } else { |
| 6312 | theme = 0; |
| 6313 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 6314 | |
| 6315 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 6316 | // This dialog will consume all events coming in to |
| 6317 | // it, to avoid it trying to do things too early in boot. |
| 6318 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 6319 | return true; |
| 6320 | } |
| 6321 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 6322 | return true; |
| 6323 | } |
| 6324 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 6325 | return true; |
| 6326 | } |
| 6327 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 6328 | return true; |
| 6329 | } |
| 6330 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 6331 | return true; |
| 6332 | } |
| 6333 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 6334 | AccessibilityEvent event) { |
| 6335 | return true; |
| 6336 | } |
| 6337 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 6338 | if (mContext.getPackageManager().isUpgrade()) { |
| 6339 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 6340 | } else { |
| 6341 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 6342 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6343 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 6344 | mBootMsgDialog.setIndeterminate(true); |
| 6345 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 6346 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6347 | mBootMsgDialog.getWindow().addFlags( |
| 6348 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 6349 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 6350 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 6351 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 6352 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 6353 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6354 | mBootMsgDialog.setCancelable(false); |
| 6355 | mBootMsgDialog.show(); |
| 6356 | } |
| 6357 | mBootMsgDialog.setMessage(msg); |
| 6358 | } |
| 6359 | }); |
| 6360 | } |
| 6361 | |
| 6362 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6363 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6364 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6365 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6366 | } |
| 6367 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6368 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6369 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6370 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6371 | // *************************************** |
| 6372 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 6373 | // *************************************** |
| 6374 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 6375 | // WITH ITS LOCKS HELD. |
| 6376 | // |
| 6377 | // This code must be VERY careful about the locks |
| 6378 | // it acquires. |
| 6379 | // In fact, the current code acquires way too many, |
| 6380 | // and probably has lurking deadlocks. |
| 6381 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6382 | synchronized (mScreenLockTimeout) { |
| 6383 | if (mLockScreenTimerActive) { |
| 6384 | // reset the timer |
| 6385 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6386 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6387 | } |
| 6388 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6389 | } |
| 6390 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6391 | class ScreenLockTimeout implements Runnable { |
| 6392 | Bundle options; |
| 6393 | |
| 6394 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6395 | public void run() { |
| 6396 | synchronized (this) { |
| 6397 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6398 | if (mKeyguardDelegate != null) { |
| 6399 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6400 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6401 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6402 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6403 | } |
| 6404 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6405 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6406 | public void setLockOptions(Bundle options) { |
| 6407 | this.options = options; |
| 6408 | } |
| 6409 | } |
| 6410 | |
| 6411 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 6412 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6413 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6414 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6415 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 6416 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6417 | if (options != null) { |
| 6418 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 6419 | // until the runnable actually executes. |
| 6420 | mScreenLockTimeout.setLockOptions(options); |
| 6421 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6422 | mHandler.post(mScreenLockTimeout); |
| 6423 | } |
| 6424 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6425 | private void updateLockScreenTimeout() { |
| 6426 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6427 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6428 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6429 | if (mLockScreenTimerActive != enable) { |
| 6430 | if (enable) { |
| 6431 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 6432 | mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6433 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6434 | } else { |
| 6435 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 6436 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6437 | } |
| 6438 | mLockScreenTimerActive = enable; |
| 6439 | } |
| 6440 | } |
| 6441 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6442 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6443 | private void updateDreamingSleepToken(boolean acquire) { |
| 6444 | if (acquire) { |
| 6445 | if (mDreamingSleepToken == null) { |
| 6446 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 6447 | } |
| 6448 | } else { |
| 6449 | if (mDreamingSleepToken != null) { |
| 6450 | mDreamingSleepToken.release(); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6451 | mDreamingSleepToken = null; |
| 6452 | } |
| 6453 | } |
| 6454 | } |
| 6455 | |
| 6456 | private void updateScreenOffSleepToken(boolean acquire) { |
| 6457 | if (acquire) { |
| 6458 | if (mScreenOffSleepToken == null) { |
| 6459 | mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff"); |
| 6460 | } |
| 6461 | } else { |
| 6462 | if (mScreenOffSleepToken != null) { |
| 6463 | mScreenOffSleepToken.release(); |
| 6464 | mScreenOffSleepToken = null; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6465 | } |
| 6466 | } |
| 6467 | } |
| 6468 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6469 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6470 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6471 | public void enableScreenAfterBoot() { |
| 6472 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6473 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6474 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6475 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 6476 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6477 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6478 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6479 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 6480 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6481 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 6482 | } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) { |
| 6483 | mWindowManagerFuncs.lockDeviceNow(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6484 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6485 | |
| 6486 | synchronized (mLock) { |
| 6487 | updateWakeGestureListenerLp(); |
| 6488 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6489 | } |
| 6490 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6491 | void updateUiMode() { |
| 6492 | if (mUiModeManager == null) { |
| 6493 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 6494 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 6495 | } |
| 6496 | try { |
| 6497 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 6498 | } catch (RemoteException e) { |
| 6499 | } |
| 6500 | } |
| 6501 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6502 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6503 | try { |
| 6504 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 6505 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 6506 | } catch (RemoteException e) { |
| 6507 | // Ignore |
| 6508 | } |
| 6509 | } |
| 6510 | |
| 6511 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 6512 | try { |
| 6513 | //set orientation on WindowManager |
| 6514 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6515 | } catch (RemoteException e) { |
| 6516 | // Ignore |
| 6517 | } |
| 6518 | } |
| 6519 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6520 | /** |
| 6521 | * Return an Intent to launch the currently active dock app as home. Returns |
| 6522 | * null if the standard home should be launched, which is the case if any of the following is |
| 6523 | * true: |
| 6524 | * <ul> |
| 6525 | * <li>The device is not in either car mode or desk mode |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 6526 | * <li>The device is in car mode but mEnableCarDockHomeCapture is false |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6527 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 6528 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 6529 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 6530 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6531 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6532 | */ |
| 6533 | Intent createHomeDockIntent() { |
| 6534 | Intent intent = null; |
| 6535 | |
| 6536 | // What home does is based on the mode, not the dock state. That |
| 6537 | // is, when in car mode you should be taken to car home regardless |
| 6538 | // of whether we are actually in a car dock. |
| 6539 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 6540 | if (mEnableCarDockHomeCapture) { |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6541 | intent = mCarDockIntent; |
| 6542 | } |
| 6543 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 6544 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 6545 | intent = mDeskDockIntent; |
| 6546 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6547 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 6548 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6549 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 6550 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 6551 | // Always launch dock home from home when watch is docked, if it exists. |
| 6552 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6553 | } |
| 6554 | |
| 6555 | if (intent == null) { |
| 6556 | return null; |
| 6557 | } |
| 6558 | |
| 6559 | ActivityInfo ai = null; |
| 6560 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 6561 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 6562 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6563 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6564 | if (info != null) { |
| 6565 | ai = info.activityInfo; |
| 6566 | } |
| 6567 | if (ai != null |
| 6568 | && ai.metaData != null |
| 6569 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 6570 | intent = new Intent(intent); |
| 6571 | intent.setClassName(ai.packageName, ai.name); |
| 6572 | return intent; |
| 6573 | } |
| 6574 | |
| 6575 | return null; |
| 6576 | } |
| 6577 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6578 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 6579 | if (awakenFromDreams) { |
| 6580 | awakenDreams(); |
| 6581 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6582 | |
| 6583 | Intent dock = createHomeDockIntent(); |
| 6584 | if (dock != null) { |
| 6585 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6586 | if (fromHomeKey) { |
| 6587 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6588 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6589 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6590 | return; |
| 6591 | } catch (ActivityNotFoundException e) { |
| 6592 | } |
| 6593 | } |
| 6594 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6595 | Intent intent; |
| 6596 | |
| 6597 | if (fromHomeKey) { |
| 6598 | intent = new Intent(mHomeIntent); |
| 6599 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6600 | } else { |
| 6601 | intent = mHomeIntent; |
| 6602 | } |
| 6603 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 6604 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6605 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6606 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6607 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6608 | * goes to the home screen |
| 6609 | * @return whether it did anything |
| 6610 | */ |
| 6611 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6612 | if (!isUserSetupComplete()) { |
| 6613 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 6614 | return false; |
| 6615 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6616 | if (false) { |
| 6617 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 6618 | try { |
| 6619 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6620 | } catch (RemoteException e) { |
| 6621 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 6622 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6623 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6624 | } else { |
| 6625 | // This code brings home to the front or, if it is already |
| 6626 | // at the front, puts the device to sleep. |
| 6627 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 6628 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 6629 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 6630 | Log.d(TAG, "UTS-TEST-MODE"); |
| 6631 | } else { |
| 6632 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 6633 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6634 | Intent dock = createHomeDockIntent(); |
| 6635 | if (dock != null) { |
| 6636 | int result = ActivityManagerNative.getDefault() |
| 6637 | .startActivityAsUser(null, null, dock, |
| 6638 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 6639 | null, null, 0, |
| 6640 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6641 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6642 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 6643 | return false; |
| 6644 | } |
| 6645 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6646 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6647 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6648 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6649 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6650 | null, null, 0, |
| 6651 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 6652 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 6653 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6654 | return false; |
| 6655 | } |
| 6656 | } catch (RemoteException ex) { |
| 6657 | // bummer, the activity manager, which is in this process, is dead |
| 6658 | } |
| 6659 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6660 | return true; |
| 6661 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6662 | |
| 6663 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6664 | public void setCurrentOrientationLw(int newOrientation) { |
| 6665 | synchronized (mLock) { |
| 6666 | if (newOrientation != mCurrentAppOrientation) { |
| 6667 | mCurrentAppOrientation = newOrientation; |
| 6668 | updateOrientationListenerLp(); |
| 6669 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6670 | } |
| 6671 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6672 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6673 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 6674 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 6675 | return; |
| 6676 | } |
| 6677 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 6678 | Context.AUDIO_SERVICE); |
| 6679 | if (audioManager.isSilentMode()) { |
| 6680 | return; |
| 6681 | } |
| 6682 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 6683 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 6684 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 6685 | ringTone.play(); |
| 6686 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6687 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 6688 | private boolean isTheaterModeEnabled() { |
| 6689 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6690 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 6691 | } |
| 6692 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 6693 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 6694 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 6695 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 6696 | } |
| 6697 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6698 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6699 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 6700 | if (!mVibrator.hasVibrator()) { |
| 6701 | return false; |
| 6702 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6703 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 6704 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 6705 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6706 | return false; |
| 6707 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6708 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6709 | switch (effectId) { |
| 6710 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6711 | pattern = mLongPressVibePattern; |
| 6712 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6713 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6714 | pattern = mVirtualKeyVibePattern; |
| 6715 | break; |
| 6716 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 6717 | pattern = mKeyboardTapVibePattern; |
| 6718 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 6719 | case HapticFeedbackConstants.CLOCK_TICK: |
| 6720 | pattern = mClockTickVibePattern; |
| 6721 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 6722 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 6723 | pattern = mCalendarDateVibePattern; |
| 6724 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6725 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6726 | pattern = mSafeModeDisabledVibePattern; |
| 6727 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6728 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6729 | pattern = mSafeModeEnabledVibePattern; |
| 6730 | break; |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 6731 | case HapticFeedbackConstants.CONTEXT_CLICK: |
| 6732 | pattern = mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 6733 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6734 | default: |
| 6735 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6736 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6737 | int owningUid; |
| 6738 | String owningPackage; |
| 6739 | if (win != null) { |
| 6740 | owningUid = win.getOwningUid(); |
| 6741 | owningPackage = win.getOwningPackage(); |
| 6742 | } else { |
| 6743 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 6744 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 6745 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6746 | if (pattern.length == 1) { |
| 6747 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6748 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6749 | } else { |
| 6750 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 6751 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 6752 | } |
| 6753 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6754 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6755 | |
| 6756 | @Override |
| 6757 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6758 | } |
| 6759 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6760 | @Override |
| 6761 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6762 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 6763 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6764 | } |
| 6765 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 6766 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6767 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6768 | // If there is no window focused, there will be nobody to handle the events |
| 6769 | // 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] | 6770 | final WindowState win = mFocusedWindow != null ? mFocusedWindow |
| 6771 | : mTopFullscreenOpaqueWindowState; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6772 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6773 | return 0; |
| 6774 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6775 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 6776 | // We are updating at a point where the keyguard has gotten |
| 6777 | // focus, but we were last in a state where the top window is |
| 6778 | // hiding it. This is probably because the keyguard as been |
| 6779 | // shown while the top window was displayed, so we want to ignore |
| 6780 | // it here because this is just a very transient change and it |
| 6781 | // will quickly lose focus once it correctly gets hidden. |
| 6782 | return 0; |
| 6783 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 6784 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 6785 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6786 | & ~mResettingSystemUiFlags |
| 6787 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6788 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 6789 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 6790 | } |
Thanh Hai Mai | 6c009f5 | 2015-09-01 16:27:32 -0700 | [diff] [blame] | 6791 | |
| 6792 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 6793 | tmpVisibility |= StatusBarManager.DISABLE_RECENT; |
| 6794 | } |
| 6795 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6796 | tmpVisibility = updateLightStatusBarLw(tmpVisibility); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6797 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6798 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6799 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 6800 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6801 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6802 | return 0; |
| 6803 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 6804 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 6805 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6806 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6807 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6808 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6809 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6810 | try { |
| 6811 | IStatusBarService statusbar = getStatusBarService(); |
| 6812 | if (statusbar != null) { |
Adrian Roos | 53f28ec | 2014-10-29 17:26:12 +0100 | [diff] [blame] | 6813 | statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString()); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6814 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6815 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 6816 | } catch (RemoteException e) { |
| 6817 | // re-acquire status bar service next time it is needed. |
| 6818 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6819 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6820 | } |
| 6821 | }); |
| 6822 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6823 | } |
| 6824 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 6825 | private int updateLightStatusBarLw(int vis) { |
| 6826 | WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6827 | ? mStatusBar |
| 6828 | : mTopFullscreenOpaqueOrDimmingWindowState; |
| 6829 | |
| 6830 | if (statusColorWin != null) { |
| 6831 | if (statusColorWin == mTopFullscreenOpaqueWindowState) { |
| 6832 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 6833 | // its light flag. |
| 6834 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6835 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 6836 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6837 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 6838 | // Otherwise if it's dimming, clear the light flag. |
| 6839 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 6840 | } |
| 6841 | } |
| 6842 | return vis; |
| 6843 | } |
| 6844 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6845 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6846 | final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 6847 | final boolean freeformStackVisible = |
| 6848 | mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID); |
| 6849 | final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible; |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 6850 | final boolean forceOpaqueSystemBars = forceShowSystemBars && !mForceStatusBarFromKeyguard; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6851 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6852 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 6853 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 6854 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6855 | : mTopFullscreenOpaqueWindowState; |
| 6856 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6857 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 6858 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6859 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 6860 | int type = win.getAttrs().type; |
| 6861 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6862 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6863 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 6864 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 6865 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 6866 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 6867 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 6868 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 6869 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 6870 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 6871 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6872 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6873 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6874 | if ((!areTranslucentBarsAllowed() && transWin != mStatusBar) |
| 6875 | || forceOpaqueSystemBars) { |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 6876 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT |
| 6877 | | View.SYSTEM_UI_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6878 | } |
| 6879 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 6880 | if (mForceWindowDrawsStatusBarBackground) { |
| 6881 | vis |= View.STATUS_BAR_TRANSPARENT; |
| 6882 | vis &= ~View.STATUS_BAR_TRANSLUCENT; |
| 6883 | } |
| 6884 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6885 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6886 | boolean immersiveSticky = |
| 6887 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6888 | final boolean hideStatusBarWM = |
| 6889 | mTopFullscreenOpaqueWindowState != null |
| 6890 | && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6891 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6892 | final boolean hideStatusBarSysui = |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6893 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6894 | final boolean hideNavBarSysui = |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6895 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6896 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6897 | final boolean transientStatusBarAllowed = mStatusBar != null |
| 6898 | && (statusBarHasFocus || (!forceShowSystemBars |
| 6899 | && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6900 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6901 | final boolean transientNavBarAllowed = mNavigationBar != null |
| 6902 | && !forceShowSystemBars && hideNavBarSysui && immersiveSticky; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6903 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 6904 | final long now = SystemClock.uptimeMillis(); |
| 6905 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 6906 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 6907 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 6908 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 6909 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 6910 | mPendingPanicGestureUptime = 0; |
| 6911 | mStatusBarController.showTransient(); |
| 6912 | mNavigationBarController.showTransient(); |
| 6913 | } |
| 6914 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6915 | final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6916 | && !transientStatusBarAllowed && hideStatusBarSysui; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6917 | final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6918 | && !transientNavBarAllowed; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 6919 | if (denyTransientStatus || denyTransientNav || forceShowSystemBars) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6920 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6921 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 6922 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6923 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6924 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6925 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 6926 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 6927 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 6928 | |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 6929 | if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType()) |
| 6930 | > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 6931 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 6932 | // the input events. |
| 6933 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 6934 | } |
| 6935 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6936 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 6937 | |
| 6938 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6939 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 6940 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 6941 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 6942 | final String pkg = win.getOwningPackage(); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 6943 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode, |
| 6944 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6945 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 6946 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6947 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 6948 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 6949 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6950 | } |
| 6951 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 6952 | private void clearClearableFlagsLw() { |
| 6953 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6954 | if (newVal != mResettingSystemUiFlags) { |
| 6955 | mResettingSystemUiFlags = newVal; |
| 6956 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 6957 | } |
| 6958 | } |
| 6959 | |
| 6960 | private boolean isImmersiveMode(int vis) { |
| 6961 | 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] | 6962 | return mNavigationBar != null |
| 6963 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 6964 | && (vis & flags) != 0 |
| 6965 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 6966 | } |
| 6967 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6968 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6969 | * @return whether the navigation or status bar can be made translucent |
| 6970 | * |
| 6971 | * This should return true unless touch exploration is not enabled or |
| 6972 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6973 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 6974 | private boolean areTranslucentBarsAllowed() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 6975 | return mTranslucentDecorEnabled; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 6976 | } |
| 6977 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6978 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 6979 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6980 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 6981 | public boolean hasNavigationBar() { |
| 6982 | return mHasNavigationBar; |
| 6983 | } |
| 6984 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 6985 | @Override |
| 6986 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 6987 | mLastInputMethodWindow = ime; |
| 6988 | mLastInputMethodTargetWindow = target; |
| 6989 | } |
| 6990 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6991 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 6992 | public int getInputMethodWindowVisibleHeightLw() { |
| 6993 | return mDockBottom - mCurBottom; |
| 6994 | } |
| 6995 | |
| 6996 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 6997 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6998 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6999 | if (mKeyguardDelegate != null) { |
| 7000 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7001 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 7002 | if (mStatusBarService != null) { |
| 7003 | try { |
| 7004 | mStatusBarService.setCurrentUser(newUserId); |
| 7005 | } catch (RemoteException e) { |
| 7006 | // oh well |
| 7007 | } |
| 7008 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7009 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 7013 | public boolean canMagnifyWindow(int windowType) { |
| 7014 | switch (windowType) { |
| 7015 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 7016 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 7017 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 7018 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 7019 | return false; |
| 7020 | } |
| 7021 | } |
| 7022 | return true; |
| 7023 | } |
| 7024 | |
| 7025 | @Override |
| 7026 | public boolean isTopLevelWindow(int windowType) { |
| 7027 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 7028 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 7029 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 7030 | } |
| 7031 | return true; |
| 7032 | } |
| 7033 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 7034 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 7035 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7036 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7037 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 7038 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 7039 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7040 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 7041 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7042 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7043 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 7044 | || mForceClearedSystemUiFlags != 0) { |
| 7045 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 7046 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 7047 | pw.print(" mResettingSystemUiFlags=0x"); |
| 7048 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 7049 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 7050 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7051 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 7052 | if (mLastFocusNeedsMenu) { |
| 7053 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 7054 | pw.println(mLastFocusNeedsMenu); |
| 7055 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7056 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 7057 | pw.println(mWakeGestureEnabledSetting); |
| 7058 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 7059 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7060 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 7061 | pw.print(" mDockMode="); pw.print(mDockMode); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7062 | pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7063 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 7064 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 7065 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 7066 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7067 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7068 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7069 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 7070 | pw.print(mCarDockEnablesAccelerometer); |
| 7071 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 7072 | pw.println(mDeskDockEnablesAccelerometer); |
| 7073 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 7074 | pw.print(mLidKeyboardAccessibility); |
| 7075 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 7076 | pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7077 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7078 | pw.print(prefix); |
| 7079 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 7080 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 7081 | pw.print(prefix); |
| 7082 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 7083 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7084 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7085 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 7086 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 7087 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 7088 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 7089 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 7090 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 7091 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7092 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 7093 | pw.print(","); pw.print(mOverscanScreenTop); |
| 7094 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 7095 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 7096 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 7097 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 7098 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 7099 | pw.print(" top="); pw.print(mOverscanTop); |
| 7100 | pw.print(" right="); pw.print(mOverscanRight); |
| 7101 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 7102 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 7103 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 7104 | pw.print(mRestrictedOverscanScreenLeft); |
| 7105 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 7106 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 7107 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7108 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 7109 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 7110 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 7111 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 7112 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 7113 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 7114 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 7115 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 7116 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 7117 | pw.print(","); pw.print(mStableFullscreenTop); |
| 7118 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 7119 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7120 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 7121 | pw.print(","); pw.print(mStableTop); |
| 7122 | pw.print(")-("); pw.print(mStableRight); |
| 7123 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 7124 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 7125 | pw.print(","); pw.print(mSystemTop); |
| 7126 | pw.print(")-("); pw.print(mSystemRight); |
| 7127 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7128 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 7129 | pw.print(","); pw.print(mCurTop); |
| 7130 | pw.print(")-("); pw.print(mCurRight); |
| 7131 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 7132 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 7133 | pw.print(","); pw.print(mContentTop); |
| 7134 | pw.print(")-("); pw.print(mContentRight); |
| 7135 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 7136 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 7137 | pw.print(","); pw.print(mVoiceContentTop); |
| 7138 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 7139 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7140 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 7141 | pw.print(","); pw.print(mDockTop); |
| 7142 | pw.print(")-("); pw.print(mDockRight); |
| 7143 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 7144 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 7145 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 7146 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 7147 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7148 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 7149 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7150 | if (mLastInputMethodWindow != null) { |
| 7151 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 7152 | pw.println(mLastInputMethodWindow); |
| 7153 | } |
| 7154 | if (mLastInputMethodTargetWindow != null) { |
| 7155 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 7156 | pw.println(mLastInputMethodTargetWindow); |
| 7157 | } |
| 7158 | if (mStatusBar != null) { |
| 7159 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 7160 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 7161 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7162 | } |
| 7163 | if (mNavigationBar != null) { |
| 7164 | pw.print(prefix); pw.print("mNavigationBar="); |
| 7165 | pw.println(mNavigationBar); |
| 7166 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7167 | if (mFocusedWindow != null) { |
| 7168 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 7169 | pw.println(mFocusedWindow); |
| 7170 | } |
| 7171 | if (mFocusedApp != null) { |
| 7172 | pw.print(prefix); pw.print("mFocusedApp="); |
| 7173 | pw.println(mFocusedApp); |
| 7174 | } |
| 7175 | if (mWinDismissingKeyguard != null) { |
| 7176 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 7177 | pw.println(mWinDismissingKeyguard); |
| 7178 | } |
| 7179 | if (mTopFullscreenOpaqueWindowState != null) { |
| 7180 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 7181 | pw.println(mTopFullscreenOpaqueWindowState); |
| 7182 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7183 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 7184 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 7185 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 7186 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 7187 | if (mForcingShowNavBar) { |
| 7188 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 7189 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 7190 | pw.println(mForcingShowNavBarLayer); |
| 7191 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 7192 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7193 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 7194 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 7195 | pw.print(" mForceStatusBarFromKeyguard="); |
| 7196 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7197 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 7198 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7199 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 7200 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 7201 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 7202 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 7203 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 7204 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 7205 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 7206 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 7207 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 7208 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 7209 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 7210 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 7211 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 7212 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7213 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 7214 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7215 | mStatusBarController.dump(pw, prefix); |
| 7216 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 7217 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7218 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7219 | if (mWakeGestureListener != null) { |
| 7220 | mWakeGestureListener.dump(pw, prefix); |
| 7221 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7222 | if (mOrientationListener != null) { |
| 7223 | mOrientationListener.dump(pw, prefix); |
| 7224 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 7225 | if (mBurnInProtectionHelper != null) { |
| 7226 | mBurnInProtectionHelper.dump(prefix, pw); |
| 7227 | } |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 7228 | if (mKeyguardDelegate != null) { |
| 7229 | mKeyguardDelegate.dump(prefix, pw); |
| 7230 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7231 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7232 | } |