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; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 22 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
| 23 | import static android.content.pm.PackageManager.FEATURE_TELEVISION; |
| 24 | import static android.content.pm.PackageManager.FEATURE_WATCH; |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 25 | import static android.content.res.Configuration.EMPTY; |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 26 | import static android.content.res.Configuration.UI_MODE_TYPE_CAR; |
| 27 | import static android.content.res.Configuration.UI_MODE_TYPE_MASK; |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.DOCKED_TOP; |
| 29 | import static android.view.WindowManager.DOCKED_LEFT; |
| 30 | import static android.view.WindowManager.DOCKED_RIGHT; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN; |
| 32 | import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.*; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 34 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 35 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT; |
| 36 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 37 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 38 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
| 39 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 40 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 41 | import android.app.ActivityManager; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 42 | import android.app.ActivityManager.StackId; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 43 | import android.app.ActivityManagerInternal; |
| 44 | import android.app.ActivityManagerInternal.SleepToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 45 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 46 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 47 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 48 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 49 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 50 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 51 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 52 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 53 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 54 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 55 | import android.content.ContentResolver; |
| 56 | import android.content.Context; |
| 57 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 58 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 59 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 60 | import android.content.pm.ActivityInfo; |
Svet Ganov | 03f2afc3 | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 61 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 62 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 63 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 64 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 65 | import android.content.res.Configuration; |
| 66 | import android.content.res.Resources; |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 67 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 68 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 69 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 70 | import android.graphics.Rect; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 71 | import android.hardware.hdmi.HdmiControlManager; |
| 72 | import android.hardware.hdmi.HdmiPlaybackClient; |
| 73 | import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 74 | import android.hardware.input.InputManagerInternal; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 75 | import android.media.AudioAttributes; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 76 | import android.media.AudioManager; |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 77 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 78 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 79 | import android.media.Ringtone; |
| 80 | import android.media.RingtoneManager; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 81 | import android.media.session.MediaSessionLegacyHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 82 | import android.os.Binder; |
Svet Ganov | 03f2afc3 | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 83 | import android.os.Build; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 84 | import android.os.Bundle; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 85 | import android.os.Debug; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 86 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 87 | import android.os.Handler; |
| 88 | import android.os.IBinder; |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 89 | import android.os.IDeviceIdleController; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 90 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 91 | import android.os.Message; |
| 92 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 93 | import android.os.PowerManager; |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 94 | import android.os.PowerManagerInternal; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 95 | import android.os.Process; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 96 | import android.os.RemoteException; |
| 97 | import android.os.ServiceManager; |
| 98 | import android.os.SystemClock; |
| 99 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 100 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 101 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 102 | import android.os.Vibrator; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 103 | import android.provider.MediaStore; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 104 | import android.provider.Settings; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 105 | import android.service.dreams.DreamManagerInternal; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 106 | import android.service.dreams.DreamService; |
| 107 | import android.service.dreams.IDreamManager; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 108 | import android.speech.RecognizerIntent; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 109 | import android.telecom.TelecomManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 110 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 111 | import android.util.EventLog; |
| 112 | import android.util.Log; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 113 | import android.util.MutableBoolean; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 114 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 115 | import android.util.SparseArray; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 116 | import android.util.LongSparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 117 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 118 | import android.view.Gravity; |
| 119 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 120 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 121 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 122 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 123 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 124 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 125 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 126 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 127 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 128 | import android.view.KeyEvent; |
| 129 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 130 | import android.view.Surface; |
| 131 | import android.view.View; |
| 132 | import android.view.ViewConfiguration; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 133 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 134 | import android.view.WindowManagerGlobal; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 135 | import android.view.WindowManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 136 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 137 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 138 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 139 | import android.view.animation.Animation; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 140 | import android.view.animation.AnimationSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 141 | import android.view.animation.AnimationUtils; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 142 | import com.android.internal.R; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 143 | import com.android.internal.logging.MetricsLogger; |
| 144 | import com.android.internal.policy.PhoneWindow; |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 145 | import com.android.internal.policy.IShortcutService; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 146 | import com.android.internal.statusbar.IStatusBarService; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 147 | import com.android.internal.util.ScreenShapeHelper; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 148 | import com.android.internal.widget.PointerLocationView; |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 149 | import com.android.server.GestureLauncherService; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 150 | import com.android.server.LocalServices; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 151 | import com.android.server.policy.keyguard.KeyguardServiceDelegate; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 152 | import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 153 | import com.android.server.statusbar.StatusBarManagerInternal; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 154 | |
| 155 | import java.io.File; |
| 156 | import java.io.FileReader; |
| 157 | import java.io.IOException; |
| 158 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 159 | import java.util.HashSet; |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 160 | import java.util.List; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 161 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 162 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 163 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 164 | * introduces a new method suffix, Lp, for an internal lock of the |
| 165 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 166 | * 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] | 167 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 168 | */ |
| 169 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 170 | static final String TAG = "WindowManager"; |
| 171 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 172 | static final boolean localLOGV = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 173 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 174 | static final boolean DEBUG_KEYGUARD = false; |
| 175 | static final boolean DEBUG_LAYOUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 176 | static final boolean DEBUG_STARTING_WINDOW = false; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 177 | static final boolean DEBUG_WAKEUP = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 178 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 179 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 180 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 181 | // 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] | 182 | // No longer recommended for desk docks; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 183 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 184 | |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 185 | static final int SHORT_PRESS_POWER_NOTHING = 0; |
| 186 | static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1; |
| 187 | static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2; |
| 188 | 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] | 189 | static final int SHORT_PRESS_POWER_GO_HOME = 4; |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 190 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 191 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 192 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 193 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 194 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 195 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 196 | static final int LONG_PRESS_BACK_NOTHING = 0; |
| 197 | static final int LONG_PRESS_BACK_GO_TO_VOICE_ASSIST = 1; |
| 198 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 199 | static final int MULTI_PRESS_POWER_NOTHING = 0; |
| 200 | static final int MULTI_PRESS_POWER_THEATER_MODE = 1; |
| 201 | static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2; |
| 202 | |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 203 | // These need to match the documentation/constant in |
| 204 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 205 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 206 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 207 | static final int LONG_PRESS_HOME_ASSIST = 2; |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 208 | static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 209 | |
| 210 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 211 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 212 | |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 213 | static final int SHORT_PRESS_WINDOW_NOTHING = 0; |
| 214 | static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1; |
| 215 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 216 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0; |
| 217 | static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1; |
| 218 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 219 | // Controls navigation bar opacity depending on which workspace stacks are currently |
| 220 | // visible. |
| 221 | // Nav bar is always opaque when either the freeform stack or docked stack is visible. |
| 222 | static final int NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED = 0; |
| 223 | // Nav bar is always translucent when the freeform stack is visible, otherwise always opaque. |
| 224 | static final int NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE = 1; |
| 225 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 226 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 227 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 228 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 229 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 230 | static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 231 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 232 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 233 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 234 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 235 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 236 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 237 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 238 | /** |
| 239 | * These are the system UI flags that, when changing, can cause the layout |
| 240 | * of the screen to change. |
| 241 | */ |
| 242 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 243 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 244 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 245 | | View.STATUS_BAR_TRANSLUCENT |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 246 | | View.NAVIGATION_BAR_TRANSLUCENT |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 247 | | View.STATUS_BAR_TRANSPARENT |
| 248 | | View.NAVIGATION_BAR_TRANSPARENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 249 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 250 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 251 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 252 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 253 | .build(); |
| 254 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 255 | // The panic gesture may become active only after the keyguard is dismissed and the immersive |
| 256 | // app shows again. If that doesn't happen for 30s we drop the gesture. |
| 257 | private static final long PANIC_GESTURE_EXPIRATION = 30000; |
| 258 | |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 259 | private static final String SYSUI_PACKAGE = "com.android.systemui"; |
| 260 | private static final String SYSUI_SCREENSHOT_SERVICE = |
| 261 | "com.android.systemui.screenshot.TakeScreenshotService"; |
| 262 | private static final String SYSUI_SCREENSHOT_ERROR_RECEIVER = |
| 263 | "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver"; |
| 264 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 265 | /** |
| 266 | * Keyguard stuff |
| 267 | */ |
| 268 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 269 | private boolean mKeyguardHidden; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 270 | private boolean mKeyguardDrawnOnce; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 271 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 272 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 273 | * |
| 274 | * These are special keys that are used to launch particular kinds of applications, |
| 275 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 276 | * usage page. We don't support quite that many yet... |
| 277 | */ |
| 278 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 279 | static { |
| 280 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 281 | sApplicationLaunchKeyCategories.append( |
| 282 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 283 | sApplicationLaunchKeyCategories.append( |
| 284 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 285 | sApplicationLaunchKeyCategories.append( |
| 286 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 287 | sApplicationLaunchKeyCategories.append( |
| 288 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 289 | sApplicationLaunchKeyCategories.append( |
| 290 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 291 | sApplicationLaunchKeyCategories.append( |
| 292 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 293 | } |
| 294 | |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 295 | /** 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] | 296 | static final int WAITING_FOR_DRAWN_TIMEOUT = 1000; |
Craig Mautner | c3daedd | 2014-09-13 11:17:23 -0700 | [diff] [blame] | 297 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 298 | /** |
| 299 | * Lock protecting internal state. Must not call out into window |
| 300 | * manager with lock held. (This lock will be acquired in places |
| 301 | * where the window manager is calling in with its own lock held.) |
| 302 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 303 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 304 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 305 | Context mContext; |
| 306 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 307 | WindowManagerFuncs mWindowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 308 | WindowManagerInternal mWindowManagerInternal; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 309 | PowerManager mPowerManager; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 310 | ActivityManagerInternal mActivityManagerInternal; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 311 | InputManagerInternal mInputManagerInternal; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 312 | DreamManagerInternal mDreamManagerInternal; |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 313 | PowerManagerInternal mPowerManagerInternal; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 314 | IStatusBarService mStatusBarService; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 315 | StatusBarManagerInternal mStatusBarManagerInternal; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 316 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 317 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 318 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 319 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 320 | AccessibilityManager mAccessibilityManager; |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 321 | BurnInProtectionHelper mBurnInProtectionHelper; |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 322 | AppOpsManager mAppOpsManager; |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 323 | private boolean mHasFeatureWatch; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 324 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 325 | // Vibrator pattern for haptic feedback of a long press. |
| 326 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 327 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 328 | // Vibrator pattern for haptic feedback of virtual key press. |
| 329 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 330 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 331 | // Vibrator pattern for a short vibration. |
| 332 | long[] mKeyboardTapVibePattern; |
| 333 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 334 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 335 | long[] mClockTickVibePattern; |
| 336 | |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 337 | // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar. |
| 338 | long[] mCalendarDateVibePattern; |
| 339 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 340 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 341 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 342 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 343 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 344 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 345 | |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 346 | // Vibrator pattern for haptic feedback of a context click. |
| 347 | long[] mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 348 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 349 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 350 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 351 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 352 | boolean mSafeMode; |
| 353 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 354 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 355 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 356 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 357 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 358 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 359 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 360 | int[] mNavigationBarHeightForRotationDefault = new int[4]; |
| 361 | int[] mNavigationBarWidthForRotationDefault = new int[4]; |
| 362 | int[] mNavigationBarHeightForRotationInCarMode = new int[4]; |
| 363 | int[] mNavigationBarWidthForRotationInCarMode = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 364 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 365 | private LongSparseArray<IShortcutService> mShortcutKeyServices = new LongSparseArray<>(); |
| 366 | |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 367 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 368 | // This is for car dock and this is updated from resource. |
| 369 | private boolean mEnableCarDockHomeCapture = true; |
| 370 | |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 371 | boolean mBootMessageNeedsHiding; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 372 | KeyguardServiceDelegate mKeyguardDelegate; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 373 | final Runnable mWindowManagerDrawCallback = new Runnable() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 374 | @Override |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 375 | public void run() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 376 | if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!"); |
| 377 | mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE); |
| 378 | } |
| 379 | }; |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 380 | final DrawnListener mKeyguardDrawnCallback = new DrawnListener() { |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 381 | @Override |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 382 | public void onDrawn() { |
| 383 | if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 384 | mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE); |
| 385 | } |
| 386 | }; |
| 387 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 388 | GlobalActions mGlobalActions; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 389 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 390 | WindowState mLastInputMethodWindow = null; |
| 391 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 392 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 393 | // FIXME This state is shared between the input reader and handler thread. |
| 394 | // Technically it's broken and buggy but it has been like this for many years |
| 395 | // and we have not yet seen any problems. Someday we'll rewrite this logic |
| 396 | // so that only one thread is involved in handling input policy. Unfortunately |
| 397 | // it's on a critical path for power management so we can't just post the work to the |
| 398 | // handler thread. We'll need to resolve this someday by teaching the input dispatcher |
| 399 | // to hold wakelocks during dispatch and eliminating the critical path. |
| 400 | volatile boolean mPowerKeyHandled; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 401 | volatile boolean mBackKeyHandled; |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 402 | volatile boolean mBeganFromNonInteractive; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 403 | volatile int mPowerKeyPressCounter; |
| 404 | volatile boolean mEndCallKeyHandled; |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 405 | volatile boolean mCameraGestureTriggeredDuringGoingToSleep; |
| 406 | volatile boolean mGoingToSleep; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 407 | volatile boolean mRecentsVisible; |
| 408 | volatile boolean mTvPictureInPictureVisible; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 409 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 410 | int mRecentAppsHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 411 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 412 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 413 | int mLidState = LID_ABSENT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 414 | int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 415 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 416 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 417 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 418 | boolean mSystemBooted; |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 419 | private boolean mDeferBindKeyguard; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 420 | boolean mHdmiPlugged; |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 421 | HdmiControl mHdmiControl; |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 422 | IUiModeManager mUiModeManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 423 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 424 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 425 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 426 | int mCarDockRotation; |
| 427 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 428 | int mUndockedHdmiRotation; |
| 429 | int mDemoHdmiRotation; |
| 430 | boolean mDemoHdmiRotationLock; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 431 | int mDemoRotation; |
| 432 | boolean mDemoRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 433 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 434 | boolean mWakeGestureEnabledSetting; |
| 435 | MyWakeGestureListener mWakeGestureListener; |
| 436 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 437 | // Default display does not rotate, apps that require non-default orientation will have to |
| 438 | // have the orientation emulated. |
| 439 | private boolean mForceDefaultOrientation = false; |
| 440 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 441 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 442 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 443 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 444 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 445 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 446 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 447 | boolean mCarDockEnablesAccelerometer; |
| 448 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 449 | int mLidKeyboardAccessibility; |
| 450 | int mLidNavigationAccessibility; |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 451 | boolean mLidControlsScreenLock; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 452 | boolean mLidControlsSleep; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 453 | int mShortPressOnPowerBehavior; |
| 454 | int mLongPressOnPowerBehavior; |
| 455 | int mDoublePressOnPowerBehavior; |
| 456 | int mTriplePressOnPowerBehavior; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 457 | int mLongPressOnBackBehavior; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 458 | int mShortPressOnSleepBehavior; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 459 | int mShortPressWindowBehavior; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 460 | boolean mAwake; |
| 461 | boolean mScreenOnEarly; |
| 462 | boolean mScreenOnFully; |
| 463 | ScreenOnListener mScreenOnListener; |
| 464 | boolean mKeyguardDrawComplete; |
| 465 | boolean mWindowManagerDrawComplete; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 466 | boolean mOrientationSensorEnabled = false; |
| 467 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 468 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 469 | boolean mTranslucentDecorEnabled = true; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 470 | boolean mUseTvRouting; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 471 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 472 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 473 | |
| 474 | // The last window we were told about in focusChanged. |
| 475 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 476 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 477 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 478 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 479 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 480 | // The current size of the screen; really; extends into the overscan area of |
| 481 | // the screen and doesn't account for any system elements like the status bar. |
| 482 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 483 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 484 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 485 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 486 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 487 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 488 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 489 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 490 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 491 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 492 | // if the status bar can't be hidden; in that case it effectively carves out |
| 493 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 494 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 495 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 496 | // During layout, the current screen borders accounting for any currently |
| 497 | // visible system UI elements. |
| 498 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 499 | // For applications requesting stable content insets, these are them. |
| 500 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 501 | // For applications requesting stable content insets but have also set the |
| 502 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 503 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 504 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 505 | // During layout, the current screen borders with all outer decoration |
| 506 | // (status bar, input method dock) accounted for. |
| 507 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 508 | // During layout, the frame in which content should be displayed |
| 509 | // to the user, accounting for all screen decoration except for any |
| 510 | // space they deem as available for other content. This is usually |
| 511 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 512 | // content insets. |
| 513 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 514 | // During layout, the frame in which voice content should be displayed |
| 515 | // to the user, accounting for all screen decoration except for any |
| 516 | // space they deem as available for other content. |
| 517 | int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 518 | // 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] | 519 | // windows are placed. |
| 520 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 521 | // During layout, the layer at which the doc window is placed. |
| 522 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 523 | // During layout, this is the layer of the status bar. |
| 524 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 525 | int mLastSystemUiFlags; |
| 526 | // Bits that we are in the process of clearing, so we want to prevent |
| 527 | // them from being set by applications until everything has been updated |
| 528 | // to have them clear. |
| 529 | int mResettingSystemUiFlags = 0; |
| 530 | // Bits that we are currently always keeping cleared. |
| 531 | int mForceClearedSystemUiFlags = 0; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 532 | int mLastFullscreenStackSysUiFlags; |
| 533 | int mLastDockedStackSysUiFlags; |
| 534 | final Rect mNonDockedStackBounds = new Rect(); |
| 535 | final Rect mDockedStackBounds = new Rect(); |
| 536 | final Rect mLastNonDockedStackBounds = new Rect(); |
| 537 | final Rect mLastDockedStackBounds = new Rect(); |
| 538 | |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 539 | // What we last reported to system UI about whether the compatibility |
| 540 | // menu needs to be displayed. |
| 541 | boolean mLastFocusNeedsMenu = false; |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 542 | // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending. |
| 543 | private long mPendingPanicGestureUptime; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 544 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 545 | InputConsumer mInputConsumer = null; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 546 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 547 | static final Rect mTmpParentFrame = new Rect(); |
| 548 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 549 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 550 | static final Rect mTmpContentFrame = new Rect(); |
| 551 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 552 | static final Rect mTmpDecorFrame = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 553 | static final Rect mTmpStableFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 554 | static final Rect mTmpNavigationFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 555 | static final Rect mTmpOutsetFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 556 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 557 | WindowState mTopFullscreenOpaqueWindowState; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 558 | WindowState mTopFullscreenOpaqueOrDimmingWindowState; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 559 | WindowState mTopDockedOpaqueWindowState; |
| 560 | WindowState mTopDockedOpaqueOrDimmingWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 561 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 562 | HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 563 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 564 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 565 | boolean mForceStatusBarFromKeyguard; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 566 | private boolean mForceStatusBarTransparent; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 567 | int mNavBarOpacityMode = NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 568 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 569 | boolean mForcingShowNavBar; |
| 570 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 571 | |
| 572 | // States of keyguard dismiss. |
| 573 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 574 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 575 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 576 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 577 | |
| 578 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 579 | * be done once per window. */ |
| 580 | private WindowState mWinDismissingKeyguard; |
| 581 | |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 582 | /** When window is currently dismissing the keyguard, dismissing the keyguard must handle |
| 583 | * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN |
| 584 | * lock SIM card. This variable is used to record the previous keyguard secure state for |
| 585 | * monitoring secure state change on window dismissing keyguard. */ |
| 586 | private boolean mSecureDismissingKeyguard; |
| 587 | |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 588 | /** The window that is currently showing "over" the keyguard. If there is an app window |
| 589 | * belonging to another app on top of this the keyguard shows. If there is a fullscreen |
| 590 | * app window under this, still dismiss the keyguard but don't show the app underneath. Show |
| 591 | * the wallpaper. */ |
| 592 | private WindowState mWinShowWhenLocked; |
| 593 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 594 | boolean mShowingLockscreen; |
| 595 | boolean mShowingDream; |
| 596 | boolean mDreamingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 597 | boolean mDreamingSleepTokenNeeded; |
| 598 | SleepToken mDreamingSleepToken; |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 599 | SleepToken mScreenOffSleepToken; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 600 | boolean mKeyguardSecure; |
| 601 | boolean mKeyguardSecureIncludingHidden; |
| 602 | volatile boolean mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 603 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 604 | boolean mHomeConsumed; |
| 605 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 606 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 607 | Intent mCarDockIntent; |
| 608 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 609 | boolean mSearchKeyShortcutPending; |
| 610 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 611 | boolean mAssistKeyLongPressed; |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 612 | boolean mPendingMetaAction; |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 613 | boolean mPendingCapsLockToggle; |
| 614 | int mMetaState; |
| 615 | int mInitialMetaState; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 616 | boolean mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 617 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 618 | // support for activating the lock screen while the screen is on |
| 619 | boolean mAllowLockscreenWhenOn; |
| 620 | int mLockScreenTimeout; |
| 621 | boolean mLockScreenTimerActive; |
| 622 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 623 | // 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] | 624 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 625 | |
| 626 | // Behavior of POWER button while in-call and screen on. |
| 627 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 628 | int mIncallPowerBehavior; |
| 629 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 630 | Display mDisplay; |
| 631 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 632 | private int mDisplayRotation; |
| 633 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 634 | int mLandscapeRotation = 0; // default landscape rotation |
| 635 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 636 | int mPortraitRotation = 0; // default portrait rotation |
| 637 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 638 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 639 | int mOverscanLeft = 0; |
| 640 | int mOverscanTop = 0; |
| 641 | int mOverscanRight = 0; |
| 642 | int mOverscanBottom = 0; |
| 643 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 644 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 645 | private int mLongPressOnHomeBehavior; |
| 646 | |
| 647 | // What we do when the user double-taps on home |
| 648 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 649 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 650 | // Allowed theater mode wake actions |
| 651 | private boolean mAllowTheaterModeWakeFromKey; |
| 652 | private boolean mAllowTheaterModeWakeFromPowerKey; |
| 653 | private boolean mAllowTheaterModeWakeFromMotion; |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 654 | private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming; |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 655 | private boolean mAllowTheaterModeWakeFromCameraLens; |
| 656 | private boolean mAllowTheaterModeWakeFromLidSwitch; |
| 657 | private boolean mAllowTheaterModeWakeFromWakeGesture; |
| 658 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 659 | // Whether to support long press from power button in non-interactive mode |
| 660 | private boolean mSupportLongPressPowerWhenNonInteractive; |
| 661 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 662 | // Whether to go to sleep entering theater mode from power button |
| 663 | private boolean mGoToSleepOnButtonPressTheaterMode; |
| 664 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 665 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 666 | // Time to volume and power must be pressed within this interval of each other. |
| 667 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 668 | // Increase the chord delay when taking a screenshot from the keyguard |
| 669 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 670 | private boolean mScreenshotChordEnabled; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 671 | private boolean mScreenshotChordVolumeDownKeyTriggered; |
| 672 | private long mScreenshotChordVolumeDownKeyTime; |
| 673 | private boolean mScreenshotChordVolumeDownKeyConsumed; |
| 674 | private boolean mScreenshotChordVolumeUpKeyTriggered; |
| 675 | private boolean mScreenshotChordPowerKeyTriggered; |
| 676 | private long mScreenshotChordPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 677 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 678 | /* The number of steps between min and max brightness */ |
| 679 | private static final int BRIGHTNESS_STEPS = 10; |
| 680 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 681 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 682 | ShortcutManager mShortcutManager; |
| 683 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 684 | PowerManager.WakeLock mPowerKeyWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 685 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 686 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 687 | private int mCurrentUserId; |
| 688 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 689 | // Maps global key codes to the components that will handle them. |
| 690 | private GlobalKeyManager mGlobalKeyManager; |
| 691 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 692 | // Fallback actions by key code. |
| 693 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 694 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 695 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 696 | private final LogDecelerateInterpolator mLogDecelerateInterpolator |
| 697 | = new LogDecelerateInterpolator(100, 0); |
| 698 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 699 | private final MutableBoolean mTmpBoolean = new MutableBoolean(false); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 700 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 701 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 702 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 703 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 704 | 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] | 705 | private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; |
| 706 | private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; |
| 707 | private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 708 | private static final int MSG_DISPATCH_SHOW_RECENTS = 9; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 709 | private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 710 | private static final int MSG_HIDE_BOOT_MESSAGE = 11; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 711 | private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 712 | private static final int MSG_POWER_DELAYED_PRESS = 13; |
| 713 | private static final int MSG_POWER_LONG_PRESS = 14; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 714 | private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 715 | private static final int MSG_REQUEST_TRANSIENT_BARS = 16; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 716 | private static final int MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU = 17; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 717 | private static final int MSG_BACK_LONG_PRESS = 18; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 718 | |
| 719 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0; |
| 720 | private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 721 | |
| 722 | private class PolicyHandler extends Handler { |
| 723 | @Override |
| 724 | public void handleMessage(Message msg) { |
| 725 | switch (msg.what) { |
| 726 | case MSG_ENABLE_POINTER_LOCATION: |
| 727 | enablePointerLocation(); |
| 728 | break; |
| 729 | case MSG_DISABLE_POINTER_LOCATION: |
| 730 | disablePointerLocation(); |
| 731 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 732 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 733 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 734 | break; |
| 735 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 736 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 737 | break; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 738 | case MSG_DISPATCH_SHOW_RECENTS: |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 739 | showRecentApps(false, msg.arg1 != 0); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 740 | break; |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 741 | case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS: |
| 742 | showGlobalActionsInternal(); |
| 743 | break; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 744 | case MSG_KEYGUARD_DRAWN_COMPLETE: |
| 745 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 746 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 747 | break; |
| 748 | case MSG_KEYGUARD_DRAWN_TIMEOUT: |
| 749 | Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 750 | finishKeyguardDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 751 | break; |
| 752 | case MSG_WINDOW_MANAGER_DRAWN_COMPLETE: |
| 753 | if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 754 | finishWindowsDrawn(); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 755 | break; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 756 | case MSG_HIDE_BOOT_MESSAGE: |
| 757 | handleHideBootMessage(); |
| 758 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 759 | case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: |
| 760 | launchVoiceAssistWithWakeLock(msg.arg1 != 0); |
| 761 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 762 | case MSG_POWER_DELAYED_PRESS: |
| 763 | powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2); |
| 764 | finishPowerKeyPress(); |
| 765 | break; |
| 766 | case MSG_POWER_LONG_PRESS: |
| 767 | powerLongPress(); |
| 768 | break; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 769 | case MSG_UPDATE_DREAMING_SLEEP_TOKEN: |
| 770 | updateDreamingSleepToken(msg.arg1 != 0); |
| 771 | break; |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 772 | case MSG_REQUEST_TRANSIENT_BARS: |
| 773 | WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ? |
| 774 | mStatusBar : mNavigationBar; |
| 775 | if (targetBar != null) { |
| 776 | requestTransientBars(targetBar); |
| 777 | } |
| 778 | break; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 779 | case MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU: |
| 780 | showTvPictureInPictureMenuInternal(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 781 | break; |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 782 | case MSG_BACK_LONG_PRESS: |
| 783 | backLongPress(); |
| 784 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 789 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 790 | @Override |
| 791 | public void onUEvent(UEventObserver.UEvent event) { |
| 792 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 793 | } |
| 794 | }; |
| 795 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 796 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 797 | SettingsObserver(Handler handler) { |
| 798 | super(handler); |
| 799 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 800 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 801 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 802 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 803 | ContentResolver resolver = mContext.getContentResolver(); |
| 804 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 805 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 806 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 807 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 808 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 809 | UserHandle.USER_ALL); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 810 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 811 | Settings.Secure.WAKE_GESTURE_ENABLED), false, this, |
| 812 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 813 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 814 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 815 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 816 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 817 | Settings.System.USER_ROTATION), false, this, |
| 818 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 819 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 820 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 821 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 822 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 823 | Settings.System.POINTER_LOCATION), false, this, |
| 824 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 825 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 826 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 827 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 828 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 829 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 830 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 831 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 832 | Settings.Global.POLICY_CONTROL), false, this, |
| 833 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 834 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 838 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 839 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 840 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 841 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 842 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 843 | class MyWakeGestureListener extends WakeGestureListener { |
| 844 | MyWakeGestureListener(Context context, Handler handler) { |
| 845 | super(context, handler); |
| 846 | } |
| 847 | |
| 848 | @Override |
| 849 | public void onWakeUp() { |
| 850 | synchronized (mLock) { |
| 851 | if (shouldEnableWakeGestureLp()) { |
Jeff Brown | e07b94b | 2014-06-18 15:56:27 -0700 | [diff] [blame] | 852 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 853 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture, |
| 854 | "android.policy:GESTURE"); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 860 | class MyOrientationListener extends WindowOrientationListener { |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 861 | private final Runnable mUpdateRotationRunnable = new Runnable() { |
| 862 | @Override |
| 863 | public void run() { |
Tim Murray | 1f40764 | 2015-10-01 17:07:12 -0700 | [diff] [blame] | 864 | // send interaction hint to improve redraw performance |
| 865 | mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 866 | updateRotation(false); |
| 867 | } |
| 868 | }; |
| 869 | |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 870 | MyOrientationListener(Context context, Handler handler) { |
| 871 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 872 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 873 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 874 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 875 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 876 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Chong Zhang | 5aaa0b3 | 2015-08-28 10:22:36 -0700 | [diff] [blame] | 877 | mHandler.post(mUpdateRotationRunnable); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 878 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 879 | } |
| 880 | MyOrientationListener mOrientationListener; |
| 881 | |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 882 | private final StatusBarController mStatusBarController = new StatusBarController(); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 883 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 884 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 885 | View.NAVIGATION_BAR_TRANSIENT, |
| 886 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 887 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 888 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 889 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, |
| 890 | View.NAVIGATION_BAR_TRANSPARENT); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 891 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 892 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 893 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 894 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 895 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 896 | IStatusBarService getStatusBarService() { |
| 897 | synchronized (mServiceAquireLock) { |
| 898 | if (mStatusBarService == null) { |
| 899 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 900 | ServiceManager.getService("statusbar")); |
| 901 | } |
| 902 | return mStatusBarService; |
| 903 | } |
| 904 | } |
| 905 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 906 | StatusBarManagerInternal getStatusBarManagerInternal() { |
| 907 | synchronized (mServiceAquireLock) { |
| 908 | if (mStatusBarManagerInternal == null) { |
| 909 | mStatusBarManagerInternal = |
| 910 | LocalServices.getService(StatusBarManagerInternal.class); |
| 911 | } |
| 912 | return mStatusBarManagerInternal; |
| 913 | } |
| 914 | } |
| 915 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 916 | /* |
| 917 | * We always let the sensor be switched on by default except when |
| 918 | * the user has explicitly disabled sensor based rotation or when the |
| 919 | * screen is switched off. |
| 920 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 921 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 922 | if (mSupportAutoRotation) { |
| 923 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 924 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 925 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 926 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 927 | // If the application has explicitly requested to follow the |
| 928 | // orientation, then we need to turn the sensor on. |
| 929 | return true; |
| 930 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 931 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 932 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 933 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 934 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 935 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 936 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 937 | // orientation management, |
| 938 | return true; |
| 939 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 940 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 941 | // If the setting for using the sensor by default is enabled, then |
| 942 | // we will always leave it on. Note that the user could go to |
| 943 | // a window that forces an orientation that does not use the |
| 944 | // sensor and in theory we could turn it off... however, when next |
| 945 | // turning it on we won't have a good value for the current |
| 946 | // orientation for a little bit, which can cause orientation |
| 947 | // changes to lag, so we'd like to keep it always on. (It will |
| 948 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 949 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 950 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 951 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 952 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 953 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 954 | /* |
| 955 | * Various use cases for invoking this function |
| 956 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 957 | * 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] | 958 | * if not already enabled |
| 959 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 960 | * already enabled |
| 961 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 962 | * screen turning on and current app has nosensor based orientation, do nothing |
| 963 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 964 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 965 | if (!mOrientationListener.canDetectOrientation()) { |
| 966 | // If sensor is turned off or nonexistent for some reason |
| 967 | return; |
| 968 | } |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 969 | // Could have been invoked due to screen turning on or off or |
| 970 | // change of the currently visible window's orientation. |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 971 | if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly |
| 972 | + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 973 | + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled |
| 974 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 975 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 976 | boolean disable = true; |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 977 | // Note: We postpone the rotating of the screen until the keyguard as well as the |
| 978 | // window manager have reported a draw complete. |
| 979 | if (mScreenOnEarly && mAwake && |
| 980 | mKeyguardDrawComplete && mWindowManagerDrawComplete) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 981 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 982 | disable = false; |
| 983 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 984 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 985 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 986 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 987 | mOrientationSensorEnabled = true; |
| 988 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 989 | } |
| 990 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 991 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 992 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 993 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 994 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 995 | mOrientationSensorEnabled = false; |
| 996 | } |
| 997 | } |
| 998 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 999 | private void interceptPowerKeyDown(KeyEvent event, boolean interactive) { |
| 1000 | // Hold a wake lock until the power key is released. |
| 1001 | if (!mPowerKeyWakeLock.isHeld()) { |
| 1002 | mPowerKeyWakeLock.acquire(); |
| 1003 | } |
| 1004 | |
| 1005 | // Cancel multi-press detection timeout. |
| 1006 | if (mPowerKeyPressCounter != 0) { |
| 1007 | mHandler.removeMessages(MSG_POWER_DELAYED_PRESS); |
| 1008 | } |
| 1009 | |
| 1010 | // Detect user pressing the power button in panic when an application has |
| 1011 | // taken over the whole screen. |
| 1012 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
Craig Mautner | 0124980e9 | 2014-11-30 21:15:34 -0800 | [diff] [blame] | 1013 | SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags)); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1014 | if (panic) { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 1015 | mHandler.post(mHiddenNavPanic); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | // Latch power key state to detect screenshot chord. |
| 1019 | if (interactive && !mScreenshotChordPowerKeyTriggered |
| 1020 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 1021 | mScreenshotChordPowerKeyTriggered = true; |
| 1022 | mScreenshotChordPowerKeyTime = event.getDownTime(); |
| 1023 | interceptScreenshotChord(); |
| 1024 | } |
| 1025 | |
| 1026 | // Stop ringing or end call if configured to do so when power is pressed. |
| 1027 | TelecomManager telecomManager = getTelecommService(); |
| 1028 | boolean hungUp = false; |
| 1029 | if (telecomManager != null) { |
| 1030 | if (telecomManager.isRinging()) { |
| 1031 | // Pressing Power while there's a ringing incoming |
| 1032 | // call should silence the ringer. |
| 1033 | telecomManager.silenceRinger(); |
| 1034 | } else if ((mIncallPowerBehavior |
| 1035 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 1036 | && telecomManager.isInCall() && interactive) { |
| 1037 | // Otherwise, if "Power button ends call" is enabled, |
| 1038 | // the Power button will hang up any current active call. |
| 1039 | hungUp = telecomManager.endCall(); |
| 1040 | } |
| 1041 | } |
| 1042 | |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1043 | GestureLauncherService gestureService = LocalServices.getService( |
| 1044 | GestureLauncherService.class); |
| 1045 | boolean gesturedServiceIntercepted = false; |
| 1046 | if (gestureService != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 1047 | gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive, |
| 1048 | mTmpBoolean); |
| 1049 | if (mTmpBoolean.value && mGoingToSleep) { |
| 1050 | mCameraGestureTriggeredDuringGoingToSleep = true; |
| 1051 | } |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1054 | // If the power key has still not yet been handled, then detect short |
| 1055 | // press, long press, or multi press and decide what to do. |
| 1056 | mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered |
Adrian Roos | 5941c98 | 2015-09-03 15:59:49 -0700 | [diff] [blame] | 1057 | || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1058 | if (!mPowerKeyHandled) { |
| 1059 | if (interactive) { |
| 1060 | // When interactive, we're already awake. |
| 1061 | // Wait for a long press or for the button to be released to decide what to do. |
| 1062 | if (hasLongPressOnPowerBehavior()) { |
| 1063 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1064 | msg.setAsynchronous(true); |
| 1065 | mHandler.sendMessageDelayed(msg, |
| 1066 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 1067 | } |
| 1068 | } else { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1069 | wakeUpFromPowerKey(event.getDownTime()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1070 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1071 | if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) { |
| 1072 | Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS); |
| 1073 | msg.setAsynchronous(true); |
| 1074 | mHandler.sendMessageDelayed(msg, |
| 1075 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1076 | mBeganFromNonInteractive = true; |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1077 | } else { |
| 1078 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1079 | |
| 1080 | if (maxCount <= 1) { |
| 1081 | mPowerKeyHandled = true; |
| 1082 | } else { |
| 1083 | mBeganFromNonInteractive = true; |
| 1084 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1085 | } |
| 1086 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1090 | private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) { |
| 1091 | final boolean handled = canceled || mPowerKeyHandled; |
| 1092 | mScreenshotChordPowerKeyTriggered = false; |
| 1093 | cancelPendingScreenshotChordAction(); |
| 1094 | cancelPendingPowerKeyAction(); |
| 1095 | |
| 1096 | if (!handled) { |
| 1097 | // Figure out how to handle the key now that it has been released. |
| 1098 | mPowerKeyPressCounter += 1; |
| 1099 | |
| 1100 | final int maxCount = getMaxMultiPressPowerCount(); |
| 1101 | final long eventTime = event.getDownTime(); |
| 1102 | if (mPowerKeyPressCounter < maxCount) { |
| 1103 | // This could be a multi-press. Wait a little bit longer to confirm. |
| 1104 | // Continue holding the wake lock. |
| 1105 | Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS, |
| 1106 | interactive ? 1 : 0, mPowerKeyPressCounter, eventTime); |
| 1107 | msg.setAsynchronous(true); |
| 1108 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout()); |
| 1109 | return; |
| 1110 | } |
| 1111 | |
| 1112 | // No other actions. Handle it immediately. |
| 1113 | powerPress(eventTime, interactive, mPowerKeyPressCounter); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1114 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1115 | |
| 1116 | // Done. Reset our state. |
| 1117 | finishPowerKeyPress(); |
| 1118 | } |
| 1119 | |
| 1120 | private void finishPowerKeyPress() { |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1121 | mBeganFromNonInteractive = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1122 | mPowerKeyPressCounter = 0; |
| 1123 | if (mPowerKeyWakeLock.isHeld()) { |
| 1124 | mPowerKeyWakeLock.release(); |
| 1125 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | private void cancelPendingPowerKeyAction() { |
| 1129 | if (!mPowerKeyHandled) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1130 | mPowerKeyHandled = true; |
| 1131 | mHandler.removeMessages(MSG_POWER_LONG_PRESS); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1132 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1135 | private void cancelPendingBackKeyAction() { |
| 1136 | if (!mBackKeyHandled) { |
| 1137 | mBackKeyHandled = true; |
| 1138 | mHandler.removeMessages(MSG_BACK_LONG_PRESS); |
| 1139 | } |
| 1140 | } |
| 1141 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1142 | private void powerPress(long eventTime, boolean interactive, int count) { |
| 1143 | if (mScreenOnEarly && !mScreenOnFully) { |
| 1144 | Slog.i(TAG, "Suppressed redundant power key press while " |
| 1145 | + "already in the process of turning the screen on."); |
| 1146 | return; |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 1147 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1148 | |
| 1149 | if (count == 2) { |
| 1150 | powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior); |
| 1151 | } else if (count == 3) { |
| 1152 | powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior); |
Bryce Lee | d9268e3 | 2014-11-17 17:40:59 -0800 | [diff] [blame] | 1153 | } else if (interactive && !mBeganFromNonInteractive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1154 | switch (mShortPressOnPowerBehavior) { |
| 1155 | case SHORT_PRESS_POWER_NOTHING: |
| 1156 | break; |
| 1157 | case SHORT_PRESS_POWER_GO_TO_SLEEP: |
| 1158 | mPowerManager.goToSleep(eventTime, |
| 1159 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1160 | break; |
| 1161 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP: |
| 1162 | mPowerManager.goToSleep(eventTime, |
| 1163 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1164 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1165 | break; |
| 1166 | case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME: |
| 1167 | mPowerManager.goToSleep(eventTime, |
| 1168 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, |
| 1169 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
| 1170 | launchHomeFromHotKey(); |
| 1171 | break; |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1172 | case SHORT_PRESS_POWER_GO_HOME: |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 1173 | launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/); |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 1174 | break; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) { |
| 1180 | switch (behavior) { |
| 1181 | case MULTI_PRESS_POWER_NOTHING: |
| 1182 | break; |
| 1183 | case MULTI_PRESS_POWER_THEATER_MODE: |
Bryce Lee | 3ae447e | 2015-06-30 12:31:41 -0700 | [diff] [blame] | 1184 | if (!isUserSetupComplete()) { |
| 1185 | Slog.i(TAG, "Ignoring toggling theater mode - device not setup."); |
| 1186 | break; |
| 1187 | } |
| 1188 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1189 | if (isTheaterModeEnabled()) { |
| 1190 | Slog.i(TAG, "Toggling theater mode off."); |
| 1191 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1192 | Settings.Global.THEATER_MODE_ON, 0); |
| 1193 | if (!interactive) { |
| 1194 | wakeUpFromPowerKey(eventTime); |
| 1195 | } |
| 1196 | } else { |
| 1197 | Slog.i(TAG, "Toggling theater mode on."); |
| 1198 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1199 | Settings.Global.THEATER_MODE_ON, 1); |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1200 | |
| 1201 | if (mGoToSleepOnButtonPressTheaterMode && interactive) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1202 | mPowerManager.goToSleep(eventTime, |
| 1203 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 1204 | } |
| 1205 | } |
| 1206 | break; |
| 1207 | case MULTI_PRESS_POWER_BRIGHTNESS_BOOST: |
Jeff Brown | 7b5be5e | 2014-11-12 18:45:31 -0800 | [diff] [blame] | 1208 | Slog.i(TAG, "Starting brightness boost."); |
| 1209 | if (!interactive) { |
| 1210 | wakeUpFromPowerKey(eventTime); |
| 1211 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1212 | mPowerManager.boostScreenBrightness(eventTime); |
| 1213 | break; |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | private int getMaxMultiPressPowerCount() { |
| 1218 | if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1219 | return 3; |
| 1220 | } |
| 1221 | if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) { |
| 1222 | return 2; |
| 1223 | } |
| 1224 | return 1; |
| 1225 | } |
| 1226 | |
| 1227 | private void powerLongPress() { |
| 1228 | final int behavior = getResolvedLongPressOnPowerBehavior(); |
| 1229 | switch (behavior) { |
| 1230 | case LONG_PRESS_POWER_NOTHING: |
| 1231 | break; |
| 1232 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 1233 | mPowerKeyHandled = true; |
| 1234 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1235 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 1236 | } |
| 1237 | showGlobalActionsInternal(); |
| 1238 | break; |
| 1239 | case LONG_PRESS_POWER_SHUT_OFF: |
| 1240 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
| 1241 | mPowerKeyHandled = true; |
| 1242 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 1243 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 1244 | mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF); |
| 1245 | break; |
| 1246 | } |
| 1247 | } |
| 1248 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1249 | private void backLongPress() { |
| 1250 | mBackKeyHandled = true; |
| 1251 | |
| 1252 | switch (mLongPressOnBackBehavior) { |
| 1253 | case LONG_PRESS_BACK_NOTHING: |
| 1254 | break; |
| 1255 | case LONG_PRESS_BACK_GO_TO_VOICE_ASSIST: |
| 1256 | Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); |
| 1257 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 1258 | break; |
| 1259 | } |
| 1260 | } |
| 1261 | |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1262 | private void sleepPress(long eventTime) { |
| 1263 | if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { |
| 1264 | launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | private void sleepRelease(long eventTime) { |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1269 | switch (mShortPressOnSleepBehavior) { |
| 1270 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP: |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1271 | case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 1272 | Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); |
| 1273 | mPowerManager.goToSleep(eventTime, |
| 1274 | PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1275 | break; |
| 1276 | } |
| 1277 | } |
| 1278 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1279 | private int getResolvedLongPressOnPowerBehavior() { |
| 1280 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 1281 | return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 1282 | } |
| 1283 | return mLongPressOnPowerBehavior; |
| 1284 | } |
| 1285 | |
| 1286 | private boolean hasLongPressOnPowerBehavior() { |
| 1287 | return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1290 | private boolean hasLongPressOnBackBehavior() { |
| 1291 | return mLongPressOnBackBehavior != LONG_PRESS_BACK_NOTHING; |
| 1292 | } |
| 1293 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1294 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1295 | if (mScreenshotChordEnabled |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1296 | && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered |
| 1297 | && !mScreenshotChordVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1298 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1299 | if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 1300 | && now <= mScreenshotChordPowerKeyTime |
| 1301 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 1302 | mScreenshotChordVolumeDownKeyConsumed = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1303 | cancelPendingPowerKeyAction(); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1304 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1305 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1310 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1311 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1312 | // Double the time it takes to take a screenshot from the keyguard |
| 1313 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1314 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1315 | } |
Justin Koh | feabd2c | 2014-05-02 10:02:44 -0700 | [diff] [blame] | 1316 | return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1319 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 1320 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1323 | private final Runnable mEndCallLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 1324 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1325 | public void run() { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1326 | mEndCallKeyHandled = true; |
| 1327 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 1328 | performAuditoryFeedbackForAccessibilityIfNeed(); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 1329 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1330 | showGlobalActionsInternal(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1331 | } |
| 1332 | }; |
| 1333 | |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1334 | private class ScreenshotRunnable implements Runnable { |
| 1335 | private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN; |
| 1336 | |
| 1337 | public void setScreenshotType(int screenshotType) { |
| 1338 | mScreenshotType = screenshotType; |
| 1339 | } |
| 1340 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1341 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1342 | public void run() { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1343 | takeScreenshot(mScreenshotType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1344 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1348 | |
Alan Viverette | e34560b2 | 2014-07-10 14:50:06 -0700 | [diff] [blame] | 1349 | @Override |
| 1350 | public void showGlobalActions() { |
| 1351 | mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1352 | mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS); |
| 1353 | } |
| 1354 | |
| 1355 | void showGlobalActionsInternal() { |
| 1356 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1357 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 1358 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1359 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 1360 | final boolean keyguardShowing = isKeyguardShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1361 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 1362 | if (keyguardShowing) { |
| 1363 | // since it took two seconds of long press to bring this up, |
| 1364 | // 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] | 1365 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 1370 | return Settings.Global.getInt( |
| 1371 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1372 | } |
| 1373 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 1374 | boolean isUserSetupComplete() { |
| 1375 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1376 | Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0; |
| 1377 | } |
| 1378 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1379 | private void handleShortPressOnHome() { |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1380 | // Turn on the connected TV and switch HDMI input if we're a HDMI playback device. |
| 1381 | getHdmiControl().turnOnTv(); |
| 1382 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1383 | // If there's a dream running then use home to escape the dream |
| 1384 | // but don't actually go home. |
| 1385 | if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) { |
| 1386 | mDreamManagerInternal.stopDream(false /*immediate*/); |
| 1387 | return; |
| 1388 | } |
| 1389 | |
| 1390 | // Go home! |
| 1391 | launchHomeFromHotKey(); |
| 1392 | } |
| 1393 | |
Jinsuk Kim | e601b71 | 2015-07-07 08:01:02 +0900 | [diff] [blame] | 1394 | /** |
| 1395 | * Creates an accessor to HDMI control service that performs the operation of |
| 1396 | * turning on TV (optional) and switching input to us. If HDMI control service |
| 1397 | * is not available or we're not a HDMI playback device, the operation is no-op. |
| 1398 | */ |
| 1399 | private HdmiControl getHdmiControl() { |
| 1400 | if (null == mHdmiControl) { |
| 1401 | HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService( |
| 1402 | Context.HDMI_CONTROL_SERVICE); |
| 1403 | HdmiPlaybackClient client = null; |
| 1404 | if (manager != null) { |
| 1405 | client = manager.getPlaybackClient(); |
| 1406 | } |
| 1407 | mHdmiControl = new HdmiControl(client); |
| 1408 | } |
| 1409 | return mHdmiControl; |
| 1410 | } |
| 1411 | |
| 1412 | private static class HdmiControl { |
| 1413 | private final HdmiPlaybackClient mClient; |
| 1414 | |
| 1415 | private HdmiControl(HdmiPlaybackClient client) { |
| 1416 | mClient = client; |
| 1417 | } |
| 1418 | |
| 1419 | public void turnOnTv() { |
| 1420 | if (mClient == null) { |
| 1421 | return; |
| 1422 | } |
| 1423 | mClient.oneTouchPlay(new OneTouchPlayCallback() { |
| 1424 | @Override |
| 1425 | public void onComplete(int result) { |
| 1426 | if (result != HdmiControlManager.RESULT_SUCCESS) { |
| 1427 | Log.w(TAG, "One touch play failed: " + result); |
| 1428 | } |
| 1429 | } |
| 1430 | }); |
| 1431 | } |
| 1432 | } |
| 1433 | |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1434 | private void handleLongPressOnHome(int deviceId) { |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1435 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) { |
| 1436 | return; |
| 1437 | } |
| 1438 | mHomeConsumed = true; |
| 1439 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1440 | |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1441 | switch (mLongPressOnHomeBehavior) { |
| 1442 | case LONG_PRESS_HOME_RECENT_SYSTEM_UI: |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1443 | toggleRecentApps(); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1444 | break; |
| 1445 | case LONG_PRESS_HOME_ASSIST: |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 1446 | launchAssistAction(null, deviceId); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1447 | break; |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1448 | default: |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 1449 | Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior); |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1450 | break; |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1451 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1452 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 1453 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1454 | private void handleDoubleTapOnHome() { |
| 1455 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1456 | mHomeConsumed = true; |
| 1457 | toggleRecentApps(); |
| 1458 | } |
| 1459 | } |
| 1460 | |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 1461 | private void showTvPictureInPictureMenu(KeyEvent event) { |
| 1462 | if (DEBUG_INPUT) Log.d(TAG, "showTvPictureInPictureMenu event=" + event); |
| 1463 | mHandler.removeMessages(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU); |
| 1464 | Message msg = mHandler.obtainMessage(MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1465 | msg.setAsynchronous(true); |
| 1466 | msg.sendToTarget(); |
| 1467 | } |
| 1468 | |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 1469 | private void showTvPictureInPictureMenuInternal() { |
| 1470 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 1471 | if (statusbar != null) { |
| 1472 | statusbar.showTvPictureInPictureMenu(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1473 | } |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1474 | } |
| 1475 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1476 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 1477 | @Override |
| 1478 | public void run() { |
| 1479 | if (mHomeDoubleTapPending) { |
| 1480 | mHomeDoubleTapPending = false; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1481 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | }; |
| 1485 | |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1486 | private boolean isRoundWindow() { |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1487 | return mContext.getResources().getConfiguration().isScreenRound(); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1488 | } |
| 1489 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1490 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1491 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1492 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1493 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1494 | mContext = context; |
| 1495 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1496 | mWindowManagerFuncs = windowManagerFuncs; |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1497 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 1498 | mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 1499 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 1500 | mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class); |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1501 | mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class); |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 1502 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 1503 | mHasFeatureWatch = mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH); |
Mark Renouf | c125691 | 2015-03-11 14:38:23 -0400 | [diff] [blame] | 1504 | |
| 1505 | // Init display burn-in protection |
| 1506 | boolean burnInProtectionEnabled = context.getResources().getBoolean( |
| 1507 | com.android.internal.R.bool.config_enableBurnInProtection); |
| 1508 | // Allow a system property to override this. Used by developer settings. |
| 1509 | boolean burnInProtectionDevMode = |
| 1510 | SystemProperties.getBoolean("persist.debug.force_burn_in", false); |
| 1511 | if (burnInProtectionEnabled || burnInProtectionDevMode) { |
| 1512 | final int minHorizontal; |
| 1513 | final int maxHorizontal; |
| 1514 | final int minVertical; |
| 1515 | final int maxVertical; |
| 1516 | final int maxRadius; |
| 1517 | if (burnInProtectionDevMode) { |
| 1518 | minHorizontal = -8; |
| 1519 | maxHorizontal = 8; |
| 1520 | minVertical = -8; |
| 1521 | maxVertical = -4; |
| 1522 | maxRadius = (isRoundWindow()) ? 6 : -1; |
| 1523 | } else { |
| 1524 | Resources resources = context.getResources(); |
| 1525 | minHorizontal = resources.getInteger( |
| 1526 | com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset); |
| 1527 | maxHorizontal = resources.getInteger( |
| 1528 | com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset); |
| 1529 | minVertical = resources.getInteger( |
| 1530 | com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset); |
| 1531 | maxVertical = resources.getInteger( |
| 1532 | com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset); |
| 1533 | maxRadius = resources.getInteger( |
| 1534 | com.android.internal.R.integer.config_burnInProtectionMaxRadius); |
| 1535 | } |
| 1536 | mBurnInProtectionHelper = new BurnInProtectionHelper( |
| 1537 | context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius); |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 1538 | } |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 1539 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1540 | mHandler = new PolicyHandler(); |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1541 | mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 1542 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 1543 | try { |
| 1544 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 1545 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1546 | mSettingsObserver = new SettingsObserver(mHandler); |
| 1547 | mSettingsObserver.observe(); |
Svetoslav | 683914b | 2015-01-15 14:22:26 -0800 | [diff] [blame] | 1548 | mShortcutManager = new ShortcutManager(context); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 1549 | mUiMode = context.getResources().getInteger( |
| 1550 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1551 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1552 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 1553 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1554 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 1555 | mEnableCarDockHomeCapture = context.getResources().getBoolean( |
| 1556 | com.android.internal.R.bool.config_enableCarDockHomeLaunch); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1557 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1558 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 1559 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1560 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1561 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 1562 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 1563 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1564 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 1565 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1566 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1567 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1568 | "PhoneWindowManager.mBroadcastWakeLock"); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1569 | mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1570 | "PhoneWindowManager.mPowerKeyWakeLock"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1571 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 1572 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 1573 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1574 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1575 | com.android.internal.R.integer.config_lidOpenRotation); |
| 1576 | mCarDockRotation = readRotation( |
| 1577 | com.android.internal.R.integer.config_carDockRotation); |
| 1578 | mDeskDockRotation = readRotation( |
| 1579 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1580 | mUndockedHdmiRotation = readRotation( |
| 1581 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1582 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1583 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 1584 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 1585 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1586 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 1587 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 1588 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 1589 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 1590 | mLidControlsScreenLock = mContext.getResources().getBoolean( |
| 1591 | com.android.internal.R.bool.config_lidControlsScreenLock); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1592 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 1593 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 1594 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 1595 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1596 | |
| 1597 | mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean( |
| 1598 | com.android.internal.R.bool.config_allowTheaterModeWakeFromKey); |
| 1599 | mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey |
| 1600 | || mContext.getResources().getBoolean( |
| 1601 | com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey); |
| 1602 | mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean( |
| 1603 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 1604 | mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean( |
| 1605 | com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming); |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 1606 | mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean( |
| 1607 | com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens); |
| 1608 | mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean( |
| 1609 | com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch); |
| 1610 | mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean( |
| 1611 | com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture); |
| 1612 | |
Bryce Lee | 55e846d | 2014-11-04 12:43:44 -0800 | [diff] [blame] | 1613 | mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean( |
| 1614 | com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode); |
| 1615 | |
Bryce Lee | d3b2840 | 2015-03-09 15:49:13 +0000 | [diff] [blame] | 1616 | mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean( |
| 1617 | com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive); |
| 1618 | |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 1619 | mLongPressOnBackBehavior = mContext.getResources().getInteger( |
| 1620 | com.android.internal.R.integer.config_longPressOnBackBehavior); |
| 1621 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1622 | mShortPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1623 | com.android.internal.R.integer.config_shortPressOnPowerBehavior); |
| 1624 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 1625 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 1626 | mDoublePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1627 | com.android.internal.R.integer.config_doublePressOnPowerBehavior); |
| 1628 | mTriplePressOnPowerBehavior = mContext.getResources().getInteger( |
| 1629 | com.android.internal.R.integer.config_triplePressOnPowerBehavior); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 1630 | mShortPressOnSleepBehavior = mContext.getResources().getInteger( |
| 1631 | com.android.internal.R.integer.config_shortPressOnSleepBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 1632 | |
John Spurlock | 6156017 | 2015-02-06 19:46:04 -0500 | [diff] [blame] | 1633 | mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 1634 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1635 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1636 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1637 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 1638 | Context.ACCESSIBILITY_SERVICE); |
| 1639 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1640 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1641 | IntentFilter filter = new IntentFilter(); |
| 1642 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 1643 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 1644 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 1645 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1646 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 1647 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 1648 | if (intent != null) { |
| 1649 | // Retrieve current sticky dock event broadcast. |
| 1650 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 1651 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 1652 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 1653 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 1654 | // register for dream-related broadcasts |
| 1655 | filter = new IntentFilter(); |
| 1656 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 1657 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 1658 | context.registerReceiver(mDreamReceiver, filter); |
| 1659 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1660 | // register for multiuser-relevant broadcasts |
| 1661 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 1662 | context.registerReceiver(mMultiuserReceiver, filter); |
| 1663 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1664 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1665 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 1666 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 1667 | @Override |
| 1668 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1669 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1670 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1671 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1672 | } |
| 1673 | @Override |
| 1674 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1675 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1676 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | @Override |
| 1680 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 1681 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 1682 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | @Override |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 1686 | public void onFling(int duration) { |
| 1687 | if (mPowerManagerInternal != null) { |
| 1688 | mPowerManagerInternal.powerHint( |
| 1689 | PowerManagerInternal.POWER_HINT_INTERACTION, duration); |
| 1690 | } |
| 1691 | } |
| 1692 | @Override |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1693 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1694 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1695 | } |
Adrian Roos | 3595be4 | 2015-03-05 16:31:15 +0100 | [diff] [blame] | 1696 | @Override |
| 1697 | public void onDown() { |
| 1698 | mOrientationListener.onTouchStart(); |
| 1699 | } |
| 1700 | @Override |
| 1701 | public void onUpOrCancel() { |
| 1702 | mOrientationListener.onTouchEnd(); |
| 1703 | } |
Jun Mukai | d2e7e35 | 2015-07-22 17:14:02 -0700 | [diff] [blame] | 1704 | @Override |
| 1705 | public void onMouseHoverAtTop() { |
| 1706 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1707 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1708 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS; |
| 1709 | mHandler.sendMessageDelayed(msg, 500); |
| 1710 | } |
| 1711 | @Override |
| 1712 | public void onMouseHoverAtBottom() { |
| 1713 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1714 | Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS); |
| 1715 | msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION; |
| 1716 | mHandler.sendMessageDelayed(msg, 500); |
| 1717 | } |
| 1718 | @Override |
| 1719 | public void onMouseLeaveFromEdge() { |
| 1720 | mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS); |
| 1721 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1722 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1723 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1724 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 1725 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 1726 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1727 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 1728 | com.android.internal.R.array.config_longPressVibePattern); |
| 1729 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 1730 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 1731 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 1732 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 1733 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 1734 | com.android.internal.R.array.config_clockTickVibePattern); |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 1735 | mCalendarDateVibePattern = getLongIntArray(mContext.getResources(), |
| 1736 | com.android.internal.R.array.config_calendarDateVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 1737 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1738 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 1739 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 1740 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 1741 | mContextClickVibePattern = getLongIntArray(mContext.getResources(), |
| 1742 | com.android.internal.R.array.config_contextClickVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1743 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1744 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 1745 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 1746 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 1747 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 1748 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 1749 | // Controls rotation and the like. |
| 1750 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1751 | |
| 1752 | // Match current screen state. |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 1753 | if (!mPowerManager.isInteractive()) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 1754 | startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 1755 | finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 1756 | } |
Jorim Jaggi | 24bec7c | 2015-02-04 12:40:14 +0100 | [diff] [blame] | 1757 | |
| 1758 | mWindowManagerInternal.registerAppTransitionListener( |
| 1759 | mStatusBarController.getAppTransitionListener()); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1762 | /** |
| 1763 | * Read values from config.xml that may be overridden depending on |
| 1764 | * the configuration of the device. |
| 1765 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1766 | */ |
| 1767 | private void readConfigurationDependentBehaviors() { |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1768 | final Resources res = mContext.getResources(); |
| 1769 | |
| 1770 | mLongPressOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1771 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1772 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
Jaewan Kim | 52632e2 | 2016-01-14 18:01:52 +0900 | [diff] [blame] | 1773 | mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) { |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1774 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1775 | } |
| 1776 | |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 1777 | mDoubleTapOnHomeBehavior = res.getInteger( |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1778 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1779 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1780 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1781 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1782 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 1783 | |
| 1784 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING; |
| 1785 | if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) { |
| 1786 | mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE; |
| 1787 | } |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 1788 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 1789 | mNavBarOpacityMode = res.getInteger( |
| 1790 | com.android.internal.R.integer.config_navBarOpacityMode); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1793 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1794 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1795 | // This method might be called before the policy has been fully initialized |
| 1796 | // or for other displays we don't care about. |
| 1797 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1798 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1799 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1800 | mDisplay = display; |
| 1801 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1802 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1803 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1804 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1805 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1806 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1807 | mLandscapeRotation = Surface.ROTATION_0; |
| 1808 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1809 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1810 | mPortraitRotation = Surface.ROTATION_90; |
| 1811 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1812 | } else { |
| 1813 | mPortraitRotation = Surface.ROTATION_270; |
| 1814 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1815 | } |
| 1816 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1817 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1818 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1819 | mPortraitRotation = Surface.ROTATION_0; |
| 1820 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1821 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1822 | mLandscapeRotation = Surface.ROTATION_270; |
| 1823 | mSeascapeRotation = Surface.ROTATION_90; |
| 1824 | } else { |
| 1825 | mLandscapeRotation = Surface.ROTATION_90; |
| 1826 | mSeascapeRotation = Surface.ROTATION_270; |
| 1827 | } |
| 1828 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1829 | |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1830 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1831 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1832 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1833 | |
Devin Kim | d7b12b4 | 2014-05-05 14:34:58 -0700 | [diff] [blame] | 1834 | // Allow the navigation bar to move on non-square small devices (phones). |
| 1835 | mNavigationBarCanMove = width != height && shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1836 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1837 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 1838 | |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1839 | // Allow a system property to override this. Used by the emulator. |
| 1840 | // See also hasNavigationBar(). |
| 1841 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1842 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1843 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1844 | } else if ("0".equals(navBarOverride)) { |
| 1845 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1846 | } |
| 1847 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1848 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1849 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1850 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1851 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1852 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1853 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1854 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1855 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1856 | |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 1857 | // For demo purposes, allow the rotation of the remote display to be controlled. |
| 1858 | // By default, remote display locks rotation to landscape. |
| 1859 | if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { |
| 1860 | mDemoRotation = mPortraitRotation; |
| 1861 | } else { |
| 1862 | mDemoRotation = mLandscapeRotation; |
| 1863 | } |
| 1864 | mDemoRotationLock = SystemProperties.getBoolean( |
| 1865 | "persist.demo.rotationlock", false); |
| 1866 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1867 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1868 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1869 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1870 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1871 | // For debug purposes the next line turns this feature off with: |
| 1872 | // $ adb shell setprop config.override_forced_orient true |
| 1873 | // $ adb shell wm size reset |
| 1874 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1875 | } |
| 1876 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1877 | /** |
| 1878 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1879 | * navigation bar and touch exploration is not enabled |
| 1880 | */ |
| 1881 | private boolean canHideNavigationBar() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 1882 | return mHasNavigationBar; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1885 | @Override |
| 1886 | public boolean isDefaultOrientationForced() { |
| 1887 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1890 | @Override |
| 1891 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1892 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1893 | mOverscanLeft = left; |
| 1894 | mOverscanTop = top; |
| 1895 | mOverscanRight = right; |
| 1896 | mOverscanBottom = bottom; |
| 1897 | } |
| 1898 | } |
| 1899 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1900 | public void updateSettings() { |
| 1901 | ContentResolver resolver = mContext.getContentResolver(); |
| 1902 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1903 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1904 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1905 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1906 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1907 | UserHandle.USER_CURRENT); |
| 1908 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1909 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1910 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1911 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1912 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1913 | // Configure wake gesture. |
| 1914 | boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver, |
| 1915 | Settings.Secure.WAKE_GESTURE_ENABLED, 0, |
| 1916 | UserHandle.USER_CURRENT) != 0; |
| 1917 | if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) { |
| 1918 | mWakeGestureEnabledSetting = wakeGestureEnabledSetting; |
| 1919 | updateWakeGestureListenerLp(); |
| 1920 | } |
| 1921 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1922 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1923 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1924 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1925 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1926 | if (mUserRotation != userRotation) { |
| 1927 | mUserRotation = userRotation; |
| 1928 | updateRotation = true; |
| 1929 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1930 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1931 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1932 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1933 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1934 | if (mUserRotationMode != userRotationMode) { |
| 1935 | mUserRotationMode = userRotationMode; |
| 1936 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1937 | updateOrientationListenerLp(); |
| 1938 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1939 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1940 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1941 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1942 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1943 | if (mPointerLocationMode != pointerLocation) { |
| 1944 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1945 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1946 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1947 | } |
| 1948 | } |
| 1949 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1950 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1951 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1952 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1953 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1954 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1955 | if (mHasSoftInput != hasSoftInput) { |
| 1956 | mHasSoftInput = hasSoftInput; |
| 1957 | updateRotation = true; |
| 1958 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1959 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1960 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1961 | } |
tiger_huang | cc6366d | 2015-06-29 17:17:30 +0800 | [diff] [blame] | 1962 | } |
| 1963 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1964 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1965 | } |
| 1966 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1967 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1968 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1971 | private void updateWakeGestureListenerLp() { |
| 1972 | if (shouldEnableWakeGestureLp()) { |
| 1973 | mWakeGestureListener.requestWakeUpTrigger(); |
| 1974 | } else { |
| 1975 | mWakeGestureListener.cancelWakeUpTrigger(); |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | private boolean shouldEnableWakeGestureLp() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 1980 | return mWakeGestureEnabledSetting && !mAwake |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 1981 | && (!mLidControlsSleep || mLidState != LID_CLOSED) |
| 1982 | && mWakeGestureListener.isSupported(); |
| 1983 | } |
| 1984 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1985 | private void enablePointerLocation() { |
| 1986 | if (mPointerLocationView == null) { |
| 1987 | mPointerLocationView = new PointerLocationView(mContext); |
| 1988 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1989 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1990 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1991 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1992 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1993 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1994 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1995 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1996 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1997 | if (ActivityManager.isHighEndGfx()) { |
| 1998 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1999 | lp.privateFlags |= |
| 2000 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 2001 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2002 | lp.format = PixelFormat.TRANSLUCENT; |
| 2003 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2004 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2005 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2006 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2007 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2008 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2009 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2010 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2011 | |
| 2012 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2013 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 2014 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 2015 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 2016 | wm.removeView(mPointerLocationView); |
| 2017 | mPointerLocationView = null; |
| 2018 | } |
| 2019 | } |
| 2020 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2021 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2022 | try { |
| 2023 | int rotation = mContext.getResources().getInteger(resID); |
| 2024 | switch (rotation) { |
| 2025 | case 0: |
| 2026 | return Surface.ROTATION_0; |
| 2027 | case 90: |
| 2028 | return Surface.ROTATION_90; |
| 2029 | case 180: |
| 2030 | return Surface.ROTATION_180; |
| 2031 | case 270: |
| 2032 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2033 | } |
| 2034 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2035 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2036 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2037 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2041 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2042 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2043 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2044 | |
| 2045 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 2046 | |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 2047 | if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) |
| 2048 | || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) |
| 2049 | || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) { |
| 2050 | return WindowManagerGlobal.ADD_INVALID_TYPE; |
| 2051 | } |
| 2052 | |
| 2053 | if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) { |
| 2054 | // Window manager will make sure these are okay. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2055 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2056 | } |
| 2057 | String permission = null; |
| 2058 | switch (type) { |
| 2059 | case TYPE_TOAST: |
| 2060 | // XXX right now the app process has complete control over |
| 2061 | // this... should introduce a token to let the system |
| 2062 | // monitor/control what they are doing. |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 2063 | outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2064 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 2065 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2066 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 2067 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2068 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2069 | case TYPE_VOICE_INTERACTION: |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2070 | case TYPE_ACCESSIBILITY_OVERLAY: |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 2071 | case TYPE_QS_DIALOG: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 2072 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2073 | break; |
| 2074 | case TYPE_PHONE: |
| 2075 | case TYPE_PRIORITY_PHONE: |
| 2076 | case TYPE_SYSTEM_ALERT: |
| 2077 | case TYPE_SYSTEM_ERROR: |
| 2078 | case TYPE_SYSTEM_OVERLAY: |
| 2079 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2080 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2081 | break; |
| 2082 | default: |
| 2083 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 2084 | } |
| 2085 | if (permission != null) { |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 2086 | if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) { |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2087 | final int callingUid = Binder.getCallingUid(); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2088 | // system processes will be automatically allowed privilege to draw |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2089 | if (callingUid == Process.SYSTEM_UID) { |
| 2090 | return WindowManagerGlobal.ADD_OKAY; |
| 2091 | } |
| 2092 | |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2093 | // check if user has enabled this operation. SecurityException will be thrown if |
| 2094 | // this app has not been allowed by the user |
Svet Ganov | 03f2afc3 | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 2095 | final int mode = mAppOpsManager.checkOpNoThrow(outAppOp[0], callingUid, |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2096 | attrs.packageName); |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2097 | switch (mode) { |
| 2098 | case AppOpsManager.MODE_ALLOWED: |
| 2099 | case AppOpsManager.MODE_IGNORED: |
| 2100 | // although we return ADD_OKAY for MODE_IGNORED, the added window will |
| 2101 | // actually be hidden in WindowManagerService |
| 2102 | return WindowManagerGlobal.ADD_OKAY; |
| 2103 | case AppOpsManager.MODE_ERRORED: |
Svet Ganov | 03f2afc3 | 2016-03-04 16:13:03 -0800 | [diff] [blame] | 2104 | try { |
| 2105 | ApplicationInfo appInfo = mContext.getPackageManager() |
| 2106 | .getApplicationInfo(attrs.packageName, |
| 2107 | UserHandle.getUserId(callingUid)); |
| 2108 | // Don't crash legacy apps |
| 2109 | if (appInfo.targetSdkVersion < Build.VERSION_CODES.M) { |
| 2110 | return WindowManagerGlobal.ADD_OKAY; |
| 2111 | } |
| 2112 | } catch (PackageManager.NameNotFoundException e) { |
| 2113 | /* ignore */ |
| 2114 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2115 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 2116 | default: |
| 2117 | // in the default mode, we will make a decision here based on |
| 2118 | // checkCallingPermission() |
| 2119 | if (mContext.checkCallingPermission(permission) != |
| 2120 | PackageManager.PERMISSION_GRANTED) { |
| 2121 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
| 2122 | } else { |
| 2123 | return WindowManagerGlobal.ADD_OKAY; |
| 2124 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2125 | } |
Billy Lau | cbe540f | 2015-06-25 01:51:44 +0100 | [diff] [blame] | 2126 | } |
| 2127 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2128 | if (mContext.checkCallingOrSelfPermission(permission) |
| 2129 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2130 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2131 | } |
| 2132 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2133 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2134 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2135 | |
| 2136 | @Override |
| 2137 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 2138 | |
| 2139 | // If this switch statement is modified, modify the comment in the declarations of |
| 2140 | // the type in {@link WindowManager.LayoutParams} as well. |
| 2141 | switch (attrs.type) { |
| 2142 | default: |
| 2143 | // These are the windows that by default are shown only to the user that created |
| 2144 | // them. If this needs to be overridden, set |
| 2145 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 2146 | // {@link WindowManager.LayoutParams}. Note that permission |
| 2147 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 2148 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 2149 | return true; |
| 2150 | } |
| 2151 | break; |
| 2152 | |
| 2153 | // These are the windows that by default are shown to all users. However, to |
| 2154 | // protect against spoofing, check permissions below. |
| 2155 | case TYPE_APPLICATION_STARTING: |
| 2156 | case TYPE_BOOT_PROGRESS: |
| 2157 | case TYPE_DISPLAY_OVERLAY: |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2158 | case TYPE_INPUT_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2159 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2160 | case TYPE_KEYGUARD_DIALOG: |
| 2161 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2162 | case TYPE_NAVIGATION_BAR: |
| 2163 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2164 | case TYPE_PHONE: |
| 2165 | case TYPE_POINTER: |
| 2166 | case TYPE_PRIORITY_PHONE: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2167 | case TYPE_SEARCH_BAR: |
| 2168 | case TYPE_STATUS_BAR: |
| 2169 | case TYPE_STATUS_BAR_PANEL: |
| 2170 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 2171 | case TYPE_SYSTEM_DIALOG: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2172 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2173 | case TYPE_PRIVATE_PRESENTATION: |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2174 | case TYPE_DOCK_DIVIDER: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2175 | break; |
| 2176 | } |
| 2177 | |
| 2178 | // Check if third party app has set window to system window type. |
| 2179 | return mContext.checkCallingOrSelfPermission( |
| 2180 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 2181 | != PackageManager.PERMISSION_GRANTED; |
| 2182 | } |
| 2183 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2184 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2185 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 2186 | switch (attrs.type) { |
| 2187 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 2188 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2189 | // These types of windows can't receive input events. |
| 2190 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 2191 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 2192 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2193 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2194 | case TYPE_STATUS_BAR: |
| 2195 | |
| 2196 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 2197 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 2198 | // the keyguard as occluded wouldn't set these flags again. |
| 2199 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 2200 | if (mKeyguardHidden) { |
| 2201 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 2202 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2203 | } |
| 2204 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2205 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 2206 | |
| 2207 | if (attrs.type != TYPE_STATUS_BAR) { |
| 2208 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 2209 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 2210 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2211 | |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2212 | if (ActivityManager.isHighEndGfx()) { |
| 2213 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { |
| 2214 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 2215 | } |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2216 | final boolean forceWindowDrawsStatusBarBackground = |
| 2217 | (attrs.privateFlags & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) |
| 2218 | != 0; |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2219 | if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 2220 | || forceWindowDrawsStatusBarBackground |
| 2221 | && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT) { |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 2222 | attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 2223 | } |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 2224 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2225 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2226 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2227 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 2228 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2229 | } |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2230 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 2231 | private void readCameraLensCoverState() { |
| 2232 | mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState(); |
| 2233 | } |
| 2234 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2235 | private boolean isHidden(int accessibilityMode) { |
| 2236 | switch (accessibilityMode) { |
| 2237 | case 1: |
| 2238 | return mLidState == LID_CLOSED; |
| 2239 | case 2: |
| 2240 | return mLidState == LID_OPEN; |
| 2241 | default: |
| 2242 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2243 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 2244 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2245 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2246 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2247 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2248 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 2249 | int navigationPresence) { |
| 2250 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 2251 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 2252 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2253 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 2254 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2255 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2256 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 2257 | || (keyboardPresence == PRESENCE_INTERNAL |
| 2258 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2259 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2260 | if (!mHasSoftInput) { |
| 2261 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 2262 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2263 | } |
| 2264 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 2265 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 2266 | || (navigationPresence == PRESENCE_INTERNAL |
| 2267 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2268 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2269 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2270 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 2271 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 2272 | @Override |
| 2273 | public void onConfigurationChanged() { |
| 2274 | final Resources res = mContext.getResources(); |
| 2275 | |
| 2276 | mStatusBarHeight = |
| 2277 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
| 2278 | |
| 2279 | // Height of the navigation bar when presented horizontally at bottom |
| 2280 | mNavigationBarHeightForRotationDefault[mPortraitRotation] = |
| 2281 | mNavigationBarHeightForRotationDefault[mUpsideDownRotation] = |
| 2282 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
| 2283 | mNavigationBarHeightForRotationDefault[mLandscapeRotation] = |
| 2284 | mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2285 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
| 2286 | |
| 2287 | // Width of the navigation bar when presented vertically along one side |
| 2288 | mNavigationBarWidthForRotationDefault[mPortraitRotation] = |
| 2289 | mNavigationBarWidthForRotationDefault[mUpsideDownRotation] = |
| 2290 | mNavigationBarWidthForRotationDefault[mLandscapeRotation] = |
| 2291 | mNavigationBarWidthForRotationDefault[mSeascapeRotation] = |
| 2292 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
| 2293 | |
| 2294 | // Height of the navigation bar when presented horizontally at bottom |
| 2295 | mNavigationBarHeightForRotationInCarMode[mPortraitRotation] = |
| 2296 | mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] = |
| 2297 | res.getDimensionPixelSize( |
| 2298 | com.android.internal.R.dimen.navigation_bar_height_car_mode); |
| 2299 | mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] = |
| 2300 | mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize( |
| 2301 | com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode); |
| 2302 | |
| 2303 | // Width of the navigation bar when presented vertically along one side |
| 2304 | mNavigationBarWidthForRotationInCarMode[mPortraitRotation] = |
| 2305 | mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] = |
| 2306 | mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] = |
| 2307 | mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] = |
| 2308 | res.getDimensionPixelSize( |
| 2309 | com.android.internal.R.dimen.navigation_bar_width_car_mode); |
| 2310 | } |
| 2311 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2312 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2313 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2314 | public int windowTypeToLayerLw(int type) { |
| 2315 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2316 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2317 | } |
| 2318 | switch (type) { |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 2319 | case TYPE_PRIVATE_PRESENTATION: |
| 2320 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2321 | case TYPE_WALLPAPER: |
| 2322 | // wallpaper is at the bottom, though the window manager may move it. |
| 2323 | return 2; |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2324 | case TYPE_DOCK_DIVIDER: |
| 2325 | return 2; |
Jason Monk | 8f7f318 | 2015-11-18 16:35:14 -0500 | [diff] [blame] | 2326 | case TYPE_QS_DIALOG: |
| 2327 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2328 | case TYPE_PHONE: |
| 2329 | return 3; |
| 2330 | case TYPE_SEARCH_BAR: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2331 | case TYPE_VOICE_INTERACTION_STARTING: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2332 | return 4; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2333 | case TYPE_VOICE_INTERACTION: |
| 2334 | // voice interaction layer is almost immediately above apps. |
| 2335 | return 5; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2336 | case TYPE_INPUT_CONSUMER: |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 2337 | return 6; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2338 | case TYPE_SYSTEM_DIALOG: |
| 2339 | return 7; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2340 | case TYPE_TOAST: |
| 2341 | // toasts and the plugged-in battery thing |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2342 | return 8; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2343 | case TYPE_PRIORITY_PHONE: |
| 2344 | // 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] | 2345 | return 9; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2346 | case TYPE_DREAM: |
| 2347 | // used for Dreams (screensavers with TYPE_DREAM windows) |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2348 | return 10; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2349 | case TYPE_SYSTEM_ALERT: |
| 2350 | // like the ANR / app crashed dialogs |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2351 | return 11; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2352 | case TYPE_INPUT_METHOD: |
| 2353 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2354 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2355 | case TYPE_INPUT_METHOD_DIALOG: |
| 2356 | // on-screen keyboards and other such input method user interfaces go here. |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 2357 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2358 | case TYPE_KEYGUARD_SCRIM: |
| 2359 | // the safety window that shows behind keyguard while keyguard is starting |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2360 | return 14; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2361 | case TYPE_STATUS_BAR_SUB_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2362 | return 15; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2363 | case TYPE_STATUS_BAR: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2364 | return 16; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2365 | case TYPE_STATUS_BAR_PANEL: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2366 | return 17; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2367 | case TYPE_KEYGUARD_DIALOG: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2368 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2369 | case TYPE_VOLUME_OVERLAY: |
| 2370 | // the on-screen volume indicator and controller shown when the user |
| 2371 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2372 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2373 | case TYPE_SYSTEM_OVERLAY: |
| 2374 | // the on-screen volume indicator and controller shown when the user |
| 2375 | // changes the device volume |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2376 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2377 | case TYPE_NAVIGATION_BAR: |
| 2378 | // the navigation bar, if available, shows atop most things |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2379 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2380 | case TYPE_NAVIGATION_BAR_PANEL: |
| 2381 | // 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] | 2382 | return 22; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2383 | case TYPE_SCREENSHOT: |
| 2384 | // screenshot selection layer shouldn't go above system error, but it should cover |
| 2385 | // navigation bars at the very least. |
| 2386 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2387 | case TYPE_SYSTEM_ERROR: |
| 2388 | // system-level error dialogs |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2389 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2390 | case TYPE_MAGNIFICATION_OVERLAY: |
| 2391 | // used to highlight the magnified portion of a display |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2392 | return 25; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2393 | case TYPE_DISPLAY_OVERLAY: |
| 2394 | // used to simulate secondary display devices |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2395 | return 26; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2396 | case TYPE_DRAG: |
| 2397 | // the drag layer: input for drag-and-drop is associated with this window, |
| 2398 | // which sits above all other focusable windows |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2399 | return 27; |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 2400 | case TYPE_ACCESSIBILITY_OVERLAY: |
| 2401 | // overlay put by accessibility services to intercept user interaction |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2402 | return 28; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2403 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 2404 | return 29; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2405 | case TYPE_BOOT_PROGRESS: |
| 2406 | return 30; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2407 | case TYPE_POINTER: |
| 2408 | // the (mouse) pointer layer |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 2409 | return 31; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2410 | } |
| 2411 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2412 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2416 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2417 | public int subWindowTypeToLayerLw(int type) { |
| 2418 | switch (type) { |
| 2419 | case TYPE_APPLICATION_PANEL: |
| 2420 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 2421 | return APPLICATION_PANEL_SUBLAYER; |
| 2422 | case TYPE_APPLICATION_MEDIA: |
| 2423 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 2424 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 2425 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2426 | case TYPE_APPLICATION_SUB_PANEL: |
| 2427 | return APPLICATION_SUB_PANEL_SUBLAYER; |
Wale Ogunwale | 0a4dc22 | 2015-04-14 12:58:42 -0700 | [diff] [blame] | 2428 | case TYPE_APPLICATION_ABOVE_SUB_PANEL: |
| 2429 | return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2430 | } |
| 2431 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 2432 | return 0; |
| 2433 | } |
| 2434 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2435 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2436 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2437 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2440 | private int getNavigationBarWidth(int rotation, int uiMode) { |
| 2441 | if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
| 2442 | return mNavigationBarWidthForRotationInCarMode[rotation]; |
| 2443 | } else { |
| 2444 | return mNavigationBarWidthForRotationDefault[rotation]; |
| 2445 | } |
| 2446 | } |
| 2447 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 2448 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2449 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, |
| 2450 | int uiMode) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2451 | if (mHasNavigationBar) { |
| 2452 | // For a basic navigation bar, when we are in landscape mode we place |
| 2453 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2454 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2455 | return fullWidth - getNavigationBarWidth(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2456 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2457 | } |
| 2458 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2459 | } |
| 2460 | |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2461 | private int getNavigationBarHeight(int rotation, int uiMode) { |
| 2462 | if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) { |
| 2463 | return mNavigationBarHeightForRotationInCarMode[rotation]; |
| 2464 | } else { |
| 2465 | return mNavigationBarHeightForRotationDefault[rotation]; |
| 2466 | } |
| 2467 | } |
| 2468 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2469 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2470 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, |
| 2471 | int uiMode) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2472 | if (mHasNavigationBar) { |
| 2473 | // For a basic navigation bar, when we are in portrait mode we place |
| 2474 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 2475 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2476 | return fullHeight - getNavigationBarHeight(rotation, uiMode); |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2482 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2483 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) { |
| 2484 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2487 | @Override |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2488 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 2489 | // There is a separate status bar at the top of the display. We don't count that as part |
| 2490 | // 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] | 2491 | // we do want to exclude it since applications can't generally use that part |
| 2492 | // of the screen. |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 2493 | return getNonDecorDisplayHeight( |
| 2494 | fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2495 | } |
| 2496 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2497 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 2498 | public boolean isForceHiding(WindowManager.LayoutParams attrs) { |
| 2499 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2500 | (isKeyguardHostWindow(attrs) && |
| 2501 | (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) || |
Adrian Roos | 69e510d | 2014-07-13 14:57:59 +0200 | [diff] [blame] | 2502 | (attrs.type == TYPE_KEYGUARD_SCRIM); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2503 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2504 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2505 | @Override |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 2506 | public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) { |
| 2507 | return attrs.type == TYPE_STATUS_BAR; |
| 2508 | } |
| 2509 | |
| 2510 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2511 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2512 | switch (attrs.type) { |
| 2513 | case TYPE_STATUS_BAR: |
| 2514 | case TYPE_NAVIGATION_BAR: |
| 2515 | case TYPE_WALLPAPER: |
| 2516 | case TYPE_DREAM: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2517 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2518 | return false; |
| 2519 | default: |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 2520 | // Hide only windows below the keyguard host window. |
| 2521 | return windowTypeToLayerLw(win.getBaseType()) |
| 2522 | < windowTypeToLayerLw(TYPE_STATUS_BAR); |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 2523 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2524 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2525 | |
Craig Mautner | 7d7808f | 2014-09-11 18:02:38 -0700 | [diff] [blame] | 2526 | @Override |
| 2527 | public WindowState getWinShowWhenLockedLw() { |
| 2528 | return mWinShowWhenLocked; |
| 2529 | } |
| 2530 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2531 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2532 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2533 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 2534 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2535 | int icon, int logo, int windowFlags, Configuration overrideConfig) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2536 | if (!SHOW_STARTING_ANIMATIONS) { |
| 2537 | return null; |
| 2538 | } |
| 2539 | if (packageName == null) { |
| 2540 | return null; |
| 2541 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2542 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2543 | WindowManager wm = null; |
| 2544 | View view = null; |
| 2545 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2546 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2547 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 2548 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 2549 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 2550 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2551 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2552 | try { |
| 2553 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 2554 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2555 | } catch (PackageManager.NameNotFoundException e) { |
| 2556 | // Ignore |
| 2557 | } |
| 2558 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2559 | |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2560 | if (overrideConfig != null && overrideConfig != EMPTY) { |
| 2561 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow: creating context based" |
| 2562 | + " on overrideConfig" + overrideConfig + " for starting window"); |
| 2563 | final Context overrideContext = context.createConfigurationContext(overrideConfig); |
| 2564 | overrideContext.setTheme(theme); |
| 2565 | final TypedArray typedArray = overrideContext.obtainStyledAttributes( |
| 2566 | com.android.internal.R.styleable.Window); |
| 2567 | final int resId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0); |
| 2568 | if (resId != 0 && overrideContext.getDrawable(resId) != null) { |
| 2569 | // We want to use the windowBackground for the override context if it is |
| 2570 | // available, otherwise we use the default one to make sure a themed starting |
| 2571 | // window is displayed for the app. |
| 2572 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow: apply overrideConfig" |
| 2573 | + overrideConfig + " to starting window resId=" + resId); |
| 2574 | context = overrideContext; |
| 2575 | } |
| 2576 | } |
| 2577 | |
| 2578 | final PhoneWindow win = new PhoneWindow(context); |
Jorim Jaggi | a16cc15 | 2015-06-01 16:55:05 -0700 | [diff] [blame] | 2579 | win.setIsStartingWindow(true); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2580 | |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2581 | final Resources r = context.getResources(); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2582 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2583 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2584 | win.setType( |
| 2585 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 2586 | |
| 2587 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2588 | // Assumes it's safe to show starting windows of launched apps while |
| 2589 | // the keyguard is being hidden. This is okay because starting windows never show |
| 2590 | // secret information. |
| 2591 | if (mKeyguardHidden) { |
| 2592 | windowFlags |= FLAG_SHOW_WHEN_LOCKED; |
| 2593 | } |
| 2594 | } |
| 2595 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2596 | // Force the window flags: this is a fake window, so it is not really |
| 2597 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 2598 | // flag because we do know that the next window will take input |
| 2599 | // focus, so we want to get the IME window up on top of us right away. |
| 2600 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2601 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2602 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2603 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2604 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2605 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2606 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 2607 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 2608 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2609 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2610 | win.setDefaultIcon(icon); |
| 2611 | win.setDefaultLogo(logo); |
| 2612 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2613 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2614 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 2615 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2616 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 2617 | params.token = appToken; |
| 2618 | params.packageName = packageName; |
| 2619 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 2620 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2621 | params.privateFlags |= |
| 2622 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2623 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2624 | |
| 2625 | if (!compatInfo.supportsScreen()) { |
| 2626 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 2627 | } |
| 2628 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2629 | params.setTitle("Starting " + packageName); |
| 2630 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2631 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 2632 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2633 | |
Wale Ogunwale | dfc1862 | 2016-04-16 15:08:48 -0700 | [diff] [blame] | 2634 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "Adding starting window for " |
| 2635 | + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2636 | |
| 2637 | wm.addView(view, params); |
| 2638 | |
| 2639 | // Only return the view if it was successfully added to the |
| 2640 | // window manager... which we can tell by it having a parent. |
| 2641 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2642 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2643 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 2644 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 2645 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2646 | } catch (RuntimeException e) { |
| 2647 | // don't crash if something else bad happens, for example a |
| 2648 | // failure loading resources because we are loading from an app |
| 2649 | // on external storage that has been unmounted. |
| 2650 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 2651 | } finally { |
| 2652 | if (view != null && view.getParent() == null) { |
| 2653 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 2654 | wm.removeViewImmediate(view); |
| 2655 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | return null; |
| 2659 | } |
| 2660 | |
| 2661 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2662 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2663 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2664 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": " |
| 2665 | + window + " Callers=" + Debug.getCallers(4)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2666 | |
| 2667 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 2668 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2669 | wm.removeView(window); |
| 2670 | } |
| 2671 | } |
| 2672 | |
| 2673 | /** |
| 2674 | * Preflight adding a window to the system. |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2675 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2676 | * Currently enforces that three window types are singletons: |
| 2677 | * <ul> |
| 2678 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2679 | * <li>KEYGUARD_TYPE</li> |
| 2680 | * </ul> |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2681 | * |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2682 | * @param win The window to be added |
| 2683 | * @param attrs Information about the window to be added |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2684 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2685 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 2686 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2687 | */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2688 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2689 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 2690 | switch (attrs.type) { |
| 2691 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 2692 | mContext.enforceCallingOrSelfPermission( |
| 2693 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2694 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2695 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2696 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2697 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2698 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2699 | } |
| 2700 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2701 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2702 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2703 | case TYPE_NAVIGATION_BAR: |
| 2704 | mContext.enforceCallingOrSelfPermission( |
| 2705 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2706 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2707 | if (mNavigationBar != null) { |
| 2708 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2709 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2710 | } |
| 2711 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2712 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2713 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2714 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2715 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 2716 | case TYPE_NAVIGATION_BAR_PANEL: |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2717 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2718 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 2719 | case TYPE_VOICE_INTERACTION_STARTING: |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2720 | mContext.enforceCallingOrSelfPermission( |
| 2721 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 2722 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2723 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2724 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 2725 | if (mKeyguardScrim != null) { |
| 2726 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 2727 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2728 | mKeyguardScrim = win; |
| 2729 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2730 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2731 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 2735 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2736 | public void removeWindowLw(WindowState win) { |
| 2737 | if (mStatusBar == win) { |
| 2738 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2739 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 2740 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2741 | } else if (mKeyguardScrim == win) { |
| 2742 | Log.v(TAG, "Removing keyguard scrim"); |
| 2743 | mKeyguardScrim = null; |
| 2744 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2745 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2746 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | static final boolean PRINT_ANIM = false; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 2751 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2752 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2753 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2754 | public int selectAnimationLw(WindowState win, int transit) { |
| 2755 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 2756 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2757 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2758 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2759 | if (transit == TRANSIT_EXIT |
| 2760 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2761 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2762 | } else if (transit == TRANSIT_ENTER |
| 2763 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2764 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2765 | } |
| 2766 | } else if (win == mNavigationBar) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 2767 | if (win.getAttrs().windowAnimations != 0) { |
| 2768 | return 0; |
| 2769 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2770 | // This can be on either the bottom or the right. |
| 2771 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2772 | if (transit == TRANSIT_EXIT |
| 2773 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2774 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2775 | } else if (transit == TRANSIT_ENTER |
| 2776 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2777 | return R.anim.dock_bottom_enter; |
| 2778 | } |
| 2779 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2780 | if (transit == TRANSIT_EXIT |
| 2781 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2782 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2783 | } else if (transit == TRANSIT_ENTER |
| 2784 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2785 | return R.anim.dock_right_enter; |
| 2786 | } |
| 2787 | } |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 2788 | } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 2789 | return selectDockedDividerAnimationLw(win, transit); |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2793 | if (win.hasAppShownWindows()) { |
| 2794 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 2795 | return com.android.internal.R.anim.app_starting_exit; |
| 2796 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 2797 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 2798 | && transit == TRANSIT_ENTER) { |
| 2799 | // Special case: we are animating in a dream, while the keyguard |
| 2800 | // is shown. We don't want an animation on the dream, because |
| 2801 | // we need it shown immediately with the keyguard animating away |
| 2802 | // to reveal it. |
| 2803 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | return 0; |
| 2807 | } |
| 2808 | |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 2809 | private int selectDockedDividerAnimationLw(WindowState win, int transit) { |
| 2810 | int insets = mWindowManagerFuncs.getDockedDividerInsetsLw(); |
| 2811 | |
| 2812 | // If the divider is behind the navigation bar, don't animate. |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 2813 | final Rect frame = win.getFrameLw(); |
| 2814 | final boolean behindNavBar = mNavigationBar != null |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2815 | && ((mNavigationBarOnBottom |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 2816 | && frame.top + insets >= mNavigationBar.getFrameLw().top) |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2817 | || (!mNavigationBarOnBottom |
Jorim Jaggi | 0cb0f72 | 2016-03-25 20:49:41 -0700 | [diff] [blame] | 2818 | && frame.left + insets >= mNavigationBar.getFrameLw().left)); |
| 2819 | final boolean landscape = frame.height() > frame.width(); |
| 2820 | final boolean offscreenLandscape = landscape && (frame.right - insets <= 0 |
| 2821 | || frame.left + insets >= win.getDisplayFrameLw().right); |
| 2822 | final boolean offscreenPortrait = !landscape && (frame.top - insets <= 0 |
| 2823 | || frame.bottom + insets >= win.getDisplayFrameLw().bottom); |
| 2824 | final boolean offscreen = offscreenLandscape || offscreenPortrait; |
| 2825 | if (behindNavBar || offscreen) { |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 2826 | return 0; |
| 2827 | } |
| 2828 | if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) { |
| 2829 | return R.anim.fade_in; |
| 2830 | } else if (transit == TRANSIT_EXIT) { |
| 2831 | return R.anim.fade_out; |
| 2832 | } else { |
| 2833 | return 0; |
| 2834 | } |
| 2835 | } |
| 2836 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 2837 | @Override |
| 2838 | public void selectRotationAnimationLw(int anim[]) { |
| 2839 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 2840 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 2841 | + (mTopFullscreenOpaqueWindowState == null ? |
| 2842 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 2843 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 2844 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 2845 | case ROTATION_ANIMATION_CROSSFADE: |
| 2846 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 2847 | anim[1] = R.anim.rotation_animation_enter; |
| 2848 | break; |
| 2849 | case ROTATION_ANIMATION_JUMPCUT: |
| 2850 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 2851 | anim[1] = R.anim.rotation_animation_enter; |
| 2852 | break; |
| 2853 | case ROTATION_ANIMATION_ROTATE: |
| 2854 | default: |
| 2855 | anim[0] = anim[1] = 0; |
| 2856 | break; |
| 2857 | } |
| 2858 | } else { |
| 2859 | anim[0] = anim[1] = 0; |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | @Override |
| 2864 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 2865 | boolean forceDefault) { |
| 2866 | switch (exitAnimId) { |
| 2867 | case R.anim.rotation_animation_xfade_exit: |
| 2868 | case R.anim.rotation_animation_jump_exit: |
| 2869 | // These are the only cases that matter. |
| 2870 | if (forceDefault) { |
| 2871 | return false; |
| 2872 | } |
| 2873 | int anim[] = new int[2]; |
| 2874 | selectRotationAnimationLw(anim); |
| 2875 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 2876 | default: |
| 2877 | return true; |
| 2878 | } |
| 2879 | } |
| 2880 | |
| 2881 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2882 | public Animation createForceHideEnterAnimation(boolean onWallpaper, |
| 2883 | boolean goingToNotificationShade) { |
| 2884 | if (goingToNotificationShade) { |
| 2885 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in); |
Craig Mautner | b834080 | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2886 | } |
Craig Mautner | 276a6eb | 2014-11-04 15:32:57 -0800 | [diff] [blame] | 2887 | |
| 2888 | AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ? |
| 2889 | R.anim.lock_screen_behind_enter_wallpaper : |
| 2890 | R.anim.lock_screen_behind_enter); |
| 2891 | |
| 2892 | // TODO: Use XML interpolators when we have log interpolators available in XML. |
| 2893 | final List<Animation> animations = set.getAnimations(); |
| 2894 | for (int i = animations.size() - 1; i >= 0; --i) { |
| 2895 | animations.get(i).setInterpolator(mLogDecelerateInterpolator); |
| 2896 | } |
| 2897 | |
| 2898 | return set; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | |
| 2902 | @Override |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 2903 | public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) { |
| 2904 | if (goingToNotificationShade) { |
| 2905 | return null; |
| 2906 | } else { |
| 2907 | return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit); |
| 2908 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 2909 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 2910 | |
| 2911 | private static void awakenDreams() { |
| 2912 | IDreamManager dreamManager = getDreamManager(); |
| 2913 | if (dreamManager != null) { |
| 2914 | try { |
| 2915 | dreamManager.awaken(); |
| 2916 | } catch (RemoteException e) { |
| 2917 | // fine, stay asleep then |
| 2918 | } |
| 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | static IDreamManager getDreamManager() { |
| 2923 | return IDreamManager.Stub.asInterface( |
| 2924 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 2925 | } |
| 2926 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 2927 | TelecomManager getTelecommService() { |
| 2928 | return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2929 | } |
| 2930 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2931 | static IAudioService getAudioService() { |
| 2932 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 2933 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 2934 | if (audioService == null) { |
| 2935 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 2936 | } |
| 2937 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | boolean keyguardOn() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2941 | return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 2945 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 2946 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 2947 | }; |
| 2948 | |
| 2949 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2950 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2951 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2952 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2953 | final int keyCode = event.getKeyCode(); |
| 2954 | final int repeatCount = event.getRepeatCount(); |
| 2955 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2956 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2957 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2958 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2959 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2960 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2961 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2962 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 2963 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2964 | } |
| 2965 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2966 | // If we think we might have a volume down & power key chord on the way |
| 2967 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 2968 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 2969 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2970 | if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2971 | final long now = SystemClock.uptimeMillis(); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2972 | final long timeoutTime = mScreenshotChordVolumeDownKeyTime |
| 2973 | + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2974 | if (now < timeoutTime) { |
| 2975 | return timeoutTime - now; |
| 2976 | } |
| 2977 | } |
| 2978 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2979 | && mScreenshotChordVolumeDownKeyConsumed) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2980 | if (!down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 2981 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2982 | } |
| 2983 | return -1; |
| 2984 | } |
| 2985 | } |
| 2986 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2987 | // Cancel any pending meta actions if we see any other keys being pressed between the down |
| 2988 | // of the meta key and its corresponding up. |
Michael Wright | 251e35d | 2014-08-22 15:40:27 -0700 | [diff] [blame] | 2989 | if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2990 | mPendingMetaAction = false; |
| 2991 | } |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 2992 | // Any key that is not Alt or Meta cancels Caps Lock combo tracking. |
| 2993 | if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) { |
| 2994 | mPendingCapsLockToggle = false; |
| 2995 | } |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 2996 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2997 | // First we always handle the home key here, so applications |
| 2998 | // can never break it, although if keyguard is on, we do let |
| 2999 | // it handle it, because that gives us the correct 5 second |
| 3000 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3001 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3002 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3003 | // If we have released the home key, and didn't do anything else |
| 3004 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3005 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3006 | cancelPreloadRecentApps(); |
| 3007 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3008 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3009 | if (mHomeConsumed) { |
| 3010 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3011 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3012 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3013 | |
| 3014 | if (canceled) { |
| 3015 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 3016 | return -1; |
| 3017 | } |
| 3018 | |
Yorke Lee | 4f80324 | 2014-12-15 23:22:06 +0000 | [diff] [blame] | 3019 | // If an incoming call is ringing, HOME is totally disabled. |
| 3020 | // (The user is already on the InCallUI at this point, |
| 3021 | // and his ONLY options are to answer or reject the call.) |
| 3022 | TelecomManager telecomManager = getTelecommService(); |
| 3023 | if (telecomManager != null && telecomManager.isRinging()) { |
| 3024 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 3025 | return -1; |
| 3026 | } |
| 3027 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3028 | // Delay handling home if a double-tap is possible. |
| 3029 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 3030 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 3031 | mHomeDoubleTapPending = true; |
| 3032 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 3033 | ViewConfiguration.getDoubleTapTimeout()); |
| 3034 | return -1; |
| 3035 | } |
| 3036 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3037 | handleShortPressOnHome(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3038 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3039 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3040 | |
| 3041 | // If a system window has focus, then it doesn't make sense |
| 3042 | // right now to interact with applications. |
| 3043 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 3044 | if (attrs != null) { |
| 3045 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3046 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 3047 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 3048 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3049 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3050 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3051 | } |
| 3052 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 3053 | for (int i=0; i<typeCount; i++) { |
| 3054 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 3055 | // 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] | 3056 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3057 | } |
| 3058 | } |
| 3059 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3060 | |
| 3061 | // Remember that home is pressed and handle special actions. |
| 3062 | if (repeatCount == 0) { |
| 3063 | mHomePressed = true; |
| 3064 | if (mHomeDoubleTapPending) { |
| 3065 | mHomeDoubleTapPending = false; |
| 3066 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 3067 | handleDoubleTapOnHome(); |
| 3068 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 3069 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 3070 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 3071 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3072 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 3073 | if (!keyguardOn) { |
Jaewan Kim | 76b7d0d | 2016-02-12 19:01:02 +0900 | [diff] [blame] | 3074 | handleLongPressOnHome(event.getDeviceId()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3075 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3076 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3077 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3078 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3079 | // Hijack modified menu keys for debugging features |
| 3080 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 3081 | |
| 3082 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3083 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3084 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3085 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 3086 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3087 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3088 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3089 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3090 | Intent service = new Intent(); |
| 3091 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 3092 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 3093 | boolean shown = Settings.Global.getInt( |
| 3094 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3095 | if (!shown) { |
| 3096 | mContext.startService(service); |
| 3097 | } else { |
| 3098 | mContext.stopService(service); |
| 3099 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 3100 | Settings.Global.putInt( |
| 3101 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3102 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3103 | } |
| 3104 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3105 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3106 | if (down) { |
| 3107 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3108 | mSearchKeyShortcutPending = true; |
| 3109 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3110 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3111 | } else { |
| 3112 | mSearchKeyShortcutPending = false; |
| 3113 | if (mConsumeSearchKeyUp) { |
| 3114 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3115 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3116 | } |
| 3117 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3118 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3119 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3120 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3121 | if (down && repeatCount == 0) { |
| 3122 | preloadRecentApps(); |
| 3123 | } else if (!down) { |
| 3124 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 3125 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3126 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3127 | return -1; |
Jun Mukai | d21b3c8 | 2015-04-23 14:09:34 -0700 | [diff] [blame] | 3128 | } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) { |
| 3129 | if (down) { |
| 3130 | IStatusBarService service = getStatusBarService(); |
| 3131 | if (service != null) { |
| 3132 | try { |
| 3133 | service.expandNotificationsPanel(); |
| 3134 | } catch (RemoteException e) { |
| 3135 | // do nothing. |
| 3136 | } |
| 3137 | } |
| 3138 | } |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3139 | } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed() |
| 3140 | && event.isCtrlPressed()) { |
| 3141 | if (down && repeatCount == 0) { |
| 3142 | int type = event.isShiftPressed() ? TAKE_SCREENSHOT_SELECTED_REGION |
| 3143 | : TAKE_SCREENSHOT_FULLSCREEN; |
| 3144 | mScreenshotRunnable.setScreenshotType(type); |
| 3145 | mHandler.post(mScreenshotRunnable); |
| 3146 | return -1; |
| 3147 | } |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3148 | } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) { |
Andrei Stingaceanu | 002f712 | 2016-03-30 12:22:05 +0100 | [diff] [blame] | 3149 | if (down && repeatCount == 0 && !isKeyguardLocked()) { |
| 3150 | toggleKeyboardShortcutsMenu(event.getDeviceId()); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3151 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3152 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 3153 | if (down) { |
| 3154 | if (repeatCount == 0) { |
| 3155 | mAssistKeyLongPressed = false; |
| 3156 | } else if (repeatCount == 1) { |
| 3157 | mAssistKeyLongPressed = true; |
| 3158 | if (!keyguardOn) { |
| 3159 | launchAssistLongPressAction(); |
| 3160 | } |
| 3161 | } |
| 3162 | } else { |
| 3163 | if (mAssistKeyLongPressed) { |
| 3164 | mAssistKeyLongPressed = false; |
| 3165 | } else { |
| 3166 | if (!keyguardOn) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3167 | launchAssistAction(null, event.getDeviceId()); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3168 | } |
| 3169 | } |
| 3170 | } |
| 3171 | return -1; |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3172 | } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) { |
| 3173 | if (!down) { |
| 3174 | Intent voiceIntent; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3175 | if (!keyguardOn) { |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3176 | voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 3177 | } else { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 3178 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 3179 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 3180 | if (dic != null) { |
| 3181 | try { |
| 3182 | dic.exitIdle("voice-search"); |
| 3183 | } catch (RemoteException e) { |
| 3184 | } |
| 3185 | } |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3186 | voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 3187 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3188 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3189 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | dc63f7b | 2014-08-21 19:05:21 -0700 | [diff] [blame] | 3190 | } |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3191 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 3192 | if (down && repeatCount == 0) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 3193 | mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN); |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 3194 | mHandler.post(mScreenshotRunnable); |
| 3195 | } |
| 3196 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3197 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 3198 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 3199 | if (down) { |
| 3200 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 3201 | |
| 3202 | // Disable autobrightness if it's on |
| 3203 | int auto = Settings.System.getIntForUser( |
| 3204 | mContext.getContentResolver(), |
| 3205 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3206 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3207 | UserHandle.USER_CURRENT_OR_SELF); |
| 3208 | if (auto != 0) { |
| 3209 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3210 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 3211 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 3212 | UserHandle.USER_CURRENT_OR_SELF); |
| 3213 | } |
| 3214 | |
| 3215 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 3216 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 3217 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 3218 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 3219 | Settings.System.SCREEN_BRIGHTNESS, |
| 3220 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 3221 | UserHandle.USER_CURRENT_OR_SELF); |
| 3222 | brightness += step; |
| 3223 | // Make sure we don't go beyond the limits. |
| 3224 | brightness = Math.min(max, brightness); |
| 3225 | brightness = Math.max(min, brightness); |
| 3226 | |
| 3227 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 3228 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 3229 | UserHandle.USER_CURRENT_OR_SELF); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3230 | startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), |
Alan Viverette | 5a39949 | 2014-07-14 16:19:38 -0700 | [diff] [blame] | 3231 | UserHandle.CURRENT_OR_SELF); |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 3232 | } |
| 3233 | return -1; |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 3234 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 3235 | || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 3236 | || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) { |
| 3237 | if (mUseTvRouting) { |
| 3238 | // On TVs volume keys never go to the foreground app. |
| 3239 | dispatchDirectAudioEvent(event); |
| 3240 | return -1; |
| 3241 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3242 | } |
| 3243 | |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 3244 | // Toggle Caps Lock on META-ALT. |
| 3245 | boolean actionTriggered = false; |
| 3246 | if (KeyEvent.isModifierKey(keyCode)) { |
| 3247 | if (!mPendingCapsLockToggle) { |
| 3248 | // Start tracking meta state for combo. |
| 3249 | mInitialMetaState = mMetaState; |
| 3250 | mPendingCapsLockToggle = true; |
| 3251 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3252 | int altOnMask = mMetaState & KeyEvent.META_ALT_MASK; |
| 3253 | int metaOnMask = mMetaState & KeyEvent.META_META_MASK; |
| 3254 | |
| 3255 | // Check for Caps Lock toggle |
| 3256 | if ((metaOnMask != 0) && (altOnMask != 0)) { |
| 3257 | // Check if nothing else is pressed |
| 3258 | if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) { |
| 3259 | // Handle Caps Lock Toggle |
| 3260 | mInputManagerInternal.toggleCapsLock(event.getDeviceId()); |
| 3261 | actionTriggered = true; |
| 3262 | } |
| 3263 | } |
| 3264 | |
| 3265 | // Always stop tracking when key goes up. |
| 3266 | mPendingCapsLockToggle = false; |
| 3267 | } |
| 3268 | } |
| 3269 | // Store current meta state to be able to evaluate it later. |
| 3270 | mMetaState = metaState; |
| 3271 | |
| 3272 | if (actionTriggered) { |
| 3273 | return -1; |
| 3274 | } |
| 3275 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3276 | if (KeyEvent.isMetaKey(keyCode)) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3277 | if (down) { |
| 3278 | mPendingMetaAction = true; |
| 3279 | } else if (mPendingMetaAction) { |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3280 | launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId()); |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3281 | } |
| 3282 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3283 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3284 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3285 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3286 | // Any printing key that is chorded with Search should be consumed |
| 3287 | // even if no shortcut was invoked. This prevents text from being |
| 3288 | // inadvertently inserted when using a keyboard that has built-in macro |
| 3289 | // 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] | 3290 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3291 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 3292 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3293 | mConsumeSearchKeyUp = true; |
| 3294 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3295 | if (down && repeatCount == 0 && !keyguardOn) { |
| 3296 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 3297 | if (shortcutIntent != null) { |
| 3298 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3299 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3300 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3301 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3302 | } catch (ActivityNotFoundException ex) { |
| 3303 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3304 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3305 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 3306 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 3307 | } else { |
| 3308 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3309 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3310 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3311 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3312 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3313 | } |
| 3314 | } |
| 3315 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3316 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3317 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3318 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 3319 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3320 | if (kcm.isPrintingKey(keyCode)) { |
| 3321 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 3322 | metaState & ~(KeyEvent.META_META_ON |
| 3323 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 3324 | if (shortcutIntent != null) { |
| 3325 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3326 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3327 | startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3328 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3329 | } catch (ActivityNotFoundException ex) { |
| 3330 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 3331 | + "the activity to which it is registered was not found: " |
| 3332 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 3333 | } |
| 3334 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3335 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3336 | } |
| 3337 | } |
| 3338 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3339 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 3340 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3341 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 3342 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 3343 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3344 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3345 | try { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3346 | startActivityAsUser(intent, UserHandle.CURRENT); |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3347 | dismissKeyboardShortcutsMenu(); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3348 | } catch (ActivityNotFoundException ex) { |
| 3349 | Slog.w(TAG, "Dropping application launch key because " |
| 3350 | + "the activity to which it is registered was not found: " |
| 3351 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 3352 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3353 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 3354 | } |
| 3355 | } |
| 3356 | |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3357 | // Display task switcher for ALT-TAB. |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3358 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Michael Wright | d847ad5 | 2015-10-24 13:24:15 +0100 | [diff] [blame] | 3359 | if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3360 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
Michael Wright | 61c4675 | 2014-08-21 16:57:33 -0700 | [diff] [blame] | 3361 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3362 | mRecentAppsHeldModifiers = shiftlessModifiers; |
| 3363 | showRecentApps(true); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3364 | return -1; |
| 3365 | } |
| 3366 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3367 | } else if (!down && mRecentAppsHeldModifiers != 0 |
| 3368 | && (metaState & mRecentAppsHeldModifiers) == 0) { |
| 3369 | mRecentAppsHeldModifiers = 0; |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3370 | hideRecentApps(true, false); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3371 | } |
| 3372 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3373 | // Handle input method switching. |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3374 | if (down && repeatCount == 0 |
| 3375 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3376 | || (keyCode == KeyEvent.KEYCODE_SPACE |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3377 | && (metaState & KeyEvent.META_META_MASK) != 0))) { |
| 3378 | final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0; |
| 3379 | mWindowManagerFuncs.switchInputMethod(forwardDirection); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 3380 | return -1; |
| 3381 | } |
| 3382 | if (mLanguageSwitchKeyPressed && !down |
| 3383 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 3384 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 3385 | mLanguageSwitchKeyPressed = false; |
| 3386 | return -1; |
| 3387 | } |
| 3388 | |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 3389 | if (isValidGlobalKey(keyCode) |
| 3390 | && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3391 | return -1; |
| 3392 | } |
| 3393 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3394 | if (down) { |
| 3395 | long shortcutCode = (long) keyCode; |
| 3396 | if (event.isCtrlPressed()) { |
| 3397 | shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE; |
| 3398 | } |
| 3399 | |
| 3400 | if (event.isAltPressed()) { |
| 3401 | shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE; |
| 3402 | } |
| 3403 | |
| 3404 | if (event.isShiftPressed()) { |
| 3405 | shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE; |
| 3406 | } |
| 3407 | |
| 3408 | if (event.isMetaPressed()) { |
| 3409 | shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE; |
| 3410 | } |
| 3411 | |
| 3412 | IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode); |
| 3413 | if (shortcutService != null) { |
| 3414 | try { |
Muyuan Li | b5dd049 | 2016-04-14 13:22:20 -0700 | [diff] [blame] | 3415 | if (isUserSetupComplete()) { |
| 3416 | shortcutService.notifyShortcutKeyPressed(shortcutCode); |
| 3417 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3418 | } catch (RemoteException e) { |
| 3419 | mShortcutKeyServices.delete(shortcutCode); |
| 3420 | } |
| 3421 | return -1; |
| 3422 | } |
| 3423 | } |
| 3424 | |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3425 | // Reserve all the META modifier combos for system behavior |
Michael Wright | ce0c13a | 2014-07-30 10:49:21 -0700 | [diff] [blame] | 3426 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
Michael Wright | 6a62e55 | 2014-06-03 19:19:48 -0700 | [diff] [blame] | 3427 | return -1; |
| 3428 | } |
| 3429 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 3430 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3431 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3432 | } |
| 3433 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3434 | /** {@inheritDoc} */ |
| 3435 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3436 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3437 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3438 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3439 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 3440 | + ", flags=" + event.getFlags() |
| 3441 | + ", keyCode=" + event.getKeyCode() |
| 3442 | + ", scanCode=" + event.getScanCode() |
| 3443 | + ", metaState=" + event.getMetaState() |
| 3444 | + ", repeatCount=" + event.getRepeatCount() |
| 3445 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3446 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3447 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3448 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3449 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3450 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 3451 | final int keyCode = event.getKeyCode(); |
| 3452 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3453 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 3454 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3455 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 3456 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3457 | final FallbackAction fallbackAction; |
| 3458 | if (initialDown) { |
| 3459 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 3460 | } else { |
| 3461 | fallbackAction = mFallbackActions.get(keyCode); |
| 3462 | } |
| 3463 | |
| 3464 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3465 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3466 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 3467 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3468 | } |
| 3469 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3470 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 3471 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3472 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3473 | event.getAction(), fallbackAction.keyCode, |
| 3474 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3475 | event.getDeviceId(), event.getScanCode(), |
| 3476 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3477 | |
| 3478 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 3479 | fallbackEvent.recycle(); |
| 3480 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3481 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3482 | |
| 3483 | if (initialDown) { |
| 3484 | mFallbackActions.put(keyCode, fallbackAction); |
| 3485 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 3486 | mFallbackActions.remove(keyCode); |
| 3487 | fallbackAction.recycle(); |
| 3488 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3489 | } |
| 3490 | } |
| 3491 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3492 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3493 | if (fallbackEvent == null) { |
| 3494 | Slog.d(TAG, "No fallback."); |
| 3495 | } else { |
| 3496 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 3497 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 3498 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3499 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3502 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3503 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 3504 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 3505 | long delayMillis = interceptKeyBeforeDispatching( |
| 3506 | win, fallbackEvent, policyFlags); |
| 3507 | if (delayMillis == 0) { |
| 3508 | return true; |
| 3509 | } |
| 3510 | } |
| 3511 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3512 | } |
| 3513 | |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3514 | public void registerShortcutKey(long shortcutCode, IShortcutService shortcutService) |
| 3515 | throws RemoteException { |
| 3516 | synchronized (mLock) { |
| 3517 | IShortcutService service = mShortcutKeyServices.get(shortcutCode); |
Muyuan Li | 24d24ac | 2016-03-03 21:15:02 -0800 | [diff] [blame] | 3518 | if (service != null && service.asBinder().pingBinder()) { |
| 3519 | throw new RemoteException("Key already exists."); |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | mShortcutKeyServices.put(shortcutCode, shortcutService); |
| 3523 | } |
| 3524 | } |
| 3525 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3526 | private void launchAssistLongPressAction() { |
| 3527 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 3528 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 3529 | |
| 3530 | // launch the search activity |
| 3531 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 3532 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 3533 | try { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 3534 | // TODO: This only stops the factory-installed search manager. |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 3535 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3536 | SearchManager searchManager = getSearchManager(); |
| 3537 | if (searchManager != null) { |
| 3538 | searchManager.stopSearch(); |
| 3539 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3540 | startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3541 | } catch (ActivityNotFoundException e) { |
| 3542 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 3543 | } |
| 3544 | } |
| 3545 | |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3546 | private void launchAssistAction(String hint, int deviceId) { |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3547 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Maurice Lam | 39d1381 | 2015-07-23 20:49:20 -0700 | [diff] [blame] | 3548 | if (!isUserSetupComplete()) { |
| 3549 | // Disable opening assist window during setup |
| 3550 | return; |
| 3551 | } |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 3552 | Bundle args = null; |
| 3553 | if (deviceId > Integer.MIN_VALUE) { |
| 3554 | args = new Bundle(); |
| 3555 | args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3556 | } |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3557 | if ((mContext.getResources().getConfiguration().uiMode |
| 3558 | & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { |
| 3559 | // On TV, use legacy handling until assistants are implemented in the proper way. |
| 3560 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 3561 | .launchLegacyAssist(hint, UserHandle.myUserId(), args); |
| 3562 | } else { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3563 | if (hint != null) { |
| 3564 | if (args == null) { |
| 3565 | args = new Bundle(); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3566 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3567 | args.putBoolean(hint, true); |
| 3568 | } |
| 3569 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3570 | if (statusbar != null) { |
| 3571 | statusbar.startAssist(args); |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 3572 | } |
| 3573 | } |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 3576 | private void startActivityAsUser(Intent intent, UserHandle handle) { |
| 3577 | if (isUserSetupComplete()) { |
| 3578 | mContext.startActivityAsUser(intent, handle); |
| 3579 | } else { |
| 3580 | Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent); |
| 3581 | } |
| 3582 | } |
| 3583 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 3584 | private SearchManager getSearchManager() { |
| 3585 | if (mSearchManager == null) { |
| 3586 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 3587 | } |
| 3588 | return mSearchManager; |
| 3589 | } |
| 3590 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3591 | private void preloadRecentApps() { |
| 3592 | mPreloadedRecentApps = true; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3593 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3594 | if (statusbar != null) { |
| 3595 | statusbar.preloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | private void cancelPreloadRecentApps() { |
| 3600 | if (mPreloadedRecentApps) { |
| 3601 | mPreloadedRecentApps = false; |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3602 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3603 | if (statusbar != null) { |
| 3604 | statusbar.cancelPreloadRecentApps(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3605 | } |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | private void toggleRecentApps() { |
| 3610 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3611 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3612 | if (statusbar != null) { |
| 3613 | statusbar.toggleRecentApps(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3614 | } |
| 3615 | } |
| 3616 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3617 | @Override |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 3618 | public void showRecentApps(boolean fromHome) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3619 | mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS); |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 3620 | mHandler.obtainMessage(MSG_DISPATCH_SHOW_RECENTS, fromHome ? 1 : 0, 0).sendToTarget(); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3621 | } |
| 3622 | |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 3623 | private void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3624 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3625 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3626 | if (statusbar != null) { |
| 3627 | statusbar.showRecentApps(triggeredFromAltTab, fromHome); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 3628 | } |
| 3629 | } |
| 3630 | |
Clara Bayarri | 4e850ff | 2016-03-02 11:12:32 -0800 | [diff] [blame] | 3631 | private void toggleKeyboardShortcutsMenu(int deviceId) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3632 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3633 | if (statusbar != null) { |
| 3634 | statusbar.toggleKeyboardShortcutsMenu(deviceId); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 3635 | } |
| 3636 | } |
| 3637 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 3638 | private void dismissKeyboardShortcutsMenu() { |
| 3639 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3640 | if (statusbar != null) { |
| 3641 | statusbar.dismissKeyboardShortcutsMenu(); |
| 3642 | } |
| 3643 | } |
| 3644 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 3645 | private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3646 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 3647 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 3648 | if (statusbar != null) { |
| 3649 | statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 3650 | } |
| 3651 | } |
| 3652 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3653 | void launchHomeFromHotKey() { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3654 | launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 3655 | } |
| 3656 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3657 | /** |
| 3658 | * A home key -> launch home action was detected. Take the appropriate action |
| 3659 | * given the situation with the keyguard. |
| 3660 | */ |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3661 | void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) { |
| 3662 | if (respectKeyguard) { |
| 3663 | if (isKeyguardShowingAndNotOccluded()) { |
| 3664 | // don't launch home if keyguard showing |
| 3665 | return; |
| 3666 | } |
| 3667 | |
| 3668 | if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
| 3669 | // when in keyguard restricted mode, must first verify unlock |
| 3670 | // before launching home |
| 3671 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
| 3672 | @Override |
| 3673 | public void onKeyguardExitResult(boolean success) { |
| 3674 | if (success) { |
| 3675 | try { |
| 3676 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3677 | } catch (RemoteException e) { |
| 3678 | } |
| 3679 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3680 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 3681 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3682 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3683 | }); |
| 3684 | return; |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | // no keyguard stuff to worry about, just launch home! |
| 3689 | try { |
| 3690 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 3691 | } catch (RemoteException e) { |
| 3692 | } |
| 3693 | if (mRecentsVisible) { |
| 3694 | // Hide Recents and notify it to launch Home |
| 3695 | if (awakenFromDreams) { |
| 3696 | awakenDreams(); |
| 3697 | } |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3698 | hideRecentApps(false, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3699 | } else { |
Bryce Lee | 662ed80 | 2015-04-10 20:11:39 +0000 | [diff] [blame] | 3700 | // Otherwise, just launch Home |
| 3701 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
| 3702 | startDockOrHome(true /*fromHomeKey*/, awakenFromDreams); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3703 | } |
| 3704 | } |
| 3705 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3706 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 3707 | @Override |
| 3708 | public void run() { |
| 3709 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 3710 | // Clear flags. |
| 3711 | mForceClearedSystemUiFlags &= |
| 3712 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 3713 | } |
| 3714 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3715 | } |
| 3716 | }; |
| 3717 | |
| 3718 | /** |
| 3719 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 3720 | * to determine when the nav bar should be shown and prevent applications from |
| 3721 | * receiving those touches. |
| 3722 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3723 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 3724 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 3725 | super(inputChannel, looper); |
| 3726 | } |
| 3727 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3728 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3729 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3730 | boolean handled = false; |
| 3731 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 3732 | if (event instanceof MotionEvent |
| 3733 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 3734 | final MotionEvent motionEvent = (MotionEvent)event; |
| 3735 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3736 | // When the user taps down, we re-show the nav bar. |
| 3737 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3738 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3739 | // Any user activity always causes us to show the |
| 3740 | // navigation controls, if they had been hidden. |
| 3741 | // We also clear the low profile and only content |
| 3742 | // flags so that tapping on the screen will atomically |
| 3743 | // restore all currently hidden screen decorations. |
| 3744 | int newVal = mResettingSystemUiFlags | |
| 3745 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 3746 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 3747 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3748 | if (mResettingSystemUiFlags != newVal) { |
| 3749 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3750 | changed = true; |
| 3751 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3752 | // We don't allow the system's nav bar to be hidden |
| 3753 | // again for 1 second, to prevent applications from |
| 3754 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3755 | newVal = mForceClearedSystemUiFlags | |
| 3756 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3757 | if (mForceClearedSystemUiFlags != newVal) { |
| 3758 | mForceClearedSystemUiFlags = newVal; |
| 3759 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 3760 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3761 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3762 | } |
| 3763 | if (changed) { |
| 3764 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 3765 | } |
| 3766 | } |
| 3767 | } |
| 3768 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3769 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3770 | } |
| 3771 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3772 | } |
| 3773 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 3774 | new InputEventReceiver.Factory() { |
| 3775 | @Override |
| 3776 | public InputEventReceiver createInputEventReceiver( |
| 3777 | InputChannel inputChannel, Looper looper) { |
| 3778 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 3779 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3780 | }; |
| 3781 | |
| 3782 | @Override |
| 3783 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 3784 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 3785 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 3786 | mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0; |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 3787 | mTvPictureInPictureVisible = (visibility & View.TV_PICTURE_IN_PICTURE_VISIBLE) > 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3788 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3789 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 3790 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3791 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3792 | // Clear any bits in the new visibility that are currently being |
| 3793 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3794 | return visibility & ~mResettingSystemUiFlags |
| 3795 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3798 | @Override |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 3799 | public boolean getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation, |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3800 | Rect outContentInsets, Rect outStableInsets, Rect outOutsets) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3801 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 3802 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 3803 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3804 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3805 | final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl); |
| 3806 | if (useOutsets) { |
| 3807 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 3808 | if (outset > 0) { |
| 3809 | if (displayRotation == Surface.ROTATION_0) { |
| 3810 | outOutsets.bottom += outset; |
| 3811 | } else if (displayRotation == Surface.ROTATION_90) { |
| 3812 | outOutsets.right += outset; |
| 3813 | } else if (displayRotation == Surface.ROTATION_180) { |
| 3814 | outOutsets.top += outset; |
| 3815 | } else if (displayRotation == Surface.ROTATION_270) { |
| 3816 | outOutsets.left += outset; |
| 3817 | } |
| 3818 | } |
| 3819 | } |
| 3820 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3821 | 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] | 3822 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3823 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3824 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3825 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3826 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3827 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 3828 | } else { |
| 3829 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3830 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 3831 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3832 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 3833 | if ((fl & FLAG_FULLSCREEN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3834 | outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3835 | availRight - mStableFullscreenRight, |
| 3836 | availBottom - mStableFullscreenBottom); |
| 3837 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3838 | outContentInsets.set(mStableLeft, mStableTop, |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3839 | availRight - mStableRight, availBottom - mStableBottom); |
| 3840 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3841 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3842 | outContentInsets.setEmpty(); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3843 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3844 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3845 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3846 | availRight - mCurRight, availBottom - mCurBottom); |
| 3847 | } else { |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3848 | outContentInsets.set(mCurLeft, mCurTop, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3849 | availRight - mCurRight, availBottom - mCurBottom); |
| 3850 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3851 | |
| 3852 | outStableInsets.set(mStableLeft, mStableTop, |
| 3853 | availRight - mStableRight, availBottom - mStableBottom); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 3854 | return mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3855 | } |
Adrian Roos | 37d7a68 | 2014-11-06 18:15:16 +0100 | [diff] [blame] | 3856 | outContentInsets.setEmpty(); |
| 3857 | outStableInsets.setEmpty(); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 3858 | return mForceShowSystemBars; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3859 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3860 | |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3861 | private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) { |
| 3862 | return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 3863 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0; |
| 3864 | } |
| 3865 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3866 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3867 | @Override |
| 3868 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3869 | int displayRotation, int uiMode) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 3870 | mDisplayRotation = displayRotation; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3871 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 3872 | if (isDefaultDisplay) { |
| 3873 | switch (displayRotation) { |
| 3874 | case Surface.ROTATION_90: |
| 3875 | overscanLeft = mOverscanTop; |
| 3876 | overscanTop = mOverscanRight; |
| 3877 | overscanRight = mOverscanBottom; |
| 3878 | overscanBottom = mOverscanLeft; |
| 3879 | break; |
| 3880 | case Surface.ROTATION_180: |
| 3881 | overscanLeft = mOverscanRight; |
| 3882 | overscanTop = mOverscanBottom; |
| 3883 | overscanRight = mOverscanLeft; |
| 3884 | overscanBottom = mOverscanTop; |
| 3885 | break; |
| 3886 | case Surface.ROTATION_270: |
| 3887 | overscanLeft = mOverscanBottom; |
| 3888 | overscanTop = mOverscanLeft; |
| 3889 | overscanRight = mOverscanTop; |
| 3890 | overscanBottom = mOverscanRight; |
| 3891 | break; |
| 3892 | default: |
| 3893 | overscanLeft = mOverscanLeft; |
| 3894 | overscanTop = mOverscanTop; |
| 3895 | overscanRight = mOverscanRight; |
| 3896 | overscanBottom = mOverscanBottom; |
| 3897 | break; |
| 3898 | } |
| 3899 | } else { |
| 3900 | overscanLeft = 0; |
| 3901 | overscanTop = 0; |
| 3902 | overscanRight = 0; |
| 3903 | overscanBottom = 0; |
| 3904 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3905 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 3906 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 3907 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 3908 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3909 | mSystemLeft = 0; |
| 3910 | mSystemTop = 0; |
| 3911 | mSystemRight = displayWidth; |
| 3912 | mSystemBottom = displayHeight; |
| 3913 | mUnrestrictedScreenLeft = overscanLeft; |
| 3914 | mUnrestrictedScreenTop = overscanTop; |
| 3915 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 3916 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 3917 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 3918 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3919 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 3920 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3921 | mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3922 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3923 | mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3924 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3925 | mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3926 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 3927 | mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3928 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3929 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3930 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3931 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3932 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 3933 | final Rect pf = mTmpParentFrame; |
| 3934 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3935 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3936 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3937 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3938 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 3939 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 3940 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 3941 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3942 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3943 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3944 | if (isDefaultDisplay) { |
| 3945 | // For purposes of putting out fake window up to steal focus, we will |
| 3946 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 3947 | final int sysui = mLastSystemUiFlags; |
| 3948 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 3949 | boolean navTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 3950 | & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3951 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 3952 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 3953 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 3954 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Adrian Roos | 4fb3ee3 | 2014-08-22 19:29:09 +0200 | [diff] [blame] | 3955 | boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen; |
| 3956 | if (!isKeyguardShowing) { |
| 3957 | navTranslucent &= areTranslucentBarsAllowed(); |
| 3958 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3959 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3960 | // When the navigation bar isn't visible, we put up a fake |
| 3961 | // input window to catch all touch events. This way we can |
| 3962 | // detect when the user presses anywhere to bring back the nav |
| 3963 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 3964 | if (navVisible || navAllowedHidden) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3965 | if (mInputConsumer != null) { |
| 3966 | mInputConsumer.dismiss(); |
| 3967 | mInputConsumer = null; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3968 | } |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 3969 | } else if (mInputConsumer == null) { |
| 3970 | mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(), |
| 3971 | mHideNavInputEventReceiverFactory); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3972 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 3973 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3974 | // For purposes of positioning and showing the nav bar, if we have |
| 3975 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 3976 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3977 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3978 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3979 | boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 3980 | displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent, |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3981 | navAllowedHidden); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3982 | 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] | 3983 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3984 | updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3985 | if (updateSysUiVisibility) { |
| 3986 | updateSystemUiVisibilityLw(); |
| 3987 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3988 | } |
| 3989 | } |
| 3990 | |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 3991 | private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui, |
| 3992 | boolean isKeyguardShowing) { |
| 3993 | // decide where the status bar goes ahead of time |
| 3994 | if (mStatusBar != null) { |
| 3995 | // apply any navigation bar insets |
| 3996 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3997 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3998 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 3999 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 4000 | + mUnrestrictedScreenTop; |
| 4001 | vf.left = mStableLeft; |
| 4002 | vf.top = mStableTop; |
| 4003 | vf.right = mStableRight; |
| 4004 | vf.bottom = mStableBottom; |
| 4005 | |
| 4006 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 4007 | |
| 4008 | // Let the status bar determine its size. |
| 4009 | mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */, |
| 4010 | vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */, |
| 4011 | dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */); |
| 4012 | |
| 4013 | // For layout, the status bar is always at the top with our fixed height. |
| 4014 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4015 | |
| 4016 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
| 4017 | boolean statusBarTranslucent = (sysui |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4018 | & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0; |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4019 | if (!isKeyguardShowing) { |
| 4020 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
| 4021 | } |
| 4022 | |
| 4023 | // If the status bar is hidden, we don't want to cause |
| 4024 | // windows behind it to scroll. |
| 4025 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
| 4026 | // Status bar may go away, so the screen area it occupies |
| 4027 | // is available to apps but just covering them when the |
| 4028 | // status bar is visible. |
| 4029 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4030 | |
| 4031 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 4032 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 4033 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 4034 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 4035 | |
| 4036 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
| 4037 | String.format( |
| 4038 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 4039 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 4040 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 4041 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 4042 | } |
| 4043 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
| 4044 | && !statusBarTransient && !statusBarTranslucent |
| 4045 | && !mStatusBarController.wasRecentlyTranslucent()) { |
| 4046 | // If the opaque status bar is currently requested to be visible, |
| 4047 | // and not in the process of animating on or off, then |
| 4048 | // we can tell the app that it is covered by it. |
| 4049 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 4050 | } |
| 4051 | if (mStatusBarController.checkHiddenLw()) { |
| 4052 | return true; |
| 4053 | } |
| 4054 | } |
| 4055 | return false; |
| 4056 | } |
| 4057 | |
| 4058 | private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation, |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4059 | int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible, |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4060 | boolean navTranslucent, boolean navAllowedHidden) { |
| 4061 | if (mNavigationBar != null) { |
| 4062 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
| 4063 | // Force the navigation bar to its appropriate place and |
| 4064 | // size. We need to do this directly, instead of relying on |
| 4065 | // it to bubble up from the nav bar, because this needs to |
| 4066 | // change atomically with screen rotations. |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 4067 | mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4068 | if (mNavigationBarOnBottom) { |
| 4069 | // It's a system nav bar or a portrait screen; nav bar goes on bottom. |
| 4070 | int top = displayHeight - overscanBottom |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4071 | - getNavigationBarHeight(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4072 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
| 4073 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
| 4074 | if (transientNavBarShowing) { |
| 4075 | mNavigationBarController.setBarShowingLw(true); |
| 4076 | } else if (navVisible) { |
| 4077 | mNavigationBarController.setBarShowingLw(true); |
| 4078 | mDockBottom = mTmpNavigationFrame.top; |
| 4079 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 4080 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
| 4081 | } else { |
| 4082 | // We currently want to hide the navigation UI. |
| 4083 | mNavigationBarController.setBarShowingLw(false); |
| 4084 | } |
| 4085 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4086 | && !mNavigationBar.isAnimatingLw() |
| 4087 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4088 | // If the opaque nav bar is currently requested to be visible, |
| 4089 | // and not in the process of animating on or off, then |
| 4090 | // we can tell the app that it is covered by it. |
| 4091 | mSystemBottom = mTmpNavigationFrame.top; |
| 4092 | } |
| 4093 | } else { |
| 4094 | // Landscape screen; nav bar goes to the right. |
| 4095 | int left = displayWidth - overscanRight |
Sriram Viswanathan | 9ebbe6a | 2015-11-16 17:59:22 -0800 | [diff] [blame] | 4096 | - getNavigationBarWidth(displayRotation, uiMode); |
Filip Gruszczynski | 83dd955 | 2015-09-17 17:50:36 -0700 | [diff] [blame] | 4097 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
| 4098 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
| 4099 | if (transientNavBarShowing) { |
| 4100 | mNavigationBarController.setBarShowingLw(true); |
| 4101 | } else if (navVisible) { |
| 4102 | mNavigationBarController.setBarShowingLw(true); |
| 4103 | mDockRight = mTmpNavigationFrame.left; |
| 4104 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 4105 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
| 4106 | } else { |
| 4107 | // We currently want to hide the navigation UI. |
| 4108 | mNavigationBarController.setBarShowingLw(false); |
| 4109 | } |
| 4110 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 4111 | && !mNavigationBar.isAnimatingLw() |
| 4112 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
| 4113 | // If the nav bar is currently requested to be visible, |
| 4114 | // and not in the process of animating on or off, then |
| 4115 | // we can tell the app that it is covered by it. |
| 4116 | mSystemRight = mTmpNavigationFrame.left; |
| 4117 | } |
| 4118 | } |
| 4119 | // Make sure the content and current rectangles are updated to |
| 4120 | // account for the restrictions from the navigation bar. |
| 4121 | mContentTop = mVoiceContentTop = mCurTop = mDockTop; |
| 4122 | mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom; |
| 4123 | mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft; |
| 4124 | mContentRight = mVoiceContentRight = mCurRight = mDockRight; |
| 4125 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 4126 | // And compute the final frame. |
| 4127 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
| 4128 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf, |
| 4129 | mTmpNavigationFrame, mTmpNavigationFrame); |
| 4130 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
| 4131 | if (mNavigationBarController.checkHiddenLw()) { |
| 4132 | return true; |
| 4133 | } |
| 4134 | } |
| 4135 | return false; |
| 4136 | } |
| 4137 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 4138 | private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) { |
| 4139 | return !mNavigationBarCanMove || displayWidth < displayHeight; |
| 4140 | } |
| 4141 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4142 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4143 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4144 | public int getSystemDecorLayerLw() { |
Bryce Lee | 2ed3e5f | 2015-04-01 22:09:19 +0000 | [diff] [blame] | 4145 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 4146 | return mStatusBar.getSurfaceLayer(); |
| 4147 | } |
| 4148 | |
| 4149 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) { |
| 4150 | return mNavigationBar.getSurfaceLayer(); |
| 4151 | } |
| 4152 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 4153 | return 0; |
| 4154 | } |
| 4155 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 4156 | @Override |
| 4157 | public void getContentRectLw(Rect r) { |
| 4158 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 4159 | } |
| 4160 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4161 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 4162 | 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] | 4163 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 4164 | // Here's a special case: if this attached window is a panel that is |
| 4165 | // above the dock window, and the window it is attached to is below |
| 4166 | // the dock window, then the frames we computed for the window it is |
| 4167 | // attached to can not be used because the dock is effectively part |
| 4168 | // of the underlying window and the attached window is floating on top |
| 4169 | // of the whole thing. So, we ignore the attached window and explicitly |
| 4170 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4171 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4172 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 4173 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 4174 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4175 | } else { |
| 4176 | // The effective display frame of the attached window depends on |
| 4177 | // whether it is taking care of insetting its content. If not, |
| 4178 | // we need to use the parent's content frame so that the entire |
| 4179 | // window is positioned within that content. Otherwise we can use |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 4180 | // 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] | 4181 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4182 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 4183 | // Set the content frame of the attached window to the parent's decor frame |
| 4184 | // (same as content frame when IME isn't present) if specifically requested by |
| 4185 | // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag. |
| 4186 | // Otherwise, use the overscan frame. |
| 4187 | cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0 |
| 4188 | ? attached.getContentFrameLw() : attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4189 | } else { |
| 4190 | // If the window is resizing, then we want to base the content |
| 4191 | // frame on our attached content frame to resize... however, |
| 4192 | // things can be tricky if the attached window is NOT in resize |
| 4193 | // mode, in which case its content frame will be larger. |
| 4194 | // Ungh. So to deal with that, make sure the content frame |
| 4195 | // we end up using is not covering the IM dock. |
| 4196 | cf.set(attached.getContentFrameLw()); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4197 | if (attached.isVoiceInteraction()) { |
| 4198 | if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft; |
| 4199 | if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop; |
| 4200 | if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight; |
| 4201 | if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom; |
| 4202 | } else if (attached.getSurfaceLayer() < mDockLayer) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4203 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 4204 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 4205 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 4206 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 4207 | } |
| 4208 | } |
| 4209 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4210 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4211 | vf.set(attached.getVisibleFrameLw()); |
| 4212 | } |
| 4213 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 4214 | // window should be positioned relative to its parent or the entire |
| 4215 | // screen. |
| 4216 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 4217 | ? attached.getFrameLw() : df); |
| 4218 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4219 | |
| 4220 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 4221 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 4222 | // If app is requesting a stable layout, don't let the |
| 4223 | // content insets go below the stable values. |
| 4224 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 4225 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 4226 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 4227 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 4228 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 4229 | } else { |
| 4230 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 4231 | if (r.top < mStableTop) r.top = mStableTop; |
| 4232 | if (r.right > mStableRight) r.right = mStableRight; |
| 4233 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 4234 | } |
| 4235 | } |
| 4236 | } |
| 4237 | |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4238 | private boolean canReceiveInput(WindowState win) { |
| 4239 | boolean notFocusable = |
| 4240 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0; |
| 4241 | boolean altFocusableIm = |
| 4242 | (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0; |
| 4243 | boolean notFocusableForIm = notFocusable ^ altFocusableIm; |
| 4244 | return !notFocusableForIm; |
| 4245 | } |
| 4246 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4247 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4248 | @Override |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4249 | public void layoutWindowLw(WindowState win, WindowState attached) { |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4250 | // We've already done the navigation bar and status bar. If the status bar can receive |
| 4251 | // input, we need to layout it again to accomodate for the IME window. |
| 4252 | if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4253 | return; |
| 4254 | } |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4255 | final WindowManager.LayoutParams attrs = win.getAttrs(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4256 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 4257 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4258 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 4259 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4260 | 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] | 4261 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 4262 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4263 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4264 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 4265 | final int pfl = attrs.privateFlags; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4266 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 4267 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4268 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4269 | final Rect pf = mTmpParentFrame; |
| 4270 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4271 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4272 | final Rect cf = mTmpContentFrame; |
| 4273 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4274 | final Rect dcf = mTmpDecorFrame; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4275 | final Rect sf = mTmpStableFrame; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4276 | Rect osf = null; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4277 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4278 | |
| 4279 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4280 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4281 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 4282 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 4283 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4284 | if (isDefaultDisplay) { |
| 4285 | sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom); |
| 4286 | } else { |
| 4287 | sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom); |
| 4288 | } |
| 4289 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4290 | if (!isDefaultDisplay) { |
| 4291 | if (attached != null) { |
| 4292 | // If this window is attached to another, our display |
| 4293 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4294 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4295 | } else { |
| 4296 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4297 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4298 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4299 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4300 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4301 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4302 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4303 | } |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4304 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4305 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 4306 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 4307 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4308 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 4309 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 4310 | // ...with content insets above the nav bar |
| 4311 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4312 | // IM dock windows always go to the bottom of the screen. |
| 4313 | attrs.gravity = Gravity.BOTTOM; |
| 4314 | mDockLayer = win.getSurfaceLayer(); |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4315 | } else if (attrs.type == TYPE_VOICE_INTERACTION) { |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4316 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4317 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4318 | pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4319 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4320 | cf.bottom = vf.bottom = mStableBottom; |
Stefan Kuhne | 2f280d06 | 2015-06-18 07:20:33 -1000 | [diff] [blame] | 4321 | // Note: In Phone landscape mode, the button bar should also be excluded. |
| 4322 | cf.right = vf.right = mStableRight; |
| 4323 | cf.left = vf.left = mStableLeft; |
Jorim Jaggi | 225d3b5 | 2015-04-01 11:18:57 -0700 | [diff] [blame] | 4324 | cf.top = vf.top = mStableTop; |
Jorim Jaggi | aa80614 | 2015-05-20 18:04:16 -0700 | [diff] [blame] | 4325 | } else if (win == mStatusBar) { |
Jorim Jaggi | e070018 | 2014-08-21 01:12:37 +0200 | [diff] [blame] | 4326 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4327 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4328 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 4329 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop; |
| 4330 | cf.left = vf.left = mStableLeft; |
| 4331 | cf.top = vf.top = mStableTop; |
| 4332 | cf.right = vf.right = mStableRight; |
| 4333 | vf.bottom = mStableBottom; |
Adrian Roos | dc5b453 | 2016-01-06 20:49:41 +0100 | [diff] [blame] | 4334 | |
| 4335 | if (adjust == SOFT_INPUT_ADJUST_RESIZE) { |
| 4336 | cf.bottom = mContentBottom; |
| 4337 | } else { |
| 4338 | cf.bottom = mDockBottom; |
| 4339 | vf.bottom = mContentBottom; |
| 4340 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4341 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4342 | |
| 4343 | // Default policy decor for the default display |
| 4344 | dcf.left = mSystemLeft; |
| 4345 | dcf.top = mSystemTop; |
| 4346 | dcf.right = mSystemRight; |
| 4347 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4348 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 4349 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 4350 | final boolean isAppWindow = |
| 4351 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 4352 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 4353 | final boolean topAtRest = |
| 4354 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 4355 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4356 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 4357 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4358 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0 |
| 4359 | && (fl & WindowManager.LayoutParams. |
Jorim Jaggi | 4fa7892 | 2015-11-30 17:13:56 -0800 | [diff] [blame] | 4360 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 4361 | && (pfl & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4362 | // Ensure policy decor includes status bar |
| 4363 | dcf.top = mStableTop; |
| 4364 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4365 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
Adrian Roos | ea56251 | 2014-05-05 13:33:03 +0200 | [diff] [blame] | 4366 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0 |
| 4367 | && (fl & WindowManager.LayoutParams. |
| 4368 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4369 | // Ensure policy decor includes navigation bar |
| 4370 | dcf.bottom = mStableBottom; |
| 4371 | dcf.right = mStableRight; |
| 4372 | } |
| 4373 | } |
| 4374 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4375 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 4376 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4377 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4378 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4379 | // This is the case for a normal activity window: we want it |
| 4380 | // to cover all of the screen space, and it can take care of |
| 4381 | // moving its contents to account for screen decorations that |
| 4382 | // intrude into that space. |
| 4383 | if (attached != null) { |
| 4384 | // If this window is attached to another, our display |
| 4385 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4386 | 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] | 4387 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4388 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 4389 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4390 | // Status bar panels are the only windows who can go on top of |
| 4391 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 4392 | // permission, so they have the same privileges as the status |
| 4393 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4394 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4395 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4396 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4397 | pf.left = df.left = of.left = hasNavBar |
| 4398 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4399 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4400 | pf.right = df.right = of.right = hasNavBar |
| 4401 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 4402 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4403 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 4404 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 4405 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4406 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4407 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4408 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 4409 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4410 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4411 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4412 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4413 | // Asking to layout into the overscan region, so give it that pure |
| 4414 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4415 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 4416 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 4417 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4418 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 4419 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4420 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4421 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4422 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4423 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4424 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4425 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4426 | // only do this for application windows to ensure no window that |
| 4427 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4428 | pf.left = df.left = mOverscanScreenLeft; |
| 4429 | pf.top = df.top = mOverscanScreenTop; |
| 4430 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4431 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4432 | // We need to tell the app about where the frame inside the overscan |
| 4433 | // is, so it can inset its content by that amount -- it didn't ask |
| 4434 | // to actually extend itself into the overscan region. |
| 4435 | of.left = mUnrestrictedScreenLeft; |
| 4436 | of.top = mUnrestrictedScreenTop; |
| 4437 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4438 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4439 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 4440 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 4441 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 4442 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 4443 | + mRestrictedOverscanScreenWidth; |
| 4444 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 4445 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4446 | // We need to tell the app about where the frame inside the overscan |
| 4447 | // is, so it can inset its content by that amount -- it didn't ask |
| 4448 | // to actually extend itself into the overscan region. |
| 4449 | of.left = mUnrestrictedScreenLeft; |
| 4450 | of.top = mUnrestrictedScreenTop; |
| 4451 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4452 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4453 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4454 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4455 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4456 | if (win.isVoiceInteraction()) { |
| 4457 | cf.left = mVoiceContentLeft; |
| 4458 | cf.top = mVoiceContentTop; |
| 4459 | cf.right = mVoiceContentRight; |
| 4460 | cf.bottom = mVoiceContentBottom; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4461 | } else { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4462 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4463 | cf.left = mDockLeft; |
| 4464 | cf.top = mDockTop; |
| 4465 | cf.right = mDockRight; |
| 4466 | cf.bottom = mDockBottom; |
| 4467 | } else { |
| 4468 | cf.left = mContentLeft; |
| 4469 | cf.top = mContentTop; |
| 4470 | cf.right = mContentRight; |
| 4471 | cf.bottom = mContentBottom; |
| 4472 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4473 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4474 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4475 | // Full screen windows are always given a layout that is as if the |
| 4476 | // status bar and other transient decors are gone. This is to avoid |
| 4477 | // bad states when moving from a window that is not hding the |
| 4478 | // status bar to one that is. |
| 4479 | cf.left = mRestrictedScreenLeft; |
| 4480 | cf.top = mRestrictedScreenTop; |
| 4481 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4482 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4483 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4484 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4485 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4486 | vf.left = mCurLeft; |
| 4487 | vf.top = mCurTop; |
| 4488 | vf.right = mCurRight; |
| 4489 | vf.bottom = mCurBottom; |
| 4490 | } else { |
| 4491 | vf.set(cf); |
| 4492 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4493 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4494 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 4495 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 4496 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4497 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4498 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4499 | // A window that has requested to fill the entire screen just |
| 4500 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4501 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4502 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL |
| 4503 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4504 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 4505 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 4506 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4507 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4508 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4509 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4510 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4511 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4512 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4513 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 4514 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 4515 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 4516 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 4517 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4518 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4519 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 4520 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 4521 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 4522 | + mUnrestrictedScreenWidth; |
| 4523 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 4524 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4525 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 4526 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 4527 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4528 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 4529 | || attrs.type == TYPE_BOOT_PROGRESS |
| 4530 | || attrs.type == TYPE_SCREENSHOT) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 4531 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 4532 | // Fullscreen secure system overlays get what they ask for. Screenshot region |
| 4533 | // selection overlay should also expand to full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4534 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4535 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4536 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4537 | + mOverscanScreenWidth; |
| 4538 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4539 | + mOverscanScreenHeight; |
Craig Mautner | 165be0c | 2015-01-27 15:16:58 -0800 | [diff] [blame] | 4540 | } else if (attrs.type == TYPE_BOOT_PROGRESS) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 4541 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4542 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4543 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4544 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 4545 | + mOverscanScreenWidth; |
| 4546 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 4547 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 4548 | } else if (attrs.type == TYPE_WALLPAPER) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4549 | // The wallpaper also has Real Ultimate Power, but we want to tell |
| 4550 | // it about the overscan area. |
| 4551 | pf.left = df.left = mOverscanScreenLeft; |
| 4552 | pf.top = df.top = mOverscanScreenTop; |
| 4553 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 4554 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
| 4555 | of.left = cf.left = mUnrestrictedScreenLeft; |
| 4556 | of.top = cf.top = mUnrestrictedScreenTop; |
| 4557 | of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 4558 | of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4559 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4560 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4561 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 4562 | // Asking to layout into the overscan region, so give it that pure |
| 4563 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4564 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 4565 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 4566 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4567 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4568 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 4569 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 4570 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4571 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Craig Mautner | beac106 | 2014-06-03 14:38:57 -0700 | [diff] [blame] | 4572 | && (attrs.type == TYPE_STATUS_BAR |
| 4573 | || attrs.type == TYPE_TOAST |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 4574 | || attrs.type == TYPE_DOCK_DIVIDER |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 4575 | || attrs.type == TYPE_VOICE_INTERACTION_STARTING |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4576 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 4577 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4578 | // Asking for layout as if the nav bar is hidden, lets the |
| 4579 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 4580 | // 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] | 4581 | // can be above the nav bar can do this. |
| 4582 | // XXX This assumes that an app asking for this will also |
| 4583 | // ask for layout in only content. We can't currently figure out |
| 4584 | // 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] | 4585 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 4586 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 4587 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 4588 | + mUnrestrictedScreenWidth; |
| 4589 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 4590 | + mUnrestrictedScreenHeight; |
Jorim Jaggi | 9f6798a | 2016-02-10 22:16:06 -0800 | [diff] [blame] | 4591 | } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) { |
| 4592 | pf.left = df.left = of.left = mRestrictedScreenLeft; |
| 4593 | pf.top = df.top = of.top = mRestrictedScreenTop; |
| 4594 | pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 4595 | pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop |
| 4596 | + mRestrictedScreenHeight; |
| 4597 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 4598 | cf.left = mDockLeft; |
| 4599 | cf.top = mDockTop; |
| 4600 | cf.right = mDockRight; |
| 4601 | cf.bottom = mDockBottom; |
| 4602 | } else { |
| 4603 | cf.left = mContentLeft; |
| 4604 | cf.top = mContentTop; |
| 4605 | cf.right = mContentRight; |
| 4606 | cf.bottom = mContentBottom; |
| 4607 | } |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4608 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4609 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4610 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4611 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4612 | + mRestrictedScreenWidth; |
| 4613 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4614 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 4615 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4616 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 4617 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4618 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4619 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4620 | vf.left = mCurLeft; |
| 4621 | vf.top = mCurTop; |
| 4622 | vf.right = mCurRight; |
| 4623 | vf.bottom = mCurBottom; |
| 4624 | } else { |
| 4625 | vf.set(cf); |
| 4626 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4627 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4628 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4629 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4630 | // A child window should be placed inside of the same visible |
| 4631 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4632 | 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] | 4633 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4634 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 4635 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4636 | // Otherwise, a normal window must be placed inside the content |
| 4637 | // of all screen decorations. |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4638 | if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 4639 | // Status bar panels and the volume dialog are the only windows who can go on |
| 4640 | // 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] | 4641 | // permission, so they have the same privileges as the status |
| 4642 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4643 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 4644 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 4645 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 4646 | + mRestrictedScreenWidth; |
| 4647 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 4648 | + mRestrictedScreenHeight; |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 4649 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) { |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4650 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 4651 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 4652 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 4653 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 4654 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4655 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4656 | pf.left = mContentLeft; |
| 4657 | pf.top = mContentTop; |
| 4658 | pf.right = mContentRight; |
| 4659 | pf.bottom = mContentBottom; |
Dianne Hackborn | 20d9474 | 2014-05-29 18:35:45 -0700 | [diff] [blame] | 4660 | if (win.isVoiceInteraction()) { |
| 4661 | df.left = of.left = cf.left = mVoiceContentLeft; |
| 4662 | df.top = of.top = cf.top = mVoiceContentTop; |
| 4663 | df.right = of.right = cf.right = mVoiceContentRight; |
| 4664 | df.bottom = of.bottom = cf.bottom = mVoiceContentBottom; |
| 4665 | } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4666 | df.left = of.left = cf.left = mDockLeft; |
| 4667 | df.top = of.top = cf.top = mDockTop; |
| 4668 | df.right = of.right = cf.right = mDockRight; |
| 4669 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4670 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4671 | df.left = of.left = cf.left = mContentLeft; |
| 4672 | df.top = of.top = cf.top = mContentTop; |
| 4673 | df.right = of.right = cf.right = mContentRight; |
| 4674 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 4675 | } |
| 4676 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 4677 | vf.left = mCurLeft; |
| 4678 | vf.top = mCurTop; |
| 4679 | vf.right = mCurRight; |
| 4680 | vf.bottom = mCurBottom; |
| 4681 | } else { |
| 4682 | vf.set(cf); |
| 4683 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 4684 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4685 | } |
| 4686 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4687 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 4688 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 4689 | // Also, we don't allow windows in multi-window mode to extend out of the screen. |
| 4690 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 4691 | && !win.isInMultiWindowMode()) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 4692 | df.left = df.top = -10000; |
| 4693 | df.right = df.bottom = 10000; |
| 4694 | if (attrs.type != TYPE_WALLPAPER) { |
| 4695 | of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 4696 | of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 4697 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4698 | } |
| 4699 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4700 | // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we |
| 4701 | // 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] | 4702 | // We only want to apply outsets to certain types of windows. For example, we never want to |
| 4703 | // 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] | 4704 | final boolean useOutsets = shouldUseOutsets(attrs, fl); |
Filip Gruszczynski | b0c673b | 2015-06-05 09:43:06 -0700 | [diff] [blame] | 4705 | if (isDefaultDisplay && useOutsets) { |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4706 | osf = mTmpOutsetFrame; |
| 4707 | osf.set(cf.left, cf.top, cf.right, cf.bottom); |
| 4708 | int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources()); |
| 4709 | if (outset > 0) { |
Filip Gruszczynski | 2987f61 | 2015-06-30 15:03:30 -0700 | [diff] [blame] | 4710 | int rotation = mDisplayRotation; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4711 | if (rotation == Surface.ROTATION_0) { |
| 4712 | osf.bottom += outset; |
| 4713 | } else if (rotation == Surface.ROTATION_90) { |
| 4714 | osf.right += outset; |
| 4715 | } else if (rotation == Surface.ROTATION_180) { |
| 4716 | osf.top -= outset; |
| 4717 | } else if (rotation == Surface.ROTATION_270) { |
| 4718 | osf.left -= outset; |
| 4719 | } |
| 4720 | if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset |
| 4721 | + " with rotation " + rotation + ", result: " + osf); |
| 4722 | } |
| 4723 | } |
| 4724 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4725 | 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] | 4726 | + ": sim=#" + Integer.toHexString(sim) |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4727 | + " attach=" + attached + " type=" + attrs.type |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 4728 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 4729 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 4730 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 4731 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 4732 | + " dcf=" + dcf.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4733 | + " sf=" + sf.toShortString() |
| 4734 | + " osf=" + (osf == null ? "null" : osf.toShortString())); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4735 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 4736 | win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 4737 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4738 | // Dock windows carve out the bottom of the screen, so normal windows |
| 4739 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 4740 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 4741 | && win.isDisplayedLw() && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4742 | setLastInputMethodWindowLw(null, null); |
| 4743 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4744 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4745 | if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw() |
| 4746 | && !win.getGivenInsetsPendingLw()) { |
| 4747 | offsetVoiceInputWindowLw(win); |
| 4748 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4749 | } |
| 4750 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4751 | private void offsetInputMethodWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4752 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4753 | top += win.getGivenContentInsetsLw().top; |
| 4754 | if (mContentBottom > top) { |
| 4755 | mContentBottom = top; |
| 4756 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4757 | if (mVoiceContentBottom > top) { |
| 4758 | mVoiceContentBottom = top; |
| 4759 | } |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4760 | top = win.getVisibleFrameLw().top; |
| 4761 | top += win.getGivenVisibleInsetsLw().top; |
| 4762 | if (mCurBottom > top) { |
| 4763 | mCurBottom = top; |
| 4764 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4765 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 4766 | + mDockBottom + " mContentBottom=" |
| 4767 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 4768 | } |
| 4769 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4770 | private void offsetVoiceInputWindowLw(WindowState win) { |
Craig Mautner | 4774f6a | 2015-03-23 11:42:55 -0700 | [diff] [blame] | 4771 | int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 4772 | top += win.getGivenContentInsetsLw().top; |
| 4773 | if (mVoiceContentBottom > top) { |
| 4774 | mVoiceContentBottom = top; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4778 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 4779 | @Override |
| 4780 | public void finishLayoutLw() { |
| 4781 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4785 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4786 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4787 | mTopFullscreenOpaqueWindowState = null; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4788 | mTopFullscreenOpaqueOrDimmingWindowState = null; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4789 | mTopDockedOpaqueWindowState = null; |
| 4790 | mTopDockedOpaqueOrDimmingWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4791 | mAppsToBeHidden.clear(); |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4792 | mAppsThatDismissKeyguard.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4793 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4794 | mForceStatusBarFromKeyguard = false; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4795 | mForceStatusBarTransparent = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4796 | mForcingShowNavBar = false; |
| 4797 | mForcingShowNavBarLayer = -1; |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 4798 | |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4799 | mHideLockScreen = false; |
| 4800 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4801 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4802 | mShowingLockscreen = false; |
| 4803 | mShowingDream = false; |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4804 | mWinShowWhenLocked = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4805 | mKeyguardSecure = isKeyguardSecure(); |
| 4806 | mKeyguardSecureIncludingHidden = mKeyguardSecure |
| 4807 | && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4811 | @Override |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 4812 | public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs, |
| 4813 | WindowState attached) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4814 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 4815 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4816 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 4817 | if (mTopFullscreenOpaqueWindowState == null |
| 4818 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 4819 | mForcingShowNavBar = true; |
| 4820 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 4821 | } |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4822 | if (attrs.type == TYPE_STATUS_BAR) { |
| 4823 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 4824 | mForceStatusBarFromKeyguard = true; |
Jorim Jaggi | e1de9f6 | 2015-09-23 14:59:50 -0700 | [diff] [blame] | 4825 | mShowingLockscreen = true; |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 4826 | } |
| 4827 | if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) { |
| 4828 | mForceStatusBarTransparent = true; |
| 4829 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 4830 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4831 | |
| 4832 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 4833 | && attrs.type < FIRST_SYSTEM_WINDOW; |
| 4834 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 4835 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4836 | final int stackId = win.getStackId(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4837 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 4838 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 4839 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 4840 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 4841 | mForceStatusBarFromKeyguard = true; |
| 4842 | } else { |
| 4843 | mForceStatusBar = true; |
| 4844 | } |
| 4845 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4846 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4847 | // If the lockscreen was showing when the dream started then wait |
| 4848 | // for the dream to draw before hiding the lockscreen. |
| 4849 | if (!mDreamingLockscreen |
| 4850 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 4851 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4852 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4853 | } |
| 4854 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4855 | |
Yohei Yukawa | d1a0922 | 2015-06-30 16:22:05 -0700 | [diff] [blame] | 4856 | final IApplicationToken appToken = win.getAppToken(); |
| 4857 | |
| 4858 | // For app windows that are not attached, we decide if all windows in the app they |
| 4859 | // represent should be hidden or if we should hide the lockscreen. For attached app |
| 4860 | // windows we defer the decision to the window it is attached to. |
| 4861 | if (appWindow && attached == null) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4862 | if (showWhenLocked) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4863 | // Remove any previous windows with the same appToken. |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4864 | mAppsToBeHidden.remove(appToken); |
| 4865 | mAppsThatDismissKeyguard.remove(appToken); |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4866 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | 192d604 | 2014-12-02 23:24:48 -0800 | [diff] [blame] | 4867 | if (dismissKeyguard && !mKeyguardSecure) { |
| 4868 | mAppsThatDismissKeyguard.add(appToken); |
Selim Cinek | 90b5e07 | 2015-08-28 17:05:56 -0700 | [diff] [blame] | 4869 | } else if (win.isDrawnLw() || win.hasAppShownWindows()) { |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4870 | mWinShowWhenLocked = win; |
| 4871 | mHideLockScreen = true; |
| 4872 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ca0a124 | 2014-12-02 12:25:14 -0800 | [diff] [blame] | 4873 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4874 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4875 | } else if (dismissKeyguard) { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4876 | if (mKeyguardSecure) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4877 | mAppsToBeHidden.add(appToken); |
| 4878 | } else { |
| 4879 | mAppsToBeHidden.remove(appToken); |
| 4880 | } |
| 4881 | mAppsThatDismissKeyguard.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4882 | } else { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4883 | mAppsToBeHidden.add(appToken); |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 4884 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4885 | if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4886 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 4887 | mTopFullscreenOpaqueWindowState = win; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4888 | if (mTopFullscreenOpaqueOrDimmingWindowState == null) { |
| 4889 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4890 | } |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4891 | if (!mAppsThatDismissKeyguard.isEmpty() && |
| 4892 | mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 4893 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4894 | "Setting mDismissKeyguard true by win " + win); |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4895 | mDismissKeyguard = (mWinDismissingKeyguard == win |
| 4896 | && mSecureDismissingKeyguard == mKeyguardSecure) |
| 4897 | ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4898 | mWinDismissingKeyguard = win; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 4899 | mSecureDismissingKeyguard = mKeyguardSecure; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 4900 | mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure; |
Selim Cinek | 90b5e07 | 2015-08-28 17:05:56 -0700 | [diff] [blame] | 4901 | } else if (mAppsToBeHidden.isEmpty() && showWhenLocked |
| 4902 | && (win.isDrawnLw() || win.hasAppShownWindows())) { |
Jorim Jaggi | c13fcac | 2014-09-11 17:36:57 +0200 | [diff] [blame] | 4903 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 4904 | "Setting mHideLockScreen to true by win " + win); |
| 4905 | mHideLockScreen = true; |
| 4906 | mForceStatusBarFromKeyguard = false; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4907 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 4908 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 4909 | mAllowLockscreenWhenOn = true; |
| 4910 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4911 | } |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4912 | |
Wale Ogunwale | 23fd1db | 2016-04-25 17:21:34 -0700 | [diff] [blame] | 4913 | if (!mKeyguardHidden && mWinShowWhenLocked != null && |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4914 | mWinShowWhenLocked.getAppToken() != win.getAppToken() && |
| 4915 | (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4916 | win.hideLw(false); |
| 4917 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4918 | } |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4919 | } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) { |
| 4920 | // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window |
| 4921 | // that is being hidden in an animation - keep the |
| 4922 | // keyguard hidden until the new window shows up and |
| 4923 | // we know whether to show the keyguard or not. |
Adrian Roos | b85e1ec | 2015-05-29 15:23:18 -0700 | [diff] [blame] | 4924 | if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) { |
Adrian Roos | 602c68e | 2015-04-24 16:03:47 -0700 | [diff] [blame] | 4925 | mHideLockScreen = true; |
| 4926 | mWinShowWhenLocked = win; |
| 4927 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4928 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4929 | |
| 4930 | // Keep track of the window if it's dimming but not necessarily fullscreen. |
| 4931 | final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw(); |
| 4932 | if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible |
| 4933 | && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 4934 | mTopFullscreenOpaqueOrDimmingWindowState = win; |
| 4935 | } |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 4936 | |
| 4937 | // We need to keep track of the top "fullscreen" opaque window for the docked stack |
| 4938 | // separately, because both the "real fullscreen" opaque window and the one for the docked |
| 4939 | // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR. |
| 4940 | if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null |
| 4941 | && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) { |
| 4942 | mTopDockedOpaqueWindowState = win; |
| 4943 | if (mTopDockedOpaqueOrDimmingWindowState == null) { |
| 4944 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 4945 | } |
| 4946 | } |
| 4947 | |
| 4948 | // Also keep track of any windows that are dimming but not necessarily fullscreen in the |
| 4949 | // docked stack. |
| 4950 | if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming() |
| 4951 | && stackId == DOCKED_STACK_ID) { |
| 4952 | mTopDockedOpaqueOrDimmingWindowState = win; |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | private boolean isFullscreen(WindowManager.LayoutParams attrs) { |
| 4957 | return attrs.x == 0 && attrs.y == 0 |
| 4958 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 4959 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 4960 | } |
| 4961 | |
| 4962 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 4963 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 4964 | public int finishPostLayoutPolicyLw() { |
Craig Mautner | c5e73bf | 2015-04-21 15:41:26 +0000 | [diff] [blame] | 4965 | if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null && |
| 4966 | mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken() |
| 4967 | && isKeyguardLocked()) { |
Craig Mautner | c9457fa | 2014-06-06 14:27:48 -0700 | [diff] [blame] | 4968 | // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the |
| 4969 | // fullscreen window. |
| 4970 | // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not. |
| 4971 | mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 4972 | mTopFullscreenOpaqueWindowState.hideLw(false); |
| 4973 | mTopFullscreenOpaqueWindowState = mWinShowWhenLocked; |
| 4974 | } |
| 4975 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4976 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 4977 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 4978 | |
| 4979 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 4980 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 4981 | : null; |
| 4982 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 4983 | // If we are not currently showing a dream then remember the current |
| 4984 | // lockscreen state. We will use this to determine whether the dream |
| 4985 | // started while the lockscreen was showing and remember this state |
| 4986 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4987 | if (!mShowingDream) { |
| 4988 | mDreamingLockscreen = mShowingLockscreen; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 4989 | if (mDreamingSleepTokenNeeded) { |
| 4990 | mDreamingSleepTokenNeeded = false; |
| 4991 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget(); |
| 4992 | } |
| 4993 | } else { |
| 4994 | if (!mDreamingSleepTokenNeeded) { |
| 4995 | mDreamingSleepTokenNeeded = true; |
| 4996 | mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget(); |
| 4997 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 4998 | } |
| 4999 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5000 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5001 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5002 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 5003 | + " top=" + mTopFullscreenOpaqueWindowState); |
Selim Cinek | 4a4a2bddc | 2015-05-07 12:50:19 -0700 | [diff] [blame] | 5004 | boolean shouldBeTransparent = mForceStatusBarTransparent |
| 5005 | && !mForceStatusBar |
| 5006 | && !mForceStatusBarFromKeyguard; |
| 5007 | if (!shouldBeTransparent) { |
| 5008 | mStatusBarController.setShowTransparent(false /* transparent */); |
| 5009 | } else if (!mStatusBar.isVisibleLw()) { |
| 5010 | mStatusBarController.setShowTransparent(true /* transparent */); |
| 5011 | } |
| 5012 | if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5013 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5014 | if (mStatusBarController.setBarShowingLw(true)) { |
| 5015 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5016 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 5017 | // Maintain fullscreen layout until incoming animation is complete. |
| 5018 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 5019 | // Transient status bar on the lockscreen is not allowed |
| 5020 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 5021 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 5022 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 5023 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5024 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5025 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5026 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5027 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 5028 | + " shown position: " |
| 5029 | + mTopFullscreenOpaqueWindowState.getShownPositionLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5030 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5031 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5032 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5033 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5034 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5035 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 5036 | // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 5037 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 5038 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5039 | if (mStatusBarController.isTransientShowing()) { |
| 5040 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5041 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5042 | } |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 5043 | } else if (topIsFullscreen |
| 5044 | && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID) |
| 5045 | && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5046 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5047 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5048 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5049 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 5050 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 5051 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5052 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5053 | 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] | 5054 | if (mStatusBarController.setBarShowingLw(true)) { |
| 5055 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5056 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5057 | } |
| 5058 | } |
| 5059 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5060 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 5061 | if (mTopIsFullscreen != topIsFullscreen) { |
| 5062 | if (!topIsFullscreen) { |
| 5063 | // Force another layout when status bar becomes fully shown. |
| 5064 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5065 | } |
| 5066 | mTopIsFullscreen = topIsFullscreen; |
| 5067 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 5068 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 5069 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 5070 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5071 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 5072 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 5073 | + mHideLockScreen); |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5074 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5075 | mKeyguardHidden = true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5076 | if (setKeyguardOccludedLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5077 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 5078 | | FINISH_LAYOUT_REDO_CONFIG |
| 5079 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 5080 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5081 | if (mKeyguardDelegate.isShowing()) { |
| 5082 | mHandler.post(new Runnable() { |
| 5083 | @Override |
| 5084 | public void run() { |
| 5085 | mKeyguardDelegate.keyguardDone(false, false); |
| 5086 | } |
| 5087 | }); |
| 5088 | } |
| 5089 | } else if (mHideLockScreen) { |
| 5090 | mKeyguardHidden = true; |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 5091 | mWinDismissingKeyguard = null; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5092 | if (setKeyguardOccludedLw(true)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5093 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 5094 | | FINISH_LAYOUT_REDO_CONFIG |
| 5095 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 5096 | } |
| 5097 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
Jorim Jaggi | 7d85ea9 | 2015-05-20 17:20:40 -0700 | [diff] [blame] | 5098 | mKeyguardHidden = false; |
| 5099 | if (setKeyguardOccludedLw(false)) { |
| 5100 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 5101 | | FINISH_LAYOUT_REDO_CONFIG |
| 5102 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 5103 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5104 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 5105 | // Only launch the next keyguard unlock window once per window. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5106 | mHandler.post(new Runnable() { |
| 5107 | @Override |
| 5108 | public void run() { |
| 5109 | mKeyguardDelegate.dismiss(); |
| 5110 | } |
| 5111 | }); |
| 5112 | } |
| 5113 | } else { |
| 5114 | mWinDismissingKeyguard = null; |
tingna_sung | e785ffa | 2015-05-12 13:23:15 +0800 | [diff] [blame] | 5115 | mSecureDismissingKeyguard = false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5116 | mKeyguardHidden = false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5117 | if (setKeyguardOccludedLw(false)) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5118 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 5119 | | FINISH_LAYOUT_REDO_CONFIG |
| 5120 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 5121 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 5122 | } |
| 5123 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5124 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5125 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5126 | // If the navigation bar has been hidden or shown, we need to do another |
| 5127 | // layout pass to update that window. |
| 5128 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 5129 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5130 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 5131 | // update since mAllowLockscreenWhenOn might have changed |
| 5132 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5133 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5134 | } |
| 5135 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5136 | /** |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5137 | * Updates the occluded state of the Keyguard. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5138 | * |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5139 | * @return Whether the flags have changed and we have to redo the layout. |
| 5140 | */ |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5141 | private boolean setKeyguardOccludedLw(boolean isOccluded) { |
| 5142 | boolean wasOccluded = mKeyguardOccluded; |
| 5143 | boolean showing = mKeyguardDelegate.isShowing(); |
| 5144 | if (wasOccluded && !isOccluded && showing) { |
| 5145 | mKeyguardOccluded = false; |
| 5146 | mKeyguardDelegate.setOccluded(false); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5147 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 5148 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 5149 | return true; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5150 | } else if (!wasOccluded && isOccluded && showing) { |
| 5151 | mKeyguardOccluded = true; |
| 5152 | mKeyguardDelegate.setOccluded(true); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5153 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 5154 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 5155 | return true; |
| 5156 | } else { |
| 5157 | return false; |
| 5158 | } |
| 5159 | } |
| 5160 | |
| 5161 | private boolean isStatusBarKeyguard() { |
| 5162 | return mStatusBar != null |
| 5163 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 5164 | } |
| 5165 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5166 | @Override |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5167 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5168 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 5169 | // 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] | 5170 | return false; |
| 5171 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 5172 | return true; |
| 5173 | } |
| 5174 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5175 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5176 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5177 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5178 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5179 | // If the navigation bar has been hidden or shown, we need to do another |
| 5180 | // layout pass to update that window. |
| 5181 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 5182 | } |
| 5183 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5184 | } |
| 5185 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 5186 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5187 | @Override |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5188 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5189 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5190 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 5191 | if (newLidState == mLidState) { |
| 5192 | return; |
| 5193 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5194 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5195 | mLidState = newLidState; |
| 5196 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5197 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5198 | |
| 5199 | if (lidOpen) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5200 | wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch, |
| 5201 | "android.policy:LID"); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 5202 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5203 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5204 | } |
| 5205 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5206 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5207 | @Override |
| 5208 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 5209 | int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED; |
| 5210 | if (mCameraLensCoverState == lensCoverState) { |
| 5211 | return; |
| 5212 | } |
| 5213 | if (mCameraLensCoverState == CAMERA_LENS_COVERED && |
| 5214 | lensCoverState == CAMERA_LENS_UNCOVERED) { |
| 5215 | Intent intent; |
| 5216 | final boolean keyguardActive = mKeyguardDelegate == null ? false : |
| 5217 | mKeyguardDelegate.isShowing(); |
| 5218 | if (keyguardActive) { |
| 5219 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE); |
| 5220 | } else { |
| 5221 | intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
| 5222 | } |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5223 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens, |
| 5224 | "android.policy:CAMERA_COVER"); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5225 | startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 5226 | } |
| 5227 | mCameraLensCoverState = lensCoverState; |
| 5228 | } |
| 5229 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5230 | void setHdmiPlugged(boolean plugged) { |
| 5231 | if (mHdmiPlugged != plugged) { |
| 5232 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 5233 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5234 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5235 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5236 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 5237 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 5238 | } |
| 5239 | } |
| 5240 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5241 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5242 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5243 | // watch for HDMI plug messages if the hdmi switch exists |
| 5244 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 5245 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 5246 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 5247 | final String filename = "/sys/class/switch/hdmi/state"; |
| 5248 | FileReader reader = null; |
| 5249 | try { |
| 5250 | reader = new FileReader(filename); |
| 5251 | char[] buf = new char[15]; |
| 5252 | int n = reader.read(buf); |
| 5253 | if (n > 1) { |
| 5254 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 5255 | } |
| 5256 | } catch (IOException ex) { |
| 5257 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5258 | } catch (NumberFormatException ex) { |
| 5259 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 5260 | } finally { |
| 5261 | if (reader != null) { |
| 5262 | try { |
| 5263 | reader.close(); |
| 5264 | } catch (IOException ex) { |
| 5265 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5266 | } |
| 5267 | } |
| 5268 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 5269 | // This dance forces the code in setHdmiPlugged to run. |
| 5270 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 5271 | mHdmiPlugged = !plugged; |
| 5272 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 5273 | } |
| 5274 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 5275 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5276 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5277 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5278 | final Runnable mScreenshotTimeout = new Runnable() { |
| 5279 | @Override public void run() { |
| 5280 | synchronized (mScreenshotLock) { |
| 5281 | if (mScreenshotConnection != null) { |
| 5282 | mContext.unbindService(mScreenshotConnection); |
| 5283 | mScreenshotConnection = null; |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5284 | notifyScreenshotError(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 5285 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 5286 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5287 | } |
| 5288 | }; |
| 5289 | |
| 5290 | // Assume this is called from the Handler thread. |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 5291 | private void takeScreenshot(final int screenshotType) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5292 | synchronized (mScreenshotLock) { |
| 5293 | if (mScreenshotConnection != null) { |
| 5294 | return; |
| 5295 | } |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5296 | final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE, |
| 5297 | SYSUI_SCREENSHOT_SERVICE); |
| 5298 | final Intent serviceIntent = new Intent(); |
| 5299 | serviceIntent.setComponent(serviceComponent); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5300 | ServiceConnection conn = new ServiceConnection() { |
| 5301 | @Override |
| 5302 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 5303 | synchronized (mScreenshotLock) { |
| 5304 | if (mScreenshotConnection != this) { |
| 5305 | return; |
| 5306 | } |
| 5307 | Messenger messenger = new Messenger(service); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 5308 | Message msg = Message.obtain(null, screenshotType); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5309 | final ServiceConnection myConn = this; |
| 5310 | Handler h = new Handler(mHandler.getLooper()) { |
| 5311 | @Override |
| 5312 | public void handleMessage(Message msg) { |
| 5313 | synchronized (mScreenshotLock) { |
| 5314 | if (mScreenshotConnection == myConn) { |
| 5315 | mContext.unbindService(mScreenshotConnection); |
| 5316 | mScreenshotConnection = null; |
| 5317 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 5318 | } |
| 5319 | } |
| 5320 | } |
| 5321 | }; |
| 5322 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 5323 | msg.arg1 = msg.arg2 = 0; |
| 5324 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 5325 | msg.arg1 = 1; |
| 5326 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 5327 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5328 | try { |
| 5329 | messenger.send(msg); |
| 5330 | } catch (RemoteException e) { |
| 5331 | } |
| 5332 | } |
| 5333 | } |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5334 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5335 | @Override |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5336 | public void onServiceDisconnected(ComponentName name) { |
| 5337 | notifyScreenshotError(); |
| 5338 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5339 | }; |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5340 | if (mContext.bindServiceAsUser(serviceIntent, conn, |
| 5341 | Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, |
| 5342 | UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5343 | mScreenshotConnection = conn; |
| 5344 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 5345 | } |
| 5346 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 5347 | } |
| 5348 | |
Winson | 44dbe29 | 2016-03-10 14:00:14 -0800 | [diff] [blame] | 5349 | /** |
| 5350 | * Notifies the screenshot service to show an error. |
| 5351 | */ |
| 5352 | private void notifyScreenshotError() { |
| 5353 | // If the service process is killed, then ask it to clean up after itself |
| 5354 | final ComponentName errorComponent = new ComponentName(SYSUI_PACKAGE, |
| 5355 | SYSUI_SCREENSHOT_ERROR_RECEIVER); |
| 5356 | Intent errorIntent = new Intent(); |
| 5357 | errorIntent.setComponent(errorComponent); |
| 5358 | errorIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | |
| 5359 | Intent.FLAG_RECEIVER_FOREGROUND); |
| 5360 | mContext.sendBroadcastAsUser(errorIntent, UserHandle.ALL); |
| 5361 | } |
| 5362 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5363 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5364 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5365 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 5366 | if (!mSystemBooted) { |
| 5367 | // If we have not yet booted, don't let key events do anything. |
| 5368 | return 0; |
| 5369 | } |
| 5370 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5371 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 5372 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 5373 | final boolean canceled = event.isCanceled(); |
| 5374 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 5375 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5376 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 5377 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 5378 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 5379 | // the same as if it were open and in front. |
| 5380 | // This will prevent any keys other than the power button from waking the screen |
| 5381 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5382 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5383 | (interactive ? |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 5384 | isKeyguardShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5385 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5386 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5387 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5388 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5389 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5390 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5391 | } |
| 5392 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5393 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5394 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 5395 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 5396 | || event.isWakeKey(); |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5397 | if (interactive || (isInjected && !isWakeKey)) { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5398 | // When the device is interactive or the key is injected pass the |
| 5399 | // key to the application. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5400 | result = ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5401 | isWakeKey = false; |
Michael Wright | fc01f04 | 2014-09-08 14:12:24 -0700 | [diff] [blame] | 5402 | } else if (!interactive && shouldDispatchInputWhenNonInteractive()) { |
| 5403 | // If we're currently dozing with the screen on and the keyguard showing, pass the key |
| 5404 | // to the application but preserve its wake key status to make sure we still move |
| 5405 | // from dozing to fully interactive if we would normally go from off to fully |
| 5406 | // interactive. |
| 5407 | result = ACTION_PASS_TO_USER; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5408 | } else { |
| 5409 | // When the screen is off and the key is not injected, determine whether |
| 5410 | // to wake the device but don't pass the key to the application. |
| 5411 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5412 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 5413 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5414 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5415 | } |
| 5416 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5417 | // If the key would be handled globally, just return the result, don't worry about special |
| 5418 | // key processing. |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5419 | if (isValidGlobalKey(keyCode) |
| 5420 | && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5421 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5422 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Michael Wright | 85b1af6 | 2014-06-04 14:51:58 -0700 | [diff] [blame] | 5423 | } |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 5424 | return result; |
| 5425 | } |
| 5426 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5427 | boolean useHapticFeedback = down |
| 5428 | && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 5429 | && event.getRepeatCount() == 0; |
| 5430 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5431 | // Handle special keys. |
| 5432 | switch (keyCode) { |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 5433 | case KeyEvent.KEYCODE_BACK: { |
| 5434 | if (down) { |
| 5435 | mBackKeyHandled = false; |
| 5436 | if (hasLongPressOnBackBehavior()) { |
| 5437 | Message msg = mHandler.obtainMessage(MSG_BACK_LONG_PRESS); |
| 5438 | msg.setAsynchronous(true); |
| 5439 | mHandler.sendMessageDelayed(msg, |
| 5440 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 5441 | } |
| 5442 | } else { |
| 5443 | boolean handled = mBackKeyHandled; |
| 5444 | |
| 5445 | // Reset back key state |
| 5446 | cancelPendingBackKeyAction(); |
| 5447 | |
| 5448 | // Don't pass back press to app if we've already handled it |
| 5449 | if (handled) { |
| 5450 | result &= ~ACTION_PASS_TO_USER; |
| 5451 | } |
| 5452 | } |
| 5453 | break; |
| 5454 | } |
| 5455 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5456 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 5457 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5458 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5459 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 5460 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5461 | if (interactive && !mScreenshotChordVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5462 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5463 | mScreenshotChordVolumeDownKeyTriggered = true; |
| 5464 | mScreenshotChordVolumeDownKeyTime = event.getDownTime(); |
| 5465 | mScreenshotChordVolumeDownKeyConsumed = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5466 | cancelPendingPowerKeyAction(); |
| 5467 | interceptScreenshotChord(); |
| 5468 | } |
| 5469 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5470 | mScreenshotChordVolumeDownKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5471 | cancelPendingScreenshotChordAction(); |
| 5472 | } |
| 5473 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 5474 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5475 | if (interactive && !mScreenshotChordVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5476 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5477 | mScreenshotChordVolumeUpKeyTriggered = true; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5478 | cancelPendingPowerKeyAction(); |
| 5479 | cancelPendingScreenshotChordAction(); |
| 5480 | } |
| 5481 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5482 | mScreenshotChordVolumeUpKeyTriggered = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 5483 | cancelPendingScreenshotChordAction(); |
| 5484 | } |
| 5485 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5486 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5487 | TelecomManager telecomManager = getTelecommService(); |
| 5488 | if (telecomManager != null) { |
| 5489 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5490 | // If an incoming call is ringing, either VOLUME key means |
| 5491 | // "silence ringer". We handle these keys here, rather than |
| 5492 | // in the InCallScreen, to make sure we'll respond to them |
| 5493 | // even if the InCallScreen hasn't come to the foreground yet. |
| 5494 | // Look for the DOWN event here, to agree with the "fallback" |
| 5495 | // behavior in the InCallScreen. |
| 5496 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5497 | + " VOLUME key-down while ringing: Silence ringer!"); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5498 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5499 | // Silence the ringer. (It's safe to call this |
| 5500 | // even if the ringer has already been silenced.) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5501 | telecomManager.silenceRinger(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5502 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5503 | // And *don't* pass this key thru to the current activity |
| 5504 | // (which is probably the InCallScreen.) |
| 5505 | result &= ~ACTION_PASS_TO_USER; |
| 5506 | break; |
| 5507 | } |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5508 | if (telecomManager.isInCall() |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5509 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 5510 | // 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] | 5511 | // the application, just pass it to the session service. |
| 5512 | |
| 5513 | MediaSessionLegacyHelper.getHelper(mContext) |
RoboErik | 3c45c29 | 2014-07-08 16:47:31 -0700 | [diff] [blame] | 5514 | .sendVolumeKeyEvent(event, false); |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5515 | break; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5516 | } |
| 5517 | } |
Jaewan Kim | 765487f | 2016-01-12 14:45:42 +0900 | [diff] [blame] | 5518 | } |
| 5519 | if (mUseTvRouting) { |
| 5520 | // On TVs, defer special key handlings to |
| 5521 | // {@link interceptKeyBeforeDispatching()}. |
| 5522 | result |= ACTION_PASS_TO_USER; |
| 5523 | } else if ((result & ACTION_PASS_TO_USER) == 0) { |
| 5524 | // If we aren't passing to the user and no one else |
| 5525 | // handled it send it to the session manager to |
| 5526 | // figure out. |
| 5527 | MediaSessionLegacyHelper.getHelper(mContext) |
| 5528 | .sendVolumeKeyEvent(event, true); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5529 | } |
| 5530 | break; |
| 5531 | } |
| 5532 | |
| 5533 | case KeyEvent.KEYCODE_ENDCALL: { |
| 5534 | result &= ~ACTION_PASS_TO_USER; |
| 5535 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5536 | TelecomManager telecomManager = getTelecommService(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5537 | boolean hungUp = false; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5538 | if (telecomManager != null) { |
| 5539 | hungUp = telecomManager.endCall(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5540 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5541 | if (interactive && !hungUp) { |
| 5542 | mEndCallKeyHandled = false; |
| 5543 | mHandler.postDelayed(mEndCallLongPress, |
| 5544 | ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout()); |
| 5545 | } else { |
| 5546 | mEndCallKeyHandled = true; |
| 5547 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5548 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5549 | if (!mEndCallKeyHandled) { |
| 5550 | mHandler.removeCallbacks(mEndCallLongPress); |
| 5551 | if (!canceled) { |
| 5552 | if ((mEndcallBehavior |
| 5553 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 5554 | if (goHome()) { |
| 5555 | break; |
| 5556 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 5557 | } |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5558 | if ((mEndcallBehavior |
| 5559 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 5560 | mPowerManager.goToSleep(event.getEventTime(), |
| 5561 | PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0); |
| 5562 | isWakeKey = false; |
| 5563 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5564 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5565 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5566 | } |
| 5567 | break; |
| 5568 | } |
| 5569 | |
| 5570 | case KeyEvent.KEYCODE_POWER: { |
| 5571 | result &= ~ACTION_PASS_TO_USER; |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5572 | isWakeKey = false; // wake-up will be handled separately |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5573 | if (down) { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5574 | interceptPowerKeyDown(event, interactive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5575 | } else { |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5576 | interceptPowerKeyUp(event, interactive, canceled); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5577 | } |
| 5578 | break; |
| 5579 | } |
| 5580 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5581 | case KeyEvent.KEYCODE_SLEEP: { |
| 5582 | result &= ~ACTION_PASS_TO_USER; |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 5583 | isWakeKey = false; |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5584 | if (!mPowerManager.isInteractive()) { |
| 5585 | useHapticFeedback = false; // suppress feedback if already non-interactive |
| 5586 | } |
Nick Vaccaro | b593a81 | 2015-05-15 11:23:05 -0700 | [diff] [blame] | 5587 | if (down) { |
| 5588 | sleepPress(event.getEventTime()); |
| 5589 | } else { |
| 5590 | sleepRelease(event.getEventTime()); |
| 5591 | } |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5592 | break; |
| 5593 | } |
| 5594 | |
Nick Armstrong-Crews | 56ecfcc | 2015-09-07 21:46:50 -0700 | [diff] [blame] | 5595 | case KeyEvent.KEYCODE_SOFT_SLEEP: { |
| 5596 | result &= ~ACTION_PASS_TO_USER; |
| 5597 | isWakeKey = false; |
| 5598 | if (!down) { |
| 5599 | mPowerManagerInternal.setUserInactiveOverrideFromWindowManager(); |
| 5600 | } |
| 5601 | break; |
| 5602 | } |
| 5603 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5604 | case KeyEvent.KEYCODE_WAKEUP: { |
| 5605 | result &= ~ACTION_PASS_TO_USER; |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 5606 | isWakeKey = true; |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 5607 | break; |
| 5608 | } |
| 5609 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5610 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5611 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5612 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5613 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5614 | case KeyEvent.KEYCODE_MUTE: |
| 5615 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5616 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5617 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5618 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5619 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5620 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 5621 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
RoboErik | de9ba39 | 2014-09-26 12:51:01 -0700 | [diff] [blame] | 5622 | if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) { |
| 5623 | // If the global session is active pass all media keys to it |
| 5624 | // instead of the active window. |
| 5625 | result &= ~ACTION_PASS_TO_USER; |
| 5626 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5627 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 5628 | // Only do this if we would otherwise not pass it to the user. In that |
| 5629 | // case, the PhoneWindow class will do the same thing, except it will |
| 5630 | // 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] | 5631 | // Note that we need to make a copy of the key event here because the |
| 5632 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5633 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5634 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 5635 | new KeyEvent(event)); |
| 5636 | msg.setAsynchronous(true); |
| 5637 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5638 | } |
| 5639 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5640 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5641 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5642 | case KeyEvent.KEYCODE_CALL: { |
| 5643 | if (down) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5644 | TelecomManager telecomManager = getTelecommService(); |
| 5645 | if (telecomManager != null) { |
| 5646 | if (telecomManager.isRinging()) { |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5647 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 5648 | + " CALL key-down while ringing: Answer the call!"); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 5649 | telecomManager.acceptRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5650 | |
Santos Cordon | 6848f72 | 2014-05-21 15:22:12 -0700 | [diff] [blame] | 5651 | // And *don't* pass this key thru to the current activity |
| 5652 | // (which is presumably the InCallScreen.) |
| 5653 | result &= ~ACTION_PASS_TO_USER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5654 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5655 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5656 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5657 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5658 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5659 | case KeyEvent.KEYCODE_VOICE_ASSIST: { |
| 5660 | // Only do this if we would otherwise not pass it to the user. In that case, |
| 5661 | // interceptKeyBeforeDispatching would apply a similar but different policy in |
| 5662 | // order to invoke voice assist actions. Note that we need to make a copy of the |
| 5663 | // key event here because the original key event will be recycled when we return. |
| 5664 | if ((result & ACTION_PASS_TO_USER) == 0 && !down) { |
| 5665 | mBroadcastWakeLock.acquire(); |
| 5666 | Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, |
| 5667 | keyguardActive ? 1 : 0, 0); |
| 5668 | msg.setAsynchronous(true); |
| 5669 | msg.sendToTarget(); |
| 5670 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 5671 | break; |
| 5672 | } |
| 5673 | case KeyEvent.KEYCODE_WINDOW: { |
| 5674 | if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) { |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 5675 | if (mTvPictureInPictureVisible) { |
| 5676 | // Consumes the key only if picture-in-picture is visible |
| 5677 | // to show picture-in-picture control menu. |
| 5678 | // This gives a chance to the foreground activity |
| 5679 | // to customize PIP key behavior. |
| 5680 | if (!down) { |
| 5681 | showTvPictureInPictureMenu(event); |
| 5682 | } |
| 5683 | result &= ~ACTION_PASS_TO_USER; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 5684 | } |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 5685 | } |
| 5686 | break; |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5687 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5688 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5689 | |
Jeff Brown | bae8e77 | 2014-06-12 19:59:45 -0700 | [diff] [blame] | 5690 | if (useHapticFeedback) { |
| 5691 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5692 | } |
| 5693 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5694 | if (isWakeKey) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5695 | wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY"); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 5696 | } |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 5697 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5698 | return result; |
| 5699 | } |
| 5700 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5701 | /** |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 5702 | * Returns true if the key can have global actions attached to it. |
| 5703 | * We reserve all power management keys for the system since they require |
| 5704 | * very careful handling. |
| 5705 | */ |
| 5706 | private static boolean isValidGlobalKey(int keyCode) { |
| 5707 | switch (keyCode) { |
| 5708 | case KeyEvent.KEYCODE_POWER: |
| 5709 | case KeyEvent.KEYCODE_WAKEUP: |
| 5710 | case KeyEvent.KEYCODE_SLEEP: |
| 5711 | return false; |
| 5712 | default: |
| 5713 | return true; |
| 5714 | } |
| 5715 | } |
| 5716 | |
| 5717 | /** |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5718 | * When the screen is off we ignore some keys that might otherwise typically |
| 5719 | * be considered wake keys. We filter them out here. |
| 5720 | * |
| 5721 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 5722 | * is always considered a wake key. |
| 5723 | */ |
| 5724 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 5725 | switch (keyCode) { |
| 5726 | // ignore volume keys unless docked |
| 5727 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5728 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5729 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5730 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 5731 | |
| 5732 | // ignore media and camera keys |
| 5733 | case KeyEvent.KEYCODE_MUTE: |
| 5734 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 5735 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 5736 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 5737 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 5738 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 5739 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 5740 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 5741 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 5742 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 5743 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 5744 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 5745 | case KeyEvent.KEYCODE_CAMERA: |
| 5746 | return false; |
| 5747 | } |
| 5748 | return true; |
| 5749 | } |
| 5750 | |
| 5751 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5752 | /** {@inheritDoc} */ |
| 5753 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5754 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 5755 | if ((policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5756 | if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion, |
| 5757 | "android.policy:MOTION")) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5758 | return 0; |
| 5759 | } |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5760 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5761 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5762 | if (shouldDispatchInputWhenNonInteractive()) { |
| 5763 | return ACTION_PASS_TO_USER; |
| 5764 | } |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5765 | |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5766 | // If we have not passed the action up and we are in theater mode without dreaming, |
| 5767 | // there will be no dream to intercept the touch and wake into ambient. The device should |
| 5768 | // wake up in this case. |
| 5769 | if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 5770 | wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming, |
| 5771 | "android.policy:MOTION"); |
Bryce Lee | 812d702 | 2014-11-10 13:33:28 -0800 | [diff] [blame] | 5772 | } |
| 5773 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 5774 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 5775 | } |
| 5776 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5777 | private boolean shouldDispatchInputWhenNonInteractive() { |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 5778 | final boolean displayOff = (mDisplay == null || mDisplay.getState() == Display.STATE_OFF); |
| 5779 | |
| 5780 | if (displayOff && !mHasFeatureWatch) { |
| 5781 | return false; |
| 5782 | } |
| 5783 | |
| 5784 | // Send events to keyguard while the screen is on and it's showing. |
| 5785 | if (isKeyguardShowingAndNotOccluded() && !displayOff) { |
Bryce Lee | 5c13832 | 2014-11-03 08:26:09 -0800 | [diff] [blame] | 5786 | return true; |
| 5787 | } |
| 5788 | |
| 5789 | // Send events to a dozing dream even if the screen is off since the dream |
| 5790 | // is in control of the state of the screen. |
| 5791 | IDreamManager dreamManager = getDreamManager(); |
| 5792 | |
| 5793 | try { |
| 5794 | if (dreamManager != null && dreamManager.isDreaming()) { |
| 5795 | return true; |
| 5796 | } |
| 5797 | } catch (RemoteException e) { |
| 5798 | Slog.e(TAG, "RemoteException when checking if dreaming", e); |
| 5799 | } |
| 5800 | |
| 5801 | // Otherwise, consume events since the user can't see what is being |
| 5802 | // interacted with. |
| 5803 | return false; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 5804 | } |
| 5805 | |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5806 | private void dispatchDirectAudioEvent(KeyEvent event) { |
| 5807 | if (event.getAction() != KeyEvent.ACTION_DOWN) { |
| 5808 | return; |
| 5809 | } |
| 5810 | int keyCode = event.getKeyCode(); |
John Spurlock | b94f2d6 | 2015-03-17 14:11:57 -0400 | [diff] [blame] | 5811 | int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND |
| 5812 | | AudioManager.FLAG_FROM_KEY; |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5813 | String pkgName = mContext.getOpPackageName(); |
| 5814 | switch (keyCode) { |
| 5815 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 5816 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5817 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5818 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5819 | } catch (RemoteException e) { |
| 5820 | Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e); |
| 5821 | } |
| 5822 | break; |
| 5823 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 5824 | try { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5825 | getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5826 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5827 | } catch (RemoteException e) { |
| 5828 | Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e); |
| 5829 | } |
| 5830 | break; |
| 5831 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 5832 | try { |
| 5833 | if (event.getRepeatCount() == 0) { |
John Spurlock | ee5ad72 | 2015-03-03 16:17:21 -0500 | [diff] [blame] | 5834 | getAudioService().adjustSuggestedStreamVolume( |
| 5835 | AudioManager.ADJUST_TOGGLE_MUTE, |
John Spurlock | 9087433 | 2015-03-10 16:00:54 -0400 | [diff] [blame] | 5836 | AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG); |
RoboErik | 001c59c | 2015-01-26 15:53:51 -0800 | [diff] [blame] | 5837 | } |
| 5838 | } catch (RemoteException e) { |
| 5839 | Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e); |
| 5840 | } |
| 5841 | break; |
| 5842 | } |
| 5843 | } |
| 5844 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5845 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 5846 | if (DEBUG_INPUT) { |
| 5847 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5848 | } |
| 5849 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 5850 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 5851 | if (DEBUG_INPUT) { |
| 5852 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 5853 | } |
| 5854 | |
| 5855 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 5856 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5857 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 5858 | } |
| 5859 | |
| 5860 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 5861 | |
| 5862 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5863 | && event.getRepeatCount() == 0) { |
| 5864 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 5865 | |
| 5866 | Message msg = mHandler.obtainMessage( |
| 5867 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 5868 | msg.setAsynchronous(true); |
| 5869 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 5870 | } else { |
| 5871 | mBroadcastWakeLock.release(); |
| 5872 | } |
| 5873 | } |
| 5874 | |
| 5875 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 5876 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 5877 | |
| 5878 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 5879 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 5880 | if (DEBUG_INPUT) { |
| 5881 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 5882 | } |
| 5883 | |
| 5884 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 5885 | mBroadcastWakeLock.release(); |
| 5886 | } |
| 5887 | |
| 5888 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 5889 | if (ActivityManagerNative.isSystemReady()) { |
RoboErik | 430fc48 | 2014-06-12 15:49:20 -0700 | [diff] [blame] | 5890 | MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5891 | } |
| 5892 | } |
| 5893 | |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5894 | void launchVoiceAssistWithWakeLock(boolean keyguardActive) { |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 5895 | IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface( |
| 5896 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 5897 | if (dic != null) { |
| 5898 | try { |
| 5899 | dic.exitIdle("voice-search"); |
| 5900 | } catch (RemoteException e) { |
| 5901 | } |
| 5902 | } |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5903 | Intent voiceIntent = |
| 5904 | new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); |
| 5905 | voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive); |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 5906 | startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF); |
Michael Wright | 869a67c | 2014-08-26 19:33:06 -0700 | [diff] [blame] | 5907 | mBroadcastWakeLock.release(); |
| 5908 | } |
| 5909 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5910 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5911 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5912 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 5913 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 5914 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 5915 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5916 | } else { |
| 5917 | try { |
| 5918 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 5919 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 5920 | mUiMode = uiModeService.getCurrentModeType(); |
| 5921 | } catch (RemoteException e) { |
| 5922 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 5923 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 5924 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 5925 | synchronized (mLock) { |
| 5926 | updateOrientationListenerLp(); |
| 5927 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 5928 | } |
| 5929 | }; |
| 5930 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5931 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 5932 | @Override |
| 5933 | public void onReceive(Context context, Intent intent) { |
| 5934 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5935 | if (mKeyguardDelegate != null) { |
| 5936 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5937 | } |
| 5938 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5939 | if (mKeyguardDelegate != null) { |
| 5940 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 5941 | } |
| 5942 | } |
| 5943 | } |
| 5944 | }; |
| 5945 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5946 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 5947 | @Override |
| 5948 | public void onReceive(Context context, Intent intent) { |
| 5949 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 5950 | // tickle the settings observer: this first ensures that we're |
| 5951 | // observing the relevant settings for the newly-active user, |
| 5952 | // and then updates our own bookkeeping based on the now- |
| 5953 | // current user. |
| 5954 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5955 | |
| 5956 | // force a re-application of focused window sysui visibility. |
| 5957 | // the window may never have been shown for this user |
| 5958 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5959 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 5960 | mLastSystemUiFlags = 0; |
| 5961 | updateSystemUiVisibilityLw(); |
| 5962 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5963 | } |
| 5964 | } |
| 5965 | }; |
| 5966 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5967 | private final Runnable mHiddenNavPanic = new Runnable() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5968 | @Override |
| 5969 | public void run() { |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 5970 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 5971 | if (!isUserSetupComplete()) { |
| 5972 | // Swipe-up for navigation bar is disabled during setup |
| 5973 | return; |
| 5974 | } |
| 5975 | mPendingPanicGestureUptime = SystemClock.uptimeMillis(); |
| 5976 | mNavigationBarController.showTransient(); |
| 5977 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 5978 | } |
| 5979 | }; |
| 5980 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5981 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5982 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 5983 | if (!isUserSetupComplete()) { |
| 5984 | // Swipe-up for navigation bar is disabled during setup |
| 5985 | return; |
| 5986 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5987 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 5988 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5989 | if (sb || nb) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 5990 | // Don't show status bar when swiping on already visible navigation bar |
| 5991 | if (!nb && swipeTarget == mNavigationBar) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5992 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5993 | return; |
| 5994 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5995 | if (sb) mStatusBarController.showTransient(); |
| 5996 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5997 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5998 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5999 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 6000 | } |
| 6001 | } |
| 6002 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6003 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6004 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6005 | public void startedGoingToSleep(int why) { |
| 6006 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")"); |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6007 | mCameraGestureTriggeredDuringGoingToSleep = false; |
| 6008 | mGoingToSleep = true; |
Jorim Jaggi | d175b6c | 2015-05-27 15:39:09 -0700 | [diff] [blame] | 6009 | if (mKeyguardDelegate != null) { |
| 6010 | mKeyguardDelegate.onStartedGoingToSleep(why); |
| 6011 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6012 | } |
| 6013 | |
| 6014 | // Called on the PowerManager's Notifier thread. |
| 6015 | @Override |
| 6016 | public void finishedGoingToSleep(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 6017 | EventLog.writeEvent(70000, 0); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6018 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")"); |
Chris Wren | 9bb290b | 2015-06-29 12:02:13 -0400 | [diff] [blame] | 6019 | MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6020 | |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6021 | mGoingToSleep = false; |
| 6022 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6023 | // We must get this work done here because the power manager will drop |
| 6024 | // 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] | 6025 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6026 | mAwake = false; |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6027 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6028 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6029 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6030 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6031 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6032 | mKeyguardDelegate.onFinishedGoingToSleep(why, |
| 6033 | mCameraGestureTriggeredDuringGoingToSleep); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6034 | } |
Jorim Jaggi | f1cdf95 | 2016-04-05 21:41:06 -0700 | [diff] [blame] | 6035 | mCameraGestureTriggeredDuringGoingToSleep = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6036 | } |
| 6037 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6038 | // Called on the PowerManager's Notifier thread. |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6039 | @Override |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6040 | public void startedWakingUp() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 6041 | EventLog.writeEvent(70000, 1); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6042 | if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up..."); |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 6043 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6044 | // Since goToSleep performs these functions synchronously, we must |
| 6045 | // do the same here. We cannot post this work to a handler because |
| 6046 | // that might cause it to become reordered with respect to what |
| 6047 | // may happen in a future call to goToSleep. |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6048 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6049 | mAwake = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6050 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6051 | updateWakeGestureListenerLp(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6052 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6053 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6054 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6055 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6056 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6057 | mKeyguardDelegate.onStartedWakingUp(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6058 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6059 | } |
| 6060 | |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6061 | // Called on the PowerManager's Notifier thread. |
| 6062 | @Override |
| 6063 | public void finishedWakingUp() { |
| 6064 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up..."); |
| 6065 | } |
| 6066 | |
| 6067 | private void wakeUpFromPowerKey(long eventTime) { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6068 | wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER"); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6069 | } |
| 6070 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6071 | private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) { |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 6072 | final boolean theaterModeEnabled = isTheaterModeEnabled(); |
| 6073 | if (!wakeInTheaterMode && theaterModeEnabled) { |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6074 | return false; |
| 6075 | } |
| 6076 | |
Bryce Lee | d389684 | 2015-06-23 17:06:51 -0700 | [diff] [blame] | 6077 | if (theaterModeEnabled) { |
| 6078 | Settings.Global.putInt(mContext.getContentResolver(), |
| 6079 | Settings.Global.THEATER_MODE_ON, 0); |
| 6080 | } |
| 6081 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 6082 | mPowerManager.wakeUp(wakeTime, reason); |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6083 | return true; |
| 6084 | } |
| 6085 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6086 | private void finishKeyguardDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6087 | synchronized (mLock) { |
Jorim Jaggi | f325548 | 2015-07-24 12:32:42 -0700 | [diff] [blame] | 6088 | if (!mScreenOnEarly || mKeyguardDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6089 | 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] | 6090 | } |
| 6091 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6092 | mKeyguardDrawComplete = true; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6093 | if (mKeyguardDelegate != null) { |
| 6094 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 6095 | } |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6096 | mWindowManagerDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6097 | } |
| 6098 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6099 | // ... eventually calls finishWindowsDrawn which will finalize our screen turn on |
| 6100 | // as well as enabling the orientation change logic/sensor. |
| 6101 | mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, |
| 6102 | WAITING_FOR_DRAWN_TIMEOUT); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6103 | } |
| 6104 | |
| 6105 | // Called on the DisplayManager's DisplayPowerController thread. |
| 6106 | @Override |
| 6107 | public void screenTurnedOff() { |
| 6108 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); |
| 6109 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6110 | updateScreenOffSleepToken(true); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6111 | synchronized (mLock) { |
| 6112 | mScreenOnEarly = false; |
| 6113 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 6114 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6115 | mWindowManagerDrawComplete = false; |
| 6116 | mScreenOnListener = null; |
| 6117 | updateOrientationListenerLp(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6118 | |
| 6119 | if (mKeyguardDelegate != null) { |
| 6120 | mKeyguardDelegate.onScreenTurnedOff(); |
| 6121 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6122 | } |
| 6123 | } |
| 6124 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6125 | // Called on the DisplayManager's DisplayPowerController thread. |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6126 | @Override |
| 6127 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6128 | if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6129 | |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6130 | updateScreenOffSleepToken(false); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6131 | synchronized (mLock) { |
| 6132 | mScreenOnEarly = true; |
| 6133 | mScreenOnFully = false; |
Jorim Jaggi | 95c6dae | 2015-07-29 15:17:23 -0700 | [diff] [blame] | 6134 | mKeyguardDrawComplete = false; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6135 | mWindowManagerDrawComplete = false; |
| 6136 | mScreenOnListener = screenOnListener; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6137 | |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6138 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | a4b51bc | 2015-08-10 18:20:43 -0700 | [diff] [blame] | 6139 | mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); |
| 6140 | mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); |
Jorim Jaggi | 4cfdcf5 | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 6141 | mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback); |
| 6142 | } else { |
| 6143 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6144 | "null mKeyguardDelegate: setting mKeyguardDrawComplete."); |
| 6145 | finishKeyguardDrawn(); |
| 6146 | } |
| 6147 | } |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6148 | } |
| 6149 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 6150 | // Called on the DisplayManager's DisplayPowerController thread. |
| 6151 | @Override |
| 6152 | public void screenTurnedOn() { |
| 6153 | synchronized (mLock) { |
| 6154 | if (mKeyguardDelegate != null) { |
| 6155 | mKeyguardDelegate.onScreenTurnedOn(); |
| 6156 | } |
| 6157 | } |
| 6158 | } |
| 6159 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6160 | private void finishWindowsDrawn() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6161 | synchronized (mLock) { |
| 6162 | if (!mScreenOnEarly || mWindowManagerDrawComplete) { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6163 | 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] | 6164 | } |
| 6165 | |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6166 | mWindowManagerDrawComplete = true; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6167 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6168 | |
| 6169 | finishScreenTurningOn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6170 | } |
| 6171 | |
Craig Mautner | 8a0da01 | 2014-05-31 15:13:37 -0700 | [diff] [blame] | 6172 | private void finishScreenTurningOn() { |
Stefan Kuhne | 9326dc1 | 2015-06-12 09:25:32 -1000 | [diff] [blame] | 6173 | synchronized (mLock) { |
| 6174 | // We have just finished drawing screen content. Since the orientation listener |
| 6175 | // gets only installed when all windows are drawn, we try to install it again. |
| 6176 | updateOrientationListenerLp(); |
| 6177 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6178 | final ScreenOnListener listener; |
| 6179 | final boolean enableScreen; |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6180 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6181 | if (DEBUG_WAKEUP) Slog.d(TAG, |
| 6182 | "finishScreenTurningOn: mAwake=" + mAwake |
| 6183 | + ", mScreenOnEarly=" + mScreenOnEarly |
| 6184 | + ", mScreenOnFully=" + mScreenOnFully |
| 6185 | + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete |
| 6186 | + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); |
| 6187 | |
| 6188 | if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete |
| 6189 | || (mAwake && !mKeyguardDrawComplete)) { |
| 6190 | return; // spurious or not ready yet |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6191 | } |
| 6192 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6193 | if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); |
| 6194 | listener = mScreenOnListener; |
Craig Mautner | 13f6ea7 | 2014-06-23 14:57:02 -0700 | [diff] [blame] | 6195 | mScreenOnListener = null; |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6196 | mScreenOnFully = true; |
| 6197 | |
| 6198 | // Remember the first time we draw the keyguard so we know when we're done with |
| 6199 | // the main part of booting and can enable the screen and hide boot messages. |
| 6200 | if (!mKeyguardDrawnOnce && mAwake) { |
| 6201 | mKeyguardDrawnOnce = true; |
| 6202 | enableScreen = true; |
| 6203 | if (mBootMessageNeedsHiding) { |
| 6204 | mBootMessageNeedsHiding = false; |
| 6205 | hideBootMessages(); |
| 6206 | } |
| 6207 | } else { |
| 6208 | enableScreen = false; |
| 6209 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6210 | } |
| 6211 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6212 | if (listener != null) { |
| 6213 | listener.onScreenOn(); |
| 6214 | } |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 6215 | |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6216 | if (enableScreen) { |
| 6217 | try { |
| 6218 | mWindowManager.enableScreenIfNeeded(); |
| 6219 | } catch (RemoteException unhandled) { |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6220 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6221 | } |
| 6222 | } |
| 6223 | |
| 6224 | private void handleHideBootMessage() { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6225 | synchronized (mLock) { |
| 6226 | if (!mKeyguardDrawnOnce) { |
| 6227 | mBootMessageNeedsHiding = true; |
| 6228 | return; // keyguard hasn't drawn the first time yet, not done booting |
| 6229 | } |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6230 | } |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6231 | |
| 6232 | if (mBootMsgDialog != null) { |
| 6233 | if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); |
| 6234 | mBootMsgDialog.dismiss(); |
| 6235 | mBootMsgDialog = null; |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6236 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6237 | } |
| 6238 | |
| 6239 | @Override |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6240 | public boolean isScreenOn() { |
| 6241 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 6242 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 6243 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 6244 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6245 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6246 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6247 | if (mKeyguardDelegate != null) { |
| 6248 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6249 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6253 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6254 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6255 | if (mKeyguardDelegate != null) { |
| 6256 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6257 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6258 | } |
| 6259 | |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6260 | private boolean isKeyguardShowingAndNotOccluded() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6261 | if (mKeyguardDelegate == null) return false; |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6262 | return mKeyguardDelegate.isShowing() && !mKeyguardOccluded; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6263 | } |
| 6264 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6265 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6266 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6267 | public boolean isKeyguardLocked() { |
| 6268 | return keyguardOn(); |
| 6269 | } |
| 6270 | |
| 6271 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6272 | @Override |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6273 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6274 | if (mKeyguardDelegate == null) return false; |
| 6275 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 6276 | } |
| 6277 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6278 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6279 | @Override |
Adrian Roos | 461829d | 2015-06-03 14:41:18 -0700 | [diff] [blame] | 6280 | public boolean isKeyguardShowingOrOccluded() { |
| 6281 | return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing(); |
| 6282 | } |
| 6283 | |
| 6284 | /** {@inheritDoc} */ |
| 6285 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6286 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6287 | if (mKeyguardDelegate == null) return false; |
| 6288 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6289 | } |
| 6290 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6291 | @Override |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 6292 | public void dismissKeyguardLw() { |
RoboErik | 8a2cfc3 | 2014-05-16 11:19:38 -0700 | [diff] [blame] | 6293 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6294 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw"); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 6295 | mHandler.post(new Runnable() { |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6296 | @Override |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 6297 | public void run() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 6298 | // ask the keyguard to prompt the user to authenticate if necessary |
| 6299 | mKeyguardDelegate.dismiss(); |
| 6300 | } |
| 6301 | }); |
| 6302 | } |
| 6303 | } |
| 6304 | |
| 6305 | public void notifyActivityDrawnForKeyguardLw() { |
| 6306 | if (mKeyguardDelegate != null) { |
| 6307 | mHandler.post(new Runnable() { |
| 6308 | @Override |
| 6309 | public void run() { |
| 6310 | mKeyguardDelegate.onActivityDrawn(); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 6311 | } |
| 6312 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 6313 | } |
| 6314 | } |
| 6315 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6316 | @Override |
| 6317 | public boolean isKeyguardDrawnLw() { |
| 6318 | synchronized (mLock) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6319 | return mKeyguardDrawnOnce; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 6320 | } |
| 6321 | } |
| 6322 | |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6323 | @Override |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6324 | public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6325 | if (mKeyguardDelegate != null) { |
Craig Mautner | c0d2d0a | 2014-10-31 16:25:15 -0700 | [diff] [blame] | 6326 | if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation"); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 6327 | mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration); |
Jorim Jaggi | 0d67462 | 2014-05-21 01:34:15 +0200 | [diff] [blame] | 6328 | } |
| 6329 | } |
| 6330 | |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6331 | @Override |
| 6332 | public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 6333 | Rect outInsets) { |
| 6334 | outInsets.setEmpty(); |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 6335 | |
| 6336 | // Navigation bar and status bar. |
| 6337 | getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets); |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6338 | if (mStatusBar != null) { |
| 6339 | outInsets.top = mStatusBarHeight; |
| 6340 | } |
Jorim Jaggi | 82c9dc9 | 2016-02-05 15:10:33 -0800 | [diff] [blame] | 6341 | } |
| 6342 | |
| 6343 | @Override |
| 6344 | public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight, |
| 6345 | Rect outInsets) { |
| 6346 | outInsets.setEmpty(); |
| 6347 | |
| 6348 | // Only navigation bar |
Jorim Jaggi | 737af72 | 2015-12-31 10:42:27 +0100 | [diff] [blame] | 6349 | if (mNavigationBar != null) { |
| 6350 | if (isNavigationBarOnBottom(displayWidth, displayHeight)) { |
| 6351 | outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode); |
| 6352 | } else { |
| 6353 | outInsets.right = getNavigationBarWidth(displayRotation, mUiMode); |
| 6354 | } |
| 6355 | } |
| 6356 | } |
| 6357 | |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 6358 | @Override |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6359 | public boolean isNavBarForcedShownLw(WindowState windowState) { |
Jorim Jaggi | e5638a6 | 2016-03-25 22:57:01 -0700 | [diff] [blame] | 6360 | return mForceShowSystemBars; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6361 | } |
| 6362 | |
| 6363 | @Override |
Jorim Jaggi | 5060bd8 | 2016-02-19 17:12:19 -0800 | [diff] [blame] | 6364 | public boolean isDockSideAllowed(int dockSide) { |
| 6365 | |
| 6366 | // We do not allow all dock sides at which the navigation bar touches the docked stack. |
| 6367 | if (!mNavigationBarCanMove) { |
| 6368 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT; |
| 6369 | } else { |
| 6370 | return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT; |
| 6371 | } |
| 6372 | } |
| 6373 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6374 | void sendCloseSystemWindows() { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6375 | PhoneWindow.sendCloseSystemWindows(mContext, null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6376 | } |
| 6377 | |
| 6378 | void sendCloseSystemWindows(String reason) { |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 6379 | PhoneWindow.sendCloseSystemWindows(mContext, reason); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6380 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 6381 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6382 | @Override |
| 6383 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6384 | if (false) { |
| 6385 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 6386 | + orientation + ", last=" + lastRotation |
| 6387 | + "); user=" + mUserRotation + " " |
| 6388 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 6389 | ? "USER_ROTATION_LOCKED" : "") |
| 6390 | ); |
| 6391 | } |
| 6392 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 6393 | if (mForceDefaultOrientation) { |
| 6394 | return Surface.ROTATION_0; |
| 6395 | } |
| 6396 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 6397 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6398 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 6399 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 6400 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6401 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6402 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6403 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 6404 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6405 | // Ignore sensor when lid switch is open and rotation is forced. |
| 6406 | preferredRotation = mLidOpenRotation; |
| 6407 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6408 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6409 | // Ignore sensor when in car dock unless explicitly enabled. |
| 6410 | // This case can override the behavior of NOSENSOR, and can also |
| 6411 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6412 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6413 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 6414 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6415 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 6416 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6417 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6418 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 6419 | // This case can override the behavior of NOSENSOR, and can also |
| 6420 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6421 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6422 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6423 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 6424 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 6425 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 6426 | preferredRotation = mDemoHdmiRotation; |
| 6427 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 6428 | && mUndockedHdmiRotation >= 0) { |
| 6429 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 6430 | // been specified in the configuration (only for legacy devices without |
| 6431 | // full multi-display support). |
| 6432 | // Note that the dock orientation overrides the HDMI orientation. |
| 6433 | preferredRotation = mUndockedHdmiRotation; |
Chong Zhang | ae6119ff | 2014-11-11 18:54:39 -0800 | [diff] [blame] | 6434 | } else if (mDemoRotationLock) { |
| 6435 | // Ignore sensor when demo rotation lock is enabled. |
| 6436 | // Note that the dock orientation and HDMI rotation lock override this. |
| 6437 | preferredRotation = mDemoRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6438 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 6439 | // Application just wants to remain locked in the last rotation. |
| 6440 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 6441 | } else if (!mSupportAutoRotation) { |
| 6442 | // If we don't support auto-rotation then bail out here and ignore |
| 6443 | // the sensor and any rotation lock settings. |
| 6444 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6445 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6446 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6447 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 6448 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 6449 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 6450 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6451 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 6452 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6453 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 6454 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 6455 | // Otherwise, use sensor only if requested by the application or enabled |
| 6456 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6457 | if (mAllowAllRotations < 0) { |
| 6458 | // Can't read this during init() because the context doesn't |
| 6459 | // have display metrics at that time so we cannot determine |
| 6460 | // tablet vs. phone then. |
| 6461 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 6462 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 6463 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6464 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 6465 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6466 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 6467 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6468 | preferredRotation = sensorRotation; |
| 6469 | } else { |
| 6470 | preferredRotation = lastRotation; |
| 6471 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 6472 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 6473 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 6474 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 6475 | // The idea is that the user rotation expresses a weak preference for the direction |
| 6476 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 6477 | // 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] | 6478 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6479 | } else { |
| 6480 | // No overriding preference. |
| 6481 | // We will do exactly what the application asked us to do. |
| 6482 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6483 | } |
| 6484 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6485 | switch (orientation) { |
| 6486 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6487 | // Return portrait unless overridden. |
| 6488 | if (isAnyPortrait(preferredRotation)) { |
| 6489 | return preferredRotation; |
| 6490 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6491 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6492 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6493 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6494 | // Return landscape unless overridden. |
| 6495 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6496 | return preferredRotation; |
| 6497 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6498 | return mLandscapeRotation; |
| 6499 | |
| 6500 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6501 | // Return reverse portrait unless overridden. |
| 6502 | if (isAnyPortrait(preferredRotation)) { |
| 6503 | return preferredRotation; |
| 6504 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6505 | return mUpsideDownRotation; |
| 6506 | |
| 6507 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 6508 | // Return seascape unless overridden. |
| 6509 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6510 | return preferredRotation; |
| 6511 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6512 | return mSeascapeRotation; |
| 6513 | |
| 6514 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6515 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6516 | // Return either landscape rotation. |
| 6517 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 6518 | return preferredRotation; |
| 6519 | } |
| 6520 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 6521 | return lastRotation; |
| 6522 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6523 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6524 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6525 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 6526 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6527 | // Return either portrait rotation. |
| 6528 | if (isAnyPortrait(preferredRotation)) { |
| 6529 | return preferredRotation; |
| 6530 | } |
| 6531 | if (isAnyPortrait(lastRotation)) { |
| 6532 | return lastRotation; |
| 6533 | } |
| 6534 | return mPortraitRotation; |
| 6535 | |
| 6536 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 6537 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 6538 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6539 | if (preferredRotation >= 0) { |
| 6540 | return preferredRotation; |
| 6541 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 6542 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 6543 | } |
| 6544 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6545 | } |
| 6546 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6547 | @Override |
| 6548 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 6549 | switch (orientation) { |
| 6550 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 6551 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 6552 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 6553 | return isAnyPortrait(rotation); |
| 6554 | |
| 6555 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 6556 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 6557 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 6558 | return isLandscapeOrSeascape(rotation); |
| 6559 | |
| 6560 | default: |
| 6561 | return true; |
| 6562 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 6563 | } |
| 6564 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 6565 | @Override |
| 6566 | public void setRotationLw(int rotation) { |
| 6567 | mOrientationListener.setCurrentRotation(rotation); |
| 6568 | } |
| 6569 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6570 | private boolean isLandscapeOrSeascape(int rotation) { |
| 6571 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6572 | } |
| 6573 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6574 | private boolean isAnyPortrait(int rotation) { |
| 6575 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 6576 | } |
| 6577 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6578 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6579 | public int getUserRotationMode() { |
| 6580 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 6581 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 6582 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 6583 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6584 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6585 | |
| 6586 | // 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] | 6587 | @Override |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6588 | public void setUserRotationMode(int mode, int rot) { |
| 6589 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6590 | |
| 6591 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6592 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6593 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6594 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6595 | rot, |
| 6596 | UserHandle.USER_CURRENT); |
| 6597 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 6598 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6599 | 0, |
| 6600 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6601 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6602 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6603 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 6604 | 1, |
| 6605 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 6606 | } |
| 6607 | } |
| 6608 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6609 | @Override |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 6610 | public void setSafeMode(boolean safeMode) { |
| 6611 | mSafeMode = safeMode; |
| 6612 | performHapticFeedbackLw(null, safeMode |
| 6613 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 6614 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6615 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6616 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 6617 | static long[] getLongIntArray(Resources r, int resid) { |
| 6618 | int[] ar = r.getIntArray(resid); |
| 6619 | if (ar == null) { |
| 6620 | return null; |
| 6621 | } |
| 6622 | long[] out = new long[ar.length]; |
| 6623 | for (int i=0; i<ar.length; i++) { |
| 6624 | out[i] = ar[i]; |
| 6625 | } |
| 6626 | return out; |
| 6627 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6628 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6629 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6630 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6631 | public void systemReady() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 6632 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext); |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 6633 | mKeyguardDelegate.onSystemReady(); |
| 6634 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 6635 | readCameraLensCoverState(); |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6636 | updateUiMode(); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6637 | boolean bindKeyguardNow; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 6638 | synchronized (mLock) { |
| 6639 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6640 | mSystemReady = true; |
| 6641 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6642 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 6643 | public void run() { |
| 6644 | updateSettings(); |
| 6645 | } |
| 6646 | }); |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6647 | |
| 6648 | bindKeyguardNow = mDeferBindKeyguard; |
| 6649 | if (bindKeyguardNow) { |
| 6650 | // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now. |
| 6651 | mDeferBindKeyguard = false; |
| 6652 | } |
| 6653 | } |
| 6654 | |
| 6655 | if (bindKeyguardNow) { |
| 6656 | mKeyguardDelegate.bindService(mContext); |
| 6657 | mKeyguardDelegate.onBootCompleted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6658 | } |
Michael Wright | a4d22d7 | 2015-09-16 23:19:26 +0100 | [diff] [blame] | 6659 | mSystemGestures.systemReady(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 6660 | mImmersiveModeConfirmation.systemReady(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6661 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6662 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6663 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6664 | @Override |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6665 | public void systemBooted() { |
Adrian Roos | 3542f7d | 2015-07-13 15:57:53 -0700 | [diff] [blame] | 6666 | boolean bindKeyguardNow = false; |
| 6667 | synchronized (mLock) { |
| 6668 | // Time to bind Keyguard; take care to only bind it once, either here if ready or |
| 6669 | // in systemReady if not. |
| 6670 | if (mKeyguardDelegate != null) { |
| 6671 | bindKeyguardNow = true; |
| 6672 | } else { |
| 6673 | // Because mKeyguardDelegate is null, we know that the synchronized block in |
| 6674 | // systemReady didn't run yet and setting this will actually have an effect. |
| 6675 | mDeferBindKeyguard = true; |
| 6676 | } |
| 6677 | } |
| 6678 | if (bindKeyguardNow) { |
Jason Monk | 5eeebf5 | 2014-09-26 12:36:51 -0400 | [diff] [blame] | 6679 | mKeyguardDelegate.bindService(mContext); |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 6680 | mKeyguardDelegate.onBootCompleted(); |
| 6681 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6682 | synchronized (mLock) { |
| 6683 | mSystemBooted = true; |
| 6684 | } |
Jeff Brown | 416c49c | 2015-05-26 19:50:18 -0700 | [diff] [blame] | 6685 | startedWakingUp(); |
Jeff Brown | 36c4db8 | 2014-09-19 12:05:31 -0700 | [diff] [blame] | 6686 | screenTurningOn(null); |
Jorim Jaggi | c049607 | 2015-08-19 15:14:52 -0700 | [diff] [blame] | 6687 | screenTurnedOn(); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 6688 | } |
| 6689 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6690 | ProgressDialog mBootMsgDialog = null; |
| 6691 | |
| 6692 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6693 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6694 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 6695 | mHandler.post(new Runnable() { |
| 6696 | @Override public void run() { |
| 6697 | if (mBootMsgDialog == null) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 6698 | int theme; |
Wale Ogunwale | 6b15ea5 | 2016-04-04 07:28:27 -0700 | [diff] [blame] | 6699 | if (mHasFeatureWatch) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 6700 | theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert; |
Jaewan Kim | 4911787 | 2016-01-19 17:24:08 +0900 | [diff] [blame] | 6701 | } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) { |
Craig Stout | 4c0cb8a | 2014-04-04 13:03:10 -0700 | [diff] [blame] | 6702 | theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert; |
| 6703 | } else { |
| 6704 | theme = 0; |
| 6705 | } |
Vinod Krishnan | fa8fc41 | 2014-04-18 14:35:53 -0700 | [diff] [blame] | 6706 | |
| 6707 | mBootMsgDialog = new ProgressDialog(mContext, theme) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 6708 | // This dialog will consume all events coming in to |
| 6709 | // it, to avoid it trying to do things too early in boot. |
| 6710 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 6711 | return true; |
| 6712 | } |
| 6713 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 6714 | return true; |
| 6715 | } |
| 6716 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 6717 | return true; |
| 6718 | } |
| 6719 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 6720 | return true; |
| 6721 | } |
| 6722 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 6723 | return true; |
| 6724 | } |
| 6725 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 6726 | AccessibilityEvent event) { |
| 6727 | return true; |
| 6728 | } |
| 6729 | }; |
Jeff Hao | 9f60c08 | 2014-10-28 18:51:07 -0700 | [diff] [blame] | 6730 | if (mContext.getPackageManager().isUpgrade()) { |
| 6731 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 6732 | } else { |
| 6733 | mBootMsgDialog.setTitle(R.string.android_start_title); |
| 6734 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6735 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 6736 | mBootMsgDialog.setIndeterminate(true); |
| 6737 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 6738 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6739 | mBootMsgDialog.getWindow().addFlags( |
| 6740 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 6741 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 6742 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95a | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 6743 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 6744 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 6745 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6746 | mBootMsgDialog.setCancelable(false); |
| 6747 | mBootMsgDialog.show(); |
| 6748 | } |
| 6749 | mBootMsgDialog.setMessage(msg); |
| 6750 | } |
| 6751 | }); |
| 6752 | } |
| 6753 | |
| 6754 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6755 | @Override |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6756 | public void hideBootMessages() { |
Craig Mautner | a631d49 | 2014-08-05 15:16:01 -0700 | [diff] [blame] | 6757 | mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 6758 | } |
| 6759 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6760 | /** {@inheritDoc} */ |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6761 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6762 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 6763 | // *************************************** |
| 6764 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 6765 | // *************************************** |
| 6766 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 6767 | // WITH ITS LOCKS HELD. |
| 6768 | // |
| 6769 | // This code must be VERY careful about the locks |
| 6770 | // it acquires. |
| 6771 | // In fact, the current code acquires way too many, |
| 6772 | // and probably has lurking deadlocks. |
| 6773 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6774 | synchronized (mScreenLockTimeout) { |
| 6775 | if (mLockScreenTimerActive) { |
| 6776 | // reset the timer |
| 6777 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6778 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6779 | } |
| 6780 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 6781 | } |
| 6782 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6783 | class ScreenLockTimeout implements Runnable { |
| 6784 | Bundle options; |
| 6785 | |
| 6786 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6787 | public void run() { |
| 6788 | synchronized (this) { |
| 6789 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6790 | if (mKeyguardDelegate != null) { |
| 6791 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 6792 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6793 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6794 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6795 | } |
| 6796 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6797 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6798 | public void setLockOptions(Bundle options) { |
| 6799 | this.options = options; |
| 6800 | } |
| 6801 | } |
| 6802 | |
| 6803 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 6804 | |
Jose Lima | 9546b20 | 2014-07-02 17:21:51 -0700 | [diff] [blame] | 6805 | @Override |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6806 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6807 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 6808 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 6809 | if (options != null) { |
| 6810 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 6811 | // until the runnable actually executes. |
| 6812 | mScreenLockTimeout.setLockOptions(options); |
| 6813 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 6814 | mHandler.post(mScreenLockTimeout); |
| 6815 | } |
| 6816 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6817 | private void updateLockScreenTimeout() { |
| 6818 | synchronized (mScreenLockTimeout) { |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 6819 | boolean enable = (mAllowLockscreenWhenOn && mAwake && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 6820 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6821 | if (mLockScreenTimerActive != enable) { |
| 6822 | if (enable) { |
| 6823 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
Jim Miller | 2967f48 | 2016-01-07 15:05:32 -0800 | [diff] [blame] | 6824 | mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 6825 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 6826 | } else { |
| 6827 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 6828 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 6829 | } |
| 6830 | mLockScreenTimerActive = enable; |
| 6831 | } |
| 6832 | } |
| 6833 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6834 | |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6835 | private void updateDreamingSleepToken(boolean acquire) { |
| 6836 | if (acquire) { |
| 6837 | if (mDreamingSleepToken == null) { |
| 6838 | mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream"); |
| 6839 | } |
| 6840 | } else { |
| 6841 | if (mDreamingSleepToken != null) { |
| 6842 | mDreamingSleepToken.release(); |
Jeff Brown | 48d1b14 | 2015-06-10 16:36:03 -0700 | [diff] [blame] | 6843 | mDreamingSleepToken = null; |
| 6844 | } |
| 6845 | } |
| 6846 | } |
| 6847 | |
| 6848 | private void updateScreenOffSleepToken(boolean acquire) { |
| 6849 | if (acquire) { |
| 6850 | if (mScreenOffSleepToken == null) { |
| 6851 | mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff"); |
| 6852 | } |
| 6853 | } else { |
| 6854 | if (mScreenOffSleepToken != null) { |
| 6855 | mScreenOffSleepToken.release(); |
| 6856 | mScreenOffSleepToken = null; |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 6857 | } |
| 6858 | } |
| 6859 | } |
| 6860 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6861 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6862 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6863 | public void enableScreenAfterBoot() { |
| 6864 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6865 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6866 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6867 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 6868 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6869 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6870 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6871 | mPowerManager.goToSleep(SystemClock.uptimeMillis(), |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 6872 | PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH, |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 6873 | PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 6874 | } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) { |
| 6875 | mWindowManagerFuncs.lockDeviceNow(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 6876 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 6877 | |
| 6878 | synchronized (mLock) { |
| 6879 | updateWakeGestureListenerLp(); |
| 6880 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6881 | } |
| 6882 | |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6883 | void updateUiMode() { |
| 6884 | if (mUiModeManager == null) { |
| 6885 | mUiModeManager = IUiModeManager.Stub.asInterface( |
| 6886 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 6887 | } |
| 6888 | try { |
| 6889 | mUiMode = mUiModeManager.getCurrentModeType(); |
| 6890 | } catch (RemoteException e) { |
| 6891 | } |
| 6892 | } |
| 6893 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 6894 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6895 | try { |
| 6896 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 6897 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 6898 | } catch (RemoteException e) { |
| 6899 | // Ignore |
| 6900 | } |
| 6901 | } |
| 6902 | |
| 6903 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 6904 | try { |
| 6905 | //set orientation on WindowManager |
| 6906 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 6907 | } catch (RemoteException e) { |
| 6908 | // Ignore |
| 6909 | } |
| 6910 | } |
| 6911 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6912 | /** |
| 6913 | * Return an Intent to launch the currently active dock app as home. Returns |
| 6914 | * null if the standard home should be launched, which is the case if any of the following is |
| 6915 | * true: |
| 6916 | * <ul> |
| 6917 | * <li>The device is not in either car mode or desk mode |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 6918 | * <li>The device is in car mode but mEnableCarDockHomeCapture is false |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6919 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 6920 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 6921 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 6922 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6923 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6924 | */ |
| 6925 | Intent createHomeDockIntent() { |
| 6926 | Intent intent = null; |
| 6927 | |
| 6928 | // What home does is based on the mode, not the dock state. That |
| 6929 | // is, when in car mode you should be taken to car home regardless |
| 6930 | // of whether we are actually in a car dock. |
| 6931 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 6932 | if (mEnableCarDockHomeCapture) { |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6933 | intent = mCarDockIntent; |
| 6934 | } |
| 6935 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 6936 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 6937 | intent = mDeskDockIntent; |
| 6938 | } |
Jeff Brown | 4f5fa28 | 2014-06-12 19:19:15 -0700 | [diff] [blame] | 6939 | } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH |
| 6940 | && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 6941 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK |
| 6942 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) { |
| 6943 | // Always launch dock home from home when watch is docked, if it exists. |
| 6944 | intent = mDeskDockIntent; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6945 | } |
| 6946 | |
| 6947 | if (intent == null) { |
| 6948 | return null; |
| 6949 | } |
| 6950 | |
| 6951 | ActivityInfo ai = null; |
| 6952 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 6953 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 6954 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 6955 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6956 | if (info != null) { |
| 6957 | ai = info.activityInfo; |
| 6958 | } |
| 6959 | if (ai != null |
| 6960 | && ai.metaData != null |
| 6961 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 6962 | intent = new Intent(intent); |
| 6963 | intent.setClassName(ai.packageName, ai.name); |
| 6964 | return intent; |
| 6965 | } |
| 6966 | |
| 6967 | return null; |
| 6968 | } |
| 6969 | |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 6970 | void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) { |
| 6971 | if (awakenFromDreams) { |
| 6972 | awakenDreams(); |
| 6973 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6974 | |
| 6975 | Intent dock = createHomeDockIntent(); |
| 6976 | if (dock != null) { |
| 6977 | try { |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6978 | if (fromHomeKey) { |
| 6979 | dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6980 | } |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 6981 | startActivityAsUser(dock, UserHandle.CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 6982 | return; |
| 6983 | } catch (ActivityNotFoundException e) { |
| 6984 | } |
| 6985 | } |
| 6986 | |
Bryce Lee | 01b0c5f | 2015-02-05 18:24:04 -0800 | [diff] [blame] | 6987 | Intent intent; |
| 6988 | |
| 6989 | if (fromHomeKey) { |
| 6990 | intent = new Intent(mHomeIntent); |
| 6991 | intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey); |
| 6992 | } else { |
| 6993 | intent = mHomeIntent; |
| 6994 | } |
| 6995 | |
Bryce Lee | 9fc0b6f | 2015-03-19 21:37:45 +0000 | [diff] [blame] | 6996 | startActivityAsUser(intent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6997 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 6998 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 6999 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7000 | * goes to the home screen |
| 7001 | * @return whether it did anything |
| 7002 | */ |
| 7003 | boolean goHome() { |
Bart Sears | 8b1c27c | 2015-03-18 23:51:02 +0000 | [diff] [blame] | 7004 | if (!isUserSetupComplete()) { |
| 7005 | Slog.i(TAG, "Not going home because user setup is in progress."); |
| 7006 | return false; |
| 7007 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7008 | if (false) { |
| 7009 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 7010 | try { |
| 7011 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 7012 | } catch (RemoteException e) { |
| 7013 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 7014 | sendCloseSystemWindows(); |
Filip Gruszczynski | a483a1d | 2015-03-17 19:06:58 +0000 | [diff] [blame] | 7015 | startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7016 | } else { |
| 7017 | // This code brings home to the front or, if it is already |
| 7018 | // at the front, puts the device to sleep. |
| 7019 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 7020 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 7021 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 7022 | Log.d(TAG, "UTS-TEST-MODE"); |
| 7023 | } else { |
| 7024 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 7025 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7026 | Intent dock = createHomeDockIntent(); |
| 7027 | if (dock != null) { |
| 7028 | int result = ActivityManagerNative.getDefault() |
| 7029 | .startActivityAsUser(null, null, dock, |
| 7030 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 7031 | null, null, 0, |
| 7032 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7033 | null, null, UserHandle.USER_CURRENT); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7034 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 7035 | return false; |
| 7036 | } |
| 7037 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 7038 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7039 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7040 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7041 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7042 | null, null, 0, |
| 7043 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 7044 | null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 7045 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7046 | return false; |
| 7047 | } |
| 7048 | } catch (RemoteException ex) { |
| 7049 | // bummer, the activity manager, which is in this process, is dead |
| 7050 | } |
| 7051 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7052 | return true; |
| 7053 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7054 | |
| 7055 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7056 | public void setCurrentOrientationLw(int newOrientation) { |
| 7057 | synchronized (mLock) { |
| 7058 | if (newOrientation != mCurrentAppOrientation) { |
| 7059 | mCurrentAppOrientation = newOrientation; |
| 7060 | updateOrientationListenerLp(); |
| 7061 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7062 | } |
| 7063 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7064 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 7065 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 7066 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 7067 | return; |
| 7068 | } |
| 7069 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 7070 | Context.AUDIO_SERVICE); |
| 7071 | if (audioManager.isSilentMode()) { |
| 7072 | return; |
| 7073 | } |
| 7074 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 7075 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 7076 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 7077 | ringTone.play(); |
| 7078 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7079 | |
Bryce Lee | 584a445 | 2014-10-21 15:55:55 -0700 | [diff] [blame] | 7080 | private boolean isTheaterModeEnabled() { |
| 7081 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 7082 | Settings.Global.THEATER_MODE_ON, 0) == 1; |
| 7083 | } |
| 7084 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 7085 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 7086 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 7087 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 7088 | } |
| 7089 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7090 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 7091 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 7092 | if (!mVibrator.hasVibrator()) { |
| 7093 | return false; |
| 7094 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 7095 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 7096 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jeff Brown | 82379ba | 2014-07-25 19:03:28 -0700 | [diff] [blame] | 7097 | if (hapticsDisabled && !always) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7098 | return false; |
| 7099 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7100 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7101 | switch (effectId) { |
| 7102 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7103 | pattern = mLongPressVibePattern; |
| 7104 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7105 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7106 | pattern = mVirtualKeyVibePattern; |
| 7107 | break; |
| 7108 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 7109 | pattern = mKeyboardTapVibePattern; |
| 7110 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 7111 | case HapticFeedbackConstants.CLOCK_TICK: |
| 7112 | pattern = mClockTickVibePattern; |
| 7113 | break; |
Fabrice Di Meglio | bd9152f | 2013-10-01 11:21:31 -0700 | [diff] [blame] | 7114 | case HapticFeedbackConstants.CALENDAR_DATE: |
| 7115 | pattern = mCalendarDateVibePattern; |
| 7116 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7117 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7118 | pattern = mSafeModeDisabledVibePattern; |
| 7119 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 7120 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7121 | pattern = mSafeModeEnabledVibePattern; |
| 7122 | break; |
Mady Mellor | e860891 | 2015-06-05 09:02:55 -0700 | [diff] [blame] | 7123 | case HapticFeedbackConstants.CONTEXT_CLICK: |
| 7124 | pattern = mContextClickVibePattern; |
Mady Mellor | e82067b | 2015-04-30 09:58:35 -0700 | [diff] [blame] | 7125 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7126 | default: |
| 7127 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7128 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7129 | int owningUid; |
| 7130 | String owningPackage; |
| 7131 | if (win != null) { |
| 7132 | owningUid = win.getOwningUid(); |
| 7133 | owningPackage = win.getOwningPackage(); |
| 7134 | } else { |
| 7135 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 7136 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 7137 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7138 | if (pattern.length == 1) { |
| 7139 | // One-shot vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 7140 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7141 | } else { |
| 7142 | // Pattern vibration |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 7143 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 7144 | } |
| 7145 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7146 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7147 | |
| 7148 | @Override |
| 7149 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 7150 | } |
| 7151 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 7152 | @Override |
| 7153 | public void keepScreenOnStoppedLw() { |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 7154 | if (isKeyguardShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 7155 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7156 | } |
| 7157 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 7158 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7159 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7160 | // If there is no window focused, there will be nobody to handle the events |
| 7161 | // 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] | 7162 | final WindowState win = mFocusedWindow != null ? mFocusedWindow |
| 7163 | : mTopFullscreenOpaqueWindowState; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7164 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7165 | return 0; |
| 7166 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 7167 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 7168 | // We are updating at a point where the keyguard has gotten |
| 7169 | // focus, but we were last in a state where the top window is |
| 7170 | // hiding it. This is probably because the keyguard as been |
| 7171 | // shown while the top window was displayed, so we want to ignore |
| 7172 | // it here because this is just a very transient change and it |
| 7173 | // will quickly lose focus once it correctly gets hidden. |
| 7174 | return 0; |
| 7175 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 7176 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 7177 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7178 | & ~mResettingSystemUiFlags |
| 7179 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7180 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 7181 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 7182 | } |
Thanh Hai Mai | 6c009f5 | 2015-09-01 16:27:32 -0700 | [diff] [blame] | 7183 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7184 | final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */, |
| 7185 | mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState); |
| 7186 | final int dockedVisibility = updateLightStatusBarLw(0 /* vis */, |
| 7187 | mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState); |
| 7188 | mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds); |
| 7189 | mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds); |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7190 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7191 | final int diff = visibility ^ mLastSystemUiFlags; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7192 | final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags; |
| 7193 | final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7194 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7195 | if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu |
| 7196 | && mFocusedApp == win.getAppToken() |
| 7197 | && mLastNonDockedStackBounds.equals(mNonDockedStackBounds) |
| 7198 | && mLastDockedStackBounds.equals(mDockedStackBounds)) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7199 | return 0; |
| 7200 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7201 | mLastSystemUiFlags = visibility; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7202 | mLastFullscreenStackSysUiFlags = fullscreenVisibility; |
| 7203 | mLastDockedStackSysUiFlags = dockedVisibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 7204 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7205 | mFocusedApp = win.getAppToken(); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7206 | final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds); |
| 7207 | final Rect dockedStackBounds = new Rect(mDockedStackBounds); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7208 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7209 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7210 | public void run() { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7211 | StatusBarManagerInternal statusbar = getStatusBarManagerInternal(); |
| 7212 | if (statusbar != null) { |
| 7213 | statusbar.setSystemUiVisibility(visibility, fullscreenVisibility, |
| 7214 | dockedVisibility, 0xffffffff, fullscreenStackBounds, |
| 7215 | dockedStackBounds, win.toString()); |
| 7216 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7217 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7218 | } |
| 7219 | }); |
| 7220 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7221 | } |
| 7222 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7223 | private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7224 | WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen |
| 7225 | ? mStatusBar |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7226 | : opaqueOrDimming; |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7227 | |
| 7228 | if (statusColorWin != null) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 7229 | if (statusColorWin == opaque) { |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7230 | // If the top fullscreen-or-dimming window is also the top fullscreen, respect |
| 7231 | // its light flag. |
| 7232 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7233 | vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null) |
| 7234 | & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7235 | } else if (statusColorWin != null && statusColorWin.isDimming()) { |
| 7236 | // Otherwise if it's dimming, clear the light flag. |
| 7237 | vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 7238 | } |
| 7239 | } |
| 7240 | return vis; |
| 7241 | } |
| 7242 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7243 | private boolean drawsSystemBarBackground(WindowState win) { |
| 7244 | return win == null || (win.getAttrs().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0; |
| 7245 | } |
| 7246 | |
| 7247 | private boolean forcesDrawStatusBarBackground(WindowState win) { |
| 7248 | return win == null || (win.getAttrs().privateFlags |
| 7249 | & PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND) != 0; |
| 7250 | } |
| 7251 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7252 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7253 | final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID); |
| 7254 | final boolean freeformStackVisible = |
| 7255 | mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7256 | final boolean resizing = mWindowManagerInternal.isDockedDividerResizing(); |
| 7257 | |
| 7258 | // We need to force system bars when the docked stack is visible, when the freeform stack |
| 7259 | // is visible but also when we are resizing for the transitions when docked stack |
| 7260 | // visibility changes. |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7261 | mForceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing; |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7262 | final boolean forceOpaqueStatusBar = mForceShowSystemBars && !mForceStatusBarFromKeyguard; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7263 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7264 | // apply translucent bar vis flags |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7265 | WindowState fullscreenTransWin = isStatusBarKeyguard() && !mHideLockScreen |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 7266 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7267 | : mTopFullscreenOpaqueWindowState; |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7268 | vis = mStatusBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 7269 | vis = mNavigationBarController.applyTranslucentFlagLw(fullscreenTransWin, vis, oldVis); |
| 7270 | final int dockedVis = mStatusBarController.applyTranslucentFlagLw( |
| 7271 | mTopDockedOpaqueWindowState, 0, 0); |
| 7272 | |
| 7273 | final boolean fullscreenDrawsStatusBarBackground = |
| 7274 | (drawsSystemBarBackground(mTopFullscreenOpaqueWindowState) |
| 7275 | && (vis & View.STATUS_BAR_TRANSLUCENT) == 0) |
| 7276 | || forcesDrawStatusBarBackground(mTopFullscreenOpaqueWindowState); |
| 7277 | final boolean dockedDrawsStatusBarBackground = |
| 7278 | (drawsSystemBarBackground(mTopDockedOpaqueWindowState) |
| 7279 | && (dockedVis & View.STATUS_BAR_TRANSLUCENT) == 0) |
| 7280 | || forcesDrawStatusBarBackground(mTopDockedOpaqueWindowState); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7281 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7282 | // prevent status bar interaction from clearing certain flags |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 7283 | int type = win.getAttrs().type; |
| 7284 | boolean statusBarHasFocus = type == TYPE_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 7285 | if (statusBarHasFocus && !isStatusBarKeyguard()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7286 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 7287 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 7288 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 73fef8d | 2015-02-16 17:32:28 +0100 | [diff] [blame] | 7289 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
| 7290 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
John Spurlock | 08ffcf5 | 2014-07-11 10:13:46 -0400 | [diff] [blame] | 7291 | if (mHideLockScreen) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 7292 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 7293 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 7294 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7295 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7296 | |
Jorim Jaggi | 8f5701b | 2016-04-04 18:36:02 -0700 | [diff] [blame] | 7297 | if (fullscreenDrawsStatusBarBackground && dockedDrawsStatusBarBackground) { |
| 7298 | vis |= View.STATUS_BAR_TRANSPARENT; |
| 7299 | vis &= ~View.STATUS_BAR_TRANSLUCENT; |
| 7300 | } else if ((!areTranslucentBarsAllowed() && fullscreenTransWin != mStatusBar) |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7301 | || forceOpaqueStatusBar) { |
| 7302 | vis &= ~(View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7303 | } |
| 7304 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7305 | vis = configureNavBarOpacity(vis, dockedStackVisible, freeformStackVisible, resizing); |
Yorke Lee | 2e4b732 | 2016-03-02 17:33:06 -0800 | [diff] [blame] | 7306 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7307 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7308 | boolean immersiveSticky = |
| 7309 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7310 | final boolean hideStatusBarWM = |
| 7311 | mTopFullscreenOpaqueWindowState != null |
| 7312 | && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7313 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7314 | final boolean hideStatusBarSysui = |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7315 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7316 | final boolean hideNavBarSysui = |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7317 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7318 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7319 | final boolean transientStatusBarAllowed = mStatusBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7320 | && (statusBarHasFocus || (!mForceShowSystemBars |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7321 | && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky)))); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7322 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7323 | final boolean transientNavBarAllowed = mNavigationBar != null |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7324 | && !mForceShowSystemBars && hideNavBarSysui && immersiveSticky; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7325 | |
Adrian Roos | ddc8b27 | 2015-05-21 16:28:27 -0700 | [diff] [blame] | 7326 | final long now = SystemClock.uptimeMillis(); |
| 7327 | final boolean pendingPanic = mPendingPanicGestureUptime != 0 |
| 7328 | && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION; |
| 7329 | if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) { |
| 7330 | // The user performed the panic gesture recently, we're about to hide the bars, |
| 7331 | // we're no longer on the Keyguard and the screen is ready. We can now request the bars. |
| 7332 | mPendingPanicGestureUptime = 0; |
| 7333 | mStatusBarController.showTransient(); |
| 7334 | mNavigationBarController.showTransient(); |
| 7335 | } |
| 7336 | |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7337 | final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7338 | && !transientStatusBarAllowed && hideStatusBarSysui; |
Wale Ogunwale | 6e94a9e | 2015-10-07 15:35:49 -0700 | [diff] [blame] | 7339 | final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7340 | && !transientNavBarAllowed; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 7341 | if (denyTransientStatus || denyTransientNav || mForceShowSystemBars) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7342 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7343 | clearClearableFlagsLw(); |
tiger_huang | c58d756 | 2014-10-23 20:24:19 +0800 | [diff] [blame] | 7344 | vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7345 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7346 | |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 7347 | final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 7348 | immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 7349 | final boolean navAllowedHidden = immersive || immersiveSticky; |
| 7350 | |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 7351 | if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType()) |
| 7352 | > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) { |
Selim Cinek | f98702e | 2015-05-20 22:48:40 -0700 | [diff] [blame] | 7353 | // We can't hide the navbar from this window otherwise the input consumer would not get |
| 7354 | // the input events. |
| 7355 | vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); |
| 7356 | } |
| 7357 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7358 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 7359 | |
| 7360 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7361 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 7362 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 7363 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 7364 | final String pkg = win.getOwningPackage(); |
Amith Yamasani | 02a0381 | 2016-04-22 17:32:00 -0700 | [diff] [blame] | 7365 | mImmersiveModeConfirmation.immersiveModeChangedLw(pkg, newImmersiveMode, |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 7366 | isUserSetupComplete()); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 7367 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7368 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7369 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 7370 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 7371 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 7372 | } |
| 7373 | |
Yorke Lee | 9b2ffb3 | 2016-03-07 20:42:01 -0800 | [diff] [blame] | 7374 | /** |
| 7375 | * @return the current visibility flags with the nav-bar opacity related flags toggled based |
| 7376 | * on the nav bar opacity rules chosen by {@link #mNavBarOpacityMode}. |
| 7377 | */ |
| 7378 | private int configureNavBarOpacity(int visibility, boolean dockedStackVisible, |
| 7379 | boolean freeformStackVisible, boolean isDockedDividerResizing) { |
| 7380 | if (mNavBarOpacityMode == NAV_BAR_OPAQUE_WHEN_FREEFORM_OR_DOCKED) { |
| 7381 | if (dockedStackVisible || freeformStackVisible || isDockedDividerResizing) { |
| 7382 | visibility = setNavBarOpaqueFlag(visibility); |
| 7383 | } |
| 7384 | } else if (mNavBarOpacityMode == NAV_BAR_TRANSLUCENT_WHEN_FREEFORM_OPAQUE_OTHERWISE) { |
| 7385 | if (isDockedDividerResizing) { |
| 7386 | visibility = setNavBarOpaqueFlag(visibility); |
| 7387 | } else if (freeformStackVisible) { |
| 7388 | visibility = setNavBarTranslucentFlag(visibility); |
| 7389 | } else { |
| 7390 | visibility = setNavBarOpaqueFlag(visibility); |
| 7391 | } |
| 7392 | } |
| 7393 | |
| 7394 | if (!areTranslucentBarsAllowed()) { |
| 7395 | visibility &= ~View.NAVIGATION_BAR_TRANSLUCENT; |
| 7396 | } |
| 7397 | return visibility; |
| 7398 | } |
| 7399 | |
| 7400 | private int setNavBarOpaqueFlag(int visibility) { |
| 7401 | return visibility &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT); |
| 7402 | } |
| 7403 | |
| 7404 | private int setNavBarTranslucentFlag(int visibility) { |
| 7405 | visibility &= ~View.NAVIGATION_BAR_TRANSPARENT; |
| 7406 | return visibility |= View.NAVIGATION_BAR_TRANSLUCENT; |
| 7407 | } |
| 7408 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 7409 | private void clearClearableFlagsLw() { |
| 7410 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 7411 | if (newVal != mResettingSystemUiFlags) { |
| 7412 | mResettingSystemUiFlags = newVal; |
| 7413 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 7414 | } |
| 7415 | } |
| 7416 | |
| 7417 | private boolean isImmersiveMode(int vis) { |
| 7418 | 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] | 7419 | return mNavigationBar != null |
| 7420 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 7421 | && (vis & flags) != 0 |
| 7422 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 7423 | } |
| 7424 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7425 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 7426 | * @return whether the navigation or status bar can be made translucent |
| 7427 | * |
| 7428 | * This should return true unless touch exploration is not enabled or |
| 7429 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7430 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 7431 | private boolean areTranslucentBarsAllowed() { |
Alan Viverette | 817f3cd | 2015-08-13 11:40:14 -0400 | [diff] [blame] | 7432 | return mTranslucentDecorEnabled; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 7433 | } |
| 7434 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 7435 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 7436 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 7437 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 7438 | public boolean hasNavigationBar() { |
| 7439 | return mHasNavigationBar; |
| 7440 | } |
| 7441 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 7442 | @Override |
| 7443 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 7444 | mLastInputMethodWindow = ime; |
| 7445 | mLastInputMethodTargetWindow = target; |
| 7446 | } |
| 7447 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7448 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 7449 | public int getInputMethodWindowVisibleHeightLw() { |
| 7450 | return mDockBottom - mCurBottom; |
| 7451 | } |
| 7452 | |
| 7453 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7454 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 7455 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 7456 | if (mKeyguardDelegate != null) { |
| 7457 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7458 | } |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 7459 | StatusBarManagerInternal statusBar = getStatusBarManagerInternal(); |
Adrian Roos | 2a62910 | 2016-04-15 16:28:03 -0700 | [diff] [blame] | 7460 | if (statusBar != null) { |
Adrian Roos | f2efdd8 | 2016-04-15 17:43:18 -0700 | [diff] [blame] | 7461 | statusBar.setCurrentUser(newUserId); |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 7462 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7463 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 7464 | } |
| 7465 | |
| 7466 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 7467 | public boolean canMagnifyWindow(int windowType) { |
| 7468 | switch (windowType) { |
| 7469 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 7470 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 7471 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 7472 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 7473 | return false; |
| 7474 | } |
| 7475 | } |
| 7476 | return true; |
| 7477 | } |
| 7478 | |
| 7479 | @Override |
| 7480 | public boolean isTopLevelWindow(int windowType) { |
| 7481 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 7482 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 7483 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 7484 | } |
| 7485 | return true; |
| 7486 | } |
| 7487 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 7488 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 7489 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7490 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 7491 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 7492 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 7493 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7494 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 7495 | pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7496 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 7497 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 7498 | || mForceClearedSystemUiFlags != 0) { |
| 7499 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 7500 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 7501 | pw.print(" mResettingSystemUiFlags=0x"); |
| 7502 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 7503 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 7504 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 7505 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 7506 | if (mLastFocusNeedsMenu) { |
| 7507 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 7508 | pw.println(mLastFocusNeedsMenu); |
| 7509 | } |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7510 | pw.print(prefix); pw.print("mWakeGestureEnabledSetting="); |
| 7511 | pw.println(mWakeGestureEnabledSetting); |
| 7512 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 7513 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 7514 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 7515 | pw.print(" mDockMode="); pw.print(mDockMode); |
keunyoung | a771049 | 2015-09-23 11:33:58 -0700 | [diff] [blame] | 7516 | pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7517 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 7518 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 7519 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 7520 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 7521 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7522 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7523 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 7524 | pw.print(mCarDockEnablesAccelerometer); |
| 7525 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 7526 | pw.println(mDeskDockEnablesAccelerometer); |
| 7527 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 7528 | pw.print(mLidKeyboardAccessibility); |
| 7529 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Edward Savage-Jones | 7def60d | 2015-11-13 13:27:03 +0100 | [diff] [blame] | 7530 | pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 7531 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7532 | pw.print(prefix); |
Anthony Hugh | 34f09ca | 2016-03-04 12:03:37 -0800 | [diff] [blame] | 7533 | pw.print(" mLongPressOnBackBehavior="); pw.println(mLongPressOnBackBehavior); |
| 7534 | pw.print(prefix); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7535 | pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); |
| 7536 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
Jeff Brown | 13f00f0 | 2014-10-31 14:45:50 -0700 | [diff] [blame] | 7537 | pw.print(prefix); |
| 7538 | pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior); |
| 7539 | pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 7540 | pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); |
Jeff Brown | 3ee549c | 2014-09-22 20:14:39 -0700 | [diff] [blame] | 7541 | pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); |
| 7542 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 7543 | pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); |
| 7544 | pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); |
| 7545 | pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); |
| 7546 | pw.print(prefix); pw.print("mOrientationSensorEnabled="); |
| 7547 | pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 7548 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 7549 | pw.print(","); pw.print(mOverscanScreenTop); |
| 7550 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 7551 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 7552 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 7553 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 7554 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 7555 | pw.print(" top="); pw.print(mOverscanTop); |
| 7556 | pw.print(" right="); pw.print(mOverscanRight); |
| 7557 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 7558 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 7559 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 7560 | pw.print(mRestrictedOverscanScreenLeft); |
| 7561 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 7562 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 7563 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7564 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 7565 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 7566 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 7567 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 7568 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 7569 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 7570 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 7571 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 7572 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 7573 | pw.print(","); pw.print(mStableFullscreenTop); |
| 7574 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 7575 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7576 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 7577 | pw.print(","); pw.print(mStableTop); |
| 7578 | pw.print(")-("); pw.print(mStableRight); |
| 7579 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 7580 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 7581 | pw.print(","); pw.print(mSystemTop); |
| 7582 | pw.print(")-("); pw.print(mSystemRight); |
| 7583 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7584 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 7585 | pw.print(","); pw.print(mCurTop); |
| 7586 | pw.print(")-("); pw.print(mCurRight); |
| 7587 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 7588 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 7589 | pw.print(","); pw.print(mContentTop); |
| 7590 | pw.print(")-("); pw.print(mContentRight); |
| 7591 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 7592 | pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft); |
| 7593 | pw.print(","); pw.print(mVoiceContentTop); |
| 7594 | pw.print(")-("); pw.print(mVoiceContentRight); |
| 7595 | pw.print(","); pw.print(mVoiceContentBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7596 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 7597 | pw.print(","); pw.print(mDockTop); |
| 7598 | pw.print(")-("); pw.print(mDockRight); |
| 7599 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 7600 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 7601 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 7602 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 7603 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
Jeff Brown | 061ea99 | 2015-04-17 19:55:47 -0700 | [diff] [blame] | 7604 | pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen); |
| 7605 | pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7606 | if (mLastInputMethodWindow != null) { |
| 7607 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 7608 | pw.println(mLastInputMethodWindow); |
| 7609 | } |
| 7610 | if (mLastInputMethodTargetWindow != null) { |
| 7611 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 7612 | pw.println(mLastInputMethodTargetWindow); |
| 7613 | } |
| 7614 | if (mStatusBar != null) { |
| 7615 | pw.print(prefix); pw.print("mStatusBar="); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 7616 | pw.print(mStatusBar); pw.print(" isStatusBarKeyguard="); |
| 7617 | pw.println(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7618 | } |
| 7619 | if (mNavigationBar != null) { |
| 7620 | pw.print(prefix); pw.print("mNavigationBar="); |
| 7621 | pw.println(mNavigationBar); |
| 7622 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 7623 | if (mFocusedWindow != null) { |
| 7624 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 7625 | pw.println(mFocusedWindow); |
| 7626 | } |
| 7627 | if (mFocusedApp != null) { |
| 7628 | pw.print(prefix); pw.print("mFocusedApp="); |
| 7629 | pw.println(mFocusedApp); |
| 7630 | } |
| 7631 | if (mWinDismissingKeyguard != null) { |
| 7632 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 7633 | pw.println(mWinDismissingKeyguard); |
| 7634 | } |
| 7635 | if (mTopFullscreenOpaqueWindowState != null) { |
| 7636 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 7637 | pw.println(mTopFullscreenOpaqueWindowState); |
| 7638 | } |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 7639 | if (mTopFullscreenOpaqueOrDimmingWindowState != null) { |
| 7640 | pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState="); |
| 7641 | pw.println(mTopFullscreenOpaqueOrDimmingWindowState); |
| 7642 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 7643 | if (mForcingShowNavBar) { |
| 7644 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 7645 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 7646 | pw.println(mForcingShowNavBarLayer); |
| 7647 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 7648 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7649 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 7650 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 7651 | pw.print(" mForceStatusBarFromKeyguard="); |
| 7652 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7653 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 7654 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7655 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 7656 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 7657 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 7658 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 7659 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 7660 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 7661 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 7662 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 7663 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 7664 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 7665 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 7666 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 7667 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 7668 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7669 | |
Tim Kilbourn | d7c0c2e | 2014-05-29 16:08:10 -0700 | [diff] [blame] | 7670 | mGlobalKeyManager.dump(prefix, pw); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 7671 | mStatusBarController.dump(pw, prefix); |
| 7672 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 7673 | PolicyControl.dump(prefix, pw); |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7674 | |
Jeff Brown | a20dda4 | 2014-05-27 20:57:24 -0700 | [diff] [blame] | 7675 | if (mWakeGestureListener != null) { |
| 7676 | mWakeGestureListener.dump(pw, prefix); |
| 7677 | } |
Jeff Brown | 600f003 | 2014-05-22 17:06:00 -0700 | [diff] [blame] | 7678 | if (mOrientationListener != null) { |
| 7679 | mOrientationListener.dump(pw, prefix); |
| 7680 | } |
Filip Gruszczynski | cfb3185 | 2015-02-25 21:47:12 +0000 | [diff] [blame] | 7681 | if (mBurnInProtectionHelper != null) { |
| 7682 | mBurnInProtectionHelper.dump(prefix, pw); |
| 7683 | } |
Jorim Jaggi | 84dc08a | 2015-09-11 17:45:22 -0700 | [diff] [blame] | 7684 | if (mKeyguardDelegate != null) { |
| 7685 | mKeyguardDelegate.dump(prefix, pw); |
| 7686 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7687 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 7688 | } |