The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 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 | |
| 17 | package android.view; |
| 18 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 19 | import static android.view.Display.INVALID_DISPLAY; |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 20 | import static android.view.View.PFLAG_DRAW_ANIMATION; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 21 | import static android.view.WindowCallbacks.RESIZE_MODE_DOCKED_DIVIDER; |
| 22 | import static android.view.WindowCallbacks.RESIZE_MODE_FREEFORM; |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 26 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 27 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 28 | |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 29 | import android.Manifest; |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 30 | import android.animation.LayoutTransition; |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 33 | import android.annotation.UnsupportedAppUsage; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 34 | import android.app.ActivityManager; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 35 | import android.app.ActivityThread; |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 36 | import android.app.ResourcesManager; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 37 | import android.content.ClipData; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 38 | import android.content.ClipDescription; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 39 | import android.content.Context; |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 40 | import android.content.pm.ActivityInfo; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
| 42 | import android.content.res.CompatibilityInfo; |
| 43 | import android.content.res.Configuration; |
| 44 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.graphics.Canvas; |
John Reck | 3e04f09 | 2017-06-02 15:50:09 -0700 | [diff] [blame] | 46 | import android.graphics.Color; |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 47 | import android.graphics.Matrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.graphics.PixelFormat; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 49 | import android.graphics.Point; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 50 | import android.graphics.PointF; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 51 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.graphics.Rect; |
| 53 | import android.graphics.Region; |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 54 | import android.graphics.drawable.AnimatedVectorDrawable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 55 | import android.graphics.drawable.Drawable; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 56 | import android.hardware.display.DisplayManager; |
| 57 | import android.hardware.display.DisplayManager.DisplayListener; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 58 | import android.hardware.input.InputManager; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 59 | import android.media.AudioManager; |
| 60 | import android.os.Binder; |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 61 | import android.os.Build; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 62 | import android.os.Bundle; |
| 63 | import android.os.Debug; |
| 64 | import android.os.Handler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 65 | import android.os.Looper; |
| 66 | import android.os.Message; |
| 67 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.os.Process; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 69 | import android.os.RemoteException; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 70 | import android.os.SystemClock; |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 71 | import android.os.SystemProperties; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 72 | import android.os.Trace; |
Kiyoung Kim | 89052d9 | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 73 | import android.sysprop.DisplayProperties; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.util.AndroidRuntimeException; |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 75 | import android.util.DisplayMetrics; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 76 | import android.util.Log; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 77 | import android.util.LongArray; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 78 | import android.util.MergedConfiguration; |
Chet Haase | 949dbf7 | 2010-08-11 18:41:06 -0700 | [diff] [blame] | 79 | import android.util.Slog; |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 80 | import android.util.SparseArray; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 81 | import android.util.TimeUtils; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 82 | import android.util.TypedValue; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 83 | import android.view.Surface.OutOfResourcesException; |
Jorim Jaggi | 64be98d | 2018-04-26 23:23:29 +0200 | [diff] [blame] | 84 | import android.view.ThreadedRenderer.FrameDrawingCallback; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 85 | import android.view.View.AttachInfo; |
Evan Rosky | 5722331 | 2017-02-08 14:42:45 -0800 | [diff] [blame] | 86 | import android.view.View.FocusDirection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.view.View.MeasureSpec; |
Yohei Yukawa | 22dac1c | 2017-02-12 16:54:16 -0800 | [diff] [blame] | 88 | import android.view.WindowManager.LayoutParams.SoftInputModeFlags; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 89 | import android.view.accessibility.AccessibilityEvent; |
| 90 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 91 | import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 92 | import android.view.accessibility.AccessibilityManager.HighTextContrastChangeListener; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 93 | import android.view.accessibility.AccessibilityNodeInfo; |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 94 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 95 | import android.view.accessibility.AccessibilityNodeProvider; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 96 | import android.view.accessibility.AccessibilityWindowInfo; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 97 | import android.view.accessibility.IAccessibilityInteractionConnection; |
| 98 | import android.view.accessibility.IAccessibilityInteractionConnectionCallback; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 99 | import android.view.animation.AccelerateDecelerateInterpolator; |
| 100 | import android.view.animation.Interpolator; |
Dake Gu | b0fa378 | 2018-02-26 12:25:14 -0800 | [diff] [blame] | 101 | import android.view.autofill.AutofillManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | import android.view.inputmethod.InputMethodManager; |
| 103 | import android.widget.Scroller; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 104 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 105 | import com.android.internal.R; |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 106 | import com.android.internal.annotations.GuardedBy; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 107 | import com.android.internal.os.IResultReceiver; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 108 | import com.android.internal.os.SomeArgs; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 109 | import com.android.internal.policy.PhoneFallbackEventHandler; |
Phil Weaver | 63e4503 | 2017-05-11 10:54:37 -0700 | [diff] [blame] | 110 | import com.android.internal.util.Preconditions; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 111 | import com.android.internal.view.BaseSurfaceHolder; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 112 | import com.android.internal.view.RootViewSurfaceTaker; |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 113 | import com.android.internal.view.SurfaceCallbackHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 115 | import java.io.FileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import java.io.IOException; |
| 117 | import java.io.OutputStream; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 118 | import java.io.PrintWriter; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 119 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | import java.util.ArrayList; |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 121 | import java.util.HashSet; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 122 | import java.util.LinkedList; |
| 123 | import java.util.Queue; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 124 | import java.util.concurrent.CountDownLatch; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | /** |
| 127 | * The top of a view hierarchy, implementing the needed protocol between View |
| 128 | * and the WindowManager. This is for the most part an internal implementation |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 129 | * detail of {@link WindowManagerGlobal}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | * |
| 131 | * {@hide} |
| 132 | */ |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 133 | @SuppressWarnings({"EmptyCatchBlock", "PointlessBooleanExpression"}) |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 134 | public final class ViewRootImpl implements ViewParent, |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 135 | View.AttachInfo.Callbacks, ThreadedRenderer.DrawCallbacks { |
Dianne Hackborn | 70a3f67 | 2011-08-08 14:32:41 -0700 | [diff] [blame] | 136 | private static final String TAG = "ViewRootImpl"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | private static final boolean DBG = false; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 138 | private static final boolean LOCAL_LOGV = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | /** @noinspection PointlessBooleanExpression*/ |
| 140 | private static final boolean DEBUG_DRAW = false || LOCAL_LOGV; |
| 141 | private static final boolean DEBUG_LAYOUT = false || LOCAL_LOGV; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 142 | private static final boolean DEBUG_DIALOG = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | private static final boolean DEBUG_INPUT_RESIZE = false || LOCAL_LOGV; |
| 144 | private static final boolean DEBUG_ORIENTATION = false || LOCAL_LOGV; |
| 145 | private static final boolean DEBUG_TRACKBALL = false || LOCAL_LOGV; |
| 146 | private static final boolean DEBUG_IMF = false || LOCAL_LOGV; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 147 | private static final boolean DEBUG_CONFIGURATION = false || LOCAL_LOGV; |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 148 | private static final boolean DEBUG_FPS = false; |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 149 | private static final boolean DEBUG_INPUT_STAGES = false || LOCAL_LOGV; |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 150 | private static final boolean DEBUG_KEEP_SCREEN_ON = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 152 | /** |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 153 | * Set to false if we do not want to use the multi threaded renderer even though |
| 154 | * threaded renderer (aka hardware renderering) is used. Note that by disabling |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 155 | * this, WindowCallbacks will not fire. |
| 156 | */ |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 157 | private static final boolean MT_RENDERER_AVAILABLE = true; |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 160 | * Set this system property to true to force the view hierarchy to render |
| 161 | * at 60 Hz. This can be used to measure the potential framerate. |
| 162 | */ |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 163 | private static final String PROPERTY_PROFILE_RENDERING = "viewroot.profile_rendering"; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 164 | |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 165 | // properties used by emulator to determine display shape |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 166 | public static final String PROPERTY_EMULATOR_WIN_OUTSET_BOTTOM_PX = |
| 167 | "ro.emu.win_outset_bottom_px"; |
Michael Kolb | 437d313 | 2014-06-20 13:28:44 -0700 | [diff] [blame] | 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | /** |
| 170 | * Maximum time we allow the user to roll the trackball enough to generate |
| 171 | * a key event, before resetting the counters. |
| 172 | */ |
| 173 | static final int MAX_TRACKBALL_DELAY = 250; |
| 174 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 175 | @UnsupportedAppUsage |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 176 | static final ThreadLocal<HandlerActionQueue> sRunQueues = new ThreadLocal<HandlerActionQueue>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 178 | static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList(); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 179 | static boolean sFirstDrawComplete = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 180 | |
Jorim Jaggi | 64be98d | 2018-04-26 23:23:29 +0200 | [diff] [blame] | 181 | private FrameDrawingCallback mNextRtFrameCallback; |
| 182 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 183 | /** |
| 184 | * Callback for notifying about global configuration changes. |
| 185 | */ |
| 186 | public interface ConfigChangedCallback { |
| 187 | |
| 188 | /** Notifies about global config change. */ |
| 189 | void onConfigurationChanged(Configuration globalConfig); |
| 190 | } |
| 191 | |
| 192 | private static final ArrayList<ConfigChangedCallback> sConfigCallbacks = new ArrayList<>(); |
| 193 | |
| 194 | /** |
| 195 | * Callback for notifying activities about override configuration changes. |
| 196 | */ |
| 197 | public interface ActivityConfigCallback { |
| 198 | |
| 199 | /** |
| 200 | * Notifies about override config change and/or move to different display. |
| 201 | * @param overrideConfig New override config to apply to activity. |
| 202 | * @param newDisplayId New display id, {@link Display#INVALID_DISPLAY} if not changed. |
| 203 | */ |
| 204 | void onConfigurationChanged(Configuration overrideConfig, int newDisplayId); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Callback used to notify corresponding activity about override configuration change and make |
| 209 | * sure that all resources are set correctly before updating the ViewRootImpl's internal state. |
| 210 | */ |
| 211 | private ActivityConfigCallback mActivityConfigCallback; |
| 212 | |
| 213 | /** |
| 214 | * Used when configuration change first updates the config of corresponding activity. |
| 215 | * In that case we receive a call back from {@link ActivityThread} and this flag is used to |
| 216 | * preserve the initial value. |
| 217 | * |
| 218 | * @see #performConfigurationChange(Configuration, Configuration, boolean, int) |
| 219 | */ |
| 220 | private boolean mForceNextConfigUpdate; |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 221 | |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 222 | /** |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 223 | * Signals that compatibility booleans have been initialized according to |
| 224 | * target SDK versions. |
| 225 | */ |
| 226 | private static boolean sCompatibilityDone = false; |
| 227 | |
| 228 | /** |
| 229 | * Always assign focus if a focusable View is available. |
| 230 | */ |
Evan Rosky | c5420ea | 2017-07-13 15:24:16 -0700 | [diff] [blame] | 231 | private static boolean sAlwaysAssignFocus; |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 232 | |
| 233 | /** |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 234 | * This list must only be modified by the main thread, so a lock is only needed when changing |
| 235 | * the list or when accessing the list from a non-main thread. |
| 236 | */ |
| 237 | @GuardedBy("mWindowCallbacks") |
| 238 | final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList<>(); |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 239 | @UnsupportedAppUsage |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 240 | final Context mContext; |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 241 | @UnsupportedAppUsage |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 242 | final IWindowSession mWindowSession; |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 243 | @NonNull Display mDisplay; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 244 | final DisplayManager mDisplayManager; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 245 | final String mBasePackageName; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | final int[] mTmpLocation = new int[2]; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 248 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 249 | final TypedValue mTmpValue = new TypedValue(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | final Thread mThread; |
| 252 | |
| 253 | final WindowLeaked mLocation; |
| 254 | |
Mihai Popa | 0450a16 | 2018-04-27 13:09:12 +0100 | [diff] [blame] | 255 | public final WindowManager.LayoutParams mWindowAttributes = new WindowManager.LayoutParams(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | |
| 257 | final W mWindow; |
| 258 | |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 259 | final int mTargetSdkVersion; |
| 260 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 261 | int mSeq; |
| 262 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 263 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | View mView; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 265 | |
| 266 | View mAccessibilityFocusedHost; |
| 267 | AccessibilityNodeInfo mAccessibilityFocusedVirtualView; |
| 268 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 269 | // True if the window currently has pointer capture enabled. |
| 270 | boolean mPointerCapture; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | int mViewVisibility; |
| 273 | boolean mAppVisible = true; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 274 | // For recents to freeform transition we need to keep drawing after the app receives information |
| 275 | // that it became invisible. This will ignore that information and depend on the decor view |
| 276 | // visibility to control drawing. The decor view visibility will get adjusted when the app get |
| 277 | // stopped and that's when the app will stop drawing further frames. |
| 278 | private boolean mForceDecorViewVisibility = false; |
Andrii Kulian | 74b561a | 2017-08-11 09:06:46 -0700 | [diff] [blame] | 279 | // Used for tracking app visibility updates separately in case we get double change. This will |
| 280 | // make sure that we always call relayout for the corresponding window. |
| 281 | private boolean mAppVisibilityChanged; |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 282 | int mOrigWindowType = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 284 | /** Whether the window had focus during the most recent traversal. */ |
| 285 | boolean mHadWindowFocus; |
| 286 | |
| 287 | /** |
| 288 | * Whether the window lost focus during a previous traversal and has not |
| 289 | * yet gained it back. Used to determine whether a WINDOW_STATE_CHANGE |
| 290 | * accessibility events should be sent during traversal. |
| 291 | */ |
| 292 | boolean mLostWindowFocus; |
| 293 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 294 | // Set to true if the owner of this window is in the stopped state, |
| 295 | // so the window should no longer be active. |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 296 | @UnsupportedAppUsage |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 297 | boolean mStopped = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 298 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 299 | // Set to true if the owner of this window is in ambient mode, |
| 300 | // which means it won't receive input events. |
| 301 | boolean mIsAmbientMode = false; |
| 302 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 303 | // Set to true to stop input during an Activity Transition. |
| 304 | boolean mPausedForTransition = false; |
| 305 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 306 | boolean mLastInCompatMode = false; |
| 307 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 308 | SurfaceHolder.Callback2 mSurfaceHolderCallback; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 309 | BaseSurfaceHolder mSurfaceHolder; |
| 310 | boolean mIsCreating; |
| 311 | boolean mDrawingAllowed; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | final Region mTransparentRegion; |
| 314 | final Region mPreviousTransparentRegion; |
| 315 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 316 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | int mWidth; |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 318 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | int mHeight; |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 320 | @UnsupportedAppUsage |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 321 | Rect mDirty; |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 322 | public boolean mIsAnimating; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 323 | |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 324 | private boolean mUseMTRenderer; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 325 | private boolean mDragResizing; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 326 | private boolean mInvalidateRootRequested; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 327 | private int mResizeMode; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 328 | private int mCanvasOffsetX; |
| 329 | private int mCanvasOffsetY; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 330 | private boolean mActivityRelaunched; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 331 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 332 | CompatibilityInfo.Translator mTranslator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 334 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | final View.AttachInfo mAttachInfo; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 336 | InputChannel mInputChannel; |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 337 | InputQueue.Callback mInputQueueCallback; |
| 338 | InputQueue mInputQueue; |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 339 | @UnsupportedAppUsage |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 340 | FallbackEventHandler mFallbackEventHandler; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 341 | Choreographer mChoreographer; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | final Rect mTempRect; // used in the transaction to not thrash the heap. |
| 344 | final Rect mVisRect; // used to retrieve visible rect of focused view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 346 | // This is used to reduce the race between window focus changes being dispatched from |
| 347 | // the window manager and input events coming through the input system. |
| 348 | @GuardedBy("this") |
Dianne Hackborn | 011944c | 2017-12-15 15:44:55 -0800 | [diff] [blame] | 349 | boolean mWindowFocusChanged; |
| 350 | @GuardedBy("this") |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 351 | boolean mUpcomingWindowFocus; |
| 352 | @GuardedBy("this") |
| 353 | boolean mUpcomingInTouchMode; |
| 354 | |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 355 | public boolean mTraversalScheduled; |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 356 | int mTraversalBarrier; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | boolean mWillDrawSoon; |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 358 | /** Set to true while in performTraversals for detecting when die(true) is called from internal |
| 359 | * callbacks such as onMeasure, onPreDraw, onDraw and deferring doDie() until later. */ |
| 360 | boolean mIsInTraversal; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 361 | boolean mApplyInsetsRequested; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | boolean mLayoutRequested; |
| 363 | boolean mFirst; |
| 364 | boolean mReportNextDraw; |
| 365 | boolean mFullRedrawNeeded; |
| 366 | boolean mNewSurfaceNeeded; |
| 367 | boolean mHasHadWindowFocus; |
| 368 | boolean mLastWasImTarget; |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 369 | boolean mForceNextWindowRelayout; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 370 | CountDownLatch mWindowDrawCountDown; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 371 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 372 | boolean mIsDrawing; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 373 | int mLastSystemUiVisibility; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 374 | int mClientWindowLayoutFlags; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 375 | boolean mLastOverscanRequested; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 376 | |
| 377 | // Pool of queued input events. |
| 378 | private static final int MAX_QUEUED_INPUT_EVENT_POOL_SIZE = 10; |
| 379 | private QueuedInputEvent mQueuedInputEventPool; |
| 380 | private int mQueuedInputEventPoolSize; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 381 | |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 382 | /* Input event queue. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 383 | * Pending input events are input events waiting to be delivered to the input stages |
| 384 | * and handled by the application. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 385 | */ |
| 386 | QueuedInputEvent mPendingInputEventHead; |
| 387 | QueuedInputEvent mPendingInputEventTail; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 388 | int mPendingInputEventCount; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 389 | boolean mProcessInputEventsScheduled; |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 390 | boolean mUnbufferedInputDispatch; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 391 | String mPendingInputEventQueueLengthCounterName = "pq"; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 392 | |
| 393 | InputStage mFirstInputStage; |
| 394 | InputStage mFirstPostImeInputStage; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 395 | InputStage mSyntheticInputStage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 397 | private final UnhandledKeyManager mUnhandledKeyManager = new UnhandledKeyManager(); |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | boolean mWindowAttributesChanged = false; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 400 | int mWindowAttributesChangesFlag = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | |
| 402 | // These can be accessed by any thread, must be protected with a lock. |
Mathias Agopian | 5583dc6 | 2009-07-09 16:28:11 -0700 | [diff] [blame] | 403 | // Surface can never be reassigned or cleared (use Surface.clear()). |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 404 | @UnsupportedAppUsage |
Andrei Stingaceanu | d2eadfa | 2017-09-22 15:32:13 +0100 | [diff] [blame] | 405 | public final Surface mSurface = new Surface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 407 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | boolean mAdded; |
| 409 | boolean mAddedTouchMode; |
| 410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | // These are accessed by multiple threads. |
| 412 | final Rect mWinFrame; // frame given by window manager. |
| 413 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 414 | final Rect mPendingOverscanInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | final Rect mPendingVisibleInsets = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 416 | final Rect mPendingStableInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | final Rect mPendingContentInsets = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 418 | final Rect mPendingOutsets = new Rect(); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 419 | final Rect mPendingBackDropFrame = new Rect(); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 420 | final DisplayCutout.ParcelableWrapper mPendingDisplayCutout = |
| 421 | new DisplayCutout.ParcelableWrapper(DisplayCutout.NO_CUTOUT); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 422 | boolean mPendingAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets |
| 424 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 425 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 426 | final Rect mDispatchContentInsets = new Rect(); |
| 427 | final Rect mDispatchStableInsets = new Rect(); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 428 | DisplayCutout mDispatchDisplayCutout = DisplayCutout.NO_CUTOUT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 429 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 430 | private WindowInsets mLastWindowInsets; |
| 431 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 432 | /** Last applied configuration obtained from resources. */ |
| 433 | private final Configuration mLastConfigurationFromResources = new Configuration(); |
| 434 | /** Last configuration reported from WM or via {@link #MSG_UPDATE_CONFIGURATION}. */ |
| 435 | private final MergedConfiguration mLastReportedMergedConfiguration = new MergedConfiguration(); |
| 436 | /** Configurations waiting to be applied. */ |
| 437 | private final MergedConfiguration mPendingMergedConfiguration = new MergedConfiguration(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | boolean mScrollMayChange; |
Yohei Yukawa | 22dac1c | 2017-02-12 16:54:16 -0800 | [diff] [blame] | 440 | @SoftInputModeFlags |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | int mSoftInputMode; |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 442 | @UnsupportedAppUsage |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 443 | WeakReference<View> mLastScrolledFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | int mScrollY; |
| 445 | int mCurScrollY; |
| 446 | Scroller mScroller; |
John Reck | e56e9df | 2014-02-21 15:45:10 -0800 | [diff] [blame] | 447 | static final Interpolator mResizeInterpolator = new AccelerateDecelerateInterpolator(); |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 448 | private ArrayList<LayoutTransition> mPendingTransitions; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 449 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 450 | final ViewConfiguration mViewConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 452 | /* Drag/drop */ |
| 453 | ClipDescription mDragDescription; |
| 454 | View mCurrentDragView; |
Christopher Tate | 7fb8b56 | 2011-01-20 13:46:41 -0800 | [diff] [blame] | 455 | volatile Object mLocalDragState; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 456 | final PointF mDragPoint = new PointF(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 457 | final PointF mLastTouchPoint = new PointF(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 458 | int mLastTouchSource; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 459 | |
| 460 | private boolean mProfileRendering; |
Romain Guy | d075031 | 2012-11-29 11:34:43 -0800 | [diff] [blame] | 461 | private Choreographer.FrameCallback mRenderProfiler; |
| 462 | private boolean mRenderProfilingEnabled; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 463 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 464 | // Variables to track frames per second, enabled via DEBUG_FPS flag |
| 465 | private long mFpsStartTime = -1; |
| 466 | private long mFpsPrevTime = -1; |
| 467 | private int mFpsNumFrames; |
| 468 | |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 469 | private int mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 470 | private PointerIcon mCustomPointerIcon = null; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | /** |
| 473 | * see {@link #playSoundEffect(int)} |
| 474 | */ |
| 475 | AudioManager mAudioManager; |
| 476 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 477 | final AccessibilityManager mAccessibilityManager; |
| 478 | |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 479 | AccessibilityInteractionController mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 480 | |
Phil Weaver | 26d709f | 2017-04-20 17:19:14 -0700 | [diff] [blame] | 481 | final AccessibilityInteractionConnectionManager mAccessibilityInteractionConnectionManager = |
| 482 | new AccessibilityInteractionConnectionManager(); |
| 483 | final HighContrastTextManager mHighContrastTextManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 484 | |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 485 | SendWindowContentChangedAccessibilityEvent mSendWindowContentChangedAccessibilityEvent; |
| 486 | |
| 487 | HashSet<View> mTempHashSet; |
| 488 | |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 489 | private final int mDensity; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 490 | private final int mNoncompatDensity; |
Adam Powell | b08013c | 2010-09-16 16:28:11 -0700 | [diff] [blame] | 491 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 492 | private boolean mInLayout = false; |
| 493 | ArrayList<View> mLayoutRequesters = new ArrayList<View>(); |
| 494 | boolean mHandlingLayoutInLayoutRequest = false; |
| 495 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 496 | private int mViewLayoutDirectionInitial; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 497 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 498 | /** Set to true once doDie() has been called. */ |
| 499 | private boolean mRemoved; |
| 500 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 501 | private boolean mNeedsRendererSetup; |
Robert Carr | 1bccabf | 2016-04-28 13:27:08 -0700 | [diff] [blame] | 502 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 503 | /** |
| 504 | * Consistency verifier for debugging purposes. |
| 505 | */ |
| 506 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 507 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 508 | new InputEventConsistencyVerifier(this, 0) : null; |
| 509 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 510 | static final class SystemUiVisibilityInfo { |
| 511 | int seq; |
| 512 | int globalVisibility; |
| 513 | int localValue; |
| 514 | int localChanges; |
| 515 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 516 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 517 | private String mTag = TAG; |
| 518 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 519 | public ViewRootImpl(Context context, Display display) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 520 | mContext = context; |
| 521 | mWindowSession = WindowManagerGlobal.getWindowSession(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 522 | mDisplay = display; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 523 | mBasePackageName = context.getBasePackageName(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | mThread = Thread.currentThread(); |
| 525 | mLocation = new WindowLeaked(null); |
| 526 | mLocation.fillInStackTrace(); |
| 527 | mWidth = -1; |
| 528 | mHeight = -1; |
| 529 | mDirty = new Rect(); |
| 530 | mTempRect = new Rect(); |
| 531 | mVisRect = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | mWinFrame = new Rect(); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 533 | mWindow = new W(this); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 534 | mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | mViewVisibility = View.GONE; |
| 536 | mTransparentRegion = new Region(); |
| 537 | mPreviousTransparentRegion = new Region(); |
| 538 | mFirst = true; // true for the first time the view is added |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | mAdded = false; |
John Reck | d94094e | 2016-09-08 14:12:26 -0700 | [diff] [blame] | 540 | mAttachInfo = new View.AttachInfo(mWindowSession, mWindow, display, this, mHandler, this, |
| 541 | context); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 542 | mAccessibilityManager = AccessibilityManager.getInstance(context); |
Svetoslav Ganov | 00d0c14 | 2012-02-24 11:30:49 -0800 | [diff] [blame] | 543 | mAccessibilityManager.addAccessibilityStateChangeListener( |
Phil Weaver | 26d709f | 2017-04-20 17:19:14 -0700 | [diff] [blame] | 544 | mAccessibilityInteractionConnectionManager, mHandler); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 545 | mHighContrastTextManager = new HighContrastTextManager(); |
| 546 | mAccessibilityManager.addHighTextContrastStateChangeListener( |
Phil Weaver | 26d709f | 2017-04-20 17:19:14 -0700 | [diff] [blame] | 547 | mHighContrastTextManager, mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | mViewConfiguration = ViewConfiguration.get(context); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 549 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 550 | mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 551 | mFallbackEventHandler = new PhoneFallbackEventHandler(context); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 552 | mChoreographer = Choreographer.getInstance(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 553 | mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 554 | |
| 555 | if (!sCompatibilityDone) { |
Evan Rosky | bdc66cb | 2017-09-08 14:27:24 -0700 | [diff] [blame] | 556 | sAlwaysAssignFocus = mTargetSdkVersion < Build.VERSION_CODES.P; |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 557 | |
| 558 | sCompatibilityDone = true; |
| 559 | } |
| 560 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 561 | loadSystemProperties(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 564 | public static void addFirstDrawHandler(Runnable callback) { |
| 565 | synchronized (sFirstDrawHandlers) { |
| 566 | if (!sFirstDrawComplete) { |
| 567 | sFirstDrawHandlers.add(callback); |
| 568 | } |
| 569 | } |
| 570 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 571 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 572 | /** Add static config callback to be notified about global config changes. */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 573 | @UnsupportedAppUsage |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 574 | public static void addConfigCallback(ConfigChangedCallback callback) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 575 | synchronized (sConfigCallbacks) { |
| 576 | sConfigCallbacks.add(callback); |
| 577 | } |
| 578 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 579 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 580 | /** Add activity config callback to be notified about override config changes. */ |
| 581 | public void setActivityConfigCallback(ActivityConfigCallback callback) { |
| 582 | mActivityConfigCallback = callback; |
| 583 | } |
| 584 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 585 | public void addWindowCallbacks(WindowCallbacks callback) { |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 586 | synchronized (mWindowCallbacks) { |
| 587 | mWindowCallbacks.add(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 591 | public void removeWindowCallbacks(WindowCallbacks callback) { |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 592 | synchronized (mWindowCallbacks) { |
| 593 | mWindowCallbacks.remove(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 597 | public void reportDrawFinish() { |
| 598 | if (mWindowDrawCountDown != null) { |
| 599 | mWindowDrawCountDown.countDown(); |
| 600 | } |
| 601 | } |
| 602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | // FIXME for perf testing only |
| 604 | private boolean mProfile = false; |
| 605 | |
| 606 | /** |
| 607 | * Call this to profile the next traversal call. |
| 608 | * FIXME for perf testing only. Remove eventually |
| 609 | */ |
| 610 | public void profile() { |
| 611 | mProfile = true; |
| 612 | } |
| 613 | |
| 614 | /** |
| 615 | * Indicates whether we are in touch mode. Calling this method triggers an IPC |
| 616 | * call and should be avoided whenever possible. |
| 617 | * |
| 618 | * @return True, if the device is in touch mode, false otherwise. |
| 619 | * |
| 620 | * @hide |
| 621 | */ |
| 622 | static boolean isInTouchMode() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 623 | IWindowSession windowSession = WindowManagerGlobal.peekWindowSession(); |
| 624 | if (windowSession != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 626 | return windowSession.getInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | } catch (RemoteException e) { |
| 628 | } |
| 629 | } |
| 630 | return false; |
| 631 | } |
| 632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | /** |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 634 | * Notifies us that our child has been rebuilt, following |
| 635 | * a window preservation operation. In these cases we |
| 636 | * keep the same DecorView, but the activity controlling it |
| 637 | * is a different instance, and we need to update our |
| 638 | * callbacks. |
| 639 | * |
| 640 | * @hide |
| 641 | */ |
| 642 | public void notifyChildRebuilt() { |
| 643 | if (mView instanceof RootViewSurfaceTaker) { |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 644 | if (mSurfaceHolderCallback != null) { |
| 645 | mSurfaceHolder.removeCallback(mSurfaceHolderCallback); |
| 646 | } |
| 647 | |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 648 | mSurfaceHolderCallback = |
| 649 | ((RootViewSurfaceTaker)mView).willYouTakeTheSurface(); |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 650 | |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 651 | if (mSurfaceHolderCallback != null) { |
| 652 | mSurfaceHolder = new TakenSurfaceHolder(); |
| 653 | mSurfaceHolder.setFormat(PixelFormat.UNKNOWN); |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 654 | mSurfaceHolder.addCallback(mSurfaceHolderCallback); |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 655 | } else { |
| 656 | mSurfaceHolder = null; |
| 657 | } |
| 658 | |
| 659 | mInputQueueCallback = |
| 660 | ((RootViewSurfaceTaker)mView).willYouTakeTheInputQueue(); |
| 661 | if (mInputQueueCallback != null) { |
| 662 | mInputQueueCallback.onInputQueueCreated(mInputQueue); |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | * We have one child |
| 669 | */ |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 670 | public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | synchronized (this) { |
| 672 | if (mView == null) { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 673 | mView = view; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 674 | |
| 675 | mAttachInfo.mDisplayState = mDisplay.getState(); |
| 676 | mDisplayManager.registerDisplayListener(mDisplayListener, mHandler); |
| 677 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 678 | mViewLayoutDirectionInitial = mView.getRawLayoutDirection(); |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 679 | mFallbackEventHandler.setView(view); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 680 | mWindowAttributes.copyFrom(attrs); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 681 | if (mWindowAttributes.packageName == null) { |
| 682 | mWindowAttributes.packageName = mBasePackageName; |
| 683 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 684 | attrs = mWindowAttributes; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 685 | setTag(); |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 686 | |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 687 | if (DEBUG_KEEP_SCREEN_ON && (mClientWindowLayoutFlags |
| 688 | & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0 |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 689 | && (attrs.flags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) == 0) { |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 690 | Slog.d(mTag, "setView: FLAG_KEEP_SCREEN_ON changed from true to false!"); |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 691 | } |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 692 | // Keep track of the actual window flags supplied by the client. |
| 693 | mClientWindowLayoutFlags = attrs.flags; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 694 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 695 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 696 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 697 | if (view instanceof RootViewSurfaceTaker) { |
| 698 | mSurfaceHolderCallback = |
| 699 | ((RootViewSurfaceTaker)view).willYouTakeTheSurface(); |
| 700 | if (mSurfaceHolderCallback != null) { |
| 701 | mSurfaceHolder = new TakenSurfaceHolder(); |
Dianne Hackborn | 289b9b6 | 2010-07-09 11:44:11 -0700 | [diff] [blame] | 702 | mSurfaceHolder.setFormat(PixelFormat.UNKNOWN); |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 703 | mSurfaceHolder.addCallback(mSurfaceHolderCallback); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 706 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 707 | // Compute surface insets required to draw at specified Z value. |
| 708 | // TODO: Use real shadow insets for a constant max Z. |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 709 | if (!attrs.hasManualSurfaceInsets) { |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 710 | attrs.setSurfaceInsets(view, false /*manual*/, true /*preservePrevious*/); |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 711 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 712 | |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 713 | CompatibilityInfo compatibilityInfo = |
| 714 | mDisplay.getDisplayAdjustments().getCompatibilityInfo(); |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 715 | mTranslator = compatibilityInfo.getTranslator(); |
| 716 | |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 717 | // If the application owns the surface, don't enable hardware acceleration |
| 718 | if (mSurfaceHolder == null) { |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 719 | // While this is supposed to enable only, it can effectively disable |
| 720 | // the acceleration too. |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 721 | enableHardwareAcceleration(attrs); |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 722 | final boolean useMTRenderer = MT_RENDERER_AVAILABLE |
| 723 | && mAttachInfo.mThreadedRenderer != null; |
| 724 | if (mUseMTRenderer != useMTRenderer) { |
| 725 | // Shouldn't be resizing, as it's done only in window setup, |
| 726 | // but end just in case. |
| 727 | endDragResizing(); |
| 728 | mUseMTRenderer = useMTRenderer; |
| 729 | } |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 730 | } |
| 731 | |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 732 | boolean restore = false; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 733 | if (mTranslator != null) { |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 734 | mSurface.setCompatibilityTranslator(mTranslator); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 735 | restore = true; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 736 | attrs.backup(); |
| 737 | mTranslator.translateWindowLayout(attrs); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 738 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 739 | if (DEBUG_LAYOUT) Log.d(mTag, "WindowLayout in setView:" + attrs); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 740 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 741 | if (!compatibilityInfo.supportsScreen()) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 742 | attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 743 | mLastInCompatMode = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 744 | } |
| 745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | mSoftInputMode = attrs.softInputMode; |
| 747 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 748 | mWindowAttributesChangesFlag = WindowManager.LayoutParams.EVERYTHING_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | mAttachInfo.mRootView = view; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 750 | mAttachInfo.mScalingRequired = mTranslator != null; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 751 | mAttachInfo.mApplicationScale = |
| 752 | mTranslator == null ? 1.0f : mTranslator.applicationScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | if (panelParentView != null) { |
| 754 | mAttachInfo.mPanelParentWindowToken |
| 755 | = panelParentView.getApplicationWindowToken(); |
| 756 | } |
| 757 | mAdded = true; |
| 758 | int res; /* = WindowManagerImpl.ADD_OKAY; */ |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 759 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | // Schedule the first layout -before- adding to the window |
| 761 | // manager, to make sure we do the relayout before receiving |
| 762 | // any other events from the system. |
| 763 | requestLayout(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 764 | if ((mWindowAttributes.inputFeatures |
| 765 | & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) { |
| 766 | mInputChannel = new InputChannel(); |
| 767 | } |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 768 | mForceDecorViewVisibility = (mWindowAttributes.privateFlags |
| 769 | & PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | try { |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 771 | mOrigWindowType = mWindowAttributes.type; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 772 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 773 | collectViewAttributes(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 774 | res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes, |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 775 | getHostVisibility(), mDisplay.getDisplayId(), mWinFrame, |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 776 | mAttachInfo.mContentInsets, mAttachInfo.mStableInsets, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 777 | mAttachInfo.mOutsets, mAttachInfo.mDisplayCutout, mInputChannel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | } catch (RemoteException e) { |
| 779 | mAdded = false; |
| 780 | mView = null; |
| 781 | mAttachInfo.mRootView = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 782 | mInputChannel = null; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 783 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 785 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | throw new RuntimeException("Adding window failed", e); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 787 | } finally { |
| 788 | if (restore) { |
| 789 | attrs.restore(); |
| 790 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 792 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 793 | if (mTranslator != null) { |
| 794 | mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 795 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 796 | mPendingOverscanInsets.set(0, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | mPendingContentInsets.set(mAttachInfo.mContentInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 798 | mPendingStableInsets.set(mAttachInfo.mStableInsets); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 799 | mPendingDisplayCutout.set(mAttachInfo.mDisplayCutout); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | mPendingVisibleInsets.set(0, 0, 0, 0); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 801 | mAttachInfo.mAlwaysConsumeNavBar = |
| 802 | (res & WindowManagerGlobal.ADD_FLAG_ALWAYS_CONSUME_NAV_BAR) != 0; |
| 803 | mPendingAlwaysConsumeNavBar = mAttachInfo.mAlwaysConsumeNavBar; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 804 | if (DEBUG_LAYOUT) Log.v(mTag, "Added window " + mWindow); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 805 | if (res < WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | mAttachInfo.mRootView = null; |
| 807 | mAdded = false; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 808 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 810 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | switch (res) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 812 | case WindowManagerGlobal.ADD_BAD_APP_TOKEN: |
| 813 | case WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN: |
| 814 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 815 | "Unable to add window -- token " + attrs.token |
| 816 | + " is not valid; is your activity running?"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 817 | case WindowManagerGlobal.ADD_NOT_APP_TOKEN: |
| 818 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 819 | "Unable to add window -- token " + attrs.token |
| 820 | + " is not for an application"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 821 | case WindowManagerGlobal.ADD_APP_EXITING: |
| 822 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 823 | "Unable to add window -- app for token " + attrs.token |
| 824 | + " is exiting"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 825 | case WindowManagerGlobal.ADD_DUPLICATE_ADD: |
| 826 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 827 | "Unable to add window -- window " + mWindow |
| 828 | + " has already been added"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 829 | case WindowManagerGlobal.ADD_STARTING_NOT_NEEDED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | // Silently ignore -- we would have just removed it |
| 831 | // right away, anyway. |
| 832 | return; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 833 | case WindowManagerGlobal.ADD_MULTIPLE_SINGLETON: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 834 | throw new WindowManager.BadTokenException("Unable to add window " |
| 835 | + mWindow + " -- another window of type " |
| 836 | + mWindowAttributes.type + " already exists"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 837 | case WindowManagerGlobal.ADD_PERMISSION_DENIED: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 838 | throw new WindowManager.BadTokenException("Unable to add window " |
| 839 | + mWindow + " -- permission denied for window type " |
| 840 | + mWindowAttributes.type); |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 841 | case WindowManagerGlobal.ADD_INVALID_DISPLAY: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 842 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 843 | + mWindow + " -- the specified display can not be found"); |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 844 | case WindowManagerGlobal.ADD_INVALID_TYPE: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 845 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 846 | + mWindow + " -- the specified window type " |
| 847 | + mWindowAttributes.type + " is not valid"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | } |
| 849 | throw new RuntimeException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 850 | "Unable to add window -- unknown error code " + res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 852 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 853 | if (view instanceof RootViewSurfaceTaker) { |
| 854 | mInputQueueCallback = |
| 855 | ((RootViewSurfaceTaker)view).willYouTakeTheInputQueue(); |
| 856 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 857 | if (mInputChannel != null) { |
| 858 | if (mInputQueueCallback != null) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 859 | mInputQueue = new InputQueue(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 860 | mInputQueueCallback.onInputQueueCreated(mInputQueue); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 861 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 862 | mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, |
| 863 | Looper.myLooper()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 864 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | view.assignParent(this); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 867 | mAddedTouchMode = (res & WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE) != 0; |
| 868 | mAppVisible = (res & WindowManagerGlobal.ADD_FLAG_APP_VISIBLE) != 0; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 869 | |
| 870 | if (mAccessibilityManager.isEnabled()) { |
| 871 | mAccessibilityInteractionConnectionManager.ensureConnection(); |
| 872 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 873 | |
| 874 | if (view.getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 875 | view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 876 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 877 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 878 | // Set up the input pipeline. |
| 879 | CharSequence counterSuffix = attrs.getTitle(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 880 | mSyntheticInputStage = new SyntheticInputStage(); |
| 881 | InputStage viewPostImeStage = new ViewPostImeInputStage(mSyntheticInputStage); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 882 | InputStage nativePostImeStage = new NativePostImeInputStage(viewPostImeStage, |
| 883 | "aq:native-post-ime:" + counterSuffix); |
| 884 | InputStage earlyPostImeStage = new EarlyPostImeInputStage(nativePostImeStage); |
| 885 | InputStage imeStage = new ImeInputStage(earlyPostImeStage, |
| 886 | "aq:ime:" + counterSuffix); |
| 887 | InputStage viewPreImeStage = new ViewPreImeInputStage(imeStage); |
| 888 | InputStage nativePreImeStage = new NativePreImeInputStage(viewPreImeStage, |
| 889 | "aq:native-pre-ime:" + counterSuffix); |
| 890 | |
| 891 | mFirstInputStage = nativePreImeStage; |
| 892 | mFirstPostImeInputStage = earlyPostImeStage; |
| 893 | mPendingInputEventQueueLengthCounterName = "aq:pending:" + counterSuffix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | } |
| 897 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 898 | private void setTag() { |
| 899 | final String[] split = mWindowAttributes.getTitle().toString().split("\\."); |
| 900 | if (split.length > 0) { |
| 901 | mTag = TAG + "[" + split[split.length - 1] + "]"; |
| 902 | } |
| 903 | } |
| 904 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 905 | /** Whether the window is in local focus mode or not */ |
| 906 | private boolean isInLocalFocusMode() { |
| 907 | return (mWindowAttributes.flags & WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE) != 0; |
| 908 | } |
| 909 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 910 | @UnsupportedAppUsage |
Dianne Hackborn | 49b043f | 2015-05-07 14:21:38 -0700 | [diff] [blame] | 911 | public int getWindowFlags() { |
| 912 | return mWindowAttributes.flags; |
| 913 | } |
| 914 | |
Dianne Hackborn | ece0f4f | 2015-06-11 13:29:01 -0700 | [diff] [blame] | 915 | public int getDisplayId() { |
| 916 | return mDisplay.getDisplayId(); |
| 917 | } |
| 918 | |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 919 | public CharSequence getTitle() { |
| 920 | return mWindowAttributes.getTitle(); |
| 921 | } |
| 922 | |
Mihai Popa | 3589c2c | 2018-01-25 19:26:30 +0000 | [diff] [blame] | 923 | /** |
| 924 | * @return the width of the root view. Note that this will return {@code -1} until the first |
| 925 | * layout traversal, when the width is set. |
| 926 | * |
| 927 | * @hide |
| 928 | */ |
| 929 | public int getWidth() { |
| 930 | return mWidth; |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * @return the height of the root view. Note that this will return {@code -1} until the first |
| 935 | * layout traversal, when the height is set. |
| 936 | * |
| 937 | * @hide |
| 938 | */ |
| 939 | public int getHeight() { |
| 940 | return mHeight; |
| 941 | } |
| 942 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 943 | void destroyHardwareResources() { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 944 | if (mAttachInfo.mThreadedRenderer != null) { |
| 945 | mAttachInfo.mThreadedRenderer.destroyHardwareResources(mView); |
| 946 | mAttachInfo.mThreadedRenderer.destroy(); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 950 | @UnsupportedAppUsage |
Bo Liu | 845535a | 2014-03-21 12:06:23 -0700 | [diff] [blame] | 951 | public void detachFunctor(long functor) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 952 | if (mAttachInfo.mThreadedRenderer != null) { |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 953 | // Fence so that any pending invokeFunctor() messages will be processed |
| 954 | // before we return from detachFunctor. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 955 | mAttachInfo.mThreadedRenderer.stopDrawing(); |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 956 | } |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 957 | } |
| 958 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 959 | /** |
| 960 | * Schedules the functor for execution in either kModeProcess or |
| 961 | * kModeProcessNoContext, depending on whether or not there is an EGLContext. |
| 962 | * |
| 963 | * @param functor The native functor to invoke |
| 964 | * @param waitForCompletion If true, this will not return until the functor |
| 965 | * has invoked. If false, the functor may be invoked |
| 966 | * asynchronously. |
| 967 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 968 | @UnsupportedAppUsage |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 969 | public static void invokeFunctor(long functor, boolean waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 970 | ThreadedRenderer.invokeFunctor(functor, waitForCompletion); |
Bo Liu | ae738a7 | 2014-04-27 16:22:04 -0700 | [diff] [blame] | 971 | } |
| 972 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 973 | public void registerAnimatingRenderNode(RenderNode animator) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 974 | if (mAttachInfo.mThreadedRenderer != null) { |
| 975 | mAttachInfo.mThreadedRenderer.registerAnimatingRenderNode(animator); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 976 | } else { |
| 977 | if (mAttachInfo.mPendingAnimatingRenderNodes == null) { |
| 978 | mAttachInfo.mPendingAnimatingRenderNodes = new ArrayList<RenderNode>(); |
| 979 | } |
| 980 | mAttachInfo.mPendingAnimatingRenderNodes.add(animator); |
| 981 | } |
| 982 | } |
| 983 | |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 984 | public void registerVectorDrawableAnimator( |
| 985 | AnimatedVectorDrawable.VectorDrawableAnimatorRT animator) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 986 | if (mAttachInfo.mThreadedRenderer != null) { |
| 987 | mAttachInfo.mThreadedRenderer.registerVectorDrawableAnimator(animator); |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | |
Jorim Jaggi | 64be98d | 2018-04-26 23:23:29 +0200 | [diff] [blame] | 991 | /** |
| 992 | * Registers a callback to be executed when the next frame is being drawn on RenderThread. This |
| 993 | * callback will be executed on a RenderThread worker thread, and only used for the next frame |
| 994 | * and thus it will only fire once. |
| 995 | * |
| 996 | * @param callback The callback to register. |
| 997 | */ |
| 998 | public void registerRtFrameCallback(FrameDrawingCallback callback) { |
| 999 | mNextRtFrameCallback = callback; |
| 1000 | } |
| 1001 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 1002 | @UnsupportedAppUsage |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 1003 | private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1004 | mAttachInfo.mHardwareAccelerated = false; |
| 1005 | mAttachInfo.mHardwareAccelerationRequested = false; |
Romain Guy | 4f6aff3 | 2011-01-12 16:21:41 -0800 | [diff] [blame] | 1006 | |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 1007 | // Don't enable hardware acceleration when the application is in compatibility mode |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 1008 | if (mTranslator != null) return; |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 1009 | |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1010 | // Try to enable hardware acceleration if requested |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1011 | final boolean hardwareAccelerated = |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 1012 | (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 1013 | |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 1014 | if (hardwareAccelerated) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 1015 | if (!ThreadedRenderer.isAvailable()) { |
Romain Guy | 1af23a3 | 2011-03-24 16:03:55 -0700 | [diff] [blame] | 1016 | return; |
| 1017 | } |
| 1018 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1019 | // Persistent processes (including the system) should not do |
| 1020 | // accelerated rendering on low-end devices. In that case, |
| 1021 | // sRendererDisabled will be set. In addition, the system process |
| 1022 | // itself should never do accelerated rendering. In that case, both |
| 1023 | // sRendererDisabled and sSystemRendererDisabled are set. When |
| 1024 | // sSystemRendererDisabled is set, PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED |
| 1025 | // can be used by code on the system process to escape that and enable |
| 1026 | // HW accelerated drawing. (This is basically for the lock screen.) |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 1027 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 1028 | final boolean fakeHwAccelerated = (attrs.privateFlags & |
| 1029 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED) != 0; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1030 | final boolean forceHwAccelerated = (attrs.privateFlags & |
| 1031 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED) != 0; |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 1032 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 1033 | if (fakeHwAccelerated) { |
| 1034 | // This is exclusively for the preview windows the window manager |
| 1035 | // shows for launching applications, so they will look more like |
| 1036 | // the app being launched. |
| 1037 | mAttachInfo.mHardwareAccelerationRequested = true; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 1038 | } else if (!ThreadedRenderer.sRendererDisabled |
| 1039 | || (ThreadedRenderer.sSystemRendererDisabled && forceHwAccelerated)) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1040 | if (mAttachInfo.mThreadedRenderer != null) { |
| 1041 | mAttachInfo.mThreadedRenderer.destroy(); |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 1042 | } |
| 1043 | |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 1044 | final Rect insets = attrs.surfaceInsets; |
Alan Viverette | 2cd23e6 | 2014-11-04 17:04:02 -0800 | [diff] [blame] | 1045 | final boolean hasSurfaceInsets = insets.left != 0 || insets.right != 0 |
| 1046 | || insets.top != 0 || insets.bottom != 0; |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 1047 | final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets; |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 1048 | final boolean wideGamut = |
Romain Guy | e89d0bb | 2017-06-20 12:23:42 -0700 | [diff] [blame] | 1049 | mContext.getResources().getConfiguration().isScreenWideColorGamut() |
| 1050 | && attrs.getColorMode() == ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT; |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 1051 | |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 1052 | mAttachInfo.mThreadedRenderer = ThreadedRenderer.create(mContext, translucent, |
| 1053 | attrs.getTitle().toString()); |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 1054 | mAttachInfo.mThreadedRenderer.setWideGamut(wideGamut); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1055 | if (mAttachInfo.mThreadedRenderer != null) { |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 1056 | mAttachInfo.mHardwareAccelerated = |
| 1057 | mAttachInfo.mHardwareAccelerationRequested = true; |
| 1058 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 1063 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | public View getView() { |
| 1065 | return mView; |
| 1066 | } |
| 1067 | |
| 1068 | final WindowLeaked getLocation() { |
| 1069 | return mLocation; |
| 1070 | } |
| 1071 | |
| 1072 | void setLayoutParams(WindowManager.LayoutParams attrs, boolean newView) { |
| 1073 | synchronized (this) { |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1074 | final int oldInsetLeft = mWindowAttributes.surfaceInsets.left; |
| 1075 | final int oldInsetTop = mWindowAttributes.surfaceInsets.top; |
| 1076 | final int oldInsetRight = mWindowAttributes.surfaceInsets.right; |
| 1077 | final int oldInsetBottom = mWindowAttributes.surfaceInsets.bottom; |
| 1078 | final int oldSoftInputMode = mWindowAttributes.softInputMode; |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 1079 | final boolean oldHasManualSurfaceInsets = mWindowAttributes.hasManualSurfaceInsets; |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 1080 | |
| 1081 | if (DEBUG_KEEP_SCREEN_ON && (mClientWindowLayoutFlags |
| 1082 | & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0 |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 1083 | && (attrs.flags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) == 0) { |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 1084 | Slog.d(mTag, "setLayoutParams: FLAG_KEEP_SCREEN_ON from true to false!"); |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 1085 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1086 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1087 | // Keep track of the actual window flags supplied by the client. |
| 1088 | mClientWindowLayoutFlags = attrs.flags; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1089 | |
| 1090 | // Preserve compatible window flag if exists. |
| 1091 | final int compatibleWindowFlag = mWindowAttributes.privateFlags |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1092 | & WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1093 | |
| 1094 | // Transfer over system UI visibility values as they carry current state. |
Craig Mautner | 3fe38c0 | 2012-05-03 17:28:09 -0700 | [diff] [blame] | 1095 | attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility; |
| 1096 | attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1097 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 1098 | mWindowAttributesChangesFlag = mWindowAttributes.copyFrom(attrs); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1099 | if ((mWindowAttributesChangesFlag |
| 1100 | & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) { |
| 1101 | // Recompute system ui visibility. |
| 1102 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 1103 | } |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 1104 | if ((mWindowAttributesChangesFlag |
| 1105 | & WindowManager.LayoutParams.LAYOUT_CHANGED) != 0) { |
| 1106 | // Request to update light center. |
| 1107 | mAttachInfo.mNeedsUpdateLightCenter = true; |
| 1108 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1109 | if (mWindowAttributes.packageName == null) { |
| 1110 | mWindowAttributes.packageName = mBasePackageName; |
| 1111 | } |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1112 | mWindowAttributes.privateFlags |= compatibleWindowFlag; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1113 | |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 1114 | if (mWindowAttributes.preservePreviousSurfaceInsets) { |
| 1115 | // Restore old surface insets. |
| 1116 | mWindowAttributes.surfaceInsets.set( |
| 1117 | oldInsetLeft, oldInsetTop, oldInsetRight, oldInsetBottom); |
| 1118 | mWindowAttributes.hasManualSurfaceInsets = oldHasManualSurfaceInsets; |
Robert Carr | 1bccabf | 2016-04-28 13:27:08 -0700 | [diff] [blame] | 1119 | } else if (mWindowAttributes.surfaceInsets.left != oldInsetLeft |
| 1120 | || mWindowAttributes.surfaceInsets.top != oldInsetTop |
| 1121 | || mWindowAttributes.surfaceInsets.right != oldInsetRight |
| 1122 | || mWindowAttributes.surfaceInsets.bottom != oldInsetBottom) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1123 | mNeedsRendererSetup = true; |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 1124 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1125 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1126 | applyKeepScreenOnFlag(mWindowAttributes); |
| 1127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | if (newView) { |
| 1129 | mSoftInputMode = attrs.softInputMode; |
| 1130 | requestLayout(); |
| 1131 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1132 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1133 | // Don't lose the mode we last auto-computed. |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1134 | if ((attrs.softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1135 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
| 1136 | mWindowAttributes.softInputMode = (mWindowAttributes.softInputMode |
| 1137 | & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1138 | | (oldSoftInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1139 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | mWindowAttributesChanged = true; |
| 1142 | scheduleTraversals(); |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | void handleAppVisibility(boolean visible) { |
| 1147 | if (mAppVisible != visible) { |
| 1148 | mAppVisible = visible; |
Andrii Kulian | 74b561a | 2017-08-11 09:06:46 -0700 | [diff] [blame] | 1149 | mAppVisibilityChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | scheduleTraversals(); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 1151 | if (!mAppVisible) { |
| 1152 | WindowManagerGlobal.trimForeground(); |
| 1153 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | void handleGetNewSurface() { |
| 1158 | mNewSurfaceNeeded = true; |
| 1159 | mFullRedrawNeeded = true; |
| 1160 | scheduleTraversals(); |
| 1161 | } |
| 1162 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 1163 | private final DisplayListener mDisplayListener = new DisplayListener() { |
| 1164 | @Override |
| 1165 | public void onDisplayChanged(int displayId) { |
| 1166 | if (mView != null && mDisplay.getDisplayId() == displayId) { |
| 1167 | final int oldDisplayState = mAttachInfo.mDisplayState; |
| 1168 | final int newDisplayState = mDisplay.getState(); |
| 1169 | if (oldDisplayState != newDisplayState) { |
| 1170 | mAttachInfo.mDisplayState = newDisplayState; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1171 | pokeDrawLockIfNeeded(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 1172 | if (oldDisplayState != Display.STATE_UNKNOWN) { |
| 1173 | final int oldScreenState = toViewScreenState(oldDisplayState); |
| 1174 | final int newScreenState = toViewScreenState(newDisplayState); |
| 1175 | if (oldScreenState != newScreenState) { |
| 1176 | mView.dispatchScreenStateChanged(newScreenState); |
| 1177 | } |
| 1178 | if (oldDisplayState == Display.STATE_OFF) { |
| 1179 | // Draw was suppressed so we need to for it to happen here. |
| 1180 | mFullRedrawNeeded = true; |
| 1181 | scheduleTraversals(); |
| 1182 | } |
| 1183 | } |
| 1184 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 1185 | } |
| 1186 | } |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 1187 | |
| 1188 | @Override |
| 1189 | public void onDisplayRemoved(int displayId) { |
| 1190 | } |
| 1191 | |
| 1192 | @Override |
| 1193 | public void onDisplayAdded(int displayId) { |
| 1194 | } |
| 1195 | |
| 1196 | private int toViewScreenState(int displayState) { |
| 1197 | return displayState == Display.STATE_OFF ? |
| 1198 | View.SCREEN_STATE_OFF : View.SCREEN_STATE_ON; |
| 1199 | } |
| 1200 | }; |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 1201 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1202 | /** |
| 1203 | * Notify about move to a different display. |
| 1204 | * @param displayId The id of the display where this view root is moved to. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 1205 | * @param config Configuration of the resources on new display after move. |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1206 | * |
| 1207 | * @hide |
| 1208 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 1209 | public void onMovedToDisplay(int displayId, Configuration config) { |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1210 | if (mDisplay.getDisplayId() == displayId) { |
| 1211 | return; |
| 1212 | } |
| 1213 | |
| 1214 | // Get new instance of display based on current display adjustments. It may be updated later |
| 1215 | // if moving between the displays also involved a configuration change. |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 1216 | mDisplay = ResourcesManager.getInstance().getAdjustedDisplay(displayId, |
| 1217 | mView.getResources()); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1218 | mAttachInfo.mDisplayState = mDisplay.getState(); |
| 1219 | // Internal state updated, now notify the view hierarchy. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 1220 | mView.dispatchMovedToDisplay(mDisplay, config); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1221 | } |
| 1222 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1223 | void pokeDrawLockIfNeeded() { |
| 1224 | final int displayState = mAttachInfo.mDisplayState; |
| 1225 | if (mView != null && mAdded && mTraversalScheduled |
| 1226 | && (displayState == Display.STATE_DOZE |
| 1227 | || displayState == Display.STATE_DOZE_SUSPEND)) { |
| 1228 | try { |
| 1229 | mWindowSession.pokeDrawLock(mWindow); |
| 1230 | } catch (RemoteException ex) { |
| 1231 | // System server died, oh well. |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1236 | @Override |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1237 | public void requestFitSystemWindows() { |
| 1238 | checkThread(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1239 | mApplyInsetsRequested = true; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1240 | scheduleTraversals(); |
| 1241 | } |
| 1242 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1243 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | public void requestLayout() { |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 1245 | if (!mHandlingLayoutInLayoutRequest) { |
| 1246 | checkThread(); |
| 1247 | mLayoutRequested = true; |
| 1248 | scheduleTraversals(); |
| 1249 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | } |
| 1251 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1252 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | public boolean isLayoutRequested() { |
| 1254 | return mLayoutRequested; |
| 1255 | } |
| 1256 | |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 1257 | @Override |
| 1258 | public void onDescendantInvalidated(@NonNull View child, @NonNull View descendant) { |
| 1259 | if ((descendant.mPrivateFlags & PFLAG_DRAW_ANIMATION) != 0) { |
| 1260 | mIsAnimating = true; |
| 1261 | } |
| 1262 | invalidate(); |
| 1263 | } |
| 1264 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 1265 | @UnsupportedAppUsage |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1266 | void invalidate() { |
| 1267 | mDirty.set(0, 0, mWidth, mHeight); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 1268 | if (!mWillDrawSoon) { |
| 1269 | scheduleTraversals(); |
| 1270 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1271 | } |
| 1272 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1273 | void invalidateWorld(View view) { |
| 1274 | view.invalidate(); |
| 1275 | if (view instanceof ViewGroup) { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 1276 | ViewGroup parent = (ViewGroup) view; |
| 1277 | for (int i = 0; i < parent.getChildCount(); i++) { |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1278 | invalidateWorld(parent.getChildAt(i)); |
| 1279 | } |
| 1280 | } |
| 1281 | } |
| 1282 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1283 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | public void invalidateChild(View child, Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1285 | invalidateChildInParent(null, dirty); |
| 1286 | } |
| 1287 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1288 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1289 | public ViewParent invalidateChildInParent(int[] location, Rect dirty) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1291 | if (DEBUG_DRAW) Log.v(mTag, "Invalidate child: " + dirty); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1292 | |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1293 | if (dirty == null) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1294 | invalidate(); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1295 | return null; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1296 | } else if (dirty.isEmpty() && !mIsAnimating) { |
Chet Haase | 05e91ed | 2012-07-03 14:17:57 -0700 | [diff] [blame] | 1297 | return null; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1298 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1299 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1300 | if (mCurScrollY != 0 || mTranslator != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | mTempRect.set(dirty); |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1302 | dirty = mTempRect; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1303 | if (mCurScrollY != 0) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1304 | dirty.offset(0, -mCurScrollY); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1305 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1306 | if (mTranslator != null) { |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1307 | mTranslator.translateRectInAppWindowToScreen(dirty); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1308 | } |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1309 | if (mAttachInfo.mScalingRequired) { |
| 1310 | dirty.inset(-1, -1); |
| 1311 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1313 | |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 1314 | invalidateRectOnScreen(dirty); |
| 1315 | |
| 1316 | return null; |
| 1317 | } |
| 1318 | |
| 1319 | private void invalidateRectOnScreen(Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1320 | final Rect localDirty = mDirty; |
| 1321 | if (!localDirty.isEmpty() && !localDirty.contains(dirty)) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 1322 | mAttachInfo.mSetIgnoreDirtyState = true; |
Romain Guy | 7d69594 | 2010-12-01 17:22:29 -0800 | [diff] [blame] | 1323 | mAttachInfo.mIgnoreDirtyState = true; |
| 1324 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1325 | |
| 1326 | // Add the new dirty rect to the current one |
| 1327 | localDirty.union(dirty.left, dirty.top, dirty.right, dirty.bottom); |
| 1328 | // Intersect with the bounds of the window to skip |
| 1329 | // updates that lie outside of the visible region |
Romain Guy | 7b2f8b8 | 2012-03-19 17:18:54 -0700 | [diff] [blame] | 1330 | final float appScale = mAttachInfo.mApplicationScale; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1331 | final boolean intersected = localDirty.intersect(0, 0, |
| 1332 | (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); |
| 1333 | if (!intersected) { |
Chet Haase | b78ee0e | 2012-10-17 11:32:01 -0700 | [diff] [blame] | 1334 | localDirty.setEmpty(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1335 | } |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1336 | if (!mWillDrawSoon && (intersected || mIsAnimating)) { |
| 1337 | scheduleTraversals(); |
| 1338 | } |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 1339 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 1341 | public void setIsAmbientMode(boolean ambient) { |
| 1342 | mIsAmbientMode = ambient; |
| 1343 | } |
| 1344 | |
Robert Carr | 414ebc6 | 2017-04-12 12:01:00 -0700 | [diff] [blame] | 1345 | interface WindowStoppedCallback { |
| 1346 | public void windowStopped(boolean stopped); |
| 1347 | } |
| 1348 | private final ArrayList<WindowStoppedCallback> mWindowStoppedCallbacks = new ArrayList<>(); |
| 1349 | |
| 1350 | void addWindowStoppedCallback(WindowStoppedCallback c) { |
| 1351 | mWindowStoppedCallbacks.add(c); |
| 1352 | } |
| 1353 | |
| 1354 | void removeWindowStoppedCallback(WindowStoppedCallback c) { |
| 1355 | mWindowStoppedCallbacks.remove(c); |
| 1356 | } |
| 1357 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1358 | void setWindowStopped(boolean stopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1359 | if (mStopped != stopped) { |
| 1360 | mStopped = stopped; |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1361 | final ThreadedRenderer renderer = mAttachInfo.mThreadedRenderer; |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 1362 | if (renderer != null) { |
| 1363 | if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle() + " set to " + mStopped); |
| 1364 | renderer.setStopped(mStopped); |
| 1365 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1366 | if (!mStopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1367 | scheduleTraversals(); |
John Reck | d9b1607 | 2016-02-23 10:35:19 -0800 | [diff] [blame] | 1368 | } else { |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 1369 | if (renderer != null) { |
| 1370 | renderer.destroyHardwareResources(mView); |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1371 | } |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1372 | } |
Robert Carr | 414ebc6 | 2017-04-12 12:01:00 -0700 | [diff] [blame] | 1373 | |
| 1374 | for (int i = 0; i < mWindowStoppedCallbacks.size(); i++) { |
| 1375 | mWindowStoppedCallbacks.get(i).windowStopped(stopped); |
| 1376 | } |
Robert Carr | 6858bb9 | 2018-04-16 11:09:49 -0700 | [diff] [blame] | 1377 | |
| 1378 | if (mStopped) { |
| 1379 | mSurface.release(); |
| 1380 | } |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1381 | } |
| 1382 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1384 | /** |
| 1385 | * Block the input events during an Activity Transition. The KEYCODE_BACK event is allowed |
| 1386 | * through to allow quick reversal of the Activity Transition. |
| 1387 | * |
| 1388 | * @param paused true to pause, false to resume. |
| 1389 | */ |
| 1390 | public void setPausedForTransition(boolean paused) { |
| 1391 | mPausedForTransition = paused; |
| 1392 | } |
| 1393 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1394 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1395 | public ViewParent getParent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1396 | return null; |
| 1397 | } |
| 1398 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1399 | @Override |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1400 | public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1401 | if (child != mView) { |
| 1402 | throw new RuntimeException("child is not mine, honest!"); |
| 1403 | } |
| 1404 | // Note: don't apply scroll offset, because we want to know its |
| 1405 | // visibility in the virtual canvas being given to the view hierarchy. |
| 1406 | return r.intersect(0, 0, mWidth, mHeight); |
| 1407 | } |
| 1408 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1409 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | public void bringChildToFront(View child) { |
| 1411 | } |
| 1412 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | int getHostVisibility() { |
Bryce Lee | 16e5089 | 2017-04-11 01:59:37 +0000 | [diff] [blame] | 1414 | return (mAppVisible || mForceDecorViewVisibility) ? mView.getVisibility() : View.GONE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1416 | |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 1417 | /** |
| 1418 | * Add LayoutTransition to the list of transitions to be started in the next traversal. |
| 1419 | * This list will be cleared after the transitions on the list are start()'ed. These |
| 1420 | * transitionsa re added by LayoutTransition itself when it sets up animations. The setup |
| 1421 | * happens during the layout phase of traversal, which we want to complete before any of the |
| 1422 | * animations are started (because those animations may side-effect properties that layout |
| 1423 | * depends upon, like the bounding rectangles of the affected views). So we add the transition |
| 1424 | * to the list and it is started just prior to starting the drawing phase of traversal. |
| 1425 | * |
| 1426 | * @param transition The LayoutTransition to be started on the next traversal. |
| 1427 | * |
| 1428 | * @hide |
| 1429 | */ |
| 1430 | public void requestTransitionStart(LayoutTransition transition) { |
| 1431 | if (mPendingTransitions == null || !mPendingTransitions.contains(transition)) { |
| 1432 | if (mPendingTransitions == null) { |
| 1433 | mPendingTransitions = new ArrayList<LayoutTransition>(); |
| 1434 | } |
| 1435 | mPendingTransitions.add(transition); |
| 1436 | } |
| 1437 | } |
| 1438 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1439 | /** |
| 1440 | * Notifies the HardwareRenderer that a new frame will be coming soon. |
| 1441 | * Currently only {@link ThreadedRenderer} cares about this, and uses |
| 1442 | * this knowledge to adjust the scheduling of off-thread animations |
| 1443 | */ |
| 1444 | void notifyRendererOfFramePending() { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1445 | if (mAttachInfo.mThreadedRenderer != null) { |
| 1446 | mAttachInfo.mThreadedRenderer.notifyFramePending(); |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 1450 | @UnsupportedAppUsage |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1451 | void scheduleTraversals() { |
| 1452 | if (!mTraversalScheduled) { |
| 1453 | mTraversalScheduled = true; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1454 | mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1455 | mChoreographer.postCallback( |
| 1456 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 1457 | if (!mUnbufferedInputDispatch) { |
| 1458 | scheduleConsumeBatchedInput(); |
| 1459 | } |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1460 | notifyRendererOfFramePending(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1461 | pokeDrawLockIfNeeded(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1462 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1463 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1464 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1465 | void unscheduleTraversals() { |
| 1466 | if (mTraversalScheduled) { |
| 1467 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1468 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1469 | mChoreographer.removeCallbacks( |
| 1470 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | void doTraversal() { |
| 1475 | if (mTraversalScheduled) { |
| 1476 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1477 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1478 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1479 | if (mProfile) { |
| 1480 | Debug.startMethodTracing("ViewAncestor"); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1481 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1482 | |
Chris Craik | e22c59b | 2015-05-21 18:33:37 -0700 | [diff] [blame] | 1483 | performTraversals(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1484 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1485 | if (mProfile) { |
| 1486 | Debug.stopMethodTracing(); |
| 1487 | mProfile = false; |
| 1488 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1489 | } |
| 1490 | } |
| 1491 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1492 | private void applyKeepScreenOnFlag(WindowManager.LayoutParams params) { |
| 1493 | // Update window's global keep screen on flag: if a view has requested |
| 1494 | // that the screen be kept on, then it is always set; otherwise, it is |
| 1495 | // set to whatever the client last requested for the global state. |
| 1496 | if (mAttachInfo.mKeepScreenOn) { |
| 1497 | params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 1498 | } else { |
| 1499 | params.flags = (params.flags&~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) |
| 1500 | | (mClientWindowLayoutFlags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1501 | } |
| 1502 | } |
| 1503 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1504 | private boolean collectViewAttributes() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1505 | if (mAttachInfo.mRecomputeGlobalAttributes) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1506 | //Log.i(mTag, "Computing view hierarchy attributes!"); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1507 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 1508 | boolean oldScreenOn = mAttachInfo.mKeepScreenOn; |
| 1509 | mAttachInfo.mKeepScreenOn = false; |
| 1510 | mAttachInfo.mSystemUiVisibility = 0; |
| 1511 | mAttachInfo.mHasSystemUiListeners = false; |
| 1512 | mView.dispatchCollectViewAttributes(mAttachInfo, 0); |
| 1513 | mAttachInfo.mSystemUiVisibility &= ~mAttachInfo.mDisabledSystemUiVisibility; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 1514 | WindowManager.LayoutParams params = mWindowAttributes; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1515 | mAttachInfo.mSystemUiVisibility |= getImpliedSystemUiVisibility(params); |
| 1516 | if (mAttachInfo.mKeepScreenOn != oldScreenOn |
| 1517 | || mAttachInfo.mSystemUiVisibility != params.subtreeSystemUiVisibility |
| 1518 | || mAttachInfo.mHasSystemUiListeners != params.hasSystemUiListeners) { |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1519 | applyKeepScreenOnFlag(params); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1520 | params.subtreeSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
| 1521 | params.hasSystemUiListeners = mAttachInfo.mHasSystemUiListeners; |
| 1522 | mView.dispatchWindowSystemUiVisiblityChanged(mAttachInfo.mSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1523 | return true; |
| 1524 | } |
| 1525 | } |
| 1526 | return false; |
| 1527 | } |
| 1528 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1529 | private int getImpliedSystemUiVisibility(WindowManager.LayoutParams params) { |
| 1530 | int vis = 0; |
| 1531 | // Translucent decor window flags imply stable system ui visibility. |
| 1532 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0) { |
| 1533 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 1534 | } |
| 1535 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) { |
| 1536 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1537 | } |
| 1538 | return vis; |
| 1539 | } |
| 1540 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1541 | private boolean measureHierarchy(final View host, final WindowManager.LayoutParams lp, |
| 1542 | final Resources res, final int desiredWindowWidth, final int desiredWindowHeight) { |
| 1543 | int childWidthMeasureSpec; |
| 1544 | int childHeightMeasureSpec; |
| 1545 | boolean windowSizeMayChange = false; |
| 1546 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1547 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1548 | "Measuring " + host + " in display " + desiredWindowWidth |
| 1549 | + "x" + desiredWindowHeight + "..."); |
| 1550 | |
| 1551 | boolean goodMeasure = false; |
| 1552 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) { |
| 1553 | // On large screens, we don't want to allow dialogs to just |
| 1554 | // stretch to fill the entire width of the screen to display |
| 1555 | // one line of text. First try doing the layout at a smaller |
| 1556 | // size to see if it will fit. |
| 1557 | final DisplayMetrics packageMetrics = res.getDisplayMetrics(); |
| 1558 | res.getValue(com.android.internal.R.dimen.config_prefDialogWidth, mTmpValue, true); |
| 1559 | int baseSize = 0; |
| 1560 | if (mTmpValue.type == TypedValue.TYPE_DIMENSION) { |
| 1561 | baseSize = (int)mTmpValue.getDimension(packageMetrics); |
| 1562 | } |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1563 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": baseSize=" + baseSize |
| 1564 | + ", desiredWindowWidth=" + desiredWindowWidth); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1565 | if (baseSize != 0 && desiredWindowWidth > baseSize) { |
| 1566 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
| 1567 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1568 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1569 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1570 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() |
| 1571 | + ") from width spec: " + MeasureSpec.toString(childWidthMeasureSpec) |
| 1572 | + " and height spec: " + MeasureSpec.toString(childHeightMeasureSpec)); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1573 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
| 1574 | goodMeasure = true; |
| 1575 | } else { |
| 1576 | // Didn't fit in that size... try expanding a bit. |
| 1577 | baseSize = (baseSize+desiredWindowWidth)/2; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1578 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": next baseSize=" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1579 | + baseSize); |
| 1580 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1581 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1582 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1583 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")"); |
| 1584 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1585 | if (DEBUG_DIALOG) Log.v(mTag, "Good!"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1586 | goodMeasure = true; |
| 1587 | } |
| 1588 | } |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | if (!goodMeasure) { |
| 1593 | childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width); |
| 1594 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1595 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1596 | if (mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) { |
| 1597 | windowSizeMayChange = true; |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | if (DBG) { |
| 1602 | System.out.println("======================================"); |
| 1603 | System.out.println("performTraversals -- after measure"); |
| 1604 | host.debug(); |
| 1605 | } |
| 1606 | |
| 1607 | return windowSizeMayChange; |
| 1608 | } |
| 1609 | |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1610 | /** |
| 1611 | * Modifies the input matrix such that it maps view-local coordinates to |
| 1612 | * on-screen coordinates. |
| 1613 | * |
| 1614 | * @param m input matrix to modify |
| 1615 | */ |
| 1616 | void transformMatrixToGlobal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1617 | m.preTranslate(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | /** |
| 1621 | * Modifies the input matrix such that it maps on-screen coordinates to |
| 1622 | * view-local coordinates. |
| 1623 | * |
| 1624 | * @param m input matrix to modify |
| 1625 | */ |
| 1626 | void transformMatrixToLocal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1627 | m.postTranslate(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1628 | } |
| 1629 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1630 | /* package */ WindowInsets getWindowInsets(boolean forceConstruct) { |
| 1631 | if (mLastWindowInsets == null || forceConstruct) { |
| 1632 | mDispatchContentInsets.set(mAttachInfo.mContentInsets); |
| 1633 | mDispatchStableInsets.set(mAttachInfo.mStableInsets); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1634 | mDispatchDisplayCutout = mAttachInfo.mDisplayCutout.get(); |
| 1635 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1636 | Rect contentInsets = mDispatchContentInsets; |
| 1637 | Rect stableInsets = mDispatchStableInsets; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1638 | DisplayCutout displayCutout = mDispatchDisplayCutout; |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1639 | // For dispatch we preserve old logic, but for direct requests from Views we allow to |
| 1640 | // immediately use pending insets. |
| 1641 | if (!forceConstruct |
| 1642 | && (!mPendingContentInsets.equals(contentInsets) || |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1643 | !mPendingStableInsets.equals(stableInsets) || |
| 1644 | !mPendingDisplayCutout.get().equals(displayCutout))) { |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1645 | contentInsets = mPendingContentInsets; |
| 1646 | stableInsets = mPendingStableInsets; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1647 | displayCutout = mPendingDisplayCutout.get(); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1648 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1649 | Rect outsets = mAttachInfo.mOutsets; |
| 1650 | if (outsets.left > 0 || outsets.top > 0 || outsets.right > 0 || outsets.bottom > 0) { |
| 1651 | contentInsets = new Rect(contentInsets.left + outsets.left, |
| 1652 | contentInsets.top + outsets.top, contentInsets.right + outsets.right, |
| 1653 | contentInsets.bottom + outsets.bottom); |
| 1654 | } |
Adrian Roos | 7419a17 | 2018-05-24 18:20:51 +0200 | [diff] [blame] | 1655 | contentInsets = ensureInsetsNonNegative(contentInsets, "content"); |
| 1656 | stableInsets = ensureInsetsNonNegative(stableInsets, "stable"); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1657 | mLastWindowInsets = new WindowInsets(contentInsets, |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1658 | null /* windowDecorInsets */, stableInsets, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1659 | mContext.getResources().getConfiguration().isScreenRound(), |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1660 | mAttachInfo.mAlwaysConsumeNavBar, displayCutout); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1661 | } |
| 1662 | return mLastWindowInsets; |
| 1663 | } |
| 1664 | |
Adrian Roos | 7419a17 | 2018-05-24 18:20:51 +0200 | [diff] [blame] | 1665 | private Rect ensureInsetsNonNegative(Rect insets, String kind) { |
| 1666 | if (insets.left < 0 || insets.top < 0 || insets.right < 0 || insets.bottom < 0) { |
Adrian Roos | 7419a17 | 2018-05-24 18:20:51 +0200 | [diff] [blame] | 1667 | return new Rect(Math.max(0, insets.left), |
| 1668 | Math.max(0, insets.top), |
| 1669 | Math.max(0, insets.right), |
| 1670 | Math.max(0, insets.bottom)); |
| 1671 | } |
| 1672 | return insets; |
| 1673 | } |
| 1674 | |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1675 | void dispatchApplyInsets(View host) { |
Adrian Roos | 2b0dcb3 | 2017-12-12 16:07:55 +0100 | [diff] [blame] | 1676 | WindowInsets insets = getWindowInsets(true /* forceConstruct */); |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 1677 | final boolean dispatchCutout = (mWindowAttributes.layoutInDisplayCutoutMode |
| 1678 | == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS); |
| 1679 | if (!dispatchCutout) { |
Adrian Roos | 2b0dcb3 | 2017-12-12 16:07:55 +0100 | [diff] [blame] | 1680 | // Window is either not laid out in cutout or the status bar inset takes care of |
| 1681 | // clearing the cutout, so we don't need to dispatch the cutout to the hierarchy. |
Adrian Roos | d07bafd | 2017-12-11 17:30:56 +0100 | [diff] [blame] | 1682 | insets = insets.consumeDisplayCutout(); |
Adrian Roos | 2b0dcb3 | 2017-12-12 16:07:55 +0100 | [diff] [blame] | 1683 | } |
| 1684 | host.dispatchApplyWindowInsets(insets); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1687 | private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { |
| 1688 | return lp.type == TYPE_STATUS_BAR_PANEL |
| 1689 | || lp.type == TYPE_INPUT_METHOD |
| 1690 | || lp.type == TYPE_VOLUME_OVERLAY; |
| 1691 | } |
| 1692 | |
| 1693 | private int dipToPx(int dip) { |
| 1694 | final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); |
| 1695 | return (int) (displayMetrics.density * dip + 0.5f); |
| 1696 | } |
| 1697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | private void performTraversals() { |
| 1699 | // cache mView since it is used so much below... |
| 1700 | final View host = mView; |
| 1701 | |
| 1702 | if (DBG) { |
| 1703 | System.out.println("======================================"); |
| 1704 | System.out.println("performTraversals"); |
| 1705 | host.debug(); |
| 1706 | } |
| 1707 | |
| 1708 | if (host == null || !mAdded) |
| 1709 | return; |
| 1710 | |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 1711 | mIsInTraversal = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1712 | mWillDrawSoon = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1713 | boolean windowSizeMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1714 | boolean newSurface = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1715 | boolean surfaceChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | WindowManager.LayoutParams lp = mWindowAttributes; |
| 1717 | |
| 1718 | int desiredWindowWidth; |
| 1719 | int desiredWindowHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1721 | final int viewVisibility = getHostVisibility(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1722 | final boolean viewVisibilityChanged = !mFirst |
Andrii Kulian | 74b561a | 2017-08-11 09:06:46 -0700 | [diff] [blame] | 1723 | && (mViewVisibility != viewVisibility || mNewSurfaceNeeded |
| 1724 | // Also check for possible double visibility update, which will make current |
| 1725 | // viewVisibility value equal to mViewVisibility and we may miss it. |
| 1726 | || mAppVisibilityChanged); |
| 1727 | mAppVisibilityChanged = false; |
Adam Powell | 06f9eb8 | 2016-08-24 17:09:01 -0700 | [diff] [blame] | 1728 | final boolean viewUserVisibilityChanged = !mFirst && |
| 1729 | ((mViewVisibility == View.VISIBLE) != (viewVisibility == View.VISIBLE)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1730 | |
| 1731 | WindowManager.LayoutParams params = null; |
| 1732 | if (mWindowAttributesChanged) { |
| 1733 | mWindowAttributesChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1734 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | params = lp; |
| 1736 | } |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 1737 | CompatibilityInfo compatibilityInfo = |
| 1738 | mDisplay.getDisplayAdjustments().getCompatibilityInfo(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1739 | if (compatibilityInfo.supportsScreen() == mLastInCompatMode) { |
| 1740 | params = lp; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1741 | mFullRedrawNeeded = true; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1742 | mLayoutRequested = true; |
| 1743 | if (mLastInCompatMode) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1744 | params.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1745 | mLastInCompatMode = false; |
| 1746 | } else { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1747 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1748 | mLastInCompatMode = true; |
| 1749 | } |
| 1750 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1751 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 1752 | mWindowAttributesChangesFlag = 0; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1753 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1754 | Rect frame = mWinFrame; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | if (mFirst) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1756 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1757 | mLayoutRequested = true; |
| 1758 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1759 | final Configuration config = mContext.getResources().getConfiguration(); |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1760 | if (shouldUseDisplaySize(lp)) { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1761 | // NOTE -- system code, won't try to do compat mode. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1762 | Point size = new Point(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1763 | mDisplay.getRealSize(size); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1764 | desiredWindowWidth = size.x; |
| 1765 | desiredWindowHeight = size.y; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1766 | } else { |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 1767 | desiredWindowWidth = mWinFrame.width(); |
| 1768 | desiredWindowHeight = mWinFrame.height(); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1769 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 1771 | // We used to use the following condition to choose 32 bits drawing caches: |
| 1772 | // PixelFormat.hasAlpha(lp.format) || lp.format == PixelFormat.RGBX_8888 |
| 1773 | // However, windows are now always 32 bits by default, so choose 32 bits |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1774 | mAttachInfo.mUse32BitDrawingCache = true; |
| 1775 | mAttachInfo.mHasWindowFocus = false; |
| 1776 | mAttachInfo.mWindowVisibility = viewVisibility; |
| 1777 | mAttachInfo.mRecomputeGlobalAttributes = false; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1778 | mLastConfigurationFromResources.setTo(config); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1779 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1780 | // Set the layout direction if it has not been set before (inherit is the default) |
| 1781 | if (mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1782 | host.setLayoutDirection(config.getLayoutDirection()); |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1783 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1784 | host.dispatchAttachedToWindow(mAttachInfo, 0); |
| 1785 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1786 | dispatchApplyInsets(host); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | } else { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1788 | desiredWindowWidth = frame.width(); |
| 1789 | desiredWindowHeight = frame.height(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | if (desiredWindowWidth != mWidth || desiredWindowHeight != mHeight) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1791 | if (DEBUG_ORIENTATION) Log.v(mTag, "View " + host + " resized to: " + frame); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1792 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | mLayoutRequested = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1794 | windowSizeMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | if (viewVisibilityChanged) { |
Bryce Lee | 16e5089 | 2017-04-11 01:59:37 +0000 | [diff] [blame] | 1799 | mAttachInfo.mWindowVisibility = viewVisibility; |
| 1800 | host.dispatchWindowVisibilityChanged(viewVisibility); |
Adam Powell | 06f9eb8 | 2016-08-24 17:09:01 -0700 | [diff] [blame] | 1801 | if (viewUserVisibilityChanged) { |
Adam Powell | 64e1ba4 | 2016-08-22 09:09:44 -0700 | [diff] [blame] | 1802 | host.dispatchVisibilityAggregated(viewVisibility == View.VISIBLE); |
| 1803 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1804 | if (viewVisibility != View.VISIBLE || mNewSurfaceNeeded) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1805 | endDragResizing(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1806 | destroyHardwareResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | } |
| 1808 | if (viewVisibility == View.GONE) { |
| 1809 | // After making a window gone, we will count it as being |
| 1810 | // shown for the first time the next time it gets focus. |
| 1811 | mHasHadWindowFocus = false; |
| 1812 | } |
| 1813 | } |
| 1814 | |
Alan Viverette | 7dbc3bf | 2015-01-28 16:14:36 -0800 | [diff] [blame] | 1815 | // Non-visible windows can't hold accessibility focus. |
| 1816 | if (mAttachInfo.mWindowVisibility != View.VISIBLE) { |
| 1817 | host.clearAccessibilityFocus(); |
| 1818 | } |
| 1819 | |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1820 | // Execute enqueued actions on every traversal in case a detached view enqueued an action |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1821 | getRunQueue().executeActions(mAttachInfo.mHandler); |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | boolean insetsChanged = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1824 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1825 | boolean layoutRequested = mLayoutRequested && (!mStopped || mReportNextDraw); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1826 | if (layoutRequested) { |
Romain Guy | 15df670 | 2009-08-17 20:17:30 -0700 | [diff] [blame] | 1827 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1828 | final Resources res = mView.getContext().getResources(); |
| 1829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1830 | if (mFirst) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1831 | // make sure touch mode code executes by setting cached value |
| 1832 | // to opposite of the added touch mode. |
| 1833 | mAttachInfo.mInTouchMode = !mAddedTouchMode; |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 1834 | ensureTouchModeLocally(mAddedTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1835 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1836 | if (!mPendingOverscanInsets.equals(mAttachInfo.mOverscanInsets)) { |
| 1837 | insetsChanged = true; |
| 1838 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1839 | if (!mPendingContentInsets.equals(mAttachInfo.mContentInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | insetsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1842 | if (!mPendingStableInsets.equals(mAttachInfo.mStableInsets)) { |
| 1843 | insetsChanged = true; |
| 1844 | } |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1845 | if (!mPendingDisplayCutout.equals(mAttachInfo.mDisplayCutout)) { |
| 1846 | insetsChanged = true; |
| 1847 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1848 | if (!mPendingVisibleInsets.equals(mAttachInfo.mVisibleInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1849 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1850 | if (DEBUG_LAYOUT) Log.v(mTag, "Visible insets changing to: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1851 | + mAttachInfo.mVisibleInsets); |
| 1852 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1853 | if (!mPendingOutsets.equals(mAttachInfo.mOutsets)) { |
| 1854 | insetsChanged = true; |
| 1855 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1856 | if (mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar) { |
| 1857 | insetsChanged = true; |
| 1858 | } |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1859 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT |
| 1860 | || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) { |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1861 | windowSizeMayChange = true; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1862 | |
| 1863 | if (shouldUseDisplaySize(lp)) { |
| 1864 | // NOTE -- system code, won't try to do compat mode. |
| 1865 | Point size = new Point(); |
| 1866 | mDisplay.getRealSize(size); |
| 1867 | desiredWindowWidth = size.x; |
| 1868 | desiredWindowHeight = size.y; |
| 1869 | } else { |
| 1870 | Configuration config = res.getConfiguration(); |
| 1871 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1872 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
| 1873 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1874 | } |
| 1875 | } |
| 1876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | // Ask host how big it wants to be |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1878 | windowSizeMayChange |= measureHierarchy(host, lp, res, |
| 1879 | desiredWindowWidth, desiredWindowHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | } |
| 1881 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1882 | if (collectViewAttributes()) { |
| 1883 | params = lp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1885 | if (mAttachInfo.mForceReportNewAttributes) { |
| 1886 | mAttachInfo.mForceReportNewAttributes = false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1887 | params = lp; |
| 1888 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1889 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1890 | if (mFirst || mAttachInfo.mViewVisibilityChanged) { |
| 1891 | mAttachInfo.mViewVisibilityChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | int resizeMode = mSoftInputMode & |
| 1893 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 1894 | // If we are in auto resize mode, then we need to determine |
| 1895 | // what mode to use now. |
| 1896 | if (resizeMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1897 | final int N = mAttachInfo.mScrollContainers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1898 | for (int i=0; i<N; i++) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1899 | if (mAttachInfo.mScrollContainers.get(i).isShown()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1900 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 1901 | } |
| 1902 | } |
| 1903 | if (resizeMode == 0) { |
| 1904 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN; |
| 1905 | } |
| 1906 | if ((lp.softInputMode & |
| 1907 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) != resizeMode) { |
| 1908 | lp.softInputMode = (lp.softInputMode & |
| 1909 | ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) | |
| 1910 | resizeMode; |
| 1911 | params = lp; |
| 1912 | } |
| 1913 | } |
| 1914 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1915 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1916 | if (params != null) { |
| 1917 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 1918 | if (!PixelFormat.formatHasAlpha(params.format)) { |
| 1919 | params.format = PixelFormat.TRANSLUCENT; |
| 1920 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1922 | mAttachInfo.mOverscanRequested = (params.flags |
| 1923 | & WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | } |
| 1925 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1926 | if (mApplyInsetsRequested) { |
| 1927 | mApplyInsetsRequested = false; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1928 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1929 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1930 | if (mLayoutRequested) { |
| 1931 | // Short-circuit catching a new layout request here, so |
| 1932 | // we don't need to go through two layout passes when things |
| 1933 | // change due to fitting system windows, which can happen a lot. |
| 1934 | windowSizeMayChange |= measureHierarchy(host, lp, |
| 1935 | mView.getContext().getResources(), |
| 1936 | desiredWindowWidth, desiredWindowHeight); |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | if (layoutRequested) { |
| 1941 | // Clear this now, so that if anything requests a layout in the |
| 1942 | // rest of this function we will catch it and re-run a full |
| 1943 | // layout pass. |
| 1944 | mLayoutRequested = false; |
| 1945 | } |
| 1946 | |
| 1947 | boolean windowShouldResize = layoutRequested && windowSizeMayChange |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1948 | && ((mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) |
Romain Guy | 2e4f426 | 2010-04-06 11:07:52 -0700 | [diff] [blame] | 1949 | || (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1950 | frame.width() < desiredWindowWidth && frame.width() != mWidth) |
| 1951 | || (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1952 | frame.height() < desiredWindowHeight && frame.height() != mHeight)); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1953 | windowShouldResize |= mDragResizing && mResizeMode == RESIZE_MODE_FREEFORM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1954 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1955 | // If the activity was just relaunched, it might have unfrozen the task bounds (while |
| 1956 | // relaunching), so we need to force a call into window manager to pick up the latest |
| 1957 | // bounds. |
| 1958 | windowShouldResize |= mActivityRelaunched; |
| 1959 | |
Jeff Brown | 2e05ec3 | 2013-09-30 15:57:43 -0700 | [diff] [blame] | 1960 | // Determine whether to compute insets. |
| 1961 | // If there are no inset listeners remaining then we may still need to compute |
| 1962 | // insets in case the old insets were non-empty and must be reset. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | final boolean computesInternalInsets = |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1964 | mAttachInfo.mTreeObserver.hasComputeInternalInsetsListeners() |
| 1965 | || mAttachInfo.mHasNonEmptyGivenInternalInsets; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1967 | boolean insetsPending = false; |
| 1968 | int relayoutResult = 0; |
Chet Haase | d86fb2c | 2016-05-04 07:26:02 -0700 | [diff] [blame] | 1969 | boolean updatedConfiguration = false; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1970 | |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 1971 | final int surfaceGenerationId = mSurface.getGenerationId(); |
| 1972 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1973 | final boolean isViewVisible = viewVisibility == View.VISIBLE; |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 1974 | final boolean windowRelayoutWasForced = mForceNextWindowRelayout; |
Bryce Lee | 46b0165 | 2017-06-07 23:01:56 +0000 | [diff] [blame] | 1975 | if (mFirst || windowShouldResize || insetsChanged || |
| 1976 | viewVisibilityChanged || params != null || mForceNextWindowRelayout) { |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 1977 | mForceNextWindowRelayout = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 1979 | if (isViewVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | // If this window is giving internal insets to the window |
| 1981 | // manager, and it is being added or changing its visibility, |
| 1982 | // then we want to first give the window manager "fake" |
| 1983 | // insets to cause it to effectively ignore the content of |
| 1984 | // the window during layout. This avoids it briefly causing |
| 1985 | // other windows to resize/move based on the raw frame of the |
| 1986 | // window, waiting until we can finish laying out this window |
| 1987 | // and get back to the window manager with the ultimately |
| 1988 | // computed insets. |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1989 | insetsPending = computesInternalInsets && (mFirst || viewVisibilityChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | } |
| 1991 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1992 | if (mSurfaceHolder != null) { |
| 1993 | mSurfaceHolder.mSurfaceLock.lock(); |
| 1994 | mDrawingAllowed = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1995 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1996 | |
Romain Guy | c361da8 | 2010-10-25 15:29:10 -0700 | [diff] [blame] | 1997 | boolean hwInitialized = false; |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 1998 | boolean contentInsetsChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1999 | boolean hadSurface = mSurface.isValid(); |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | try { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 2002 | if (DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2003 | Log.i(mTag, "host=w:" + host.getMeasuredWidth() + ", h:" + |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 2004 | host.getMeasuredHeight() + ", params=" + params); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 2005 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 2006 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2007 | if (mAttachInfo.mThreadedRenderer != null) { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 2008 | // relayoutWindow may decide to destroy mSurface. As that decision |
| 2009 | // happens in WindowManager service, we need to be defensive here |
| 2010 | // and stop using the surface in case it gets destroyed. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2011 | if (mAttachInfo.mThreadedRenderer.pauseSurface(mSurface)) { |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 2012 | // Animations were running so we need to push a frame |
| 2013 | // to resume them |
| 2014 | mDirty.set(0, 0, mWidth, mHeight); |
| 2015 | } |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 2016 | mChoreographer.mFrameInfo.addFlags(FrameInfo.FLAG_WINDOW_LAYOUT_CHANGED); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 2017 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 2018 | relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); |
| 2019 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2020 | if (DEBUG_LAYOUT) Log.v(mTag, "relayout: frame=" + frame.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2021 | + " overscan=" + mPendingOverscanInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2022 | + " content=" + mPendingContentInsets.toShortString() |
| 2023 | + " visible=" + mPendingVisibleInsets.toShortString() |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 2024 | + " stable=" + mPendingStableInsets.toShortString() |
| 2025 | + " cutout=" + mPendingDisplayCutout.get().toString() |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 2026 | + " outsets=" + mPendingOutsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2027 | + " surface=" + mSurface); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2028 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2029 | // If the pending {@link MergedConfiguration} handed back from |
| 2030 | // {@link #relayoutWindow} does not match the one last reported, |
| 2031 | // WindowManagerService has reported back a frame from a configuration not yet |
| 2032 | // handled by the client. In this case, we need to accept the configuration so we |
| 2033 | // do not lay out and draw with the wrong configuration. |
| 2034 | if (!mPendingMergedConfiguration.equals(mLastReportedMergedConfiguration)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2035 | if (DEBUG_CONFIGURATION) Log.v(mTag, "Visible with new config: " |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2036 | + mPendingMergedConfiguration.getMergedConfiguration()); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 2037 | performConfigurationChange(mPendingMergedConfiguration, !mFirst, |
| 2038 | INVALID_DISPLAY /* same display */); |
Chet Haase | d86fb2c | 2016-05-04 07:26:02 -0700 | [diff] [blame] | 2039 | updatedConfiguration = true; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2040 | } |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 2041 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2042 | final boolean overscanInsetsChanged = !mPendingOverscanInsets.equals( |
| 2043 | mAttachInfo.mOverscanInsets); |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 2044 | contentInsetsChanged = !mPendingContentInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2045 | mAttachInfo.mContentInsets); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2046 | final boolean visibleInsetsChanged = !mPendingVisibleInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2047 | mAttachInfo.mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2048 | final boolean stableInsetsChanged = !mPendingStableInsets.equals( |
| 2049 | mAttachInfo.mStableInsets); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 2050 | final boolean cutoutChanged = !mPendingDisplayCutout.equals( |
| 2051 | mAttachInfo.mDisplayCutout); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2052 | final boolean outsetsChanged = !mPendingOutsets.equals(mAttachInfo.mOutsets); |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 2053 | final boolean surfaceSizeChanged = (relayoutResult |
| 2054 | & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0; |
Adrian Roos | dcf50a4f | 2018-01-29 18:31:34 +0100 | [diff] [blame] | 2055 | surfaceChanged |= surfaceSizeChanged; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 2056 | final boolean alwaysConsumeNavBarChanged = |
| 2057 | mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2058 | if (contentInsetsChanged) { |
| 2059 | mAttachInfo.mContentInsets.set(mPendingContentInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2060 | if (DEBUG_LAYOUT) Log.v(mTag, "Content insets changing to: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2061 | + mAttachInfo.mContentInsets); |
| 2062 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2063 | if (overscanInsetsChanged) { |
| 2064 | mAttachInfo.mOverscanInsets.set(mPendingOverscanInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2065 | if (DEBUG_LAYOUT) Log.v(mTag, "Overscan insets changing to: " |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2066 | + mAttachInfo.mOverscanInsets); |
| 2067 | // Need to relayout with content insets. |
| 2068 | contentInsetsChanged = true; |
| 2069 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2070 | if (stableInsetsChanged) { |
| 2071 | mAttachInfo.mStableInsets.set(mPendingStableInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2072 | if (DEBUG_LAYOUT) Log.v(mTag, "Decor insets changing to: " |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2073 | + mAttachInfo.mStableInsets); |
| 2074 | // Need to relayout with content insets. |
| 2075 | contentInsetsChanged = true; |
| 2076 | } |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 2077 | if (cutoutChanged) { |
| 2078 | mAttachInfo.mDisplayCutout.set(mPendingDisplayCutout); |
| 2079 | if (DEBUG_LAYOUT) { |
| 2080 | Log.v(mTag, "DisplayCutout changing to: " + mAttachInfo.mDisplayCutout); |
| 2081 | } |
| 2082 | // Need to relayout with content insets. |
| 2083 | contentInsetsChanged = true; |
| 2084 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 2085 | if (alwaysConsumeNavBarChanged) { |
| 2086 | mAttachInfo.mAlwaysConsumeNavBar = mPendingAlwaysConsumeNavBar; |
| 2087 | contentInsetsChanged = true; |
| 2088 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2089 | if (contentInsetsChanged || mLastSystemUiVisibility != |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2090 | mAttachInfo.mSystemUiVisibility || mApplyInsetsRequested |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2091 | || mLastOverscanRequested != mAttachInfo.mOverscanRequested |
| 2092 | || outsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2093 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2094 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2095 | mAttachInfo.mOutsets.set(mPendingOutsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2096 | mApplyInsetsRequested = false; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 2097 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2098 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2099 | if (visibleInsetsChanged) { |
| 2100 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2101 | if (DEBUG_LAYOUT) Log.v(mTag, "Visible insets changing to: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | + mAttachInfo.mVisibleInsets); |
| 2103 | } |
| 2104 | |
| 2105 | if (!hadSurface) { |
| 2106 | if (mSurface.isValid()) { |
| 2107 | // If we are creating a new surface, then we need to |
| 2108 | // completely redraw it. Also, when we get to the |
| 2109 | // point of drawing it we will hold off and schedule |
| 2110 | // a new traversal instead. This is so we can tell the |
| 2111 | // window manager about all of the windows being displayed |
| 2112 | // before actually drawing them, so it can display then |
| 2113 | // all at once. |
| 2114 | newSurface = true; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2115 | mFullRedrawNeeded = true; |
Jack Palevich | 61a6e68 | 2009-10-09 17:37:50 -0700 | [diff] [blame] | 2116 | mPreviousTransparentRegion.setEmpty(); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2117 | |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 2118 | // Only initialize up-front if transparent regions are not |
| 2119 | // requested, otherwise defer to see if the entire window |
| 2120 | // will be transparent |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2121 | if (mAttachInfo.mThreadedRenderer != null) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2122 | try { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2123 | hwInitialized = mAttachInfo.mThreadedRenderer.initialize( |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 2124 | mSurface); |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 2125 | if (hwInitialized && (host.mPrivateFlags |
| 2126 | & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) { |
| 2127 | // Don't pre-allocate if transparent regions |
| 2128 | // are requested as they may not be needed |
Jorim Jaggi | 7823ee7 | 2018-07-17 15:24:16 +0200 | [diff] [blame] | 2129 | mAttachInfo.mThreadedRenderer.allocateBuffers(mSurface); |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 2130 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2131 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2132 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2133 | return; |
| 2134 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | } |
| 2136 | } |
| 2137 | } else if (!mSurface.isValid()) { |
| 2138 | // If the surface has been removed, then reset the scroll |
| 2139 | // positions. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2140 | if (mLastScrolledFocus != null) { |
| 2141 | mLastScrolledFocus.clear(); |
| 2142 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2143 | mScrollY = mCurScrollY = 0; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 2144 | if (mView instanceof RootViewSurfaceTaker) { |
| 2145 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 2146 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2147 | if (mScroller != null) { |
| 2148 | mScroller.abortAnimation(); |
| 2149 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 2150 | // Our surface is gone |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2151 | if (mAttachInfo.mThreadedRenderer != null && |
| 2152 | mAttachInfo.mThreadedRenderer.isEnabled()) { |
| 2153 | mAttachInfo.mThreadedRenderer.destroy(); |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 2154 | } |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 2155 | } else if ((surfaceGenerationId != mSurface.getGenerationId() |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 2156 | || surfaceSizeChanged || windowRelayoutWasForced) |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 2157 | && mSurfaceHolder == null |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2158 | && mAttachInfo.mThreadedRenderer != null) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2159 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2160 | try { |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 2161 | // Need to do updateSurface (which leads to CanvasContext::setSurface and |
| 2162 | // re-create the EGLSurface) if either the Surface changed (as indicated by |
| 2163 | // generation id), or WindowManager changed the surface size. The latter is |
| 2164 | // because on some chips, changing the consumer side's BufferQueue size may |
| 2165 | // not take effect immediately unless we create a new EGLSurface. |
| 2166 | // Note that frame size change doesn't always imply surface size change (eg. |
| 2167 | // drag resizing uses fullscreen surface), need to check surfaceSizeChanged |
| 2168 | // flag from WindowManager. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2169 | mAttachInfo.mThreadedRenderer.updateSurface(mSurface); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2170 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2171 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2172 | return; |
| 2173 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2174 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2175 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2176 | final boolean freeformResizing = (relayoutResult |
| 2177 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; |
| 2178 | final boolean dockedResizing = (relayoutResult |
| 2179 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; |
| 2180 | final boolean dragResizing = freeformResizing || dockedResizing; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2181 | if (mDragResizing != dragResizing) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 2182 | if (dragResizing) { |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2183 | mResizeMode = freeformResizing |
| 2184 | ? RESIZE_MODE_FREEFORM |
| 2185 | : RESIZE_MODE_DOCKED_DIVIDER; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 2186 | // TODO: Need cutout? |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2187 | startDragResizing(mPendingBackDropFrame, |
| 2188 | mWinFrame.equals(mPendingBackDropFrame), mPendingVisibleInsets, |
| 2189 | mPendingStableInsets, mResizeMode); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 2190 | } else { |
| 2191 | // We shouldn't come here, but if we come we should end the resize. |
| 2192 | endDragResizing(); |
| 2193 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2194 | } |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 2195 | if (!mUseMTRenderer) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 2196 | if (dragResizing) { |
| 2197 | mCanvasOffsetX = mWinFrame.left; |
| 2198 | mCanvasOffsetY = mWinFrame.top; |
| 2199 | } else { |
| 2200 | mCanvasOffsetX = mCanvasOffsetY = 0; |
| 2201 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2202 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2203 | } catch (RemoteException e) { |
| 2204 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 2205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | if (DEBUG_ORIENTATION) Log.v( |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2207 | TAG, "Relayout returned: frame=" + frame + ", surface=" + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2208 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2209 | mAttachInfo.mWindowLeft = frame.left; |
| 2210 | mAttachInfo.mWindowTop = frame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | |
| 2212 | // !!FIXME!! This next section handles the case where we did not get the |
| 2213 | // window size we asked for. We should avoid this by getting a maximum size from |
| 2214 | // the window session beforehand. |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 2215 | if (mWidth != frame.width() || mHeight != frame.height()) { |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 2216 | mWidth = frame.width(); |
| 2217 | mHeight = frame.height(); |
| 2218 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2219 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2220 | if (mSurfaceHolder != null) { |
| 2221 | // The app owns the surface; tell it about what is going on. |
| 2222 | if (mSurface.isValid()) { |
| 2223 | // XXX .copyFrom() doesn't work! |
| 2224 | //mSurfaceHolder.mSurface.copyFrom(mSurface); |
| 2225 | mSurfaceHolder.mSurface = mSurface; |
| 2226 | } |
Jeff Brown | 30bc34f | 2011-01-25 12:56:56 -0800 | [diff] [blame] | 2227 | mSurfaceHolder.setSurfaceFrameSize(mWidth, mHeight); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2228 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 2229 | if (mSurface.isValid()) { |
John Reck | 208c47c | 2016-06-09 16:26:21 -0700 | [diff] [blame] | 2230 | if (!hadSurface) { |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2231 | mSurfaceHolder.ungetCallbacks(); |
| 2232 | |
| 2233 | mIsCreating = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2234 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2235 | if (callbacks != null) { |
| 2236 | for (SurfaceHolder.Callback c : callbacks) { |
| 2237 | c.surfaceCreated(mSurfaceHolder); |
| 2238 | } |
| 2239 | } |
| 2240 | surfaceChanged = true; |
| 2241 | } |
John Reck | 208c47c | 2016-06-09 16:26:21 -0700 | [diff] [blame] | 2242 | if (surfaceChanged || surfaceGenerationId != mSurface.getGenerationId()) { |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2243 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2244 | if (callbacks != null) { |
| 2245 | for (SurfaceHolder.Callback c : callbacks) { |
| 2246 | c.surfaceChanged(mSurfaceHolder, lp.format, |
| 2247 | mWidth, mHeight); |
| 2248 | } |
| 2249 | } |
| 2250 | } |
| 2251 | mIsCreating = false; |
| 2252 | } else if (hadSurface) { |
| 2253 | mSurfaceHolder.ungetCallbacks(); |
| 2254 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2255 | if (callbacks != null) { |
| 2256 | for (SurfaceHolder.Callback c : callbacks) { |
| 2257 | c.surfaceDestroyed(mSurfaceHolder); |
| 2258 | } |
| 2259 | } |
| 2260 | mSurfaceHolder.mSurfaceLock.lock(); |
Jozef BABJAK | 93c5b6a | 2011-02-22 09:33:19 +0100 | [diff] [blame] | 2261 | try { |
| 2262 | mSurfaceHolder.mSurface = new Surface(); |
| 2263 | } finally { |
| 2264 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 2265 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2266 | } |
| 2267 | } |
Romain Guy | 53389bd | 2010-09-07 17:16:32 -0700 | [diff] [blame] | 2268 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2269 | final ThreadedRenderer threadedRenderer = mAttachInfo.mThreadedRenderer; |
| 2270 | if (threadedRenderer != null && threadedRenderer.isEnabled()) { |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2271 | if (hwInitialized |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2272 | || mWidth != threadedRenderer.getWidth() |
| 2273 | || mHeight != threadedRenderer.getHeight() |
| 2274 | || mNeedsRendererSetup) { |
| 2275 | threadedRenderer.setup(mWidth, mHeight, mAttachInfo, |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2276 | mWindowAttributes.surfaceInsets); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2277 | mNeedsRendererSetup = false; |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 2278 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2279 | } |
| 2280 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 2281 | if (!mStopped || mReportNextDraw) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2282 | boolean focusChangedDueToTouchMode = ensureTouchModeLocally( |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2283 | (relayoutResult&WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE) != 0); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2284 | if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth() |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 2285 | || mHeight != host.getMeasuredHeight() || contentInsetsChanged || |
Chet Haase | d86fb2c | 2016-05-04 07:26:02 -0700 | [diff] [blame] | 2286 | updatedConfiguration) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2287 | int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width); |
| 2288 | int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2289 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2290 | if (DEBUG_LAYOUT) Log.v(mTag, "Ooops, something changed! mWidth=" |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2291 | + mWidth + " measuredWidth=" + host.getMeasuredWidth() |
| 2292 | + " mHeight=" + mHeight |
| 2293 | + " measuredHeight=" + host.getMeasuredHeight() |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 2294 | + " coveredInsetsChanged=" + contentInsetsChanged); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2295 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2296 | // Ask host how big it wants to be |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2297 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2298 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2299 | // Implementation of weights from WindowManager.LayoutParams |
| 2300 | // We just grow the dimensions as needed and re-measure if |
| 2301 | // needs be |
| 2302 | int width = host.getMeasuredWidth(); |
| 2303 | int height = host.getMeasuredHeight(); |
| 2304 | boolean measureAgain = false; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2305 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2306 | if (lp.horizontalWeight > 0.0f) { |
| 2307 | width += (int) ((mWidth - width) * lp.horizontalWeight); |
| 2308 | childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, |
| 2309 | MeasureSpec.EXACTLY); |
| 2310 | measureAgain = true; |
| 2311 | } |
| 2312 | if (lp.verticalWeight > 0.0f) { |
| 2313 | height += (int) ((mHeight - height) * lp.verticalWeight); |
| 2314 | childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, |
| 2315 | MeasureSpec.EXACTLY); |
| 2316 | measureAgain = true; |
| 2317 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2318 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2319 | if (measureAgain) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2320 | if (DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2321 | "And hey let's measure once more: width=" + width |
| 2322 | + " height=" + height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2323 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2324 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2325 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2326 | layoutRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2327 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | } |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2329 | } else { |
| 2330 | // Not the first pass and no window/insets/visibility change but the window |
| 2331 | // may have moved and we need check that and if so to update the left and right |
| 2332 | // in the attach info. We translate only the window frame since on window move |
| 2333 | // the window manager tells us only for the new frame but the insets are the |
| 2334 | // same and we do not want to translate them more than once. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2335 | maybeHandleWindowMove(frame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2336 | } |
| 2337 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 2338 | final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2339 | boolean triggerGlobalLayoutListener = didLayout |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2340 | || mAttachInfo.mRecomputeGlobalAttributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2341 | if (didLayout) { |
Jorim Jaggi | 26d02d2 | 2016-02-24 18:37:51 -0500 | [diff] [blame] | 2342 | performLayout(lp, mWidth, mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2343 | |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 2344 | // By this point all views have been sized and positioned |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2345 | // We can compute the transparent area |
| 2346 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2347 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | // start out transparent |
| 2349 | // TODO: AVOID THAT CALL BY CACHING THE RESULT? |
| 2350 | host.getLocationInWindow(mTmpLocation); |
| 2351 | mTransparentRegion.set(mTmpLocation[0], mTmpLocation[1], |
| 2352 | mTmpLocation[0] + host.mRight - host.mLeft, |
| 2353 | mTmpLocation[1] + host.mBottom - host.mTop); |
| 2354 | |
| 2355 | host.gatherTransparentRegion(mTransparentRegion); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 2356 | if (mTranslator != null) { |
| 2357 | mTranslator.translateRegionInWindowToScreen(mTransparentRegion); |
| 2358 | } |
| 2359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | if (!mTransparentRegion.equals(mPreviousTransparentRegion)) { |
| 2361 | mPreviousTransparentRegion.set(mTransparentRegion); |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 2362 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2363 | // reconfigure window manager |
| 2364 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2365 | mWindowSession.setTransparentRegion(mWindow, mTransparentRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | } catch (RemoteException e) { |
| 2367 | } |
| 2368 | } |
| 2369 | } |
| 2370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | if (DBG) { |
| 2372 | System.out.println("======================================"); |
Chet Haase | 4610eef | 2015-12-03 07:38:11 -0800 | [diff] [blame] | 2373 | System.out.println("performTraversals -- after setFrame"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | host.debug(); |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | if (triggerGlobalLayoutListener) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2379 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 2380 | mAttachInfo.mTreeObserver.dispatchOnGlobalLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | if (computesInternalInsets) { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2384 | // Clear the original insets. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2385 | final ViewTreeObserver.InternalInsetsInfo insets = mAttachInfo.mGivenInternalInsets; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2386 | insets.reset(); |
| 2387 | |
| 2388 | // Compute new insets in place. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2389 | mAttachInfo.mTreeObserver.dispatchOnComputeInternalInsets(insets); |
| 2390 | mAttachInfo.mHasNonEmptyGivenInternalInsets = !insets.isEmpty(); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2391 | |
| 2392 | // Tell the window manager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | if (insetsPending || !mLastGivenInsets.equals(insets)) { |
| 2394 | mLastGivenInsets.set(insets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2395 | |
| 2396 | // Translate insets to screen coordinates if needed. |
| 2397 | final Rect contentInsets; |
| 2398 | final Rect visibleInsets; |
| 2399 | final Region touchableRegion; |
| 2400 | if (mTranslator != null) { |
| 2401 | contentInsets = mTranslator.getTranslatedContentInsets(insets.contentInsets); |
| 2402 | visibleInsets = mTranslator.getTranslatedVisibleInsets(insets.visibleInsets); |
| 2403 | touchableRegion = mTranslator.getTranslatedTouchableArea(insets.touchableRegion); |
| 2404 | } else { |
| 2405 | contentInsets = insets.contentInsets; |
| 2406 | visibleInsets = insets.visibleInsets; |
| 2407 | touchableRegion = insets.touchableRegion; |
| 2408 | } |
| 2409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2411 | mWindowSession.setInsets(mWindow, insets.mTouchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2412 | contentInsets, visibleInsets, touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2413 | } catch (RemoteException e) { |
| 2414 | } |
| 2415 | } |
| 2416 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2417 | |
Evan Rosky | adf5bec | 2017-10-19 10:24:07 -0700 | [diff] [blame] | 2418 | if (mFirst) { |
Evan Rosky | bdc66cb | 2017-09-08 14:27:24 -0700 | [diff] [blame] | 2419 | if (sAlwaysAssignFocus || !isInTouchMode()) { |
Evan Rosky | adf5bec | 2017-10-19 10:24:07 -0700 | [diff] [blame] | 2420 | // handle first focus request |
| 2421 | if (DEBUG_INPUT_RESIZE) { |
| 2422 | Log.v(mTag, "First: mView.hasFocus()=" + mView.hasFocus()); |
| 2423 | } |
| 2424 | if (mView != null) { |
| 2425 | if (!mView.hasFocus()) { |
| 2426 | mView.restoreDefaultFocus(); |
| 2427 | if (DEBUG_INPUT_RESIZE) { |
| 2428 | Log.v(mTag, "First: requested focused view=" + mView.findFocus()); |
| 2429 | } |
| 2430 | } else { |
| 2431 | if (DEBUG_INPUT_RESIZE) { |
| 2432 | Log.v(mTag, "First: existing focused view=" + mView.findFocus()); |
| 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | } else { |
| 2437 | // Some views (like ScrollView) won't hand focus to descendants that aren't within |
| 2438 | // their viewport. Before layout, there's a good change these views are size 0 |
| 2439 | // which means no children can get focus. After layout, this view now has size, but |
| 2440 | // is not guaranteed to hand-off focus to a focusable child (specifically, the edge- |
| 2441 | // case where the child has a size prior to layout and thus won't trigger |
| 2442 | // focusableViewAvailable). |
| 2443 | View focused = mView.findFocus(); |
| 2444 | if (focused instanceof ViewGroup |
| 2445 | && ((ViewGroup) focused).getDescendantFocusability() |
| 2446 | == ViewGroup.FOCUS_AFTER_DESCENDANTS) { |
| 2447 | focused.restoreDefaultFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | } |
| 2449 | } |
| 2450 | } |
| 2451 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2452 | final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible; |
| 2453 | final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible; |
| 2454 | final boolean regainedFocus = hasWindowFocus && mLostWindowFocus; |
| 2455 | if (regainedFocus) { |
| 2456 | mLostWindowFocus = false; |
| 2457 | } else if (!hasWindowFocus && mHadWindowFocus) { |
| 2458 | mLostWindowFocus = true; |
| 2459 | } |
| 2460 | |
| 2461 | if (changedVisibility || regainedFocus) { |
Phil Weaver | 532c799 | 2016-08-29 15:59:03 -0700 | [diff] [blame] | 2462 | // Toasts are presented as notifications - don't present them as windows as well |
| 2463 | boolean isToast = (mWindowAttributes == null) ? false |
| 2464 | : (mWindowAttributes.type == WindowManager.LayoutParams.TYPE_TOAST); |
| 2465 | if (!isToast) { |
| 2466 | host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2467 | } |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2468 | } |
| 2469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2470 | mFirst = false; |
| 2471 | mWillDrawSoon = false; |
| 2472 | mNewSurfaceNeeded = false; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2473 | mActivityRelaunched = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2474 | mViewVisibility = viewVisibility; |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2475 | mHadWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2476 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2477 | if (hasWindowFocus && !isInLocalFocusMode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | final boolean imTarget = WindowManager.LayoutParams |
| 2479 | .mayUseInputMethod(mWindowAttributes.flags); |
| 2480 | if (imTarget != mLastWasImTarget) { |
| 2481 | mLastWasImTarget = imTarget; |
| 2482 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 2483 | if (imm != null && imTarget) { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2484 | imm.onPreWindowFocus(mView, hasWindowFocus); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 2485 | imm.onPostWindowFocus(mView, mView.findFocus(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | mWindowAttributes.softInputMode, |
| 2487 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 2488 | } |
| 2489 | } |
| 2490 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2491 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2492 | // Remember if we must report the next draw. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2493 | if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 2494 | reportNextDraw(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2495 | } |
| 2496 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2497 | boolean cancelDraw = mAttachInfo.mTreeObserver.dispatchOnPreDraw() || !isViewVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2498 | |
Jorim Jaggi | 75c21ca | 2016-03-28 19:26:09 -0400 | [diff] [blame] | 2499 | if (!cancelDraw && !newSurface) { |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2500 | if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
| 2501 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2502 | mPendingTransitions.get(i).startChangingAnimations(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2503 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2504 | mPendingTransitions.clear(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2505 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2506 | |
| 2507 | performDraw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2508 | } else { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2509 | if (isViewVisible) { |
Chris Wren | 78cb7cf | 2012-05-15 12:36:44 -0400 | [diff] [blame] | 2510 | // Try again |
| 2511 | scheduleTraversals(); |
| 2512 | } else if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2513 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2514 | mPendingTransitions.get(i).endChangingAnimations(); |
| 2515 | } |
| 2516 | mPendingTransitions.clear(); |
| 2517 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2518 | } |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 2519 | |
| 2520 | mIsInTraversal = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2521 | } |
| 2522 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2523 | private void maybeHandleWindowMove(Rect frame) { |
| 2524 | |
| 2525 | // TODO: Well, we are checking whether the frame has changed similarly |
| 2526 | // to how this is done for the insets. This is however incorrect since |
| 2527 | // the insets and the frame are translated. For example, the old frame |
| 2528 | // was (1, 1 - 1, 1) and was translated to say (2, 2 - 2, 2), now the new |
| 2529 | // reported frame is (2, 2 - 2, 2) which implies no change but this is not |
| 2530 | // true since we are comparing a not translated value to a translated one. |
| 2531 | // This scenario is rare but we may want to fix that. |
| 2532 | |
| 2533 | final boolean windowMoved = mAttachInfo.mWindowLeft != frame.left |
| 2534 | || mAttachInfo.mWindowTop != frame.top; |
| 2535 | if (windowMoved) { |
| 2536 | if (mTranslator != null) { |
| 2537 | mTranslator.translateRectInScreenToAppWinFrame(frame); |
| 2538 | } |
| 2539 | mAttachInfo.mWindowLeft = frame.left; |
| 2540 | mAttachInfo.mWindowTop = frame.top; |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 2541 | } |
| 2542 | if (windowMoved || mAttachInfo.mNeedsUpdateLightCenter) { |
| 2543 | // Update the light position for the new offsets. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2544 | if (mAttachInfo.mThreadedRenderer != null) { |
| 2545 | mAttachInfo.mThreadedRenderer.setLightCenter(mAttachInfo); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2546 | } |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 2547 | mAttachInfo.mNeedsUpdateLightCenter = false; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2548 | } |
| 2549 | } |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 2550 | |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 2551 | private void handleWindowFocusChanged() { |
| 2552 | final boolean hasWindowFocus; |
| 2553 | final boolean inTouchMode; |
| 2554 | synchronized (this) { |
Dianne Hackborn | 011944c | 2017-12-15 15:44:55 -0800 | [diff] [blame] | 2555 | if (!mWindowFocusChanged) { |
| 2556 | return; |
| 2557 | } |
| 2558 | mWindowFocusChanged = false; |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 2559 | hasWindowFocus = mUpcomingWindowFocus; |
| 2560 | inTouchMode = mUpcomingInTouchMode; |
| 2561 | } |
| 2562 | |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 2563 | if (mAdded) { |
| 2564 | profileRendering(hasWindowFocus); |
| 2565 | |
| 2566 | if (hasWindowFocus) { |
| 2567 | ensureTouchModeLocally(inTouchMode); |
| 2568 | if (mAttachInfo.mThreadedRenderer != null && mSurface.isValid()) { |
| 2569 | mFullRedrawNeeded = true; |
| 2570 | try { |
| 2571 | final WindowManager.LayoutParams lp = mWindowAttributes; |
| 2572 | final Rect surfaceInsets = lp != null ? lp.surfaceInsets : null; |
| 2573 | mAttachInfo.mThreadedRenderer.initializeIfNeeded( |
| 2574 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
| 2575 | } catch (OutOfResourcesException e) { |
| 2576 | Log.e(mTag, "OutOfResourcesException locking surface", e); |
| 2577 | try { |
| 2578 | if (!mWindowSession.outOfMemory(mWindow)) { |
| 2579 | Slog.w(mTag, "No processes killed for memory;" |
| 2580 | + " killing self"); |
| 2581 | Process.killProcess(Process.myPid()); |
| 2582 | } |
| 2583 | } catch (RemoteException ex) { |
| 2584 | } |
| 2585 | // Retry in a bit. |
| 2586 | mHandler.sendMessageDelayed(mHandler.obtainMessage( |
| 2587 | MSG_WINDOW_FOCUS_CHANGED), 500); |
| 2588 | return; |
| 2589 | } |
| 2590 | } |
| 2591 | } |
| 2592 | |
| 2593 | mAttachInfo.mHasWindowFocus = hasWindowFocus; |
| 2594 | |
| 2595 | mLastWasImTarget = WindowManager.LayoutParams |
| 2596 | .mayUseInputMethod(mWindowAttributes.flags); |
| 2597 | |
| 2598 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 2599 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
| 2600 | imm.onPreWindowFocus(mView, hasWindowFocus); |
| 2601 | } |
| 2602 | if (mView != null) { |
| 2603 | mAttachInfo.mKeyDispatchState.reset(); |
| 2604 | mView.dispatchWindowFocusChanged(hasWindowFocus); |
| 2605 | mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus); |
| 2606 | |
| 2607 | if (mAttachInfo.mTooltipHost != null) { |
| 2608 | mAttachInfo.mTooltipHost.hideTooltip(); |
| 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | // Note: must be done after the focus change callbacks, |
| 2613 | // so all of the view state is set up correctly. |
| 2614 | if (hasWindowFocus) { |
| 2615 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
| 2616 | imm.onPostWindowFocus(mView, mView.findFocus(), |
| 2617 | mWindowAttributes.softInputMode, |
| 2618 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 2619 | } |
| 2620 | // Clear the forward bit. We can just do this directly, since |
| 2621 | // the window manager doesn't care about it. |
| 2622 | mWindowAttributes.softInputMode &= |
| 2623 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
| 2624 | ((WindowManager.LayoutParams) mView.getLayoutParams()) |
| 2625 | .softInputMode &= |
| 2626 | ~WindowManager.LayoutParams |
| 2627 | .SOFT_INPUT_IS_FORWARD_NAVIGATION; |
| 2628 | mHasHadWindowFocus = true; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 2629 | |
| 2630 | // Refocusing a window that has a focused view should fire a |
| 2631 | // focus event for the view since the global focused view changed. |
| 2632 | fireAccessibilityFocusEventIfHasFocusedNode(); |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 2633 | } else { |
| 2634 | if (mPointerCapture) { |
| 2635 | handlePointerCaptureChanged(false); |
| 2636 | } |
| 2637 | } |
| 2638 | } |
| 2639 | mFirstInputStage.onWindowFocusChanged(hasWindowFocus); |
| 2640 | } |
| 2641 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 2642 | private void fireAccessibilityFocusEventIfHasFocusedNode() { |
| 2643 | if (!AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 2644 | return; |
| 2645 | } |
| 2646 | final View focusedView = mView.findFocus(); |
| 2647 | if (focusedView == null) { |
| 2648 | return; |
| 2649 | } |
| 2650 | final AccessibilityNodeProvider provider = focusedView.getAccessibilityNodeProvider(); |
| 2651 | if (provider == null) { |
| 2652 | focusedView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 2653 | } else { |
| 2654 | final AccessibilityNodeInfo focusedNode = findFocusedVirtualNode(provider); |
| 2655 | if (focusedNode != null) { |
| 2656 | final int virtualId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 2657 | focusedNode.getSourceNodeId()); |
| 2658 | // This is a best effort since clearing and setting the focus via the |
| 2659 | // provider APIs could have side effects. We don't have a provider API |
| 2660 | // similar to that on View to ask a given event to be fired. |
| 2661 | final AccessibilityEvent event = AccessibilityEvent.obtain( |
| 2662 | AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 2663 | event.setSource(focusedView, virtualId); |
| 2664 | event.setPackageName(focusedNode.getPackageName()); |
| 2665 | event.setChecked(focusedNode.isChecked()); |
| 2666 | event.setContentDescription(focusedNode.getContentDescription()); |
| 2667 | event.setPassword(focusedNode.isPassword()); |
| 2668 | event.getText().add(focusedNode.getText()); |
| 2669 | event.setEnabled(focusedNode.isEnabled()); |
| 2670 | focusedView.getParent().requestSendAccessibilityEvent(focusedView, event); |
| 2671 | focusedNode.recycle(); |
| 2672 | } |
| 2673 | } |
| 2674 | } |
| 2675 | |
| 2676 | private AccessibilityNodeInfo findFocusedVirtualNode(AccessibilityNodeProvider provider) { |
| 2677 | AccessibilityNodeInfo focusedNode = provider.findFocus( |
| 2678 | AccessibilityNodeInfo.FOCUS_INPUT); |
| 2679 | if (focusedNode != null) { |
| 2680 | return focusedNode; |
| 2681 | } |
| 2682 | |
| 2683 | if (!mContext.isAutofillCompatibilityEnabled()) { |
| 2684 | return null; |
| 2685 | } |
| 2686 | |
| 2687 | // Unfortunately some provider implementations don't properly |
| 2688 | // implement AccessibilityNodeProvider#findFocus |
| 2689 | AccessibilityNodeInfo current = provider.createAccessibilityNodeInfo( |
| 2690 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 2691 | if (current.isFocused()) { |
| 2692 | return current; |
| 2693 | } |
| 2694 | |
| 2695 | final Queue<AccessibilityNodeInfo> fringe = new LinkedList<>(); |
| 2696 | fringe.offer(current); |
| 2697 | |
| 2698 | while (!fringe.isEmpty()) { |
| 2699 | current = fringe.poll(); |
| 2700 | final LongArray childNodeIds = current.getChildNodeIds(); |
| 2701 | if (childNodeIds== null || childNodeIds.size() <= 0) { |
| 2702 | continue; |
| 2703 | } |
| 2704 | final int childCount = childNodeIds.size(); |
| 2705 | for (int i = 0; i < childCount; i++) { |
| 2706 | final int virtualId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 2707 | childNodeIds.get(i)); |
| 2708 | final AccessibilityNodeInfo child = provider.createAccessibilityNodeInfo(virtualId); |
| 2709 | if (child != null) { |
| 2710 | if (child.isFocused()) { |
| 2711 | return child; |
| 2712 | } |
| 2713 | fringe.offer(child); |
| 2714 | } |
| 2715 | } |
| 2716 | current.recycle(); |
| 2717 | } |
| 2718 | |
| 2719 | return null; |
| 2720 | } |
| 2721 | |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2722 | private void handleOutOfResourcesException(Surface.OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2723 | Log.e(mTag, "OutOfResourcesException initializing HW surface", e); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2724 | try { |
| 2725 | if (!mWindowSession.outOfMemory(mWindow) && |
| 2726 | Process.myUid() != Process.SYSTEM_UID) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2727 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2728 | Process.killProcess(Process.myPid()); |
| 2729 | } |
| 2730 | } catch (RemoteException ex) { |
| 2731 | } |
| 2732 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2733 | } |
| 2734 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2735 | private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) { |
Robert Carr | 001e55a | 2017-05-15 17:21:38 -0700 | [diff] [blame] | 2736 | if (mView == null) { |
| 2737 | return; |
| 2738 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2739 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "measure"); |
| 2740 | try { |
| 2741 | mView.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 2742 | } finally { |
| 2743 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2744 | } |
| 2745 | } |
| 2746 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2747 | /** |
| 2748 | * Called by {@link android.view.View#isInLayout()} to determine whether the view hierarchy |
| 2749 | * is currently undergoing a layout pass. |
| 2750 | * |
| 2751 | * @return whether the view hierarchy is currently undergoing a layout pass |
| 2752 | */ |
| 2753 | boolean isInLayout() { |
| 2754 | return mInLayout; |
| 2755 | } |
| 2756 | |
| 2757 | /** |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2758 | * Called by {@link android.view.View#requestLayout()} if the view hierarchy is currently |
| 2759 | * undergoing a layout pass. requestLayout() should not generally be called during layout, |
| 2760 | * unless the container hierarchy knows what it is doing (i.e., it is fine as long as |
| 2761 | * all children in that container hierarchy are measured and laid out at the end of the layout |
| 2762 | * pass for that container). If requestLayout() is called anyway, we handle it correctly |
| 2763 | * by registering all requesters during a frame as it proceeds. At the end of the frame, |
| 2764 | * we check all of those views to see if any still have pending layout requests, which |
| 2765 | * indicates that they were not correctly handled by their container hierarchy. If that is |
| 2766 | * the case, we clear all such flags in the tree, to remove the buggy flag state that leads |
| 2767 | * to blank containers, and force a second request/measure/layout pass in this frame. If |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2768 | * more requestLayout() calls are received during that second layout pass, we post those |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2769 | * requests to the next frame to avoid possible infinite loops. |
| 2770 | * |
| 2771 | * <p>The return value from this method indicates whether the request should proceed |
| 2772 | * (if it is a request during the first layout pass) or should be skipped and posted to the |
| 2773 | * next frame (if it is a request during the second layout pass).</p> |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2774 | * |
| 2775 | * @param view the view that requested the layout. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2776 | * |
| 2777 | * @return true if request should proceed, false otherwise. |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2778 | */ |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2779 | boolean requestLayoutDuringLayout(final View view) { |
| 2780 | if (view.mParent == null || view.mAttachInfo == null) { |
| 2781 | // Would not normally trigger another layout, so just let it pass through as usual |
| 2782 | return true; |
| 2783 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2784 | if (!mLayoutRequesters.contains(view)) { |
| 2785 | mLayoutRequesters.add(view); |
| 2786 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2787 | if (!mHandlingLayoutInLayoutRequest) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2788 | // Let the request proceed normally; it will be processed in a second layout pass |
| 2789 | // if necessary |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2790 | return true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2791 | } else { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2792 | // Don't let the request proceed during the second layout pass. |
| 2793 | // It will post to the next frame instead. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2794 | return false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2795 | } |
| 2796 | } |
| 2797 | |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 2798 | private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth, |
| 2799 | int desiredWindowHeight) { |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2800 | mLayoutRequested = false; |
| 2801 | mScrollMayChange = true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2802 | mInLayout = true; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2803 | |
| 2804 | final View host = mView; |
Robert Carr | 32f37ab | 2017-06-15 12:39:34 -0700 | [diff] [blame] | 2805 | if (host == null) { |
| 2806 | return; |
| 2807 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2808 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2809 | Log.v(mTag, "Laying out " + host + " to (" + |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2810 | host.getMeasuredWidth() + ", " + host.getMeasuredHeight() + ")"); |
| 2811 | } |
| 2812 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2813 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "layout"); |
| 2814 | try { |
| 2815 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2816 | |
Chet Haase | d5a8352 | 2012-11-21 16:24:44 -0800 | [diff] [blame] | 2817 | mInLayout = false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2818 | int numViewsRequestingLayout = mLayoutRequesters.size(); |
| 2819 | if (numViewsRequestingLayout > 0) { |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2820 | // requestLayout() was called during layout. |
| 2821 | // If no layout-request flags are set on the requesting views, there is no problem. |
| 2822 | // If some requests are still pending, then we need to clear those flags and do |
| 2823 | // a full request/measure/layout pass to handle this situation. |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2824 | ArrayList<View> validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, |
| 2825 | false); |
| 2826 | if (validLayoutRequesters != null) { |
| 2827 | // Set this flag to indicate that any further requests are happening during |
| 2828 | // the second pass, which may result in posting those requests to the next |
| 2829 | // frame instead |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2830 | mHandlingLayoutInLayoutRequest = true; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2831 | |
| 2832 | // Process fresh layout requests, then measure and layout |
| 2833 | int numValidRequests = validLayoutRequesters.size(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2834 | for (int i = 0; i < numValidRequests; ++i) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2835 | final View view = validLayoutRequesters.get(i); |
| 2836 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2837 | " during layout: running second layout pass"); |
| 2838 | view.requestLayout(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2839 | } |
| 2840 | measureHierarchy(host, lp, mView.getContext().getResources(), |
| 2841 | desiredWindowWidth, desiredWindowHeight); |
| 2842 | mInLayout = true; |
| 2843 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2844 | |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2845 | mHandlingLayoutInLayoutRequest = false; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2846 | |
| 2847 | // Check the valid requests again, this time without checking/clearing the |
| 2848 | // layout flags, since requests happening during the second pass get noop'd |
| 2849 | validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, true); |
| 2850 | if (validLayoutRequesters != null) { |
| 2851 | final ArrayList<View> finalRequesters = validLayoutRequesters; |
| 2852 | // Post second-pass requests to the next frame |
| 2853 | getRunQueue().post(new Runnable() { |
| 2854 | @Override |
| 2855 | public void run() { |
| 2856 | int numValidRequests = finalRequesters.size(); |
| 2857 | for (int i = 0; i < numValidRequests; ++i) { |
| 2858 | final View view = finalRequesters.get(i); |
| 2859 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2860 | " during second layout pass: posting in next frame"); |
| 2861 | view.requestLayout(); |
| 2862 | } |
| 2863 | } |
| 2864 | }); |
| 2865 | } |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2866 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2867 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2868 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2869 | } finally { |
| 2870 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2871 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2872 | mInLayout = false; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2873 | } |
| 2874 | |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2875 | /** |
| 2876 | * This method is called during layout when there have been calls to requestLayout() during |
| 2877 | * layout. It walks through the list of views that requested layout to determine which ones |
| 2878 | * still need it, based on visibility in the hierarchy and whether they have already been |
| 2879 | * handled (as is usually the case with ListView children). |
| 2880 | * |
| 2881 | * @param layoutRequesters The list of views that requested layout during layout |
| 2882 | * @param secondLayoutRequests Whether the requests were issued during the second layout pass. |
| 2883 | * If so, the FORCE_LAYOUT flag was not set on requesters. |
| 2884 | * @return A list of the actual views that still need to be laid out. |
| 2885 | */ |
| 2886 | private ArrayList<View> getValidLayoutRequesters(ArrayList<View> layoutRequesters, |
| 2887 | boolean secondLayoutRequests) { |
| 2888 | |
| 2889 | int numViewsRequestingLayout = layoutRequesters.size(); |
| 2890 | ArrayList<View> validLayoutRequesters = null; |
| 2891 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2892 | View view = layoutRequesters.get(i); |
| 2893 | if (view != null && view.mAttachInfo != null && view.mParent != null && |
| 2894 | (secondLayoutRequests || (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) == |
| 2895 | View.PFLAG_FORCE_LAYOUT)) { |
| 2896 | boolean gone = false; |
| 2897 | View parent = view; |
| 2898 | // Only trigger new requests for views in a non-GONE hierarchy |
| 2899 | while (parent != null) { |
| 2900 | if ((parent.mViewFlags & View.VISIBILITY_MASK) == View.GONE) { |
| 2901 | gone = true; |
| 2902 | break; |
| 2903 | } |
| 2904 | if (parent.mParent instanceof View) { |
| 2905 | parent = (View) parent.mParent; |
| 2906 | } else { |
| 2907 | parent = null; |
| 2908 | } |
| 2909 | } |
| 2910 | if (!gone) { |
| 2911 | if (validLayoutRequesters == null) { |
| 2912 | validLayoutRequesters = new ArrayList<View>(); |
| 2913 | } |
| 2914 | validLayoutRequesters.add(view); |
| 2915 | } |
| 2916 | } |
| 2917 | } |
| 2918 | if (!secondLayoutRequests) { |
| 2919 | // If we're checking the layout flags, then we need to clean them up also |
| 2920 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2921 | View view = layoutRequesters.get(i); |
| 2922 | while (view != null && |
| 2923 | (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) != 0) { |
| 2924 | view.mPrivateFlags &= ~View.PFLAG_FORCE_LAYOUT; |
| 2925 | if (view.mParent instanceof View) { |
| 2926 | view = (View) view.mParent; |
| 2927 | } else { |
| 2928 | view = null; |
| 2929 | } |
| 2930 | } |
| 2931 | } |
| 2932 | } |
| 2933 | layoutRequesters.clear(); |
| 2934 | return validLayoutRequesters; |
| 2935 | } |
| 2936 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2937 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | public void requestTransparentRegion(View child) { |
| 2939 | // the test below should not fail unless someone is messing with us |
| 2940 | checkThread(); |
| 2941 | if (mView == child) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2942 | mView.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | // Need to make sure we re-evaluate the window attributes next |
| 2944 | // time around, to ensure the window has the correct format. |
| 2945 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 2946 | mWindowAttributesChangesFlag = 0; |
Mathias Agopian | 1bd80ad | 2010-11-04 17:13:39 -0700 | [diff] [blame] | 2947 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | /** |
| 2952 | * Figures out the measure spec for the root view in a window based on it's |
| 2953 | * layout params. |
| 2954 | * |
| 2955 | * @param windowSize |
| 2956 | * The available width or height of the window |
| 2957 | * |
| 2958 | * @param rootDimension |
| 2959 | * The layout params for one dimension (width or height) of the |
| 2960 | * window. |
| 2961 | * |
| 2962 | * @return The measure spec to use to measure the root view. |
| 2963 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 2964 | private static int getRootMeasureSpec(int windowSize, int rootDimension) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | int measureSpec; |
| 2966 | switch (rootDimension) { |
| 2967 | |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 2968 | case ViewGroup.LayoutParams.MATCH_PARENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | // Window can't resize. Force root view to be windowSize. |
| 2970 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY); |
| 2971 | break; |
| 2972 | case ViewGroup.LayoutParams.WRAP_CONTENT: |
| 2973 | // Window can resize. Set max size for root view. |
| 2974 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST); |
| 2975 | break; |
| 2976 | default: |
| 2977 | // Window wants to be an exact size. Force root view to be that size. |
| 2978 | measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY); |
| 2979 | break; |
| 2980 | } |
| 2981 | return measureSpec; |
| 2982 | } |
| 2983 | |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2984 | int mHardwareXOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2985 | int mHardwareYOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2986 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2987 | @Override |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2988 | public void onPreDraw(DisplayListCanvas canvas) { |
John Reck | 3e04f09 | 2017-06-02 15:50:09 -0700 | [diff] [blame] | 2989 | // If mCurScrollY is not 0 then this influences the hardwareYOffset. The end result is we |
| 2990 | // can apply offsets that are not handled by anything else, resulting in underdraw as |
| 2991 | // the View is shifted (thus shifting the window background) exposing unpainted |
| 2992 | // content. To handle this with minimal glitches we just clear to BLACK if the window |
| 2993 | // is opaque. If it's not opaque then HWUI already internally does a glClear to |
| 2994 | // transparent, so there's no risk of underdraw on non-opaque surfaces. |
| 2995 | if (mCurScrollY != 0 && mHardwareYOffset != 0 && mAttachInfo.mThreadedRenderer.isOpaque()) { |
| 2996 | canvas.drawColor(Color.BLACK); |
| 2997 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2998 | canvas.translate(-mHardwareXOffset, -mHardwareYOffset); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2999 | } |
| 3000 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3001 | @Override |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3002 | public void onPostDraw(DisplayListCanvas canvas) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3003 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3004 | if (mUseMTRenderer) { |
| 3005 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 3006 | mWindowCallbacks.get(i).onPostDraw(canvas); |
| 3007 | } |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 3008 | } |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3009 | } |
| 3010 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 3011 | /** |
| 3012 | * @hide |
| 3013 | */ |
| 3014 | void outputDisplayList(View view) { |
Chris Craik | 356b5fe | 2015-07-07 10:39:36 -0700 | [diff] [blame] | 3015 | view.mRenderNode.output(); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3016 | if (mAttachInfo.mThreadedRenderer != null) { |
John Reck | 3e04f09 | 2017-06-02 15:50:09 -0700 | [diff] [blame] | 3017 | mAttachInfo.mThreadedRenderer.serializeDisplayListTree(); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 3018 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | /** |
| 3022 | * @see #PROPERTY_PROFILE_RENDERING |
| 3023 | */ |
| 3024 | private void profileRendering(boolean enabled) { |
| 3025 | if (mProfileRendering) { |
| 3026 | mRenderProfilingEnabled = enabled; |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 3027 | |
| 3028 | if (mRenderProfiler != null) { |
| 3029 | mChoreographer.removeFrameCallback(mRenderProfiler); |
| 3030 | } |
| 3031 | if (mRenderProfilingEnabled) { |
| 3032 | if (mRenderProfiler == null) { |
| 3033 | mRenderProfiler = new Choreographer.FrameCallback() { |
| 3034 | @Override |
| 3035 | public void doFrame(long frameTimeNanos) { |
| 3036 | mDirty.set(0, 0, mWidth, mHeight); |
| 3037 | scheduleTraversals(); |
| 3038 | if (mRenderProfilingEnabled) { |
| 3039 | mChoreographer.postFrameCallback(mRenderProfiler); |
| 3040 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3041 | } |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 3042 | }; |
| 3043 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 3044 | mChoreographer.postFrameCallback(mRenderProfiler); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3045 | } else { |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3046 | mRenderProfiler = null; |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 3047 | } |
| 3048 | } |
| 3049 | } |
| 3050 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 3051 | /** |
| 3052 | * Called from draw() when DEBUG_FPS is enabled |
| 3053 | */ |
| 3054 | private void trackFPS() { |
| 3055 | // Tracks frames per second drawn. First value in a series of draws may be bogus |
| 3056 | // because it down not account for the intervening idle time |
| 3057 | long nowTime = System.currentTimeMillis(); |
| 3058 | if (mFpsStartTime < 0) { |
| 3059 | mFpsStartTime = mFpsPrevTime = nowTime; |
| 3060 | mFpsNumFrames = 0; |
| 3061 | } else { |
| 3062 | ++mFpsNumFrames; |
| 3063 | String thisHash = Integer.toHexString(System.identityHashCode(this)); |
| 3064 | long frameTime = nowTime - mFpsPrevTime; |
| 3065 | long totalTime = nowTime - mFpsStartTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3066 | Log.v(mTag, "0x" + thisHash + "\tFrame time:\t" + frameTime); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 3067 | mFpsPrevTime = nowTime; |
| 3068 | if (totalTime > 1000) { |
| 3069 | float fps = (float) mFpsNumFrames * 1000 / totalTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3070 | Log.v(mTag, "0x" + thisHash + "\tFPS:\t" + fps); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 3071 | mFpsStartTime = nowTime; |
| 3072 | mFpsNumFrames = 0; |
| 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3077 | /** |
| 3078 | * A count of the number of calls to pendingDrawFinished we |
| 3079 | * require to notify the WM drawing is complete. |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3080 | */ |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 3081 | int mDrawsNeededToReport = 0; |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3082 | |
| 3083 | /** |
| 3084 | * Delay notifying WM of draw finished until |
| 3085 | * a balanced call to pendingDrawFinished. |
| 3086 | */ |
| 3087 | void drawPending() { |
| 3088 | mDrawsNeededToReport++; |
| 3089 | } |
| 3090 | |
| 3091 | void pendingDrawFinished() { |
| 3092 | if (mDrawsNeededToReport == 0) { |
| 3093 | throw new RuntimeException("Unbalanced drawPending/pendingDrawFinished calls"); |
| 3094 | } |
| 3095 | mDrawsNeededToReport--; |
| 3096 | if (mDrawsNeededToReport == 0) { |
| 3097 | reportDrawFinished(); |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | private void postDrawFinished() { |
| 3102 | mHandler.sendEmptyMessage(MSG_DRAW_FINISHED); |
| 3103 | } |
| 3104 | |
| 3105 | private void reportDrawFinished() { |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 3106 | try { |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 3107 | mDrawsNeededToReport = 0; |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 3108 | mWindowSession.finishDrawing(mWindow); |
| 3109 | } catch (RemoteException e) { |
| 3110 | // Have fun! |
| 3111 | } |
| 3112 | } |
| 3113 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3114 | private void performDraw() { |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 3115 | if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) { |
Craig Mautner | 006f0e4 | 2012-03-21 11:00:32 -0700 | [diff] [blame] | 3116 | return; |
Robert Carr | 32f37ab | 2017-06-15 12:39:34 -0700 | [diff] [blame] | 3117 | } else if (mView == null) { |
| 3118 | return; |
Craig Mautner | 006f0e4 | 2012-03-21 11:00:32 -0700 | [diff] [blame] | 3119 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 3120 | |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3121 | final boolean fullRedrawNeeded = mFullRedrawNeeded || mReportNextDraw; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3122 | mFullRedrawNeeded = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3123 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 3124 | mIsDrawing = true; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3125 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "draw"); |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3126 | |
| 3127 | boolean usingAsyncReport = false; |
| 3128 | if (mReportNextDraw && mAttachInfo.mThreadedRenderer != null |
| 3129 | && mAttachInfo.mThreadedRenderer.isEnabled()) { |
| 3130 | usingAsyncReport = true; |
| 3131 | mAttachInfo.mThreadedRenderer.setFrameCompleteCallback((long frameNr) -> { |
| 3132 | // TODO: Use the frame number |
| 3133 | pendingDrawFinished(); |
| 3134 | }); |
| 3135 | } |
| 3136 | |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3137 | try { |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3138 | boolean canUseAsync = draw(fullRedrawNeeded); |
| 3139 | if (usingAsyncReport && !canUseAsync) { |
| 3140 | mAttachInfo.mThreadedRenderer.setFrameCompleteCallback(null); |
| 3141 | usingAsyncReport = false; |
| 3142 | } |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3143 | } finally { |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 3144 | mIsDrawing = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3145 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 3146 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3147 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 3148 | // For whatever reason we didn't create a HardwareRenderer, end any |
| 3149 | // hardware animations that are now dangling |
| 3150 | if (mAttachInfo.mPendingAnimatingRenderNodes != null) { |
| 3151 | final int count = mAttachInfo.mPendingAnimatingRenderNodes.size(); |
| 3152 | for (int i = 0; i < count; i++) { |
| 3153 | mAttachInfo.mPendingAnimatingRenderNodes.get(i).endAllAnimators(); |
| 3154 | } |
| 3155 | mAttachInfo.mPendingAnimatingRenderNodes.clear(); |
| 3156 | } |
| 3157 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3158 | if (mReportNextDraw) { |
| 3159 | mReportNextDraw = false; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 3160 | |
| 3161 | // if we're using multi-thread renderer, wait for the window frame draws |
| 3162 | if (mWindowDrawCountDown != null) { |
| 3163 | try { |
| 3164 | mWindowDrawCountDown.await(); |
| 3165 | } catch (InterruptedException e) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 3166 | Log.e(mTag, "Window redraw count down interrupted!"); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 3167 | } |
| 3168 | mWindowDrawCountDown = null; |
| 3169 | } |
| 3170 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3171 | if (mAttachInfo.mThreadedRenderer != null) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3172 | mAttachInfo.mThreadedRenderer.setStopped(mStopped); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 3173 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3174 | |
| 3175 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3176 | Log.v(mTag, "FINISHED DRAWING: " + mWindowAttributes.getTitle()); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3177 | } |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 3178 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3179 | if (mSurfaceHolder != null && mSurface.isValid()) { |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3180 | SurfaceCallbackHelper sch = new SurfaceCallbackHelper(this::postDrawFinished); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3181 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 3182 | |
| 3183 | sch.dispatchSurfaceRedrawNeededAsync(mSurfaceHolder, callbacks); |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3184 | } else if (!usingAsyncReport) { |
| 3185 | if (mAttachInfo.mThreadedRenderer != null) { |
| 3186 | mAttachInfo.mThreadedRenderer.fence(); |
| 3187 | } |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3188 | pendingDrawFinished(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3189 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3193 | private boolean draw(boolean fullRedrawNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | Surface surface = mSurface; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3195 | if (!surface.isValid()) { |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3196 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | } |
| 3198 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 3199 | if (DEBUG_FPS) { |
| 3200 | trackFPS(); |
| 3201 | } |
| 3202 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3203 | if (!sFirstDrawComplete) { |
| 3204 | synchronized (sFirstDrawHandlers) { |
| 3205 | sFirstDrawComplete = true; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3206 | final int count = sFirstDrawHandlers.size(); |
| 3207 | for (int i = 0; i< count; i++) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3208 | mHandler.post(sFirstDrawHandlers.get(i)); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3209 | } |
| 3210 | } |
| 3211 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | scrollToRectOrFocus(null, false); |
| 3214 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3215 | if (mAttachInfo.mViewScrollChanged) { |
| 3216 | mAttachInfo.mViewScrollChanged = false; |
| 3217 | mAttachInfo.mTreeObserver.dispatchOnScrollChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3218 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3219 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3220 | boolean animating = mScroller != null && mScroller.computeScrollOffset(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3221 | final int curScrollY; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3222 | if (animating) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3223 | curScrollY = mScroller.getCurrY(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3224 | } else { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3225 | curScrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3226 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3227 | if (mCurScrollY != curScrollY) { |
| 3228 | mCurScrollY = curScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3229 | fullRedrawNeeded = true; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 3230 | if (mView instanceof RootViewSurfaceTaker) { |
| 3231 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 3232 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3234 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3235 | final float appScale = mAttachInfo.mApplicationScale; |
| 3236 | final boolean scalingRequired = mAttachInfo.mScalingRequired; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3238 | final Rect dirty = mDirty; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 3239 | if (mSurfaceHolder != null) { |
| 3240 | // The app owns the surface, we won't draw. |
| 3241 | dirty.setEmpty(); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 3242 | if (animating && mScroller != null) { |
| 3243 | mScroller.abortAnimation(); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3244 | } |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3245 | return false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 3246 | } |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 3247 | |
| 3248 | if (fullRedrawNeeded) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3249 | mAttachInfo.mIgnoreDirtyState = true; |
Romain Guy | c3166e1 | 2011-08-08 15:00:03 -0700 | [diff] [blame] | 3250 | dirty.set(0, 0, (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 3251 | } |
Chet Haase | ad4f703 | 2011-06-22 09:18:31 -0700 | [diff] [blame] | 3252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3254 | Log.v(mTag, "Draw " + mView + "/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3255 | + mWindowAttributes.getTitle() |
| 3256 | + ": dirty={" + dirty.left + "," + dirty.top |
| 3257 | + "," + dirty.right + "," + dirty.bottom + "} surface=" |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 3258 | + surface + " surface.isValid()=" + surface.isValid() + ", appScale:" + |
| 3259 | appScale + ", width=" + mWidth + ", height=" + mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3260 | } |
| 3261 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3262 | mAttachInfo.mTreeObserver.dispatchOnDraw(); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3263 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 3264 | int xOffset = -mCanvasOffsetX; |
| 3265 | int yOffset = -mCanvasOffsetY + curScrollY; |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 3266 | final WindowManager.LayoutParams params = mWindowAttributes; |
| 3267 | final Rect surfaceInsets = params != null ? params.surfaceInsets : null; |
| 3268 | if (surfaceInsets != null) { |
| 3269 | xOffset -= surfaceInsets.left; |
| 3270 | yOffset -= surfaceInsets.top; |
| 3271 | |
| 3272 | // Offset dirty rect for surface insets. |
| 3273 | dirty.offset(surfaceInsets.left, surfaceInsets.right); |
| 3274 | } |
| 3275 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3276 | boolean accessibilityFocusDirty = false; |
| 3277 | final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable; |
| 3278 | if (drawable != null) { |
| 3279 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 3280 | final boolean hasFocus = getAccessibilityFocusedRect(bounds); |
| 3281 | if (!hasFocus) { |
| 3282 | bounds.setEmpty(); |
| 3283 | } |
| 3284 | if (!bounds.equals(drawable.getBounds())) { |
| 3285 | accessibilityFocusDirty = true; |
| 3286 | } |
| 3287 | } |
| 3288 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 3289 | mAttachInfo.mDrawingTime = |
| 3290 | mChoreographer.getFrameTimeNanos() / TimeUtils.NANOS_PER_MS; |
| 3291 | |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3292 | boolean useAsyncReport = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3293 | if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3294 | if (mAttachInfo.mThreadedRenderer != null && mAttachInfo.mThreadedRenderer.isEnabled()) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3295 | // If accessibility focus moved, always invalidate the root. |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 3296 | boolean invalidateRoot = accessibilityFocusDirty || mInvalidateRootRequested; |
| 3297 | mInvalidateRootRequested = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3298 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3299 | // Draw with hardware renderer. |
| 3300 | mIsAnimating = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3301 | |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3302 | if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) { |
| 3303 | mHardwareYOffset = yOffset; |
| 3304 | mHardwareXOffset = xOffset; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3305 | invalidateRoot = true; |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 3306 | } |
| 3307 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3308 | if (invalidateRoot) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3309 | mAttachInfo.mThreadedRenderer.invalidateRoot(); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3312 | dirty.setEmpty(); |
| 3313 | |
Skuhne | 980ee47 | 2015-10-06 11:31:31 -0700 | [diff] [blame] | 3314 | // Stage the content drawn size now. It will be transferred to the renderer |
| 3315 | // shortly before the draw commands get send to the renderer. |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 3316 | final boolean updated = updateContentDrawBounds(); |
| 3317 | |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 3318 | if (mReportNextDraw) { |
| 3319 | // report next draw overrides setStopped() |
| 3320 | // This value is re-sync'd to the value of mStopped |
| 3321 | // in the handling of mReportNextDraw post-draw. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3322 | mAttachInfo.mThreadedRenderer.setStopped(false); |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 3323 | } |
| 3324 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 3325 | if (updated) { |
| 3326 | requestDrawWindow(); |
| 3327 | } |
Jorim Jaggi | 0d6222d | 2016-04-18 20:42:10 -0700 | [diff] [blame] | 3328 | |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3329 | useAsyncReport = true; |
Jorim Jaggi | e6a026b | 2018-06-06 18:42:16 +0200 | [diff] [blame] | 3330 | |
| 3331 | // draw(...) might invoke post-draw, which might register the next callback already. |
| 3332 | final FrameDrawingCallback callback = mNextRtFrameCallback; |
Jorim Jaggi | 64be98d | 2018-04-26 23:23:29 +0200 | [diff] [blame] | 3333 | mNextRtFrameCallback = null; |
Jorim Jaggi | e6a026b | 2018-06-06 18:42:16 +0200 | [diff] [blame] | 3334 | mAttachInfo.mThreadedRenderer.draw(mView, mAttachInfo, this, callback); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3335 | } else { |
| 3336 | // If we get here with a disabled & requested hardware renderer, something went |
| 3337 | // wrong (an invalidate posted right before we destroyed the hardware surface |
| 3338 | // for instance) so we should just bail out. Locking the surface with software |
| 3339 | // rendering at this point would lock it forever and prevent hardware renderer |
| 3340 | // from doing its job when it comes back. |
| 3341 | // Before we request a new frame we must however attempt to reinitiliaze the |
| 3342 | // hardware renderer if it's in requested state. This would happen after an |
| 3343 | // eglTerminate() for instance. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3344 | if (mAttachInfo.mThreadedRenderer != null && |
| 3345 | !mAttachInfo.mThreadedRenderer.isEnabled() && |
Robert Carr | 80923d5 | 2018-04-19 13:05:08 -0700 | [diff] [blame] | 3346 | mAttachInfo.mThreadedRenderer.isRequested() && |
| 3347 | mSurface.isValid()) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3348 | |
| 3349 | try { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3350 | mAttachInfo.mThreadedRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 3351 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3352 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3353 | handleOutOfResourcesException(e); |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3354 | return false; |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | mFullRedrawNeeded = true; |
| 3358 | scheduleTraversals(); |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3359 | return false; |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3360 | } |
| 3361 | |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3362 | if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, |
| 3363 | scalingRequired, dirty, surfaceInsets)) { |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3364 | return false; |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3365 | } |
Jeff Brown | 95db2b2 | 2011-11-30 19:54:41 -0800 | [diff] [blame] | 3366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3367 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3368 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3369 | if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | mFullRedrawNeeded = true; |
| 3371 | scheduleTraversals(); |
| 3372 | } |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3373 | return useAsyncReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | } |
| 3375 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3376 | /** |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3377 | * @return true if drawing was successful, false if an error occurred |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3378 | */ |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3379 | private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, int yoff, |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3380 | boolean scalingRequired, Rect dirty, Rect surfaceInsets) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3381 | |
| 3382 | // Draw with software renderer. |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 3383 | final Canvas canvas; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3384 | |
| 3385 | // We already have the offset of surfaceInsets in xoff, yoff and dirty region, |
| 3386 | // therefore we need to add it back when moving the dirty region. |
| 3387 | int dirtyXOffset = xoff; |
| 3388 | int dirtyYOffset = yoff; |
| 3389 | if (surfaceInsets != null) { |
| 3390 | dirtyXOffset += surfaceInsets.left; |
| 3391 | dirtyYOffset += surfaceInsets.top; |
| 3392 | } |
| 3393 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3394 | try { |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3395 | dirty.offset(-dirtyXOffset, -dirtyYOffset); |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 3396 | final int left = dirty.left; |
| 3397 | final int top = dirty.top; |
| 3398 | final int right = dirty.right; |
| 3399 | final int bottom = dirty.bottom; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3400 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3401 | canvas = mSurface.lockCanvas(dirty); |
| 3402 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 3403 | // The dirty rectangle can be modified by Surface.lockCanvas() |
| 3404 | //noinspection ConstantConditions |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 3405 | if (left != dirty.left || top != dirty.top || right != dirty.right |
| 3406 | || bottom != dirty.bottom) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3407 | attachInfo.mIgnoreDirtyState = true; |
| 3408 | } |
| 3409 | |
| 3410 | // TODO: Do this in native |
| 3411 | canvas.setDensity(mDensity); |
| 3412 | } catch (Surface.OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3413 | handleOutOfResourcesException(e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3414 | return false; |
| 3415 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3416 | Log.e(mTag, "Could not lock surface", e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3417 | // Don't assume this is due to out of memory, it could be |
| 3418 | // something else, and if it is something else then we could |
| 3419 | // kill stuff (or ourself) for no reason. |
| 3420 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 3421 | return false; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3422 | } finally { |
| 3423 | dirty.offset(dirtyXOffset, dirtyYOffset); // Reset to the original value. |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | try { |
| 3427 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3428 | Log.v(mTag, "Surface " + surface + " drawing to bitmap w=" |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3429 | + canvas.getWidth() + ", h=" + canvas.getHeight()); |
| 3430 | //canvas.drawARGB(255, 255, 0, 0); |
| 3431 | } |
| 3432 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3433 | // If this bitmap's format includes an alpha channel, we |
| 3434 | // need to clear it before drawing so that the child will |
| 3435 | // properly re-composite its drawing on a transparent |
| 3436 | // background. This automatically respects the clip/dirty region |
| 3437 | // or |
| 3438 | // If we are applying an offset, we need to clear the area |
| 3439 | // where the offset doesn't appear to avoid having garbage |
| 3440 | // left in the blank areas. |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3441 | if (!canvas.isOpaque() || yoff != 0 || xoff != 0) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3442 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 3443 | } |
| 3444 | |
| 3445 | dirty.setEmpty(); |
| 3446 | mIsAnimating = false; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3447 | mView.mPrivateFlags |= View.PFLAG_DRAWN; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3448 | |
| 3449 | if (DEBUG_DRAW) { |
| 3450 | Context cxt = mView.getContext(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3451 | Log.i(mTag, "Drawing: package:" + cxt.getPackageName() + |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3452 | ", metrics=" + cxt.getResources().getDisplayMetrics() + |
| 3453 | ", compatibilityInfo=" + cxt.getResources().getCompatibilityInfo()); |
| 3454 | } |
| 3455 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3456 | canvas.translate(-xoff, -yoff); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3457 | if (mTranslator != null) { |
| 3458 | mTranslator.translateCanvas(canvas); |
| 3459 | } |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3460 | canvas.setScreenDensity(scalingRequired ? mNoncompatDensity : 0); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3461 | attachInfo.mSetIgnoreDirtyState = false; |
| 3462 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3463 | mView.draw(canvas); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3464 | |
| 3465 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3466 | } finally { |
| 3467 | if (!attachInfo.mSetIgnoreDirtyState) { |
| 3468 | // Only clear the flag if it was not set during the mView.draw() call |
| 3469 | attachInfo.mIgnoreDirtyState = false; |
| 3470 | } |
| 3471 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3472 | } finally { |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 3473 | try { |
| 3474 | surface.unlockCanvasAndPost(canvas); |
| 3475 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3476 | Log.e(mTag, "Could not unlock surface", e); |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 3477 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 3478 | //noinspection ReturnInsideFinallyBlock |
| 3479 | return false; |
| 3480 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3481 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3482 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3483 | Log.v(mTag, "Surface " + surface + " unlockCanvasAndPost"); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3484 | } |
| 3485 | } |
| 3486 | return true; |
| 3487 | } |
| 3488 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3489 | /** |
| 3490 | * We want to draw a highlight around the current accessibility focused. |
| 3491 | * Since adding a style for all possible view is not a viable option we |
| 3492 | * have this specialized drawing method. |
| 3493 | * |
| 3494 | * Note: We are doing this here to be able to draw the highlight for |
| 3495 | * virtual views in addition to real ones. |
| 3496 | * |
| 3497 | * @param canvas The canvas on which to draw. |
| 3498 | */ |
| 3499 | private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) { |
| 3500 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 3501 | if (getAccessibilityFocusedRect(bounds)) { |
| 3502 | final Drawable drawable = getAccessibilityFocusedDrawable(); |
| 3503 | if (drawable != null) { |
| 3504 | drawable.setBounds(bounds); |
| 3505 | drawable.draw(canvas); |
| 3506 | } |
| 3507 | } else if (mAttachInfo.mAccessibilityFocusDrawable != null) { |
| 3508 | mAttachInfo.mAccessibilityFocusDrawable.setBounds(0, 0, 0, 0); |
| 3509 | } |
| 3510 | } |
| 3511 | |
| 3512 | private boolean getAccessibilityFocusedRect(Rect bounds) { |
| 3513 | final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext); |
| 3514 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
| 3515 | return false; |
| 3516 | } |
| 3517 | |
| 3518 | final View host = mAccessibilityFocusedHost; |
| 3519 | if (host == null || host.mAttachInfo == null) { |
| 3520 | return false; |
| 3521 | } |
| 3522 | |
| 3523 | final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 3524 | if (provider == null) { |
Svetoslav | ded133c | 2015-01-30 20:28:41 -0800 | [diff] [blame] | 3525 | host.getBoundsOnScreen(bounds, true); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3526 | } else if (mAccessibilityFocusedVirtualView != null) { |
| 3527 | mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds); |
| 3528 | } else { |
| 3529 | return false; |
| 3530 | } |
| 3531 | |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 3532 | // Transform the rect into window-relative coordinates. |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3533 | final AttachInfo attachInfo = mAttachInfo; |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 3534 | bounds.offset(0, attachInfo.mViewRootImpl.mScrollY); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3535 | bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop); |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 3536 | if (!bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, |
| 3537 | attachInfo.mViewRootImpl.mHeight)) { |
| 3538 | // If no intersection, set bounds to empty. |
| 3539 | bounds.setEmpty(); |
| 3540 | } |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3541 | return !bounds.isEmpty(); |
| 3542 | } |
| 3543 | |
| 3544 | private Drawable getAccessibilityFocusedDrawable() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3545 | // Lazily load the accessibility focus drawable. |
| 3546 | if (mAttachInfo.mAccessibilityFocusDrawable == null) { |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 3547 | final TypedValue value = new TypedValue(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3548 | final boolean resolved = mView.mContext.getTheme().resolveAttribute( |
| 3549 | R.attr.accessibilityFocusedDrawable, value, true); |
| 3550 | if (resolved) { |
| 3551 | mAttachInfo.mAccessibilityFocusDrawable = |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 3552 | mView.mContext.getDrawable(value.resourceId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3553 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3554 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3555 | return mAttachInfo.mAccessibilityFocusDrawable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 3558 | /** |
| 3559 | * Requests that the root render node is invalidated next time we perform a draw, such that |
| 3560 | * {@link WindowCallbacks#onPostDraw} gets called. |
| 3561 | */ |
| 3562 | public void requestInvalidateRootRenderNode() { |
| 3563 | mInvalidateRootRequested = true; |
| 3564 | } |
| 3565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3567 | final Rect ci = mAttachInfo.mContentInsets; |
| 3568 | final Rect vi = mAttachInfo.mVisibleInsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | int scrollY = 0; |
| 3570 | boolean handled = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | if (vi.left > ci.left || vi.top > ci.top |
| 3573 | || vi.right > ci.right || vi.bottom > ci.bottom) { |
| 3574 | // We'll assume that we aren't going to change the scroll |
| 3575 | // offset, since we want to avoid that unless it is actually |
| 3576 | // going to make the focus visible... otherwise we scroll |
| 3577 | // all over the place. |
| 3578 | scrollY = mScrollY; |
| 3579 | // We can be called for two different situations: during a draw, |
| 3580 | // to update the scroll position if the focus has changed (in which |
| 3581 | // case 'rectangle' is null), or in response to a |
| 3582 | // requestChildRectangleOnScreen() call (in which case 'rectangle' |
| 3583 | // is non-null and we just want to scroll to whatever that |
| 3584 | // rectangle is). |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 3585 | final View focus = mView.findFocus(); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3586 | if (focus == null) { |
Romain Guy | e8b1652 | 2009-07-14 13:06:42 -0700 | [diff] [blame] | 3587 | return false; |
| 3588 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3589 | View lastScrolledFocus = (mLastScrolledFocus != null) ? mLastScrolledFocus.get() : null; |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 3590 | if (focus != lastScrolledFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | // If the focus has changed, then ignore any requests to scroll |
| 3592 | // to a rectangle; first we want to make sure the entire focus |
| 3593 | // view is visible. |
| 3594 | rectangle = null; |
| 3595 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3596 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Eval scroll: focus=" + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | + " rectangle=" + rectangle + " ci=" + ci |
| 3598 | + " vi=" + vi); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3599 | if (focus == lastScrolledFocus && !mScrollMayChange && rectangle == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3600 | // Optimization: if the focus hasn't changed since last |
| 3601 | // time, and no layout has happened, then just leave things |
| 3602 | // as they are. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3603 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Keeping scroll y=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3604 | + mScrollY + " vi=" + vi.toShortString()); |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 3605 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | // We need to determine if the currently focused view is |
| 3607 | // within the visible part of the window and, if not, apply |
| 3608 | // a pan so it can be seen. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3609 | mLastScrolledFocus = new WeakReference<View>(focus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3610 | mScrollMayChange = false; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3611 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Need to scroll?"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | // Try to find the rectangle from the focus view. |
| 3613 | if (focus.getGlobalVisibleRect(mVisRect, null)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3614 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Root w=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3615 | + mView.getWidth() + " h=" + mView.getHeight() |
| 3616 | + " ci=" + ci.toShortString() |
| 3617 | + " vi=" + vi.toShortString()); |
| 3618 | if (rectangle == null) { |
| 3619 | focus.getFocusedRect(mTempRect); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3620 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Focus " + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | + ": focusRect=" + mTempRect.toShortString()); |
Dianne Hackborn | 1c6a894 | 2010-03-23 16:34:20 -0700 | [diff] [blame] | 3622 | if (mView instanceof ViewGroup) { |
| 3623 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 3624 | focus, mTempRect); |
| 3625 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3626 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3627 | "Focus in window: focusRect=" |
| 3628 | + mTempRect.toShortString() |
| 3629 | + " visRect=" + mVisRect.toShortString()); |
| 3630 | } else { |
| 3631 | mTempRect.set(rectangle); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3632 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | "Request scroll to rect: " |
| 3634 | + mTempRect.toShortString() |
| 3635 | + " visRect=" + mVisRect.toShortString()); |
| 3636 | } |
| 3637 | if (mTempRect.intersect(mVisRect)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3638 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | "Focus window visible rect: " |
| 3640 | + mTempRect.toShortString()); |
| 3641 | if (mTempRect.height() > |
| 3642 | (mView.getHeight()-vi.top-vi.bottom)) { |
| 3643 | // If the focus simply is not going to fit, then |
| 3644 | // best is probably just to leave things as-is. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3645 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3646 | "Too tall; leaving scrollY=" + scrollY); |
Chong Zhang | 6725472 | 2016-06-02 12:56:54 -0700 | [diff] [blame] | 3647 | } |
| 3648 | // Next, check whether top or bottom is covered based on the non-scrolled |
| 3649 | // position, and calculate new scrollY (or set it to 0). |
| 3650 | // We can't keep using mScrollY here. For example mScrollY is non-zero |
| 3651 | // due to IME, then IME goes away. The current value of mScrollY leaves top |
| 3652 | // and bottom both visible, but we still need to scroll it back to 0. |
| 3653 | else if (mTempRect.top < vi.top) { |
| 3654 | scrollY = mTempRect.top - vi.top; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3655 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3656 | "Top covered; scrollY=" + scrollY); |
Chong Zhang | 6725472 | 2016-06-02 12:56:54 -0700 | [diff] [blame] | 3657 | } else if (mTempRect.bottom > (mView.getHeight()-vi.bottom)) { |
| 3658 | scrollY = mTempRect.bottom - (mView.getHeight()-vi.bottom); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3659 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3660 | "Bottom covered; scrollY=" + scrollY); |
Chong Zhang | 6725472 | 2016-06-02 12:56:54 -0700 | [diff] [blame] | 3661 | } else { |
| 3662 | scrollY = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | } |
| 3664 | handled = true; |
| 3665 | } |
| 3666 | } |
| 3667 | } |
| 3668 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | if (scrollY != mScrollY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3671 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Pan scroll changed: old=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | + mScrollY + " , new=" + scrollY); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 3673 | if (!immediate) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | if (mScroller == null) { |
| 3675 | mScroller = new Scroller(mView.getContext()); |
| 3676 | } |
| 3677 | mScroller.startScroll(0, mScrollY, 0, scrollY-mScrollY); |
| 3678 | } else if (mScroller != null) { |
| 3679 | mScroller.abortAnimation(); |
| 3680 | } |
| 3681 | mScrollY = scrollY; |
| 3682 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3684 | return handled; |
| 3685 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3686 | |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3687 | /** |
| 3688 | * @hide |
| 3689 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 3690 | @UnsupportedAppUsage |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3691 | public View getAccessibilityFocusedHost() { |
| 3692 | return mAccessibilityFocusedHost; |
| 3693 | } |
| 3694 | |
| 3695 | /** |
| 3696 | * @hide |
| 3697 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 3698 | @UnsupportedAppUsage |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3699 | public AccessibilityNodeInfo getAccessibilityFocusedVirtualView() { |
| 3700 | return mAccessibilityFocusedVirtualView; |
| 3701 | } |
| 3702 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3703 | void setAccessibilityFocus(View view, AccessibilityNodeInfo node) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3704 | // If we have a virtual view with accessibility focus we need |
| 3705 | // to clear the focus and invalidate the virtual view bounds. |
| 3706 | if (mAccessibilityFocusedVirtualView != null) { |
| 3707 | |
| 3708 | AccessibilityNodeInfo focusNode = mAccessibilityFocusedVirtualView; |
| 3709 | View focusHost = mAccessibilityFocusedHost; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3710 | |
| 3711 | // Wipe the state of the current accessibility focus since |
| 3712 | // the call into the provider to clear accessibility focus |
| 3713 | // will fire an accessibility event which will end up calling |
| 3714 | // this method and we want to have clean state when this |
| 3715 | // invocation happens. |
| 3716 | mAccessibilityFocusedHost = null; |
| 3717 | mAccessibilityFocusedVirtualView = null; |
| 3718 | |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3719 | // Clear accessibility focus on the host after clearing state since |
| 3720 | // this method may be reentrant. |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 3721 | focusHost.clearAccessibilityFocusNoCallbacks( |
| 3722 | AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3723 | |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3724 | AccessibilityNodeProvider provider = focusHost.getAccessibilityNodeProvider(); |
| 3725 | if (provider != null) { |
| 3726 | // Invalidate the area of the cleared accessibility focus. |
| 3727 | focusNode.getBoundsInParent(mTempRect); |
| 3728 | focusHost.invalidate(mTempRect); |
| 3729 | // Clear accessibility focus in the virtual node. |
| 3730 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 3731 | focusNode.getSourceNodeId()); |
| 3732 | provider.performAction(virtualNodeId, |
| 3733 | AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); |
| 3734 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3735 | focusNode.recycle(); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3736 | } |
Phil Weaver | da46927 | 2016-06-24 18:17:21 -0700 | [diff] [blame] | 3737 | if ((mAccessibilityFocusedHost != null) && (mAccessibilityFocusedHost != view)) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3738 | // Clear accessibility focus in the view. |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 3739 | mAccessibilityFocusedHost.clearAccessibilityFocusNoCallbacks( |
| 3740 | AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3741 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3742 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3743 | // Set the new focus host and node. |
| 3744 | mAccessibilityFocusedHost = view; |
| 3745 | mAccessibilityFocusedVirtualView = node; |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3746 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3747 | if (mAttachInfo.mThreadedRenderer != null) { |
| 3748 | mAttachInfo.mThreadedRenderer.invalidateRoot(); |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3749 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3750 | } |
| 3751 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 3752 | boolean hasPointerCapture() { |
| 3753 | return mPointerCapture; |
| 3754 | } |
| 3755 | |
| 3756 | void requestPointerCapture(boolean enabled) { |
| 3757 | if (mPointerCapture == enabled) { |
| 3758 | return; |
| 3759 | } |
| 3760 | InputManager.getInstance().requestPointerCapture(mAttachInfo.mWindowToken, enabled); |
| 3761 | } |
| 3762 | |
| 3763 | private void handlePointerCaptureChanged(boolean hasCapture) { |
| 3764 | if (mPointerCapture == hasCapture) { |
| 3765 | return; |
| 3766 | } |
| 3767 | mPointerCapture = hasCapture; |
| 3768 | if (mView != null) { |
| 3769 | mView.dispatchPointerCaptureChanged(hasCapture); |
| 3770 | } |
| 3771 | } |
| 3772 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3773 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3774 | public void requestChildFocus(View child, View focused) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3775 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3776 | Log.v(mTag, "Request child focus: focus now " + focused); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3777 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3778 | checkThread(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3779 | scheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | } |
| 3781 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3782 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | public void clearChildFocus(View child) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3784 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3785 | Log.v(mTag, "Clearing child focus"); |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3786 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3787 | checkThread(); |
| 3788 | scheduleTraversals(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3789 | } |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3790 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3791 | @Override |
| 3792 | public ViewParent getParentForAccessibility() { |
| 3793 | return null; |
| 3794 | } |
| 3795 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3796 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3797 | public void focusableViewAvailable(View v) { |
| 3798 | checkThread(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3799 | if (mView != null) { |
| 3800 | if (!mView.hasFocus()) { |
Evan Rosky | 2888404 | 2018-04-03 13:21:55 -0700 | [diff] [blame] | 3801 | if (sAlwaysAssignFocus || !mAttachInfo.mInTouchMode) { |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 3802 | v.requestFocus(); |
| 3803 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3804 | } else { |
| 3805 | // the one case where will transfer focus away from the current one |
| 3806 | // is if the current view is a view group that prefers to give focus |
| 3807 | // to its children first AND the view is a descendant of it. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3808 | View focused = mView.findFocus(); |
| 3809 | if (focused instanceof ViewGroup) { |
| 3810 | ViewGroup group = (ViewGroup) focused; |
| 3811 | if (group.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3812 | && isViewDescendantOf(v, focused)) { |
| 3813 | v.requestFocus(); |
| 3814 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3815 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3816 | } |
| 3817 | } |
| 3818 | } |
| 3819 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3820 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | public void recomputeViewAttributes(View child) { |
| 3822 | checkThread(); |
| 3823 | if (mView == child) { |
| 3824 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 3825 | if (!mWillDrawSoon) { |
| 3826 | scheduleTraversals(); |
| 3827 | } |
| 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | void dispatchDetachedFromWindow() { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 3832 | mFirstInputStage.onDetachedFromWindow(); |
Romain Guy | 90fc03b | 2011-01-16 13:07:15 -0800 | [diff] [blame] | 3833 | if (mView != null && mView.mAttachInfo != null) { |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3834 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3835 | mView.dispatchDetachedFromWindow(); |
| 3836 | } |
| 3837 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3838 | mAccessibilityInteractionConnectionManager.ensureNoConnection(); |
| 3839 | mAccessibilityManager.removeAccessibilityStateChangeListener( |
| 3840 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 3841 | mAccessibilityManager.removeHighTextContrastStateChangeListener( |
| 3842 | mHighContrastTextManager); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3843 | removeSendWindowContentChangedCallback(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3844 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3845 | destroyHardwareRenderer(); |
| 3846 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3847 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3848 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 3849 | mView.assignParent(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3850 | mView = null; |
| 3851 | mAttachInfo.mRootView = null; |
| 3852 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 3853 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3854 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3855 | if (mInputQueueCallback != null && mInputQueue != null) { |
| 3856 | mInputQueueCallback.onInputQueueDestroyed(mInputQueue); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3857 | mInputQueue.dispose(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3858 | mInputQueueCallback = null; |
| 3859 | mInputQueue = null; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3860 | } |
| 3861 | if (mInputEventReceiver != null) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3862 | mInputEventReceiver.dispose(); |
| 3863 | mInputEventReceiver = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3864 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3866 | mWindowSession.remove(mWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | } catch (RemoteException e) { |
| 3868 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3869 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3870 | // Dispose the input channel after removing the window so the Window Manager |
| 3871 | // doesn't interpret the input channel being closed as an abnormal termination. |
| 3872 | if (mInputChannel != null) { |
| 3873 | mInputChannel.dispose(); |
| 3874 | mInputChannel = null; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3875 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3876 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 3877 | mDisplayManager.unregisterDisplayListener(mDisplayListener); |
| 3878 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 3879 | unscheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3881 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3882 | /** |
| 3883 | * Notifies all callbacks that configuration and/or display has changed and updates internal |
| 3884 | * state. |
| 3885 | * @param mergedConfiguration New global and override config in {@link MergedConfiguration} |
| 3886 | * container. |
| 3887 | * @param force Flag indicating if we should force apply the config. |
| 3888 | * @param newDisplayId Id of new display if moved, {@link Display#INVALID_DISPLAY} if not |
| 3889 | * changed. |
| 3890 | */ |
| 3891 | private void performConfigurationChange(MergedConfiguration mergedConfiguration, boolean force, |
| 3892 | int newDisplayId) { |
| 3893 | if (mergedConfiguration == null) { |
| 3894 | throw new IllegalArgumentException("No merged config provided."); |
| 3895 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3896 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3897 | Configuration globalConfig = mergedConfiguration.getGlobalConfiguration(); |
| 3898 | final Configuration overrideConfig = mergedConfiguration.getOverrideConfiguration(); |
| 3899 | if (DEBUG_CONFIGURATION) Log.v(mTag, |
| 3900 | "Applying new config to window " + mWindowAttributes.getTitle() |
| 3901 | + ", globalConfig: " + globalConfig |
| 3902 | + ", overrideConfig: " + overrideConfig); |
| 3903 | |
| 3904 | final CompatibilityInfo ci = mDisplay.getDisplayAdjustments().getCompatibilityInfo(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3905 | if (!ci.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3906 | globalConfig = new Configuration(globalConfig); |
| 3907 | ci.applyToConfiguration(mNoncompatDensity, globalConfig); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3910 | synchronized (sConfigCallbacks) { |
| 3911 | for (int i=sConfigCallbacks.size()-1; i>=0; i--) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3912 | sConfigCallbacks.get(i).onConfigurationChanged(globalConfig); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3913 | } |
| 3914 | } |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 3915 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3916 | mLastReportedMergedConfiguration.setConfiguration(globalConfig, overrideConfig); |
| 3917 | |
| 3918 | mForceNextConfigUpdate = force; |
| 3919 | if (mActivityConfigCallback != null) { |
| 3920 | // An activity callback is set - notify it about override configuration update. |
| 3921 | // This basically initiates a round trip to ActivityThread and back, which will ensure |
| 3922 | // that corresponding activity and resources are updated before updating inner state of |
| 3923 | // ViewRootImpl. Eventually it will call #updateConfiguration(). |
| 3924 | mActivityConfigCallback.onConfigurationChanged(overrideConfig, newDisplayId); |
| 3925 | } else { |
| 3926 | // There is no activity callback - update the configuration right away. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3927 | updateConfiguration(newDisplayId); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3928 | } |
| 3929 | mForceNextConfigUpdate = false; |
| 3930 | } |
| 3931 | |
| 3932 | /** |
| 3933 | * Update display and views if last applied merged configuration changed. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3934 | * @param newDisplayId Id of new display if moved, {@link Display#INVALID_DISPLAY} otherwise. |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3935 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3936 | public void updateConfiguration(int newDisplayId) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3937 | if (mView == null) { |
| 3938 | return; |
| 3939 | } |
| 3940 | |
| 3941 | // At this point the resources have been updated to |
| 3942 | // have the most recent config, whatever that is. Use |
| 3943 | // the one in them which may be newer. |
| 3944 | final Resources localResources = mView.getResources(); |
| 3945 | final Configuration config = localResources.getConfiguration(); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3946 | |
| 3947 | // Handle move to display. |
| 3948 | if (newDisplayId != INVALID_DISPLAY) { |
| 3949 | onMovedToDisplay(newDisplayId, config); |
| 3950 | } |
| 3951 | |
| 3952 | // Handle configuration change. |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3953 | if (mForceNextConfigUpdate || mLastConfigurationFromResources.diff(config) != 0) { |
| 3954 | // Update the display with new DisplayAdjustments. |
| 3955 | mDisplay = ResourcesManager.getInstance().getAdjustedDisplay( |
| 3956 | mDisplay.getDisplayId(), localResources); |
| 3957 | |
| 3958 | final int lastLayoutDirection = mLastConfigurationFromResources.getLayoutDirection(); |
| 3959 | final int currentLayoutDirection = config.getLayoutDirection(); |
| 3960 | mLastConfigurationFromResources.setTo(config); |
| 3961 | if (lastLayoutDirection != currentLayoutDirection |
| 3962 | && mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
| 3963 | mView.setLayoutDirection(currentLayoutDirection); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3964 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3965 | mView.dispatchConfigurationChanged(config); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 3966 | |
| 3967 | // We could have gotten this {@link Configuration} update after we called |
| 3968 | // {@link #performTraversals} with an older {@link Configuration}. As a result, our |
| 3969 | // window frame may be stale. We must ensure the next pass of {@link #performTraversals} |
| 3970 | // catches this. |
| 3971 | mForceNextWindowRelayout = true; |
| 3972 | requestLayout(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3973 | } |
| 3974 | } |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 3975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | /** |
| 3977 | * Return true if child is an ancestor of parent, (or equal to the parent). |
| 3978 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3979 | public static boolean isViewDescendantOf(View child, View parent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | if (child == parent) { |
| 3981 | return true; |
| 3982 | } |
| 3983 | |
| 3984 | final ViewParent theParent = child.getParent(); |
| 3985 | return (theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent); |
| 3986 | } |
| 3987 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3988 | private static void forceLayout(View view) { |
| 3989 | view.forceLayout(); |
| 3990 | if (view instanceof ViewGroup) { |
| 3991 | ViewGroup group = (ViewGroup) view; |
| 3992 | final int count = group.getChildCount(); |
| 3993 | for (int i = 0; i < count; i++) { |
| 3994 | forceLayout(group.getChildAt(i)); |
| 3995 | } |
| 3996 | } |
| 3997 | } |
| 3998 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3999 | private final static int MSG_INVALIDATE = 1; |
| 4000 | private final static int MSG_INVALIDATE_RECT = 2; |
| 4001 | private final static int MSG_DIE = 3; |
| 4002 | private final static int MSG_RESIZED = 4; |
| 4003 | private final static int MSG_RESIZED_REPORT = 5; |
| 4004 | private final static int MSG_WINDOW_FOCUS_CHANGED = 6; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4005 | private final static int MSG_DISPATCH_INPUT_EVENT = 7; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4006 | private final static int MSG_DISPATCH_APP_VISIBILITY = 8; |
| 4007 | private final static int MSG_DISPATCH_GET_NEW_SURFACE = 9; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4008 | private final static int MSG_DISPATCH_KEY_FROM_IME = 11; |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4009 | private final static int MSG_DISPATCH_KEY_FROM_AUTOFILL = 12; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4010 | private final static int MSG_CHECK_FOCUS = 13; |
| 4011 | private final static int MSG_CLOSE_SYSTEM_DIALOGS = 14; |
| 4012 | private final static int MSG_DISPATCH_DRAG_EVENT = 15; |
| 4013 | private final static int MSG_DISPATCH_DRAG_LOCATION_EVENT = 16; |
| 4014 | private final static int MSG_DISPATCH_SYSTEM_UI_VISIBILITY = 17; |
| 4015 | private final static int MSG_UPDATE_CONFIGURATION = 18; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4016 | private final static int MSG_PROCESS_INPUT_EVENTS = 19; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 4017 | private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 21; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 4018 | private final static int MSG_INVALIDATE_WORLD = 22; |
| 4019 | private final static int MSG_WINDOW_MOVED = 23; |
| 4020 | private final static int MSG_SYNTHESIZE_INPUT_EVENT = 24; |
| 4021 | private final static int MSG_DISPATCH_WINDOW_SHOWN = 25; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 4022 | private final static int MSG_REQUEST_KEYBOARD_SHORTCUTS = 26; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4023 | private final static int MSG_UPDATE_POINTER_ICON = 27; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 4024 | private final static int MSG_POINTER_CAPTURE_CHANGED = 28; |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 4025 | private final static int MSG_DRAW_FINISHED = 29; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4026 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4027 | final class ViewRootHandler extends Handler { |
| 4028 | @Override |
| 4029 | public String getMessageName(Message message) { |
| 4030 | switch (message.what) { |
| 4031 | case MSG_INVALIDATE: |
| 4032 | return "MSG_INVALIDATE"; |
| 4033 | case MSG_INVALIDATE_RECT: |
| 4034 | return "MSG_INVALIDATE_RECT"; |
| 4035 | case MSG_DIE: |
| 4036 | return "MSG_DIE"; |
| 4037 | case MSG_RESIZED: |
| 4038 | return "MSG_RESIZED"; |
| 4039 | case MSG_RESIZED_REPORT: |
| 4040 | return "MSG_RESIZED_REPORT"; |
| 4041 | case MSG_WINDOW_FOCUS_CHANGED: |
| 4042 | return "MSG_WINDOW_FOCUS_CHANGED"; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4043 | case MSG_DISPATCH_INPUT_EVENT: |
| 4044 | return "MSG_DISPATCH_INPUT_EVENT"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4045 | case MSG_DISPATCH_APP_VISIBILITY: |
| 4046 | return "MSG_DISPATCH_APP_VISIBILITY"; |
| 4047 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 4048 | return "MSG_DISPATCH_GET_NEW_SURFACE"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4049 | case MSG_DISPATCH_KEY_FROM_IME: |
| 4050 | return "MSG_DISPATCH_KEY_FROM_IME"; |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4051 | case MSG_DISPATCH_KEY_FROM_AUTOFILL: |
| 4052 | return "MSG_DISPATCH_KEY_FROM_AUTOFILL"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4053 | case MSG_CHECK_FOCUS: |
| 4054 | return "MSG_CHECK_FOCUS"; |
| 4055 | case MSG_CLOSE_SYSTEM_DIALOGS: |
| 4056 | return "MSG_CLOSE_SYSTEM_DIALOGS"; |
| 4057 | case MSG_DISPATCH_DRAG_EVENT: |
| 4058 | return "MSG_DISPATCH_DRAG_EVENT"; |
| 4059 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: |
| 4060 | return "MSG_DISPATCH_DRAG_LOCATION_EVENT"; |
| 4061 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: |
| 4062 | return "MSG_DISPATCH_SYSTEM_UI_VISIBILITY"; |
| 4063 | case MSG_UPDATE_CONFIGURATION: |
| 4064 | return "MSG_UPDATE_CONFIGURATION"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4065 | case MSG_PROCESS_INPUT_EVENTS: |
| 4066 | return "MSG_PROCESS_INPUT_EVENTS"; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 4067 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: |
| 4068 | return "MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST"; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 4069 | case MSG_WINDOW_MOVED: |
| 4070 | return "MSG_WINDOW_MOVED"; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4071 | case MSG_SYNTHESIZE_INPUT_EVENT: |
| 4072 | return "MSG_SYNTHESIZE_INPUT_EVENT"; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 4073 | case MSG_DISPATCH_WINDOW_SHOWN: |
| 4074 | return "MSG_DISPATCH_WINDOW_SHOWN"; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4075 | case MSG_UPDATE_POINTER_ICON: |
| 4076 | return "MSG_UPDATE_POINTER_ICON"; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 4077 | case MSG_POINTER_CAPTURE_CHANGED: |
| 4078 | return "MSG_POINTER_CAPTURE_CHANGED"; |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 4079 | case MSG_DRAW_FINISHED: |
| 4080 | return "MSG_DRAW_FINISHED"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4081 | } |
| 4082 | return super.getMessageName(message); |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 4083 | } |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 4084 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4085 | @Override |
Michael Wright | 53b854a | 2016-04-12 19:22:41 -0400 | [diff] [blame] | 4086 | public boolean sendMessageAtTime(Message msg, long uptimeMillis) { |
| 4087 | if (msg.what == MSG_REQUEST_KEYBOARD_SHORTCUTS && msg.obj == null) { |
| 4088 | // Debugging for b/27963013 |
| 4089 | throw new NullPointerException( |
| 4090 | "Attempted to call MSG_REQUEST_KEYBOARD_SHORTCUTS with null receiver:"); |
| 4091 | } |
| 4092 | return super.sendMessageAtTime(msg, uptimeMillis); |
| 4093 | } |
| 4094 | |
| 4095 | @Override |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4096 | public void handleMessage(Message msg) { |
| 4097 | switch (msg.what) { |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4098 | case MSG_INVALIDATE: |
| 4099 | ((View) msg.obj).invalidate(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4100 | break; |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4101 | case MSG_INVALIDATE_RECT: |
| 4102 | final View.AttachInfo.InvalidateInfo info = |
| 4103 | (View.AttachInfo.InvalidateInfo) msg.obj; |
| 4104 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
| 4105 | info.recycle(); |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 4106 | break; |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4107 | case MSG_PROCESS_INPUT_EVENTS: |
| 4108 | mProcessInputEventsScheduled = false; |
| 4109 | doProcessInputEvents(); |
| 4110 | break; |
| 4111 | case MSG_DISPATCH_APP_VISIBILITY: |
| 4112 | handleAppVisibility(msg.arg1 != 0); |
| 4113 | break; |
| 4114 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 4115 | handleGetNewSurface(); |
| 4116 | break; |
| 4117 | case MSG_RESIZED: { |
| 4118 | // Recycled in the fall through... |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4119 | SomeArgs args = (SomeArgs) msg.obj; |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4120 | if (mWinFrame.equals(args.arg1) |
| 4121 | && mPendingOverscanInsets.equals(args.arg5) |
| 4122 | && mPendingContentInsets.equals(args.arg2) |
| 4123 | && mPendingStableInsets.equals(args.arg6) |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 4124 | && mPendingDisplayCutout.get().equals(args.arg9) |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4125 | && mPendingVisibleInsets.equals(args.arg3) |
| 4126 | && mPendingOutsets.equals(args.arg7) |
| 4127 | && mPendingBackDropFrame.equals(args.arg8) |
| 4128 | && args.arg4 == null |
| 4129 | && args.argi1 == 0 |
| 4130 | && mDisplay.getDisplayId() == args.argi3) { |
| 4131 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4132 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4133 | } // fall through... |
| 4134 | case MSG_RESIZED_REPORT: |
| 4135 | if (mAdded) { |
| 4136 | SomeArgs args = (SomeArgs) msg.obj; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4137 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4138 | final int displayId = args.argi3; |
| 4139 | MergedConfiguration mergedConfiguration = (MergedConfiguration) args.arg4; |
| 4140 | final boolean displayChanged = mDisplay.getDisplayId() != displayId; |
Jorim Jaggi | 26952d7 | 2016-04-01 17:43:14 -0700 | [diff] [blame] | 4141 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4142 | if (!mLastReportedMergedConfiguration.equals(mergedConfiguration)) { |
| 4143 | // If configuration changed - notify about that and, maybe, |
| 4144 | // about move to display. |
| 4145 | performConfigurationChange(mergedConfiguration, false /* force */, |
| 4146 | displayChanged |
| 4147 | ? displayId : INVALID_DISPLAY /* same display */); |
| 4148 | } else if (displayChanged) { |
| 4149 | // Moved to display without config change - report last applied one. |
| 4150 | onMovedToDisplay(displayId, mLastConfigurationFromResources); |
| 4151 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4152 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4153 | final boolean framesChanged = !mWinFrame.equals(args.arg1) |
| 4154 | || !mPendingOverscanInsets.equals(args.arg5) |
| 4155 | || !mPendingContentInsets.equals(args.arg2) |
| 4156 | || !mPendingStableInsets.equals(args.arg6) |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 4157 | || !mPendingDisplayCutout.get().equals(args.arg9) |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4158 | || !mPendingVisibleInsets.equals(args.arg3) |
| 4159 | || !mPendingOutsets.equals(args.arg7); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4160 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4161 | mWinFrame.set((Rect) args.arg1); |
| 4162 | mPendingOverscanInsets.set((Rect) args.arg5); |
| 4163 | mPendingContentInsets.set((Rect) args.arg2); |
| 4164 | mPendingStableInsets.set((Rect) args.arg6); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 4165 | mPendingDisplayCutout.set((DisplayCutout) args.arg9); |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4166 | mPendingVisibleInsets.set((Rect) args.arg3); |
| 4167 | mPendingOutsets.set((Rect) args.arg7); |
| 4168 | mPendingBackDropFrame.set((Rect) args.arg8); |
| 4169 | mForceNextWindowRelayout = args.argi1 != 0; |
| 4170 | mPendingAlwaysConsumeNavBar = args.argi2 != 0; |
| 4171 | |
| 4172 | args.recycle(); |
| 4173 | |
| 4174 | if (msg.what == MSG_RESIZED_REPORT) { |
| 4175 | reportNextDraw(); |
| 4176 | } |
| 4177 | |
| 4178 | if (mView != null && framesChanged) { |
| 4179 | forceLayout(mView); |
| 4180 | } |
| 4181 | requestLayout(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4182 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4183 | break; |
| 4184 | case MSG_WINDOW_MOVED: |
| 4185 | if (mAdded) { |
| 4186 | final int w = mWinFrame.width(); |
| 4187 | final int h = mWinFrame.height(); |
| 4188 | final int l = msg.arg1; |
| 4189 | final int t = msg.arg2; |
| 4190 | mWinFrame.left = l; |
| 4191 | mWinFrame.right = l + w; |
| 4192 | mWinFrame.top = t; |
| 4193 | mWinFrame.bottom = t + h; |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 4194 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4195 | mPendingBackDropFrame.set(mWinFrame); |
| 4196 | maybeHandleWindowMove(mWinFrame); |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 4197 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4198 | break; |
| 4199 | case MSG_WINDOW_FOCUS_CHANGED: { |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 4200 | handleWindowFocusChanged(); |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4201 | } break; |
| 4202 | case MSG_DIE: |
| 4203 | doDie(); |
| 4204 | break; |
| 4205 | case MSG_DISPATCH_INPUT_EVENT: { |
| 4206 | SomeArgs args = (SomeArgs) msg.obj; |
| 4207 | InputEvent event = (InputEvent) args.arg1; |
| 4208 | InputEventReceiver receiver = (InputEventReceiver) args.arg2; |
| 4209 | enqueueInputEvent(event, receiver, 0, true); |
| 4210 | args.recycle(); |
| 4211 | } break; |
| 4212 | case MSG_SYNTHESIZE_INPUT_EVENT: { |
| 4213 | InputEvent event = (InputEvent) msg.obj; |
| 4214 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_UNHANDLED, true); |
| 4215 | } break; |
| 4216 | case MSG_DISPATCH_KEY_FROM_IME: { |
| 4217 | if (LOCAL_LOGV) { |
| 4218 | Log.v(TAG, "Dispatching key " + msg.obj + " from IME to " + mView); |
| 4219 | } |
| 4220 | KeyEvent event = (KeyEvent) msg.obj; |
| 4221 | if ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) != 0) { |
| 4222 | // The IME is trying to say this event is from the |
| 4223 | // system! Bad bad bad! |
| 4224 | //noinspection UnusedAssignment |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 4225 | event = KeyEvent.changeFlags(event, |
| 4226 | event.getFlags() & ~KeyEvent.FLAG_FROM_SYSTEM); |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4227 | } |
| 4228 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_DELIVER_POST_IME, true); |
| 4229 | } break; |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4230 | case MSG_DISPATCH_KEY_FROM_AUTOFILL: { |
| 4231 | if (LOCAL_LOGV) { |
| 4232 | Log.v(TAG, "Dispatching key " + msg.obj + " from Autofill to " + mView); |
| 4233 | } |
| 4234 | KeyEvent event = (KeyEvent) msg.obj; |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 4235 | enqueueInputEvent(event, null, 0, true); |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4236 | } break; |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4237 | case MSG_CHECK_FOCUS: { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4238 | InputMethodManager imm = InputMethodManager.peekInstance(); |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4239 | if (imm != null) { |
| 4240 | imm.checkFocus(); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 4241 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4242 | } break; |
| 4243 | case MSG_CLOSE_SYSTEM_DIALOGS: { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4244 | if (mView != null) { |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4245 | mView.onCloseSystemDialogs((String) msg.obj); |
| 4246 | } |
| 4247 | } break; |
| 4248 | case MSG_DISPATCH_DRAG_EVENT: { |
| 4249 | } // fall through |
| 4250 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: { |
| 4251 | DragEvent event = (DragEvent) msg.obj; |
| 4252 | // only present when this app called startDrag() |
| 4253 | event.mLocalState = mLocalDragState; |
| 4254 | handleDragEvent(event); |
| 4255 | } break; |
| 4256 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: { |
| 4257 | handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo) msg.obj); |
| 4258 | } break; |
| 4259 | case MSG_UPDATE_CONFIGURATION: { |
| 4260 | Configuration config = (Configuration) msg.obj; |
| 4261 | if (config.isOtherSeqNewer( |
| 4262 | mLastReportedMergedConfiguration.getMergedConfiguration())) { |
| 4263 | // If we already have a newer merged config applied - use its global part. |
| 4264 | config = mLastReportedMergedConfiguration.getGlobalConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4265 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4266 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4267 | // Use the newer global config and last reported override config. |
| 4268 | mPendingMergedConfiguration.setConfiguration(config, |
| 4269 | mLastReportedMergedConfiguration.getOverrideConfiguration()); |
| 4270 | |
| 4271 | performConfigurationChange(mPendingMergedConfiguration, false /* force */, |
| 4272 | INVALID_DISPLAY /* same display */); |
| 4273 | } break; |
| 4274 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: { |
| 4275 | setAccessibilityFocus(null, null); |
| 4276 | } break; |
| 4277 | case MSG_INVALIDATE_WORLD: { |
| 4278 | if (mView != null) { |
| 4279 | invalidateWorld(mView); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4280 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4281 | } break; |
| 4282 | case MSG_DISPATCH_WINDOW_SHOWN: { |
| 4283 | handleDispatchWindowShown(); |
| 4284 | } break; |
| 4285 | case MSG_REQUEST_KEYBOARD_SHORTCUTS: { |
| 4286 | final IResultReceiver receiver = (IResultReceiver) msg.obj; |
| 4287 | final int deviceId = msg.arg1; |
| 4288 | handleRequestKeyboardShortcuts(receiver, deviceId); |
| 4289 | } break; |
| 4290 | case MSG_UPDATE_POINTER_ICON: { |
| 4291 | MotionEvent event = (MotionEvent) msg.obj; |
| 4292 | resetPointerIcon(event); |
| 4293 | } break; |
| 4294 | case MSG_POINTER_CAPTURE_CHANGED: { |
| 4295 | final boolean hasCapture = msg.arg1 != 0; |
| 4296 | handlePointerCaptureChanged(hasCapture); |
| 4297 | } break; |
| 4298 | case MSG_DRAW_FINISHED: { |
| 4299 | pendingDrawFinished(); |
| 4300 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4301 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | } |
| 4303 | } |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 4304 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4305 | final ViewRootHandler mHandler = new ViewRootHandler(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | /** |
| 4308 | * Something in the current window tells us we need to change the touch mode. For |
| 4309 | * example, we are not in touch mode, and the user touches the screen. |
| 4310 | * |
| 4311 | * If the touch mode has changed, tell the window manager, and handle it locally. |
| 4312 | * |
| 4313 | * @param inTouchMode Whether we want to be in touch mode. |
| 4314 | * @return True if the touch mode changed and focus changed was changed as a result |
| 4315 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 4316 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4317 | boolean ensureTouchMode(boolean inTouchMode) { |
| 4318 | if (DBG) Log.d("touchmode", "ensureTouchMode(" + inTouchMode + "), current " |
| 4319 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 4320 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 4321 | |
| 4322 | // tell the window manager |
| 4323 | try { |
Matt Wu | d6bc96d | 2016-01-14 12:59:24 -0800 | [diff] [blame] | 4324 | mWindowSession.setInTouchMode(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | } catch (RemoteException e) { |
| 4326 | throw new RuntimeException(e); |
| 4327 | } |
| 4328 | |
| 4329 | // handle the change |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 4330 | return ensureTouchModeLocally(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | /** |
| 4334 | * Ensure that the touch mode for this window is set, and if it is changing, |
| 4335 | * take the appropriate action. |
| 4336 | * @param inTouchMode Whether we want to be in touch mode. |
| 4337 | * @return True if the touch mode changed and focus changed was changed as a result |
| 4338 | */ |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 4339 | private boolean ensureTouchModeLocally(boolean inTouchMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4340 | if (DBG) Log.d("touchmode", "ensureTouchModeLocally(" + inTouchMode + "), current " |
| 4341 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 4342 | |
| 4343 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 4344 | |
| 4345 | mAttachInfo.mInTouchMode = inTouchMode; |
| 4346 | mAttachInfo.mTreeObserver.dispatchOnTouchModeChanged(inTouchMode); |
| 4347 | |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 4348 | return (inTouchMode) ? enterTouchMode() : leaveTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | private boolean enterTouchMode() { |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 4352 | if (mView != null && mView.hasFocus()) { |
| 4353 | // note: not relying on mFocusedView here because this could |
| 4354 | // be when the window is first being added, and mFocused isn't |
| 4355 | // set yet. |
| 4356 | final View focused = mView.findFocus(); |
| 4357 | if (focused != null && !focused.isFocusableInTouchMode()) { |
| 4358 | final ViewGroup ancestorToTakeFocus = findAncestorToTakeFocusInTouchMode(focused); |
| 4359 | if (ancestorToTakeFocus != null) { |
| 4360 | // there is an ancestor that wants focus after its |
| 4361 | // descendants that is focusable in touch mode.. give it |
| 4362 | // focus |
| 4363 | return ancestorToTakeFocus.requestFocus(); |
| 4364 | } else { |
Alan Viverette | 973f3b4 | 2013-08-13 16:57:28 -0700 | [diff] [blame] | 4365 | // There's nothing to focus. Clear and propagate through the |
| 4366 | // hierarchy, but don't attempt to place new focus. |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 4367 | focused.clearFocusInternal(null, true, false); |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 4368 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | } |
| 4370 | } |
| 4371 | } |
| 4372 | return false; |
| 4373 | } |
| 4374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4375 | /** |
| 4376 | * Find an ancestor of focused that wants focus after its descendants and is |
| 4377 | * focusable in touch mode. |
| 4378 | * @param focused The currently focused view. |
| 4379 | * @return An appropriate view, or null if no such view exists. |
| 4380 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4381 | private static ViewGroup findAncestorToTakeFocusInTouchMode(View focused) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4382 | ViewParent parent = focused.getParent(); |
| 4383 | while (parent instanceof ViewGroup) { |
| 4384 | final ViewGroup vgParent = (ViewGroup) parent; |
| 4385 | if (vgParent.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 4386 | && vgParent.isFocusableInTouchMode()) { |
| 4387 | return vgParent; |
| 4388 | } |
| 4389 | if (vgParent.isRootNamespace()) { |
| 4390 | return null; |
| 4391 | } else { |
| 4392 | parent = vgParent.getParent(); |
| 4393 | } |
| 4394 | } |
| 4395 | return null; |
| 4396 | } |
| 4397 | |
| 4398 | private boolean leaveTouchMode() { |
| 4399 | if (mView != null) { |
| 4400 | if (mView.hasFocus()) { |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4401 | View focusedView = mView.findFocus(); |
| 4402 | if (!(focusedView instanceof ViewGroup)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | // some view has focus, let it keep it |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 4404 | return false; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4405 | } else if (((ViewGroup) focusedView).getDescendantFocusability() != |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4406 | ViewGroup.FOCUS_AFTER_DESCENDANTS) { |
| 4407 | // some view group has focus, and doesn't prefer its children |
| 4408 | // over itself for focus, so let them keep it. |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 4409 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | } |
| 4411 | } |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 4412 | |
| 4413 | // find the best view to give focus to in this brave new non-touch-mode |
| 4414 | // world |
Evan Rosky | bdc66cb | 2017-09-08 14:27:24 -0700 | [diff] [blame] | 4415 | return mView.restoreDefaultFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | } |
| 4417 | return false; |
| 4418 | } |
| 4419 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4420 | /** |
| 4421 | * Base class for implementing a stage in the chain of responsibility |
| 4422 | * for processing input events. |
| 4423 | * <p> |
| 4424 | * Events are delivered to the stage by the {@link #deliver} method. The stage |
| 4425 | * then has the choice of finishing the event or forwarding it to the next stage. |
| 4426 | * </p> |
| 4427 | */ |
| 4428 | abstract class InputStage { |
| 4429 | private final InputStage mNext; |
| 4430 | |
| 4431 | protected static final int FORWARD = 0; |
| 4432 | protected static final int FINISH_HANDLED = 1; |
| 4433 | protected static final int FINISH_NOT_HANDLED = 2; |
| 4434 | |
| 4435 | /** |
| 4436 | * Creates an input stage. |
| 4437 | * @param next The next stage to which events should be forwarded. |
| 4438 | */ |
| 4439 | public InputStage(InputStage next) { |
| 4440 | mNext = next; |
| 4441 | } |
| 4442 | |
| 4443 | /** |
| 4444 | * Delivers an event to be processed. |
| 4445 | */ |
| 4446 | public final void deliver(QueuedInputEvent q) { |
| 4447 | if ((q.mFlags & QueuedInputEvent.FLAG_FINISHED) != 0) { |
| 4448 | forward(q); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4449 | } else if (shouldDropInputEvent(q)) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4450 | finish(q, false); |
| 4451 | } else { |
| 4452 | apply(q, onProcess(q)); |
| 4453 | } |
| 4454 | } |
| 4455 | |
| 4456 | /** |
| 4457 | * Marks the the input event as finished then forwards it to the next stage. |
| 4458 | */ |
| 4459 | protected void finish(QueuedInputEvent q, boolean handled) { |
| 4460 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED; |
| 4461 | if (handled) { |
| 4462 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED_HANDLED; |
| 4463 | } |
| 4464 | forward(q); |
| 4465 | } |
| 4466 | |
| 4467 | /** |
| 4468 | * Forwards the event to the next stage. |
| 4469 | */ |
| 4470 | protected void forward(QueuedInputEvent q) { |
| 4471 | onDeliverToNext(q); |
| 4472 | } |
| 4473 | |
| 4474 | /** |
| 4475 | * Applies a result code from {@link #onProcess} to the specified event. |
| 4476 | */ |
| 4477 | protected void apply(QueuedInputEvent q, int result) { |
| 4478 | if (result == FORWARD) { |
| 4479 | forward(q); |
| 4480 | } else if (result == FINISH_HANDLED) { |
| 4481 | finish(q, true); |
| 4482 | } else if (result == FINISH_NOT_HANDLED) { |
| 4483 | finish(q, false); |
| 4484 | } else { |
| 4485 | throw new IllegalArgumentException("Invalid result: " + result); |
| 4486 | } |
| 4487 | } |
| 4488 | |
| 4489 | /** |
| 4490 | * Called when an event is ready to be processed. |
| 4491 | * @return A result code indicating how the event was handled. |
| 4492 | */ |
| 4493 | protected int onProcess(QueuedInputEvent q) { |
| 4494 | return FORWARD; |
| 4495 | } |
| 4496 | |
| 4497 | /** |
| 4498 | * Called when an event is being delivered to the next stage. |
| 4499 | */ |
| 4500 | protected void onDeliverToNext(QueuedInputEvent q) { |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 4501 | if (DEBUG_INPUT_STAGES) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4502 | Log.v(mTag, "Done with " + getClass().getSimpleName() + ". " + q); |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 4503 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4504 | if (mNext != null) { |
| 4505 | mNext.deliver(q); |
| 4506 | } else { |
| 4507 | finishInputEvent(q); |
| 4508 | } |
| 4509 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4510 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 4511 | protected void onWindowFocusChanged(boolean hasWindowFocus) { |
| 4512 | if (mNext != null) { |
| 4513 | mNext.onWindowFocusChanged(hasWindowFocus); |
| 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | protected void onDetachedFromWindow() { |
| 4518 | if (mNext != null) { |
| 4519 | mNext.onDetachedFromWindow(); |
| 4520 | } |
| 4521 | } |
| 4522 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4523 | protected boolean shouldDropInputEvent(QueuedInputEvent q) { |
| 4524 | if (mView == null || !mAdded) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4525 | Slog.w(mTag, "Dropping event due to root view being removed: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4526 | return true; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4527 | } else if ((!mAttachInfo.mHasWindowFocus |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4528 | && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER) |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 4529 | && !isAutofillUiShowing()) || mStopped |
Joe LaPenna | 90776de | 2016-01-22 07:11:49 -0800 | [diff] [blame] | 4530 | || (mIsAmbientMode && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_BUTTON)) |
| 4531 | || (mPausedForTransition && !isBack(q.mEvent))) { |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 4532 | // This is a focus event and the window doesn't currently have input focus or |
| 4533 | // has stopped. This could be an event that came back from the previous stage |
| 4534 | // but the window has lost focus or stopped in the meantime. |
| 4535 | if (isTerminalInputEvent(q.mEvent)) { |
| 4536 | // Don't drop terminal input events, however mark them as canceled. |
| 4537 | q.mEvent.cancel(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4538 | Slog.w(mTag, "Cancelling event due to no window focus: " + q.mEvent); |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 4539 | return false; |
| 4540 | } |
| 4541 | |
| 4542 | // Drop non-terminal input events. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4543 | Slog.w(mTag, "Dropping event due to no window focus: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4544 | return true; |
| 4545 | } |
| 4546 | return false; |
| 4547 | } |
| 4548 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4549 | void dump(String prefix, PrintWriter writer) { |
| 4550 | if (mNext != null) { |
| 4551 | mNext.dump(prefix, writer); |
| 4552 | } |
| 4553 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4554 | |
| 4555 | private boolean isBack(InputEvent event) { |
| 4556 | if (event instanceof KeyEvent) { |
| 4557 | return ((KeyEvent) event).getKeyCode() == KeyEvent.KEYCODE_BACK; |
| 4558 | } else { |
| 4559 | return false; |
| 4560 | } |
| 4561 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | /** |
| 4565 | * Base class for implementing an input pipeline stage that supports |
| 4566 | * asynchronous and out-of-order processing of input events. |
| 4567 | * <p> |
| 4568 | * In addition to what a normal input stage can do, an asynchronous |
| 4569 | * input stage may also defer an input event that has been delivered to it |
| 4570 | * and finish or forward it later. |
| 4571 | * </p> |
| 4572 | */ |
| 4573 | abstract class AsyncInputStage extends InputStage { |
| 4574 | private final String mTraceCounter; |
| 4575 | |
| 4576 | private QueuedInputEvent mQueueHead; |
| 4577 | private QueuedInputEvent mQueueTail; |
| 4578 | private int mQueueLength; |
| 4579 | |
| 4580 | protected static final int DEFER = 3; |
| 4581 | |
| 4582 | /** |
| 4583 | * Creates an asynchronous input stage. |
| 4584 | * @param next The next stage to which events should be forwarded. |
| 4585 | * @param traceCounter The name of a counter to record the size of |
| 4586 | * the queue of pending events. |
| 4587 | */ |
| 4588 | public AsyncInputStage(InputStage next, String traceCounter) { |
| 4589 | super(next); |
| 4590 | mTraceCounter = traceCounter; |
| 4591 | } |
| 4592 | |
| 4593 | /** |
| 4594 | * Marks the event as deferred, which is to say that it will be handled |
| 4595 | * asynchronously. The caller is responsible for calling {@link #forward} |
| 4596 | * or {@link #finish} later when it is done handling the event. |
| 4597 | */ |
| 4598 | protected void defer(QueuedInputEvent q) { |
| 4599 | q.mFlags |= QueuedInputEvent.FLAG_DEFERRED; |
| 4600 | enqueue(q); |
| 4601 | } |
| 4602 | |
| 4603 | @Override |
| 4604 | protected void forward(QueuedInputEvent q) { |
| 4605 | // Clear the deferred flag. |
| 4606 | q.mFlags &= ~QueuedInputEvent.FLAG_DEFERRED; |
| 4607 | |
| 4608 | // Fast path if the queue is empty. |
| 4609 | QueuedInputEvent curr = mQueueHead; |
| 4610 | if (curr == null) { |
| 4611 | super.forward(q); |
| 4612 | return; |
| 4613 | } |
| 4614 | |
| 4615 | // Determine whether the event must be serialized behind any others |
| 4616 | // before it can be delivered to the next stage. This is done because |
| 4617 | // deferred events might be handled out of order by the stage. |
| 4618 | final int deviceId = q.mEvent.getDeviceId(); |
| 4619 | QueuedInputEvent prev = null; |
| 4620 | boolean blocked = false; |
| 4621 | while (curr != null && curr != q) { |
| 4622 | if (!blocked && deviceId == curr.mEvent.getDeviceId()) { |
| 4623 | blocked = true; |
| 4624 | } |
| 4625 | prev = curr; |
| 4626 | curr = curr.mNext; |
| 4627 | } |
| 4628 | |
| 4629 | // If the event is blocked, then leave it in the queue to be delivered later. |
| 4630 | // Note that the event might not yet be in the queue if it was not previously |
| 4631 | // deferred so we will enqueue it if needed. |
| 4632 | if (blocked) { |
| 4633 | if (curr == null) { |
| 4634 | enqueue(q); |
| 4635 | } |
| 4636 | return; |
| 4637 | } |
| 4638 | |
| 4639 | // The event is not blocked. Deliver it immediately. |
| 4640 | if (curr != null) { |
| 4641 | curr = curr.mNext; |
| 4642 | dequeue(q, prev); |
| 4643 | } |
| 4644 | super.forward(q); |
| 4645 | |
| 4646 | // Dequeuing this event may have unblocked successors. Deliver them. |
| 4647 | while (curr != null) { |
| 4648 | if (deviceId == curr.mEvent.getDeviceId()) { |
| 4649 | if ((curr.mFlags & QueuedInputEvent.FLAG_DEFERRED) != 0) { |
| 4650 | break; |
| 4651 | } |
| 4652 | QueuedInputEvent next = curr.mNext; |
| 4653 | dequeue(curr, prev); |
| 4654 | super.forward(curr); |
| 4655 | curr = next; |
| 4656 | } else { |
| 4657 | prev = curr; |
| 4658 | curr = curr.mNext; |
| 4659 | } |
| 4660 | } |
| 4661 | } |
| 4662 | |
| 4663 | @Override |
| 4664 | protected void apply(QueuedInputEvent q, int result) { |
| 4665 | if (result == DEFER) { |
| 4666 | defer(q); |
| 4667 | } else { |
| 4668 | super.apply(q, result); |
| 4669 | } |
| 4670 | } |
| 4671 | |
| 4672 | private void enqueue(QueuedInputEvent q) { |
| 4673 | if (mQueueTail == null) { |
| 4674 | mQueueHead = q; |
| 4675 | mQueueTail = q; |
| 4676 | } else { |
| 4677 | mQueueTail.mNext = q; |
| 4678 | mQueueTail = q; |
| 4679 | } |
| 4680 | |
| 4681 | mQueueLength += 1; |
| 4682 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 4683 | } |
| 4684 | |
| 4685 | private void dequeue(QueuedInputEvent q, QueuedInputEvent prev) { |
| 4686 | if (prev == null) { |
| 4687 | mQueueHead = q.mNext; |
| 4688 | } else { |
| 4689 | prev.mNext = q.mNext; |
| 4690 | } |
| 4691 | if (mQueueTail == q) { |
| 4692 | mQueueTail = prev; |
| 4693 | } |
| 4694 | q.mNext = null; |
| 4695 | |
| 4696 | mQueueLength -= 1; |
| 4697 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 4698 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4699 | |
| 4700 | @Override |
| 4701 | void dump(String prefix, PrintWriter writer) { |
| 4702 | writer.print(prefix); |
| 4703 | writer.print(getClass().getName()); |
| 4704 | writer.print(": mQueueLength="); |
| 4705 | writer.println(mQueueLength); |
| 4706 | |
| 4707 | super.dump(prefix, writer); |
| 4708 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | /** |
| 4712 | * Delivers pre-ime input events to a native activity. |
| 4713 | * Does not support pointer events. |
| 4714 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4715 | final class NativePreImeInputStage extends AsyncInputStage |
| 4716 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4717 | public NativePreImeInputStage(InputStage next, String traceCounter) { |
| 4718 | super(next, traceCounter); |
| 4719 | } |
| 4720 | |
| 4721 | @Override |
| 4722 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4723 | if (mInputQueue != null && q.mEvent instanceof KeyEvent) { |
| 4724 | mInputQueue.sendInputEvent(q.mEvent, q, true, this); |
| 4725 | return DEFER; |
| 4726 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4727 | return FORWARD; |
| 4728 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4729 | |
| 4730 | @Override |
| 4731 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4732 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4733 | if (handled) { |
| 4734 | finish(q, true); |
| 4735 | return; |
| 4736 | } |
| 4737 | forward(q); |
| 4738 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | /** |
| 4742 | * Delivers pre-ime input events to the view hierarchy. |
| 4743 | * Does not support pointer events. |
| 4744 | */ |
| 4745 | final class ViewPreImeInputStage extends InputStage { |
| 4746 | public ViewPreImeInputStage(InputStage next) { |
| 4747 | super(next); |
| 4748 | } |
| 4749 | |
| 4750 | @Override |
| 4751 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4752 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4753 | return processKeyEvent(q); |
| 4754 | } |
| 4755 | return FORWARD; |
| 4756 | } |
| 4757 | |
| 4758 | private int processKeyEvent(QueuedInputEvent q) { |
| 4759 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4760 | if (mView.dispatchKeyEventPreIme(event)) { |
| 4761 | return FINISH_HANDLED; |
| 4762 | } |
| 4763 | return FORWARD; |
| 4764 | } |
| 4765 | } |
| 4766 | |
| 4767 | /** |
| 4768 | * Delivers input events to the ime. |
| 4769 | * Does not support pointer events. |
| 4770 | */ |
| 4771 | final class ImeInputStage extends AsyncInputStage |
| 4772 | implements InputMethodManager.FinishedInputEventCallback { |
| 4773 | public ImeInputStage(InputStage next, String traceCounter) { |
| 4774 | super(next, traceCounter); |
| 4775 | } |
| 4776 | |
| 4777 | @Override |
| 4778 | protected int onProcess(QueuedInputEvent q) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4779 | if (mLastWasImTarget && !isInLocalFocusMode()) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4780 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4781 | if (imm != null) { |
| 4782 | final InputEvent event = q.mEvent; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4783 | if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4784 | int result = imm.dispatchInputEvent(event, q, this, mHandler); |
| 4785 | if (result == InputMethodManager.DISPATCH_HANDLED) { |
| 4786 | return FINISH_HANDLED; |
| 4787 | } else if (result == InputMethodManager.DISPATCH_NOT_HANDLED) { |
Adam Lesinski | c0f6eed | 2013-10-28 16:03:19 -0700 | [diff] [blame] | 4788 | // The IME could not handle it, so skip along to the next InputStage |
| 4789 | return FORWARD; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4790 | } else { |
| 4791 | return DEFER; // callback will be invoked later |
| 4792 | } |
| 4793 | } |
| 4794 | } |
| 4795 | return FORWARD; |
| 4796 | } |
| 4797 | |
| 4798 | @Override |
| 4799 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4800 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4801 | if (handled) { |
| 4802 | finish(q, true); |
| 4803 | return; |
| 4804 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4805 | forward(q); |
| 4806 | } |
| 4807 | } |
| 4808 | |
| 4809 | /** |
| 4810 | * Performs early processing of post-ime input events. |
| 4811 | */ |
| 4812 | final class EarlyPostImeInputStage extends InputStage { |
| 4813 | public EarlyPostImeInputStage(InputStage next) { |
| 4814 | super(next); |
| 4815 | } |
| 4816 | |
| 4817 | @Override |
| 4818 | protected int onProcess(QueuedInputEvent q) { |
| 4819 | if (q.mEvent instanceof KeyEvent) { |
| 4820 | return processKeyEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4821 | } else { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4822 | final int source = q.mEvent.getSource(); |
| 4823 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4824 | return processPointerEvent(q); |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4825 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4826 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4827 | return FORWARD; |
| 4828 | } |
| 4829 | |
| 4830 | private int processKeyEvent(QueuedInputEvent q) { |
| 4831 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4832 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 4833 | if (mAttachInfo.mTooltipHost != null) { |
| 4834 | mAttachInfo.mTooltipHost.handleTooltipKey(event); |
| 4835 | } |
| 4836 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4837 | // If the key's purpose is to exit touch mode then we consume it |
| 4838 | // and consider it handled. |
| 4839 | if (checkForLeavingTouchModeAndConsume(event)) { |
| 4840 | return FINISH_HANDLED; |
| 4841 | } |
| 4842 | |
| 4843 | // Make sure the fallback event policy sees all keys that will be |
| 4844 | // delivered to the view hierarchy. |
| 4845 | mFallbackEventHandler.preDispatchKeyEvent(event); |
| 4846 | return FORWARD; |
| 4847 | } |
| 4848 | |
| 4849 | private int processPointerEvent(QueuedInputEvent q) { |
| 4850 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4851 | |
| 4852 | // Translate the pointer event for compatibility, if needed. |
| 4853 | if (mTranslator != null) { |
| 4854 | mTranslator.translateEventInScreenToAppWindow(event); |
| 4855 | } |
| 4856 | |
Vladislav Kaznacheev | 7614cdf | 2017-02-21 11:57:59 -0800 | [diff] [blame] | 4857 | // Enter touch mode on down or scroll, if it is coming from a touch screen device, |
| 4858 | // exit otherwise. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4859 | final int action = event.getAction(); |
Vladislav Kaznacheev | 7614cdf | 2017-02-21 11:57:59 -0800 | [diff] [blame] | 4860 | if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_SCROLL) { |
| 4861 | ensureTouchMode(event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4862 | } |
| 4863 | |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 4864 | if (action == MotionEvent.ACTION_DOWN) { |
Dake Gu | b0fa378 | 2018-02-26 12:25:14 -0800 | [diff] [blame] | 4865 | // Upon motion event within app window, close autofill ui. |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 4866 | AutofillManager afm = getAutofillManager(); |
| 4867 | if (afm != null) { |
| 4868 | afm.requestHideFillUi(); |
Dake Gu | b0fa378 | 2018-02-26 12:25:14 -0800 | [diff] [blame] | 4869 | } |
| 4870 | } |
| 4871 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 4872 | if (action == MotionEvent.ACTION_DOWN && mAttachInfo.mTooltipHost != null) { |
| 4873 | mAttachInfo.mTooltipHost.hideTooltip(); |
| 4874 | } |
| 4875 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4876 | // Offset the scroll position. |
| 4877 | if (mCurScrollY != 0) { |
| 4878 | event.offsetLocation(0, mCurScrollY); |
| 4879 | } |
| 4880 | |
| 4881 | // Remember the touch position for possible drag-initiation. |
| 4882 | if (event.isTouchEvent()) { |
| 4883 | mLastTouchPoint.x = event.getRawX(); |
| 4884 | mLastTouchPoint.y = event.getRawY(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 4885 | mLastTouchSource = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4886 | } |
| 4887 | return FORWARD; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4888 | } |
| 4889 | } |
| 4890 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4891 | /** |
| 4892 | * Delivers post-ime input events to a native activity. |
| 4893 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4894 | final class NativePostImeInputStage extends AsyncInputStage |
| 4895 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4896 | public NativePostImeInputStage(InputStage next, String traceCounter) { |
| 4897 | super(next, traceCounter); |
| 4898 | } |
| 4899 | |
| 4900 | @Override |
| 4901 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4902 | if (mInputQueue != null) { |
| 4903 | mInputQueue.sendInputEvent(q.mEvent, q, false, this); |
| 4904 | return DEFER; |
| 4905 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4906 | return FORWARD; |
| 4907 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4908 | |
| 4909 | @Override |
| 4910 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4911 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4912 | if (handled) { |
| 4913 | finish(q, true); |
| 4914 | return; |
| 4915 | } |
| 4916 | forward(q); |
| 4917 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4918 | } |
| 4919 | |
| 4920 | /** |
| 4921 | * Delivers post-ime input events to the view hierarchy. |
| 4922 | */ |
| 4923 | final class ViewPostImeInputStage extends InputStage { |
| 4924 | public ViewPostImeInputStage(InputStage next) { |
| 4925 | super(next); |
| 4926 | } |
| 4927 | |
| 4928 | @Override |
| 4929 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4930 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4931 | return processKeyEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4932 | } else { |
| 4933 | final int source = q.mEvent.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4934 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4935 | return processPointerEvent(q); |
| 4936 | } else if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
| 4937 | return processTrackballEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4938 | } else { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4939 | return processGenericMotionEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4940 | } |
| 4941 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4942 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4943 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4944 | @Override |
| 4945 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4946 | if (mUnbufferedInputDispatch |
| 4947 | && q.mEvent instanceof MotionEvent |
| 4948 | && ((MotionEvent)q.mEvent).isTouchEvent() |
| 4949 | && isTerminalInputEvent(q.mEvent)) { |
| 4950 | mUnbufferedInputDispatch = false; |
| 4951 | scheduleConsumeBatchedInput(); |
| 4952 | } |
| 4953 | super.onDeliverToNext(q); |
| 4954 | } |
| 4955 | |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4956 | private boolean performFocusNavigation(KeyEvent event) { |
| 4957 | int direction = 0; |
| 4958 | switch (event.getKeyCode()) { |
| 4959 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 4960 | if (event.hasNoModifiers()) { |
| 4961 | direction = View.FOCUS_LEFT; |
| 4962 | } |
| 4963 | break; |
| 4964 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 4965 | if (event.hasNoModifiers()) { |
| 4966 | direction = View.FOCUS_RIGHT; |
| 4967 | } |
| 4968 | break; |
| 4969 | case KeyEvent.KEYCODE_DPAD_UP: |
| 4970 | if (event.hasNoModifiers()) { |
| 4971 | direction = View.FOCUS_UP; |
| 4972 | } |
| 4973 | break; |
| 4974 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 4975 | if (event.hasNoModifiers()) { |
| 4976 | direction = View.FOCUS_DOWN; |
| 4977 | } |
| 4978 | break; |
| 4979 | case KeyEvent.KEYCODE_TAB: |
| 4980 | if (event.hasNoModifiers()) { |
| 4981 | direction = View.FOCUS_FORWARD; |
| 4982 | } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { |
| 4983 | direction = View.FOCUS_BACKWARD; |
| 4984 | } |
| 4985 | break; |
| 4986 | } |
| 4987 | if (direction != 0) { |
| 4988 | View focused = mView.findFocus(); |
| 4989 | if (focused != null) { |
| 4990 | View v = focused.focusSearch(direction); |
| 4991 | if (v != null && v != focused) { |
| 4992 | // do the math the get the interesting rect |
| 4993 | // of previous focused into the coord system of |
| 4994 | // newly focused view |
| 4995 | focused.getFocusedRect(mTempRect); |
| 4996 | if (mView instanceof ViewGroup) { |
| 4997 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 4998 | focused, mTempRect); |
| 4999 | ((ViewGroup) mView).offsetRectIntoDescendantCoords( |
| 5000 | v, mTempRect); |
| 5001 | } |
| 5002 | if (v.requestFocus(direction, mTempRect)) { |
| 5003 | playSoundEffect(SoundEffectConstants |
| 5004 | .getContantForFocusDirection(direction)); |
| 5005 | return true; |
| 5006 | } |
| 5007 | } |
| 5008 | |
| 5009 | // Give the focused view a last chance to handle the dpad key. |
| 5010 | if (mView.dispatchUnhandledMove(focused, direction)) { |
| 5011 | return true; |
| 5012 | } |
| 5013 | } else { |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 5014 | if (mView.restoreDefaultFocus()) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5015 | return true; |
| 5016 | } |
| 5017 | } |
| 5018 | } |
| 5019 | return false; |
| 5020 | } |
| 5021 | |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 5022 | private boolean performKeyboardGroupNavigation(int direction) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5023 | final View focused = mView.findFocus(); |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 5024 | if (focused == null && mView.restoreDefaultFocus()) { |
| 5025 | return true; |
| 5026 | } |
Evan Rosky | 5b86071 | 2017-04-17 16:40:16 -0700 | [diff] [blame] | 5027 | View cluster = focused == null ? keyboardNavigationClusterSearch(null, direction) |
| 5028 | : focused.keyboardNavigationClusterSearch(null, direction); |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5029 | |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5030 | // Since requestFocus only takes "real" focus directions (and therefore also |
| 5031 | // restoreFocusInCluster), convert forward/backward focus into FOCUS_DOWN. |
| 5032 | int realDirection = direction; |
| 5033 | if (direction == View.FOCUS_FORWARD || direction == View.FOCUS_BACKWARD) { |
| 5034 | realDirection = View.FOCUS_DOWN; |
| 5035 | } |
| 5036 | |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 5037 | if (cluster != null && cluster.isRootNamespace()) { |
| 5038 | // the default cluster. Try to find a non-clustered view to focus. |
| 5039 | if (cluster.restoreFocusNotInCluster()) { |
Evan Rosky | bd10c52 | 2017-03-27 15:50:38 -0700 | [diff] [blame] | 5040 | playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction)); |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 5041 | return true; |
| 5042 | } |
| 5043 | // otherwise skip to next actual cluster |
| 5044 | cluster = keyboardNavigationClusterSearch(null, direction); |
| 5045 | } |
| 5046 | |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5047 | if (cluster != null && cluster.restoreFocusInCluster(realDirection)) { |
Evan Rosky | bd10c52 | 2017-03-27 15:50:38 -0700 | [diff] [blame] | 5048 | playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction)); |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5049 | return true; |
| 5050 | } |
| 5051 | |
| 5052 | return false; |
| 5053 | } |
| 5054 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5055 | private int processKeyEvent(QueuedInputEvent q) { |
| 5056 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 5057 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 5058 | if (mUnhandledKeyManager.preViewDispatch(event)) { |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 5059 | return FINISH_HANDLED; |
| 5060 | } |
| 5061 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5062 | // Deliver the key to the view hierarchy. |
| 5063 | if (mView.dispatchKeyEvent(event)) { |
| 5064 | return FINISH_HANDLED; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5065 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5066 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 5067 | if (shouldDropInputEvent(q)) { |
| 5068 | return FINISH_NOT_HANDLED; |
| 5069 | } |
| 5070 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 5071 | // This dispatch is for windows that don't have a Window.Callback. Otherwise, |
| 5072 | // the Window.Callback usually will have already called this (see |
| 5073 | // DecorView.superDispatchKeyEvent) leaving this call a no-op. |
| 5074 | if (mUnhandledKeyManager.dispatch(mView, event)) { |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 5075 | return FINISH_HANDLED; |
| 5076 | } |
| 5077 | |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5078 | int groupNavigationDirection = 0; |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5079 | |
Evan Rosky | 516f9e6 | 2017-01-23 16:43:52 -0800 | [diff] [blame] | 5080 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5081 | && event.getKeyCode() == KeyEvent.KEYCODE_TAB) { |
| 5082 | if (KeyEvent.metaStateHasModifiers(event.getMetaState(), KeyEvent.META_META_ON)) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5083 | groupNavigationDirection = View.FOCUS_FORWARD; |
Evan Rosky | 516f9e6 | 2017-01-23 16:43:52 -0800 | [diff] [blame] | 5084 | } else if (KeyEvent.metaStateHasModifiers(event.getMetaState(), |
| 5085 | KeyEvent.META_META_ON | KeyEvent.META_SHIFT_ON)) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5086 | groupNavigationDirection = View.FOCUS_BACKWARD; |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5087 | } |
| 5088 | } |
| 5089 | |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 5090 | // If a modifier is held, try to interpret the key as a shortcut. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5091 | if (event.getAction() == KeyEvent.ACTION_DOWN |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 5092 | && !KeyEvent.metaStateHasNoModifiers(event.getMetaState()) |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5093 | && event.getRepeatCount() == 0 |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5094 | && !KeyEvent.isModifierKey(event.getKeyCode()) |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5095 | && groupNavigationDirection == 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5096 | if (mView.dispatchKeyShortcutEvent(event)) { |
| 5097 | return FINISH_HANDLED; |
| 5098 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 5099 | if (shouldDropInputEvent(q)) { |
| 5100 | return FINISH_NOT_HANDLED; |
| 5101 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | // Apply the fallback event policy. |
| 5105 | if (mFallbackEventHandler.dispatchKeyEvent(event)) { |
| 5106 | return FINISH_HANDLED; |
| 5107 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 5108 | if (shouldDropInputEvent(q)) { |
| 5109 | return FINISH_NOT_HANDLED; |
| 5110 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5111 | |
| 5112 | // Handle automatic focus changes. |
| 5113 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5114 | if (groupNavigationDirection != 0) { |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 5115 | if (performKeyboardGroupNavigation(groupNavigationDirection)) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5116 | return FINISH_HANDLED; |
| 5117 | } |
| 5118 | } else { |
| 5119 | if (performFocusNavigation(event)) { |
| 5120 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5121 | } |
| 5122 | } |
| 5123 | } |
| 5124 | return FORWARD; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5125 | } |
| 5126 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5127 | private int processPointerEvent(QueuedInputEvent q) { |
| 5128 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 5129 | |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 5130 | mAttachInfo.mUnbufferedDispatchRequested = false; |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 5131 | mAttachInfo.mHandlingPointerEvent = true; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 5132 | boolean handled = mView.dispatchPointerEvent(event); |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 5133 | maybeUpdatePointerIcon(event); |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 5134 | maybeUpdateTooltip(event); |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 5135 | mAttachInfo.mHandlingPointerEvent = false; |
| 5136 | if (mAttachInfo.mUnbufferedDispatchRequested && !mUnbufferedInputDispatch) { |
| 5137 | mUnbufferedInputDispatch = true; |
| 5138 | if (mConsumeBatchedInputScheduled) { |
| 5139 | scheduleConsumeBatchedInputImmediately(); |
| 5140 | } |
| 5141 | } |
| 5142 | return handled ? FINISH_HANDLED : FORWARD; |
| 5143 | } |
| 5144 | |
| 5145 | private void maybeUpdatePointerIcon(MotionEvent event) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5146 | if (event.getPointerCount() == 1 && event.isFromSource(InputDevice.SOURCE_MOUSE)) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 5147 | if (event.getActionMasked() == MotionEvent.ACTION_HOVER_ENTER |
| 5148 | || event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5149 | // Other apps or the window manager may change the icon type outside of |
| 5150 | // this app, therefore the icon type has to be reset on enter/exit event. |
| 5151 | mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 5152 | } |
| 5153 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5154 | if (event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT) { |
| 5155 | if (!updatePointerIcon(event) && |
| 5156 | event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5157 | mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 5158 | } |
| 5159 | } |
| 5160 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5163 | private int processTrackballEvent(QueuedInputEvent q) { |
| 5164 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 5165 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 5166 | if (event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)) { |
| 5167 | if (!hasPointerCapture() || mView.dispatchCapturedPointerEvent(event)) { |
| 5168 | return FINISH_HANDLED; |
| 5169 | } |
| 5170 | } |
| 5171 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5172 | if (mView.dispatchTrackballEvent(event)) { |
| 5173 | return FINISH_HANDLED; |
| 5174 | } |
| 5175 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5176 | } |
| 5177 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5178 | private int processGenericMotionEvent(QueuedInputEvent q) { |
| 5179 | final MotionEvent event = (MotionEvent)q.mEvent; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5180 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5181 | // Deliver the event to the view. |
| 5182 | if (mView.dispatchGenericMotionEvent(event)) { |
| 5183 | return FINISH_HANDLED; |
| 5184 | } |
| 5185 | return FORWARD; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5186 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5187 | } |
| 5188 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5189 | private void resetPointerIcon(MotionEvent event) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5190 | mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5191 | updatePointerIcon(event); |
| 5192 | } |
| 5193 | |
| 5194 | private boolean updatePointerIcon(MotionEvent event) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5195 | final int pointerIndex = 0; |
| 5196 | final float x = event.getX(pointerIndex); |
| 5197 | final float y = event.getY(pointerIndex); |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 5198 | if (mView == null) { |
| 5199 | // E.g. click outside a popup to dismiss it |
| 5200 | Slog.d(mTag, "updatePointerIcon called after view was removed"); |
| 5201 | return false; |
| 5202 | } |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5203 | if (x < 0 || x >= mView.getWidth() || y < 0 || y >= mView.getHeight()) { |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 5204 | // E.g. when moving window divider with mouse |
| 5205 | Slog.d(mTag, "updatePointerIcon called with position out of bounds"); |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5206 | return false; |
| 5207 | } |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5208 | final PointerIcon pointerIcon = mView.onResolvePointerIcon(event, pointerIndex); |
| 5209 | final int pointerType = (pointerIcon != null) ? |
| 5210 | pointerIcon.getType() : PointerIcon.TYPE_DEFAULT; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5211 | |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5212 | if (mPointerIconType != pointerType) { |
| 5213 | mPointerIconType = pointerType; |
Vladislav Kaznacheev | e40fb27 | 2017-01-03 16:45:42 -0800 | [diff] [blame] | 5214 | mCustomPointerIcon = null; |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5215 | if (mPointerIconType != PointerIcon.TYPE_CUSTOM) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5216 | InputManager.getInstance().setPointerIconType(pointerType); |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5217 | return true; |
| 5218 | } |
| 5219 | } |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5220 | if (mPointerIconType == PointerIcon.TYPE_CUSTOM && |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5221 | !pointerIcon.equals(mCustomPointerIcon)) { |
| 5222 | mCustomPointerIcon = pointerIcon; |
| 5223 | InputManager.getInstance().setCustomPointerIcon(mCustomPointerIcon); |
| 5224 | } |
| 5225 | return true; |
| 5226 | } |
| 5227 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 5228 | private void maybeUpdateTooltip(MotionEvent event) { |
| 5229 | if (event.getPointerCount() != 1) { |
| 5230 | return; |
| 5231 | } |
| 5232 | final int action = event.getActionMasked(); |
| 5233 | if (action != MotionEvent.ACTION_HOVER_ENTER |
| 5234 | && action != MotionEvent.ACTION_HOVER_MOVE |
| 5235 | && action != MotionEvent.ACTION_HOVER_EXIT) { |
| 5236 | return; |
| 5237 | } |
| 5238 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 5239 | if (manager.isEnabled() && manager.isTouchExplorationEnabled()) { |
| 5240 | return; |
| 5241 | } |
| 5242 | if (mView == null) { |
| 5243 | Slog.d(mTag, "maybeUpdateTooltip called after view was removed"); |
| 5244 | return; |
| 5245 | } |
| 5246 | mView.dispatchTooltipHoverEvent(event); |
| 5247 | } |
| 5248 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5249 | /** |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5250 | * Performs synthesis of new input events from unhandled input events. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5251 | */ |
| 5252 | final class SyntheticInputStage extends InputStage { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5253 | private final SyntheticTrackballHandler mTrackball = new SyntheticTrackballHandler(); |
| 5254 | private final SyntheticJoystickHandler mJoystick = new SyntheticJoystickHandler(); |
| 5255 | private final SyntheticTouchNavigationHandler mTouchNavigation = |
| 5256 | new SyntheticTouchNavigationHandler(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5257 | private final SyntheticKeyboardHandler mKeyboard = new SyntheticKeyboardHandler(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5258 | |
| 5259 | public SyntheticInputStage() { |
| 5260 | super(null); |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5263 | @Override |
| 5264 | protected int onProcess(QueuedInputEvent q) { |
| 5265 | q.mFlags |= QueuedInputEvent.FLAG_RESYNTHESIZED; |
| 5266 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5267 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 5268 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5269 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5270 | mTrackball.process(event); |
| 5271 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5272 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5273 | mJoystick.process(event); |
| 5274 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5275 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 5276 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5277 | mTouchNavigation.process(event); |
| 5278 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5279 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5280 | } else if ((q.mFlags & QueuedInputEvent.FLAG_UNHANDLED) != 0) { |
| 5281 | mKeyboard.process((KeyEvent)q.mEvent); |
| 5282 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5283 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5284 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5285 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5286 | } |
| 5287 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5288 | @Override |
| 5289 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 5290 | if ((q.mFlags & QueuedInputEvent.FLAG_RESYNTHESIZED) == 0) { |
| 5291 | // Cancel related synthetic events if any prior stage has handled the event. |
| 5292 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5293 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 5294 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5295 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5296 | mTrackball.cancel(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5297 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5298 | mJoystick.cancel(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5299 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 5300 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5301 | mTouchNavigation.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5302 | } |
| 5303 | } |
| 5304 | } |
| 5305 | super.onDeliverToNext(q); |
| 5306 | } |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5307 | |
| 5308 | @Override |
| 5309 | protected void onWindowFocusChanged(boolean hasWindowFocus) { |
| 5310 | if (!hasWindowFocus) { |
| 5311 | mJoystick.cancel(); |
| 5312 | } |
| 5313 | } |
| 5314 | |
| 5315 | @Override |
| 5316 | protected void onDetachedFromWindow() { |
| 5317 | mJoystick.cancel(); |
| 5318 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5319 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5320 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5321 | /** |
| 5322 | * Creates dpad events from unhandled trackball movements. |
| 5323 | */ |
| 5324 | final class SyntheticTrackballHandler { |
| 5325 | private final TrackballAxis mX = new TrackballAxis(); |
| 5326 | private final TrackballAxis mY = new TrackballAxis(); |
| 5327 | private long mLastTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5328 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5329 | public void process(MotionEvent event) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5330 | // Translate the trackball event into DPAD keys and try to deliver those. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5331 | long curTime = SystemClock.uptimeMillis(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5332 | if ((mLastTime + MAX_TRACKBALL_DELAY) < curTime) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5333 | // It has been too long since the last movement, |
| 5334 | // so restart at the beginning. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5335 | mX.reset(0); |
| 5336 | mY.reset(0); |
| 5337 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | final int action = event.getAction(); |
| 5341 | final int metaState = event.getMetaState(); |
| 5342 | switch (action) { |
| 5343 | case MotionEvent.ACTION_DOWN: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5344 | mX.reset(2); |
| 5345 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5346 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5347 | KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 5348 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5349 | InputDevice.SOURCE_KEYBOARD)); |
| 5350 | break; |
| 5351 | case MotionEvent.ACTION_UP: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5352 | mX.reset(2); |
| 5353 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5354 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5355 | KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 5356 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5357 | InputDevice.SOURCE_KEYBOARD)); |
| 5358 | break; |
| 5359 | } |
| 5360 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5361 | if (DEBUG_TRACKBALL) Log.v(mTag, "TB X=" + mX.position + " step=" |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5362 | + mX.step + " dir=" + mX.dir + " acc=" + mX.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5363 | + " move=" + event.getX() |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5364 | + " / Y=" + mY.position + " step=" |
| 5365 | + mY.step + " dir=" + mY.dir + " acc=" + mY.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5366 | + " move=" + event.getY()); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5367 | final float xOff = mX.collect(event.getX(), event.getEventTime(), "X"); |
| 5368 | final float yOff = mY.collect(event.getY(), event.getEventTime(), "Y"); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5369 | |
| 5370 | // Generate DPAD events based on the trackball movement. |
| 5371 | // We pick the axis that has moved the most as the direction of |
| 5372 | // the DPAD. When we generate DPAD events for one axis, then the |
| 5373 | // other axis is reset -- we don't want to perform DPAD jumps due |
| 5374 | // to slight movements in the trackball when making major movements |
| 5375 | // along the other axis. |
| 5376 | int keycode = 0; |
| 5377 | int movement = 0; |
| 5378 | float accel = 1; |
| 5379 | if (xOff > yOff) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5380 | movement = mX.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5381 | if (movement != 0) { |
| 5382 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_RIGHT |
| 5383 | : KeyEvent.KEYCODE_DPAD_LEFT; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5384 | accel = mX.acceleration; |
| 5385 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5386 | } |
| 5387 | } else if (yOff > 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5388 | movement = mY.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5389 | if (movement != 0) { |
| 5390 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_DOWN |
| 5391 | : KeyEvent.KEYCODE_DPAD_UP; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5392 | accel = mY.acceleration; |
| 5393 | mX.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | if (keycode != 0) { |
| 5398 | if (movement < 0) movement = -movement; |
| 5399 | int accelMovement = (int)(movement * accel); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5400 | if (DEBUG_TRACKBALL) Log.v(mTag, "Move: movement=" + movement |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5401 | + " accelMovement=" + accelMovement |
| 5402 | + " accel=" + accel); |
| 5403 | if (accelMovement > movement) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5404 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5405 | + keycode); |
| 5406 | movement--; |
| 5407 | int repeatCount = accelMovement - movement; |
| 5408 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5409 | KeyEvent.ACTION_MULTIPLE, keycode, repeatCount, metaState, |
| 5410 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5411 | InputDevice.SOURCE_KEYBOARD)); |
| 5412 | } |
| 5413 | while (movement > 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5414 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5415 | + keycode); |
| 5416 | movement--; |
| 5417 | curTime = SystemClock.uptimeMillis(); |
| 5418 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5419 | KeyEvent.ACTION_DOWN, keycode, 0, metaState, |
| 5420 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5421 | InputDevice.SOURCE_KEYBOARD)); |
| 5422 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5423 | KeyEvent.ACTION_UP, keycode, 0, metaState, |
| 5424 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5425 | InputDevice.SOURCE_KEYBOARD)); |
| 5426 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5427 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5428 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5429 | } |
| 5430 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5431 | public void cancel() { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5432 | mLastTime = Integer.MIN_VALUE; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5433 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5434 | // If we reach this, we consumed a trackball event. |
| 5435 | // Because we will not translate the trackball event into a key event, |
| 5436 | // touch mode will not exit, so we exit touch mode here. |
| 5437 | if (mView != null && mAdded) { |
| 5438 | ensureTouchMode(false); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5439 | } |
| 5440 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5441 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5442 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5443 | /** |
| 5444 | * Maintains state information for a single trackball axis, generating |
| 5445 | * discrete (DPAD) movements based on raw trackball motion. |
| 5446 | */ |
| 5447 | static final class TrackballAxis { |
| 5448 | /** |
| 5449 | * The maximum amount of acceleration we will apply. |
| 5450 | */ |
| 5451 | static final float MAX_ACCELERATION = 20; |
| 5452 | |
| 5453 | /** |
| 5454 | * The maximum amount of time (in milliseconds) between events in order |
| 5455 | * for us to consider the user to be doing fast trackball movements, |
| 5456 | * and thus apply an acceleration. |
| 5457 | */ |
| 5458 | static final long FAST_MOVE_TIME = 150; |
| 5459 | |
| 5460 | /** |
| 5461 | * Scaling factor to the time (in milliseconds) between events to how |
| 5462 | * much to multiple/divide the current acceleration. When movement |
| 5463 | * is < FAST_MOVE_TIME this multiplies the acceleration; when > |
| 5464 | * FAST_MOVE_TIME it divides it. |
| 5465 | */ |
| 5466 | static final float ACCEL_MOVE_SCALING_FACTOR = (1.0f/40); |
| 5467 | |
| 5468 | static final float FIRST_MOVEMENT_THRESHOLD = 0.5f; |
| 5469 | static final float SECOND_CUMULATIVE_MOVEMENT_THRESHOLD = 2.0f; |
| 5470 | static final float SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD = 1.0f; |
| 5471 | |
| 5472 | float position; |
| 5473 | float acceleration = 1; |
| 5474 | long lastMoveTime = 0; |
| 5475 | int step; |
| 5476 | int dir; |
| 5477 | int nonAccelMovement; |
| 5478 | |
| 5479 | void reset(int _step) { |
| 5480 | position = 0; |
| 5481 | acceleration = 1; |
| 5482 | lastMoveTime = 0; |
| 5483 | step = _step; |
| 5484 | dir = 0; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 5485 | } |
| 5486 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5487 | /** |
| 5488 | * Add trackball movement into the state. If the direction of movement |
| 5489 | * has been reversed, the state is reset before adding the |
| 5490 | * movement (so that you don't have to compensate for any previously |
| 5491 | * collected movement before see the result of the movement in the |
| 5492 | * new direction). |
| 5493 | * |
| 5494 | * @return Returns the absolute value of the amount of movement |
| 5495 | * collected so far. |
| 5496 | */ |
| 5497 | float collect(float off, long time, String axis) { |
| 5498 | long normTime; |
| 5499 | if (off > 0) { |
| 5500 | normTime = (long)(off * FAST_MOVE_TIME); |
| 5501 | if (dir < 0) { |
| 5502 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to positive!"); |
| 5503 | position = 0; |
| 5504 | step = 0; |
| 5505 | acceleration = 1; |
| 5506 | lastMoveTime = 0; |
| 5507 | } |
| 5508 | dir = 1; |
| 5509 | } else if (off < 0) { |
| 5510 | normTime = (long)((-off) * FAST_MOVE_TIME); |
| 5511 | if (dir > 0) { |
| 5512 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to negative!"); |
| 5513 | position = 0; |
| 5514 | step = 0; |
| 5515 | acceleration = 1; |
| 5516 | lastMoveTime = 0; |
| 5517 | } |
| 5518 | dir = -1; |
| 5519 | } else { |
| 5520 | normTime = 0; |
| 5521 | } |
| 5522 | |
| 5523 | // The number of milliseconds between each movement that is |
| 5524 | // considered "normal" and will not result in any acceleration |
| 5525 | // or deceleration, scaled by the offset we have here. |
| 5526 | if (normTime > 0) { |
| 5527 | long delta = time - lastMoveTime; |
| 5528 | lastMoveTime = time; |
| 5529 | float acc = acceleration; |
| 5530 | if (delta < normTime) { |
| 5531 | // The user is scrolling rapidly, so increase acceleration. |
| 5532 | float scale = (normTime-delta) * ACCEL_MOVE_SCALING_FACTOR; |
| 5533 | if (scale > 1) acc *= scale; |
| 5534 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " accelerate: off=" |
| 5535 | + off + " normTime=" + normTime + " delta=" + delta |
| 5536 | + " scale=" + scale + " acc=" + acc); |
| 5537 | acceleration = acc < MAX_ACCELERATION ? acc : MAX_ACCELERATION; |
| 5538 | } else { |
| 5539 | // The user is scrolling slowly, so decrease acceleration. |
| 5540 | float scale = (delta-normTime) * ACCEL_MOVE_SCALING_FACTOR; |
| 5541 | if (scale > 1) acc /= scale; |
| 5542 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " deccelerate: off=" |
| 5543 | + off + " normTime=" + normTime + " delta=" + delta |
| 5544 | + " scale=" + scale + " acc=" + acc); |
| 5545 | acceleration = acc > 1 ? acc : 1; |
| 5546 | } |
| 5547 | } |
| 5548 | position += off; |
| 5549 | return Math.abs(position); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 5550 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5551 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5552 | /** |
| 5553 | * Generate the number of discrete movement events appropriate for |
| 5554 | * the currently collected trackball movement. |
| 5555 | * |
| 5556 | * @return Returns the number of discrete movements, either positive |
| 5557 | * or negative, or 0 if there is not enough trackball movement yet |
| 5558 | * for a discrete movement. |
| 5559 | */ |
| 5560 | int generate() { |
| 5561 | int movement = 0; |
| 5562 | nonAccelMovement = 0; |
| 5563 | do { |
| 5564 | final int dir = position >= 0 ? 1 : -1; |
| 5565 | switch (step) { |
| 5566 | // If we are going to execute the first step, then we want |
| 5567 | // to do this as soon as possible instead of waiting for |
| 5568 | // a full movement, in order to make things look responsive. |
| 5569 | case 0: |
| 5570 | if (Math.abs(position) < FIRST_MOVEMENT_THRESHOLD) { |
| 5571 | return movement; |
| 5572 | } |
| 5573 | movement += dir; |
| 5574 | nonAccelMovement += dir; |
| 5575 | step = 1; |
| 5576 | break; |
| 5577 | // If we have generated the first movement, then we need |
| 5578 | // to wait for the second complete trackball motion before |
| 5579 | // generating the second discrete movement. |
| 5580 | case 1: |
| 5581 | if (Math.abs(position) < SECOND_CUMULATIVE_MOVEMENT_THRESHOLD) { |
| 5582 | return movement; |
| 5583 | } |
| 5584 | movement += dir; |
| 5585 | nonAccelMovement += dir; |
| 5586 | position -= SECOND_CUMULATIVE_MOVEMENT_THRESHOLD * dir; |
| 5587 | step = 2; |
| 5588 | break; |
| 5589 | // After the first two, we generate discrete movements |
| 5590 | // consistently with the trackball, applying an acceleration |
| 5591 | // if the trackball is moving quickly. This is a simple |
| 5592 | // acceleration on top of what we already compute based |
| 5593 | // on how quickly the wheel is being turned, to apply |
| 5594 | // a longer increasing acceleration to continuous movement |
| 5595 | // in one direction. |
| 5596 | default: |
| 5597 | if (Math.abs(position) < SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD) { |
| 5598 | return movement; |
| 5599 | } |
| 5600 | movement += dir; |
| 5601 | position -= dir * SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD; |
| 5602 | float acc = acceleration; |
| 5603 | acc *= 1.1f; |
| 5604 | acceleration = acc < MAX_ACCELERATION ? acc : acceleration; |
| 5605 | break; |
| 5606 | } |
| 5607 | } while (true); |
| 5608 | } |
| 5609 | } |
| 5610 | |
| 5611 | /** |
| 5612 | * Creates dpad events from unhandled joystick movements. |
| 5613 | */ |
| 5614 | final class SyntheticJoystickHandler extends Handler { |
| 5615 | private final static int MSG_ENQUEUE_X_AXIS_KEY_REPEAT = 1; |
| 5616 | private final static int MSG_ENQUEUE_Y_AXIS_KEY_REPEAT = 2; |
| 5617 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5618 | private final JoystickAxesState mJoystickAxesState = new JoystickAxesState(); |
| 5619 | private final SparseArray<KeyEvent> mDeviceKeyEvents = new SparseArray<>(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5620 | |
| 5621 | public SyntheticJoystickHandler() { |
| 5622 | super(true); |
| 5623 | } |
| 5624 | |
| 5625 | @Override |
| 5626 | public void handleMessage(Message msg) { |
| 5627 | switch (msg.what) { |
| 5628 | case MSG_ENQUEUE_X_AXIS_KEY_REPEAT: |
| 5629 | case MSG_ENQUEUE_Y_AXIS_KEY_REPEAT: { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5630 | if (mAttachInfo.mHasWindowFocus) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5631 | KeyEvent oldEvent = (KeyEvent) msg.obj; |
| 5632 | KeyEvent e = KeyEvent.changeTimeRepeat(oldEvent, |
| 5633 | SystemClock.uptimeMillis(), oldEvent.getRepeatCount() + 1); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5634 | enqueueInputEvent(e); |
| 5635 | Message m = obtainMessage(msg.what, e); |
| 5636 | m.setAsynchronous(true); |
| 5637 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatDelay()); |
| 5638 | } |
| 5639 | } break; |
| 5640 | } |
| 5641 | } |
| 5642 | |
| 5643 | public void process(MotionEvent event) { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5644 | switch(event.getActionMasked()) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5645 | case MotionEvent.ACTION_CANCEL: |
| 5646 | cancel(); |
| 5647 | break; |
| 5648 | case MotionEvent.ACTION_MOVE: |
| 5649 | update(event); |
| 5650 | break; |
| 5651 | default: |
| 5652 | Log.w(mTag, "Unexpected action: " + event.getActionMasked()); |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5653 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5654 | } |
| 5655 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5656 | private void cancel() { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5657 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
| 5658 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5659 | for (int i = 0; i < mDeviceKeyEvents.size(); i++) { |
| 5660 | final KeyEvent keyEvent = mDeviceKeyEvents.valueAt(i); |
| 5661 | if (keyEvent != null) { |
| 5662 | enqueueInputEvent(KeyEvent.changeTimeRepeat(keyEvent, |
| 5663 | SystemClock.uptimeMillis(), 0)); |
| 5664 | } |
| 5665 | } |
| 5666 | mDeviceKeyEvents.clear(); |
| 5667 | mJoystickAxesState.resetState(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5668 | } |
| 5669 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5670 | private void update(MotionEvent event) { |
| 5671 | final int historySize = event.getHistorySize(); |
| 5672 | for (int h = 0; h < historySize; h++) { |
| 5673 | final long time = event.getHistoricalEventTime(h); |
| 5674 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_X, |
| 5675 | event.getHistoricalAxisValue(MotionEvent.AXIS_X, 0, h)); |
| 5676 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_Y, |
| 5677 | event.getHistoricalAxisValue(MotionEvent.AXIS_Y, 0, h)); |
| 5678 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_HAT_X, |
| 5679 | event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_X, 0, h)); |
| 5680 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_HAT_Y, |
| 5681 | event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_Y, 0, h)); |
| 5682 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5683 | final long time = event.getEventTime(); |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5684 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_X, |
| 5685 | event.getAxisValue(MotionEvent.AXIS_X)); |
| 5686 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_Y, |
| 5687 | event.getAxisValue(MotionEvent.AXIS_Y)); |
| 5688 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_HAT_X, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5689 | event.getAxisValue(MotionEvent.AXIS_HAT_X)); |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5690 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_HAT_Y, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5691 | event.getAxisValue(MotionEvent.AXIS_HAT_Y)); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5692 | } |
| 5693 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5694 | final class JoystickAxesState { |
| 5695 | // State machine: from neutral state (no button press) can go into |
| 5696 | // button STATE_UP_OR_LEFT or STATE_DOWN_OR_RIGHT state, emitting an ACTION_DOWN event. |
| 5697 | // From STATE_UP_OR_LEFT or STATE_DOWN_OR_RIGHT state can go into neutral state, |
| 5698 | // emitting an ACTION_UP event. |
| 5699 | private static final int STATE_UP_OR_LEFT = -1; |
| 5700 | private static final int STATE_NEUTRAL = 0; |
| 5701 | private static final int STATE_DOWN_OR_RIGHT = 1; |
| 5702 | |
| 5703 | final int[] mAxisStatesHat = {STATE_NEUTRAL, STATE_NEUTRAL}; // {AXIS_HAT_X, AXIS_HAT_Y} |
| 5704 | final int[] mAxisStatesStick = {STATE_NEUTRAL, STATE_NEUTRAL}; // {AXIS_X, AXIS_Y} |
| 5705 | |
| 5706 | void resetState() { |
| 5707 | mAxisStatesHat[0] = STATE_NEUTRAL; |
| 5708 | mAxisStatesHat[1] = STATE_NEUTRAL; |
| 5709 | mAxisStatesStick[0] = STATE_NEUTRAL; |
| 5710 | mAxisStatesStick[1] = STATE_NEUTRAL; |
| 5711 | } |
| 5712 | |
| 5713 | void updateStateForAxis(MotionEvent event, long time, int axis, float value) { |
| 5714 | // Emit KeyEvent if necessary |
| 5715 | // axis can be AXIS_X, AXIS_Y, AXIS_HAT_X, AXIS_HAT_Y |
| 5716 | final int axisStateIndex; |
| 5717 | final int repeatMessage; |
| 5718 | if (isXAxis(axis)) { |
| 5719 | axisStateIndex = 0; |
| 5720 | repeatMessage = MSG_ENQUEUE_X_AXIS_KEY_REPEAT; |
| 5721 | } else if (isYAxis(axis)) { |
| 5722 | axisStateIndex = 1; |
| 5723 | repeatMessage = MSG_ENQUEUE_Y_AXIS_KEY_REPEAT; |
| 5724 | } else { |
| 5725 | Log.e(mTag, "Unexpected axis " + axis + " in updateStateForAxis!"); |
| 5726 | return; |
| 5727 | } |
| 5728 | final int newState = joystickAxisValueToState(value); |
| 5729 | |
| 5730 | final int currentState; |
| 5731 | if (axis == MotionEvent.AXIS_X || axis == MotionEvent.AXIS_Y) { |
| 5732 | currentState = mAxisStatesStick[axisStateIndex]; |
| 5733 | } else { |
| 5734 | currentState = mAxisStatesHat[axisStateIndex]; |
| 5735 | } |
| 5736 | |
| 5737 | if (currentState == newState) { |
| 5738 | return; |
| 5739 | } |
| 5740 | |
| 5741 | final int metaState = event.getMetaState(); |
| 5742 | final int deviceId = event.getDeviceId(); |
| 5743 | final int source = event.getSource(); |
| 5744 | |
| 5745 | if (currentState == STATE_DOWN_OR_RIGHT || currentState == STATE_UP_OR_LEFT) { |
| 5746 | // send a button release event |
| 5747 | final int keyCode = joystickAxisAndStateToKeycode(axis, currentState); |
| 5748 | if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 5749 | enqueueInputEvent(new KeyEvent(time, time, KeyEvent.ACTION_UP, keyCode, |
| 5750 | 0, metaState, deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
| 5751 | // remove the corresponding pending UP event if focus lost/view detached |
| 5752 | mDeviceKeyEvents.put(deviceId, null); |
| 5753 | } |
| 5754 | removeMessages(repeatMessage); |
| 5755 | } |
| 5756 | |
| 5757 | if (newState == STATE_DOWN_OR_RIGHT || newState == STATE_UP_OR_LEFT) { |
| 5758 | // send a button down event |
| 5759 | final int keyCode = joystickAxisAndStateToKeycode(axis, newState); |
| 5760 | if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 5761 | KeyEvent keyEvent = new KeyEvent(time, time, KeyEvent.ACTION_DOWN, keyCode, |
| 5762 | 0, metaState, deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 5763 | enqueueInputEvent(keyEvent); |
| 5764 | Message m = obtainMessage(repeatMessage, keyEvent); |
| 5765 | m.setAsynchronous(true); |
| 5766 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
| 5767 | // store the corresponding ACTION_UP event so that it can be sent |
| 5768 | // if focus is lost or root view is removed |
| 5769 | mDeviceKeyEvents.put(deviceId, |
| 5770 | new KeyEvent(time, time, KeyEvent.ACTION_UP, keyCode, |
| 5771 | 0, metaState, deviceId, 0, |
| 5772 | KeyEvent.FLAG_FALLBACK | KeyEvent.FLAG_CANCELED, |
| 5773 | source)); |
| 5774 | } |
| 5775 | } |
| 5776 | if (axis == MotionEvent.AXIS_X || axis == MotionEvent.AXIS_Y) { |
| 5777 | mAxisStatesStick[axisStateIndex] = newState; |
| 5778 | } else { |
| 5779 | mAxisStatesHat[axisStateIndex] = newState; |
| 5780 | } |
| 5781 | } |
| 5782 | |
| 5783 | private boolean isXAxis(int axis) { |
| 5784 | return axis == MotionEvent.AXIS_X || axis == MotionEvent.AXIS_HAT_X; |
| 5785 | } |
| 5786 | private boolean isYAxis(int axis) { |
| 5787 | return axis == MotionEvent.AXIS_Y || axis == MotionEvent.AXIS_HAT_Y; |
| 5788 | } |
| 5789 | |
| 5790 | private int joystickAxisAndStateToKeycode(int axis, int state) { |
| 5791 | if (isXAxis(axis) && state == STATE_UP_OR_LEFT) { |
| 5792 | return KeyEvent.KEYCODE_DPAD_LEFT; |
| 5793 | } |
| 5794 | if (isXAxis(axis) && state == STATE_DOWN_OR_RIGHT) { |
| 5795 | return KeyEvent.KEYCODE_DPAD_RIGHT; |
| 5796 | } |
| 5797 | if (isYAxis(axis) && state == STATE_UP_OR_LEFT) { |
| 5798 | return KeyEvent.KEYCODE_DPAD_UP; |
| 5799 | } |
| 5800 | if (isYAxis(axis) && state == STATE_DOWN_OR_RIGHT) { |
| 5801 | return KeyEvent.KEYCODE_DPAD_DOWN; |
| 5802 | } |
| 5803 | Log.e(mTag, "Unknown axis " + axis + " or direction " + state); |
| 5804 | return KeyEvent.KEYCODE_UNKNOWN; // should never happen |
| 5805 | } |
| 5806 | |
| 5807 | private int joystickAxisValueToState(float value) { |
| 5808 | if (value >= 0.5f) { |
| 5809 | return STATE_DOWN_OR_RIGHT; |
| 5810 | } else if (value <= -0.5f) { |
| 5811 | return STATE_UP_OR_LEFT; |
| 5812 | } else { |
| 5813 | return STATE_NEUTRAL; |
| 5814 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5815 | } |
| 5816 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5817 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5818 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5819 | /** |
| 5820 | * Creates dpad events from unhandled touch navigation movements. |
| 5821 | */ |
| 5822 | final class SyntheticTouchNavigationHandler extends Handler { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5823 | private static final String LOCAL_TAG = "SyntheticTouchNavigationHandler"; |
| 5824 | private static final boolean LOCAL_DEBUG = false; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5825 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5826 | // Assumed nominal width and height in millimeters of a touch navigation pad, |
| 5827 | // if no resolution information is available from the input system. |
| 5828 | private static final float DEFAULT_WIDTH_MILLIMETERS = 48; |
| 5829 | private static final float DEFAULT_HEIGHT_MILLIMETERS = 48; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5830 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5831 | /* TODO: These constants should eventually be moved to ViewConfiguration. */ |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5832 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5833 | // The nominal distance traveled to move by one unit. |
| 5834 | private static final int TICK_DISTANCE_MILLIMETERS = 12; |
| 5835 | |
| 5836 | // Minimum and maximum fling velocity in ticks per second. |
| 5837 | // The minimum velocity should be set such that we perform enough ticks per |
| 5838 | // second that the fling appears to be fluid. For example, if we set the minimum |
| 5839 | // to 2 ticks per second, then there may be up to half a second delay between the next |
| 5840 | // to last and last ticks which is noticeably discrete and jerky. This value should |
| 5841 | // probably not be set to anything less than about 4. |
| 5842 | // If fling accuracy is a problem then consider tuning the tick distance instead. |
| 5843 | private static final float MIN_FLING_VELOCITY_TICKS_PER_SECOND = 6f; |
| 5844 | private static final float MAX_FLING_VELOCITY_TICKS_PER_SECOND = 20f; |
| 5845 | |
| 5846 | // Fling velocity decay factor applied after each new key is emitted. |
| 5847 | // This parameter controls the deceleration and overall duration of the fling. |
| 5848 | // The fling stops automatically when its velocity drops below the minimum |
| 5849 | // fling velocity defined above. |
| 5850 | private static final float FLING_TICK_DECAY = 0.8f; |
| 5851 | |
| 5852 | /* The input device that we are tracking. */ |
| 5853 | |
| 5854 | private int mCurrentDeviceId = -1; |
| 5855 | private int mCurrentSource; |
| 5856 | private boolean mCurrentDeviceSupported; |
| 5857 | |
| 5858 | /* Configuration for the current input device. */ |
| 5859 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5860 | // The scaled tick distance. A movement of this amount should generally translate |
| 5861 | // into a single dpad event in a given direction. |
| 5862 | private float mConfigTickDistance; |
| 5863 | |
| 5864 | // The minimum and maximum scaled fling velocity. |
| 5865 | private float mConfigMinFlingVelocity; |
| 5866 | private float mConfigMaxFlingVelocity; |
| 5867 | |
| 5868 | /* Tracking state. */ |
| 5869 | |
| 5870 | // The velocity tracker for detecting flings. |
| 5871 | private VelocityTracker mVelocityTracker; |
| 5872 | |
| 5873 | // The active pointer id, or -1 if none. |
| 5874 | private int mActivePointerId = -1; |
| 5875 | |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 5876 | // Location where tracking started. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5877 | private float mStartX; |
| 5878 | private float mStartY; |
| 5879 | |
| 5880 | // Most recently observed position. |
| 5881 | private float mLastX; |
| 5882 | private float mLastY; |
| 5883 | |
| 5884 | // Accumulated movement delta since the last direction key was sent. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5885 | private float mAccumulatedX; |
| 5886 | private float mAccumulatedY; |
| 5887 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5888 | // Set to true if any movement was delivered to the app. |
| 5889 | // Implies that tap slop was exceeded. |
| 5890 | private boolean mConsumedMovement; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5891 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5892 | // The most recently sent key down event. |
| 5893 | // The keycode remains set until the direction changes or a fling ends |
| 5894 | // so that repeated key events may be generated as required. |
| 5895 | private long mPendingKeyDownTime; |
| 5896 | private int mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5897 | private int mPendingKeyRepeatCount; |
| 5898 | private int mPendingKeyMetaState; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5899 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5900 | // The current fling velocity while a fling is in progress. |
| 5901 | private boolean mFlinging; |
| 5902 | private float mFlingVelocity; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5903 | |
| 5904 | public SyntheticTouchNavigationHandler() { |
| 5905 | super(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | public void process(MotionEvent event) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5909 | // Update the current device information. |
| 5910 | final long time = event.getEventTime(); |
| 5911 | final int deviceId = event.getDeviceId(); |
| 5912 | final int source = event.getSource(); |
| 5913 | if (mCurrentDeviceId != deviceId || mCurrentSource != source) { |
| 5914 | finishKeys(time); |
| 5915 | finishTracking(time); |
| 5916 | mCurrentDeviceId = deviceId; |
| 5917 | mCurrentSource = source; |
| 5918 | mCurrentDeviceSupported = false; |
| 5919 | InputDevice device = event.getDevice(); |
| 5920 | if (device != null) { |
| 5921 | // In order to support an input device, we must know certain |
| 5922 | // characteristics about it, such as its size and resolution. |
| 5923 | InputDevice.MotionRange xRange = device.getMotionRange(MotionEvent.AXIS_X); |
| 5924 | InputDevice.MotionRange yRange = device.getMotionRange(MotionEvent.AXIS_Y); |
| 5925 | if (xRange != null && yRange != null) { |
| 5926 | mCurrentDeviceSupported = true; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5927 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5928 | // Infer the resolution if it not actually known. |
| 5929 | float xRes = xRange.getResolution(); |
| 5930 | if (xRes <= 0) { |
| 5931 | xRes = xRange.getRange() / DEFAULT_WIDTH_MILLIMETERS; |
| 5932 | } |
| 5933 | float yRes = yRange.getResolution(); |
| 5934 | if (yRes <= 0) { |
| 5935 | yRes = yRange.getRange() / DEFAULT_HEIGHT_MILLIMETERS; |
| 5936 | } |
| 5937 | float nominalRes = (xRes + yRes) * 0.5f; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5938 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5939 | // Precompute all of the configuration thresholds we will need. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5940 | mConfigTickDistance = TICK_DISTANCE_MILLIMETERS * nominalRes; |
| 5941 | mConfigMinFlingVelocity = |
| 5942 | MIN_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5943 | mConfigMaxFlingVelocity = |
| 5944 | MAX_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5945 | |
| 5946 | if (LOCAL_DEBUG) { |
| 5947 | Log.d(LOCAL_TAG, "Configured device " + mCurrentDeviceId |
| 5948 | + " (" + Integer.toHexString(mCurrentSource) + "): " |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5949 | + ", mConfigTickDistance=" + mConfigTickDistance |
| 5950 | + ", mConfigMinFlingVelocity=" + mConfigMinFlingVelocity |
| 5951 | + ", mConfigMaxFlingVelocity=" + mConfigMaxFlingVelocity); |
| 5952 | } |
| 5953 | } |
| 5954 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5955 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5956 | if (!mCurrentDeviceSupported) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5957 | return; |
| 5958 | } |
| 5959 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5960 | // Handle the event. |
| 5961 | final int action = event.getActionMasked(); |
| 5962 | switch (action) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5963 | case MotionEvent.ACTION_DOWN: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5964 | boolean caughtFling = mFlinging; |
| 5965 | finishKeys(time); |
| 5966 | finishTracking(time); |
| 5967 | mActivePointerId = event.getPointerId(0); |
| 5968 | mVelocityTracker = VelocityTracker.obtain(); |
| 5969 | mVelocityTracker.addMovement(event); |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5970 | mStartX = event.getX(); |
| 5971 | mStartY = event.getY(); |
| 5972 | mLastX = mStartX; |
| 5973 | mLastY = mStartY; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5974 | mAccumulatedX = 0; |
| 5975 | mAccumulatedY = 0; |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5976 | |
| 5977 | // If we caught a fling, then pretend that the tap slop has already |
| 5978 | // been exceeded to suppress taps whose only purpose is to stop the fling. |
| 5979 | mConsumedMovement = caughtFling; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5980 | break; |
| 5981 | } |
| 5982 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5983 | case MotionEvent.ACTION_MOVE: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5984 | case MotionEvent.ACTION_UP: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5985 | if (mActivePointerId < 0) { |
| 5986 | break; |
| 5987 | } |
| 5988 | final int index = event.findPointerIndex(mActivePointerId); |
| 5989 | if (index < 0) { |
| 5990 | finishKeys(time); |
| 5991 | finishTracking(time); |
| 5992 | break; |
| 5993 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5994 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5995 | mVelocityTracker.addMovement(event); |
| 5996 | final float x = event.getX(index); |
| 5997 | final float y = event.getY(index); |
| 5998 | mAccumulatedX += x - mLastX; |
| 5999 | mAccumulatedY += y - mLastY; |
| 6000 | mLastX = x; |
| 6001 | mLastY = y; |
| 6002 | |
| 6003 | // Consume any accumulated movement so far. |
| 6004 | final int metaState = event.getMetaState(); |
| 6005 | consumeAccumulatedMovement(time, metaState); |
| 6006 | |
| 6007 | // Detect taps and flings. |
| 6008 | if (action == MotionEvent.ACTION_UP) { |
Michael Wright | 88d7f79 | 2013-08-27 15:45:42 -0700 | [diff] [blame] | 6009 | if (mConsumedMovement && mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 6010 | // It might be a fling. |
| 6011 | mVelocityTracker.computeCurrentVelocity(1000, mConfigMaxFlingVelocity); |
| 6012 | final float vx = mVelocityTracker.getXVelocity(mActivePointerId); |
| 6013 | final float vy = mVelocityTracker.getYVelocity(mActivePointerId); |
| 6014 | if (!startFling(time, vx, vy)) { |
| 6015 | finishKeys(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 6016 | } |
| 6017 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 6018 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 6019 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 6020 | break; |
| 6021 | } |
| 6022 | |
| 6023 | case MotionEvent.ACTION_CANCEL: { |
| 6024 | finishKeys(time); |
| 6025 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 6026 | break; |
| 6027 | } |
| 6028 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6029 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 6030 | |
| 6031 | public void cancel(MotionEvent event) { |
| 6032 | if (mCurrentDeviceId == event.getDeviceId() |
| 6033 | && mCurrentSource == event.getSource()) { |
| 6034 | final long time = event.getEventTime(); |
| 6035 | finishKeys(time); |
| 6036 | finishTracking(time); |
| 6037 | } |
| 6038 | } |
| 6039 | |
| 6040 | private void finishKeys(long time) { |
| 6041 | cancelFling(); |
| 6042 | sendKeyUp(time); |
| 6043 | } |
| 6044 | |
| 6045 | private void finishTracking(long time) { |
| 6046 | if (mActivePointerId >= 0) { |
| 6047 | mActivePointerId = -1; |
| 6048 | mVelocityTracker.recycle(); |
| 6049 | mVelocityTracker = null; |
| 6050 | } |
| 6051 | } |
| 6052 | |
| 6053 | private void consumeAccumulatedMovement(long time, int metaState) { |
| 6054 | final float absX = Math.abs(mAccumulatedX); |
| 6055 | final float absY = Math.abs(mAccumulatedY); |
| 6056 | if (absX >= absY) { |
| 6057 | if (absX >= mConfigTickDistance) { |
| 6058 | mAccumulatedX = consumeAccumulatedMovement(time, metaState, mAccumulatedX, |
| 6059 | KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT); |
| 6060 | mAccumulatedY = 0; |
| 6061 | mConsumedMovement = true; |
| 6062 | } |
| 6063 | } else { |
| 6064 | if (absY >= mConfigTickDistance) { |
| 6065 | mAccumulatedY = consumeAccumulatedMovement(time, metaState, mAccumulatedY, |
| 6066 | KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN); |
| 6067 | mAccumulatedX = 0; |
| 6068 | mConsumedMovement = true; |
| 6069 | } |
| 6070 | } |
| 6071 | } |
| 6072 | |
| 6073 | private float consumeAccumulatedMovement(long time, int metaState, |
| 6074 | float accumulator, int negativeKeyCode, int positiveKeyCode) { |
| 6075 | while (accumulator <= -mConfigTickDistance) { |
| 6076 | sendKeyDownOrRepeat(time, negativeKeyCode, metaState); |
| 6077 | accumulator += mConfigTickDistance; |
| 6078 | } |
| 6079 | while (accumulator >= mConfigTickDistance) { |
| 6080 | sendKeyDownOrRepeat(time, positiveKeyCode, metaState); |
| 6081 | accumulator -= mConfigTickDistance; |
| 6082 | } |
| 6083 | return accumulator; |
| 6084 | } |
| 6085 | |
| 6086 | private void sendKeyDownOrRepeat(long time, int keyCode, int metaState) { |
| 6087 | if (mPendingKeyCode != keyCode) { |
| 6088 | sendKeyUp(time); |
| 6089 | mPendingKeyDownTime = time; |
| 6090 | mPendingKeyCode = keyCode; |
| 6091 | mPendingKeyRepeatCount = 0; |
| 6092 | } else { |
| 6093 | mPendingKeyRepeatCount += 1; |
| 6094 | } |
| 6095 | mPendingKeyMetaState = metaState; |
| 6096 | |
| 6097 | // Note: Normally we would pass FLAG_LONG_PRESS when the repeat count is 1 |
| 6098 | // but it doesn't quite make sense when simulating the events in this way. |
| 6099 | if (LOCAL_DEBUG) { |
| 6100 | Log.d(LOCAL_TAG, "Sending key down: keyCode=" + mPendingKeyCode |
| 6101 | + ", repeatCount=" + mPendingKeyRepeatCount |
| 6102 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 6103 | } |
| 6104 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 6105 | KeyEvent.ACTION_DOWN, mPendingKeyCode, mPendingKeyRepeatCount, |
| 6106 | mPendingKeyMetaState, mCurrentDeviceId, |
| 6107 | KeyEvent.FLAG_FALLBACK, mCurrentSource)); |
| 6108 | } |
| 6109 | |
| 6110 | private void sendKeyUp(long time) { |
| 6111 | if (mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 6112 | if (LOCAL_DEBUG) { |
| 6113 | Log.d(LOCAL_TAG, "Sending key up: keyCode=" + mPendingKeyCode |
| 6114 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 6115 | } |
| 6116 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 6117 | KeyEvent.ACTION_UP, mPendingKeyCode, 0, mPendingKeyMetaState, |
| 6118 | mCurrentDeviceId, 0, KeyEvent.FLAG_FALLBACK, |
| 6119 | mCurrentSource)); |
| 6120 | mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 6121 | } |
| 6122 | } |
| 6123 | |
| 6124 | private boolean startFling(long time, float vx, float vy) { |
| 6125 | if (LOCAL_DEBUG) { |
| 6126 | Log.d(LOCAL_TAG, "Considering fling: vx=" + vx + ", vy=" + vy |
| 6127 | + ", min=" + mConfigMinFlingVelocity); |
| 6128 | } |
| 6129 | |
| 6130 | // Flings must be oriented in the same direction as the preceding movements. |
| 6131 | switch (mPendingKeyCode) { |
| 6132 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 6133 | if (-vx >= mConfigMinFlingVelocity |
| 6134 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 6135 | mFlingVelocity = -vx; |
| 6136 | break; |
| 6137 | } |
| 6138 | return false; |
| 6139 | |
| 6140 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 6141 | if (vx >= mConfigMinFlingVelocity |
| 6142 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 6143 | mFlingVelocity = vx; |
| 6144 | break; |
| 6145 | } |
| 6146 | return false; |
| 6147 | |
| 6148 | case KeyEvent.KEYCODE_DPAD_UP: |
| 6149 | if (-vy >= mConfigMinFlingVelocity |
| 6150 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 6151 | mFlingVelocity = -vy; |
| 6152 | break; |
| 6153 | } |
| 6154 | return false; |
| 6155 | |
| 6156 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 6157 | if (vy >= mConfigMinFlingVelocity |
| 6158 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 6159 | mFlingVelocity = vy; |
| 6160 | break; |
| 6161 | } |
| 6162 | return false; |
| 6163 | } |
| 6164 | |
| 6165 | // Post the first fling event. |
| 6166 | mFlinging = postFling(time); |
| 6167 | return mFlinging; |
| 6168 | } |
| 6169 | |
| 6170 | private boolean postFling(long time) { |
| 6171 | // The idea here is to estimate the time when the pointer would have |
| 6172 | // traveled one tick distance unit given the current fling velocity. |
| 6173 | // This effect creates continuity of motion. |
| 6174 | if (mFlingVelocity >= mConfigMinFlingVelocity) { |
| 6175 | long delay = (long)(mConfigTickDistance / mFlingVelocity * 1000); |
| 6176 | postAtTime(mFlingRunnable, time + delay); |
| 6177 | if (LOCAL_DEBUG) { |
| 6178 | Log.d(LOCAL_TAG, "Posted fling: velocity=" |
| 6179 | + mFlingVelocity + ", delay=" + delay |
| 6180 | + ", keyCode=" + mPendingKeyCode); |
| 6181 | } |
| 6182 | return true; |
| 6183 | } |
| 6184 | return false; |
| 6185 | } |
| 6186 | |
| 6187 | private void cancelFling() { |
| 6188 | if (mFlinging) { |
| 6189 | removeCallbacks(mFlingRunnable); |
| 6190 | mFlinging = false; |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | private final Runnable mFlingRunnable = new Runnable() { |
| 6195 | @Override |
| 6196 | public void run() { |
| 6197 | final long time = SystemClock.uptimeMillis(); |
| 6198 | sendKeyDownOrRepeat(time, mPendingKeyCode, mPendingKeyMetaState); |
| 6199 | mFlingVelocity *= FLING_TICK_DECAY; |
| 6200 | if (!postFling(time)) { |
| 6201 | mFlinging = false; |
| 6202 | finishKeys(time); |
| 6203 | } |
| 6204 | } |
| 6205 | }; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6206 | } |
| 6207 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6208 | final class SyntheticKeyboardHandler { |
| 6209 | public void process(KeyEvent event) { |
| 6210 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) != 0) { |
| 6211 | return; |
| 6212 | } |
| 6213 | |
| 6214 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 6215 | final int keyCode = event.getKeyCode(); |
| 6216 | final int metaState = event.getMetaState(); |
| 6217 | |
| 6218 | // Check for fallback actions specified by the key character map. |
| 6219 | KeyCharacterMap.FallbackAction fallbackAction = |
| 6220 | kcm.getFallbackAction(keyCode, metaState); |
| 6221 | if (fallbackAction != null) { |
| 6222 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 6223 | KeyEvent fallbackEvent = KeyEvent.obtain( |
| 6224 | event.getDownTime(), event.getEventTime(), |
| 6225 | event.getAction(), fallbackAction.keyCode, |
| 6226 | event.getRepeatCount(), fallbackAction.metaState, |
| 6227 | event.getDeviceId(), event.getScanCode(), |
| 6228 | flags, event.getSource(), null); |
| 6229 | fallbackAction.recycle(); |
| 6230 | enqueueInputEvent(fallbackEvent); |
| 6231 | } |
| 6232 | } |
| 6233 | } |
| 6234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6235 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6236 | * Returns true if the key is used for keyboard navigation. |
| 6237 | * @param keyEvent The key event. |
| 6238 | * @return True if the key is used for keyboard navigation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6239 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6240 | private static boolean isNavigationKey(KeyEvent keyEvent) { |
| 6241 | switch (keyEvent.getKeyCode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6242 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 6243 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 6244 | case KeyEvent.KEYCODE_DPAD_UP: |
| 6245 | case KeyEvent.KEYCODE_DPAD_DOWN: |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6246 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6247 | case KeyEvent.KEYCODE_PAGE_UP: |
| 6248 | case KeyEvent.KEYCODE_PAGE_DOWN: |
| 6249 | case KeyEvent.KEYCODE_MOVE_HOME: |
| 6250 | case KeyEvent.KEYCODE_MOVE_END: |
| 6251 | case KeyEvent.KEYCODE_TAB: |
| 6252 | case KeyEvent.KEYCODE_SPACE: |
| 6253 | case KeyEvent.KEYCODE_ENTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6254 | return true; |
| 6255 | } |
| 6256 | return false; |
| 6257 | } |
| 6258 | |
| 6259 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6260 | * Returns true if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6261 | * @param keyEvent The key event. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6262 | * @return True if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6264 | private static boolean isTypingKey(KeyEvent keyEvent) { |
| 6265 | return keyEvent.getUnicodeChar() > 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6266 | } |
| 6267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6268 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6269 | * See if the key event means we should leave touch mode (and leave touch mode if so). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6270 | * @param event The key event. |
| 6271 | * @return Whether this key event should be consumed (meaning the act of |
| 6272 | * leaving touch mode alone is considered the event). |
| 6273 | */ |
| 6274 | private boolean checkForLeavingTouchModeAndConsume(KeyEvent event) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6275 | // Only relevant in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | if (!mAttachInfo.mInTouchMode) { |
| 6277 | return false; |
| 6278 | } |
| 6279 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6280 | // Only consider leaving touch mode on DOWN or MULTIPLE actions, never on UP. |
| 6281 | final int action = event.getAction(); |
| 6282 | if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_MULTIPLE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6283 | return false; |
| 6284 | } |
| 6285 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6286 | // Don't leave touch mode if the IME told us not to. |
| 6287 | if ((event.getFlags() & KeyEvent.FLAG_KEEP_TOUCH_MODE) != 0) { |
| 6288 | return false; |
| 6289 | } |
| 6290 | |
| 6291 | // If the key can be used for keyboard navigation then leave touch mode |
| 6292 | // and select a focused view if needed (in ensureTouchMode). |
| 6293 | // When a new focused view is selected, we consume the navigation key because |
| 6294 | // navigation doesn't make much sense unless a view already has focus so |
| 6295 | // the key's purpose is to set focus. |
| 6296 | if (isNavigationKey(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6297 | return ensureTouchMode(false); |
| 6298 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6299 | |
| 6300 | // If the key can be used for typing then leave touch mode |
| 6301 | // and select a focused view if needed (in ensureTouchMode). |
| 6302 | // Always allow the view to process the typing key. |
| 6303 | if (isTypingKey(event)) { |
| 6304 | ensureTouchMode(false); |
| 6305 | return false; |
| 6306 | } |
| 6307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6308 | return false; |
| 6309 | } |
| 6310 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6311 | /* drag/drop */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 6312 | @UnsupportedAppUsage |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6313 | void setLocalDragState(Object obj) { |
| 6314 | mLocalDragState = obj; |
| 6315 | } |
| 6316 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6317 | private void handleDragEvent(DragEvent event) { |
| 6318 | // From the root, only drag start/end/location are dispatched. entered/exited |
| 6319 | // are determined and dispatched by the viewgroup hierarchy, who then report |
| 6320 | // that back here for ultimate reporting back to the framework. |
| 6321 | if (mView != null && mAdded) { |
| 6322 | final int what = event.mAction; |
| 6323 | |
Vladislav Kaznacheev | 7fe1f79 | 2016-07-14 17:15:02 -0700 | [diff] [blame] | 6324 | // Cache the drag description when the operation starts, then fill it in |
| 6325 | // on subsequent calls as a convenience |
| 6326 | if (what == DragEvent.ACTION_DRAG_STARTED) { |
| 6327 | mCurrentDragView = null; // Start the current-recipient tracking |
| 6328 | mDragDescription = event.mClipDescription; |
| 6329 | } else { |
Vladislav Kaznacheev | cd84cfa | 2016-07-26 15:17:49 -0700 | [diff] [blame] | 6330 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
| 6331 | mDragDescription = null; |
| 6332 | } |
Vladislav Kaznacheev | 7fe1f79 | 2016-07-14 17:15:02 -0700 | [diff] [blame] | 6333 | event.mClipDescription = mDragDescription; |
| 6334 | } |
| 6335 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6336 | if (what == DragEvent.ACTION_DRAG_EXITED) { |
| 6337 | // A direct EXITED event means that the window manager knows we've just crossed |
| 6338 | // a window boundary, so the current drag target within this one must have |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6339 | // just been exited. Send the EXITED notification to the current drag view, if any. |
Vadim Tryshev | 45bee6b | 2016-09-19 11:00:37 -0700 | [diff] [blame] | 6340 | if (View.sCascadedDragDrop) { |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 6341 | mView.dispatchDragEnterExitInPreN(event); |
| 6342 | } |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6343 | setDragFocus(null, event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6344 | } else { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6345 | // For events with a [screen] location, translate into window coordinates |
| 6346 | if ((what == DragEvent.ACTION_DRAG_LOCATION) || (what == DragEvent.ACTION_DROP)) { |
| 6347 | mDragPoint.set(event.mX, event.mY); |
| 6348 | if (mTranslator != null) { |
| 6349 | mTranslator.translatePointInScreenToAppWindow(mDragPoint); |
| 6350 | } |
| 6351 | |
| 6352 | if (mCurScrollY != 0) { |
| 6353 | mDragPoint.offset(0, mCurScrollY); |
| 6354 | } |
| 6355 | |
| 6356 | event.mX = mDragPoint.x; |
| 6357 | event.mY = mDragPoint.y; |
| 6358 | } |
| 6359 | |
| 6360 | // Remember who the current drag target is pre-dispatch |
| 6361 | final View prevDragView = mCurrentDragView; |
| 6362 | |
Vadim Tryshev | 6973317 | 2016-09-30 17:25:30 -0700 | [diff] [blame] | 6363 | if (what == DragEvent.ACTION_DROP && event.mClipData != null) { |
| 6364 | event.mClipData.prepareToEnterProcess(); |
Vladislav Kaznacheev | 854d3f2 | 2016-08-11 10:19:36 -0700 | [diff] [blame] | 6365 | } |
| 6366 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6367 | // Now dispatch the drag/drop event |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6368 | boolean result = mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6369 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6370 | if (what == DragEvent.ACTION_DRAG_LOCATION && !event.mEventHandlerWasCalled) { |
| 6371 | // If the LOCATION event wasn't delivered to any handler, no view now has a drag |
| 6372 | // focus. |
| 6373 | setDragFocus(null, event); |
| 6374 | } |
| 6375 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6376 | // If we changed apparent drag target, tell the OS about it |
| 6377 | if (prevDragView != mCurrentDragView) { |
| 6378 | try { |
| 6379 | if (prevDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6380 | mWindowSession.dragRecipientExited(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6381 | } |
| 6382 | if (mCurrentDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6383 | mWindowSession.dragRecipientEntered(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6384 | } |
| 6385 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6386 | Slog.e(mTag, "Unable to note drag target change"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6387 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6388 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6389 | |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6390 | // Report the drop result when we're done |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6391 | if (what == DragEvent.ACTION_DROP) { |
| 6392 | try { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6393 | Log.i(mTag, "Reporting drop result: " + result); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6394 | mWindowSession.reportDropResult(mWindow, result); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6395 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6396 | Log.e(mTag, "Unable to report drop result"); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6397 | } |
| 6398 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6399 | |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 6400 | // When the drag operation ends, reset drag-related state |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6401 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6402 | mCurrentDragView = null; |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6403 | setLocalDragState(null); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 6404 | mAttachInfo.mDragToken = null; |
Vladislav Kaznacheev | 4f63974 | 2015-11-18 13:21:35 -0800 | [diff] [blame] | 6405 | if (mAttachInfo.mDragSurface != null) { |
| 6406 | mAttachInfo.mDragSurface.release(); |
| 6407 | mAttachInfo.mDragSurface = null; |
| 6408 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6409 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6410 | } |
| 6411 | } |
| 6412 | event.recycle(); |
| 6413 | } |
| 6414 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6415 | public void handleDispatchSystemUiVisibilityChanged(SystemUiVisibilityInfo args) { |
| 6416 | if (mSeq != args.seq) { |
| 6417 | // The sequence has changed, so we need to update our value and make |
| 6418 | // sure to do a traversal afterward so the window manager is given our |
| 6419 | // most recent data. |
| 6420 | mSeq = args.seq; |
| 6421 | mAttachInfo.mForceReportNewAttributes = true; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6422 | scheduleTraversals(); |
Joe Onorato | 14782f7 | 2011-01-25 19:53:17 -0800 | [diff] [blame] | 6423 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6424 | if (mView == null) return; |
| 6425 | if (args.localChanges != 0) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6426 | mView.updateLocalSystemUiVisibility(args.localValue, args.localChanges); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6427 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6428 | |
| 6429 | int visibility = args.globalVisibility&View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6430 | if (visibility != mAttachInfo.mGlobalSystemUiVisibility) { |
| 6431 | mAttachInfo.mGlobalSystemUiVisibility = visibility; |
| 6432 | mView.dispatchSystemUiVisibilityChanged(visibility); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 6433 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6434 | } |
| 6435 | |
Phil Weaver | 964c68e | 2016-10-27 16:22:05 -0700 | [diff] [blame] | 6436 | /** |
| 6437 | * Notify that the window title changed |
| 6438 | */ |
| 6439 | public void onWindowTitleChanged() { |
| 6440 | mAttachInfo.mForceReportNewAttributes = true; |
| 6441 | } |
| 6442 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 6443 | public void handleDispatchWindowShown() { |
| 6444 | mAttachInfo.mTreeObserver.dispatchOnWindowShown(); |
| 6445 | } |
| 6446 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 6447 | public void handleRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6448 | Bundle data = new Bundle(); |
| 6449 | ArrayList<KeyboardShortcutGroup> list = new ArrayList<>(); |
| 6450 | if (mView != null) { |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 6451 | mView.requestKeyboardShortcuts(list, deviceId); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6452 | } |
| 6453 | data.putParcelableArrayList(WindowManager.PARCEL_KEY_SHORTCUTS_ARRAY, list); |
| 6454 | try { |
| 6455 | receiver.send(0, data); |
| 6456 | } catch (RemoteException e) { |
| 6457 | } |
| 6458 | } |
| 6459 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 6460 | @UnsupportedAppUsage |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6461 | public void getLastTouchPoint(Point outLocation) { |
| 6462 | outLocation.x = (int) mLastTouchPoint.x; |
| 6463 | outLocation.y = (int) mLastTouchPoint.y; |
| 6464 | } |
| 6465 | |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 6466 | public int getLastTouchSource() { |
| 6467 | return mLastTouchSource; |
| 6468 | } |
| 6469 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6470 | public void setDragFocus(View newDragTarget, DragEvent event) { |
Vadim Tryshev | 45bee6b | 2016-09-19 11:00:37 -0700 | [diff] [blame] | 6471 | if (mCurrentDragView != newDragTarget && !View.sCascadedDragDrop) { |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6472 | // Send EXITED and ENTERED notifications to the old and new drag focus views. |
| 6473 | |
| 6474 | final float tx = event.mX; |
| 6475 | final float ty = event.mY; |
| 6476 | final int action = event.mAction; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 6477 | final ClipData td = event.mClipData; |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6478 | // Position should not be available for ACTION_DRAG_ENTERED and ACTION_DRAG_EXITED. |
| 6479 | event.mX = 0; |
| 6480 | event.mY = 0; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 6481 | event.mClipData = null; |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6482 | |
| 6483 | if (mCurrentDragView != null) { |
| 6484 | event.mAction = DragEvent.ACTION_DRAG_EXITED; |
| 6485 | mCurrentDragView.callDragEventHandler(event); |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6486 | } |
| 6487 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6488 | if (newDragTarget != null) { |
| 6489 | event.mAction = DragEvent.ACTION_DRAG_ENTERED; |
| 6490 | newDragTarget.callDragEventHandler(event); |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6491 | } |
| 6492 | |
| 6493 | event.mAction = action; |
| 6494 | event.mX = tx; |
| 6495 | event.mY = ty; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 6496 | event.mClipData = td; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6497 | } |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 6498 | |
| 6499 | mCurrentDragView = newDragTarget; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6500 | } |
| 6501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6502 | private AudioManager getAudioManager() { |
| 6503 | if (mView == null) { |
| 6504 | throw new IllegalStateException("getAudioManager called when there is no mView"); |
| 6505 | } |
| 6506 | if (mAudioManager == null) { |
| 6507 | mAudioManager = (AudioManager) mView.getContext().getSystemService(Context.AUDIO_SERVICE); |
| 6508 | } |
| 6509 | return mAudioManager; |
| 6510 | } |
| 6511 | |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 6512 | private @Nullable AutofillManager getAutofillManager() { |
| 6513 | if (mView instanceof ViewGroup) { |
| 6514 | ViewGroup decorView = (ViewGroup) mView; |
| 6515 | if (decorView.getChildCount() > 0) { |
| 6516 | // We cannot use decorView's Context for querying AutofillManager: DecorView's |
| 6517 | // context is based on Application Context, it would allocate a different |
| 6518 | // AutofillManager instance. |
| 6519 | return decorView.getChildAt(0).getContext() |
| 6520 | .getSystemService(AutofillManager.class); |
| 6521 | } |
| 6522 | } |
| 6523 | return null; |
| 6524 | } |
| 6525 | |
| 6526 | private boolean isAutofillUiShowing() { |
| 6527 | AutofillManager afm = getAutofillManager(); |
| 6528 | if (afm == null) { |
| 6529 | return false; |
| 6530 | } |
| 6531 | return afm.isAutofillUiShowing(); |
| 6532 | } |
| 6533 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6534 | public AccessibilityInteractionController getAccessibilityInteractionController() { |
| 6535 | if (mView == null) { |
| 6536 | throw new IllegalStateException("getAccessibilityInteractionController" |
| 6537 | + " called when there is no mView"); |
| 6538 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 6539 | if (mAccessibilityInteractionController == null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6540 | mAccessibilityInteractionController = new AccessibilityInteractionController(this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6541 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 6542 | return mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6543 | } |
| 6544 | |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 6545 | private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility, |
| 6546 | boolean insetsPending) throws RemoteException { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6547 | |
| 6548 | float appScale = mAttachInfo.mApplicationScale; |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6549 | boolean restore = false; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6550 | if (params != null && mTranslator != null) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6551 | restore = true; |
| 6552 | params.backup(); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6553 | mTranslator.translateWindowLayout(params); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6554 | } |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 6555 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6556 | if (params != null) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6557 | if (DBG) Log.d(mTag, "WindowLayout in layoutWindow:" + params); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 6558 | |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 6559 | if (mOrigWindowType != params.type) { |
| 6560 | // For compatibility with old apps, don't crash here. |
| 6561 | if (mTargetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
| 6562 | Slog.w(mTag, "Window type can not be changed after " |
| 6563 | + "the window is added; ignoring change of " + mView); |
| 6564 | params.type = mOrigWindowType; |
| 6565 | } |
| 6566 | } |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 6567 | } |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 6568 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 6569 | long frameNumber = -1; |
| 6570 | if (mSurface.isValid()) { |
| 6571 | frameNumber = mSurface.getNextFrameNumber(); |
| 6572 | } |
| 6573 | |
| 6574 | int relayoutResult = mWindowSession.relayout(mWindow, mSeq, params, |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6575 | (int) (mView.getMeasuredWidth() * appScale + 0.5f), |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 6576 | (int) (mView.getMeasuredHeight() * appScale + 0.5f), viewVisibility, |
| 6577 | insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, frameNumber, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6578 | mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 6579 | mPendingStableInsets, mPendingOutsets, mPendingBackDropFrame, mPendingDisplayCutout, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6580 | mPendingMergedConfiguration, mSurface); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6581 | |
| 6582 | mPendingAlwaysConsumeNavBar = |
| 6583 | (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_CONSUME_ALWAYS_NAV_BAR) != 0; |
| 6584 | |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6585 | if (restore) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6586 | params.restore(); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6587 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6588 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6589 | if (mTranslator != null) { |
| 6590 | mTranslator.translateRectInScreenToAppWinFrame(mWinFrame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6591 | mTranslator.translateRectInScreenToAppWindow(mPendingOverscanInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6592 | mTranslator.translateRectInScreenToAppWindow(mPendingContentInsets); |
| 6593 | mTranslator.translateRectInScreenToAppWindow(mPendingVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 6594 | mTranslator.translateRectInScreenToAppWindow(mPendingStableInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6595 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 6596 | return relayoutResult; |
| 6597 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6598 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6599 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6600 | * {@inheritDoc} |
| 6601 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6602 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6603 | public void playSoundEffect(int effectId) { |
| 6604 | checkThread(); |
| 6605 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 6606 | try { |
| 6607 | final AudioManager audioManager = getAudioManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6608 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 6609 | switch (effectId) { |
| 6610 | case SoundEffectConstants.CLICK: |
| 6611 | audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); |
| 6612 | return; |
| 6613 | case SoundEffectConstants.NAVIGATION_DOWN: |
| 6614 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_DOWN); |
| 6615 | return; |
| 6616 | case SoundEffectConstants.NAVIGATION_LEFT: |
| 6617 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_LEFT); |
| 6618 | return; |
| 6619 | case SoundEffectConstants.NAVIGATION_RIGHT: |
| 6620 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_RIGHT); |
| 6621 | return; |
| 6622 | case SoundEffectConstants.NAVIGATION_UP: |
| 6623 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_UP); |
| 6624 | return; |
| 6625 | default: |
| 6626 | throw new IllegalArgumentException("unknown effect id " + effectId + |
| 6627 | " not defined in " + SoundEffectConstants.class.getCanonicalName()); |
| 6628 | } |
| 6629 | } catch (IllegalStateException e) { |
| 6630 | // Exception thrown by getAudioManager() when mView is null |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6631 | Log.e(mTag, "FATAL EXCEPTION when attempting to play sound effect: " + e); |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 6632 | e.printStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | } |
| 6634 | } |
| 6635 | |
| 6636 | /** |
| 6637 | * {@inheritDoc} |
| 6638 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6639 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6640 | public boolean performHapticFeedback(int effectId, boolean always) { |
| 6641 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6642 | return mWindowSession.performHapticFeedback(mWindow, effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6643 | } catch (RemoteException e) { |
| 6644 | return false; |
| 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | /** |
| 6649 | * {@inheritDoc} |
| 6650 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6651 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | public View focusSearch(View focused, int direction) { |
| 6653 | checkThread(); |
| 6654 | if (!(mView instanceof ViewGroup)) { |
| 6655 | return null; |
| 6656 | } |
| 6657 | return FocusFinder.getInstance().findNextFocus((ViewGroup) mView, focused, direction); |
| 6658 | } |
| 6659 | |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 6660 | /** |
| 6661 | * {@inheritDoc} |
| 6662 | */ |
| 6663 | @Override |
Evan Rosky | 5722331 | 2017-02-08 14:42:45 -0800 | [diff] [blame] | 6664 | public View keyboardNavigationClusterSearch(View currentCluster, |
| 6665 | @FocusDirection int direction) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 6666 | checkThread(); |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 6667 | return FocusFinder.getInstance().findNextKeyboardNavigationCluster( |
| 6668 | mView, currentCluster, direction); |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 6669 | } |
| 6670 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6671 | public void debug() { |
| 6672 | mView.debug(); |
| 6673 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6674 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6675 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 6676 | String innerPrefix = prefix + " "; |
| 6677 | writer.print(prefix); writer.println("ViewRoot:"); |
| 6678 | writer.print(innerPrefix); writer.print("mAdded="); writer.print(mAdded); |
| 6679 | writer.print(" mRemoved="); writer.println(mRemoved); |
| 6680 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputScheduled="); |
| 6681 | writer.println(mConsumeBatchedInputScheduled); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6682 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputImmediatelyScheduled="); |
| 6683 | writer.println(mConsumeBatchedInputImmediatelyScheduled); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6684 | writer.print(innerPrefix); writer.print("mPendingInputEventCount="); |
| 6685 | writer.println(mPendingInputEventCount); |
| 6686 | writer.print(innerPrefix); writer.print("mProcessInputEventsScheduled="); |
| 6687 | writer.println(mProcessInputEventsScheduled); |
| 6688 | writer.print(innerPrefix); writer.print("mTraversalScheduled="); |
| 6689 | writer.print(mTraversalScheduled); |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 6690 | writer.print(innerPrefix); writer.print("mIsAmbientMode="); |
| 6691 | writer.print(mIsAmbientMode); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6692 | if (mTraversalScheduled) { |
| 6693 | writer.print(" (barrier="); writer.print(mTraversalBarrier); writer.println(")"); |
| 6694 | } else { |
| 6695 | writer.println(); |
| 6696 | } |
| 6697 | mFirstInputStage.dump(innerPrefix, writer); |
| 6698 | |
| 6699 | mChoreographer.dump(prefix, writer); |
| 6700 | |
| 6701 | writer.print(prefix); writer.println("View Hierarchy:"); |
| 6702 | dumpViewHierarchy(innerPrefix, writer, mView); |
| 6703 | } |
| 6704 | |
| 6705 | private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) { |
| 6706 | writer.print(prefix); |
| 6707 | if (view == null) { |
| 6708 | writer.println("null"); |
| 6709 | return; |
| 6710 | } |
| 6711 | writer.println(view.toString()); |
| 6712 | if (!(view instanceof ViewGroup)) { |
| 6713 | return; |
| 6714 | } |
| 6715 | ViewGroup grp = (ViewGroup)view; |
| 6716 | final int N = grp.getChildCount(); |
| 6717 | if (N <= 0) { |
| 6718 | return; |
| 6719 | } |
| 6720 | prefix = prefix + " "; |
| 6721 | for (int i=0; i<N; i++) { |
| 6722 | dumpViewHierarchy(prefix, writer, grp.getChildAt(i)); |
| 6723 | } |
| 6724 | } |
| 6725 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 6726 | public void dumpGfxInfo(int[] info) { |
Romain Guy | 54ab347 | 2012-06-14 12:52:53 -0700 | [diff] [blame] | 6727 | info[0] = info[1] = 0; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6728 | if (mView != null) { |
| 6729 | getGfxInfo(mView, info); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6730 | } |
| 6731 | } |
| 6732 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6733 | private static void getGfxInfo(View view, int[] info) { |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 6734 | RenderNode renderNode = view.mRenderNode; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6735 | info[0]++; |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 6736 | if (renderNode != null) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 6737 | info[1] += renderNode.getDebugSize(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | if (view instanceof ViewGroup) { |
| 6741 | ViewGroup group = (ViewGroup) view; |
| 6742 | |
| 6743 | int count = group.getChildCount(); |
| 6744 | for (int i = 0; i < count; i++) { |
| 6745 | getGfxInfo(group.getChildAt(i), info); |
| 6746 | } |
| 6747 | } |
| 6748 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6749 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6750 | /** |
| 6751 | * @param immediate True, do now if not in traversal. False, put on queue and do later. |
| 6752 | * @return True, request has been queued. False, request has been completed. |
| 6753 | */ |
| 6754 | boolean die(boolean immediate) { |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 6755 | // Make sure we do execute immediately if we are in the middle of a traversal or the damage |
| 6756 | // done by dispatchDetachedFromWindow will cause havoc on return. |
| 6757 | if (immediate && !mIsInTraversal) { |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 6758 | doDie(); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6759 | return false; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 6760 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6761 | |
| 6762 | if (!mIsDrawing) { |
| 6763 | destroyHardwareRenderer(); |
| 6764 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6765 | Log.e(mTag, "Attempting to destroy the window while drawing!\n" + |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6766 | " window=" + this + ", title=" + mWindowAttributes.getTitle()); |
| 6767 | } |
| 6768 | mHandler.sendEmptyMessage(MSG_DIE); |
| 6769 | return true; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 6770 | } |
| 6771 | |
| 6772 | void doDie() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6773 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6774 | if (LOCAL_LOGV) Log.v(mTag, "DIE in " + this + " of " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6775 | synchronized (this) { |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6776 | if (mRemoved) { |
| 6777 | return; |
| 6778 | } |
| 6779 | mRemoved = true; |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 6780 | if (mAdded) { |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 6781 | dispatchDetachedFromWindow(); |
| 6782 | } |
| 6783 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6784 | if (mAdded && !mFirst) { |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 6785 | destroyHardwareRenderer(); |
| 6786 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6787 | if (mView != null) { |
| 6788 | int viewVisibility = mView.getVisibility(); |
| 6789 | boolean viewVisibilityChanged = mViewVisibility != viewVisibility; |
| 6790 | if (mWindowAttributesChanged || viewVisibilityChanged) { |
| 6791 | // If layout params have been changed, first give them |
| 6792 | // to the window manager to make sure it has the correct |
| 6793 | // animation info. |
| 6794 | try { |
| 6795 | if ((relayoutWindow(mWindowAttributes, viewVisibility, false) |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6796 | & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
| 6797 | mWindowSession.finishDrawing(mWindow); |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6798 | } |
| 6799 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6801 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6802 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6803 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6805 | } |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6806 | |
| 6807 | mAdded = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6808 | } |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 6809 | WindowManagerGlobal.getInstance().doRemoveView(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6810 | } |
| 6811 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6812 | public void requestUpdateConfiguration(Configuration config) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6813 | Message msg = mHandler.obtainMessage(MSG_UPDATE_CONFIGURATION, config); |
| 6814 | mHandler.sendMessage(msg); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6815 | } |
| 6816 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 6817 | public void loadSystemProperties() { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6818 | mHandler.post(new Runnable() { |
| 6819 | @Override |
| 6820 | public void run() { |
| 6821 | // Profiling |
| 6822 | mProfileRendering = SystemProperties.getBoolean(PROPERTY_PROFILE_RENDERING, false); |
| 6823 | profileRendering(mAttachInfo.mHasWindowFocus); |
| 6824 | |
| 6825 | // Hardware rendering |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 6826 | if (mAttachInfo.mThreadedRenderer != null) { |
| 6827 | if (mAttachInfo.mThreadedRenderer.loadSystemProperties()) { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6828 | invalidate(); |
| 6829 | } |
| 6830 | } |
| 6831 | |
| 6832 | // Layout debugging |
Kiyoung Kim | 89052d9 | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 6833 | boolean layout = DisplayProperties.debug_layout().orElse(false); |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6834 | if (layout != mAttachInfo.mDebugLayout) { |
| 6835 | mAttachInfo.mDebugLayout = layout; |
| 6836 | if (!mHandler.hasMessages(MSG_INVALIDATE_WORLD)) { |
| 6837 | mHandler.sendEmptyMessageDelayed(MSG_INVALIDATE_WORLD, 200); |
| 6838 | } |
| 6839 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 6840 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6841 | }); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 6842 | } |
| 6843 | |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 6844 | private void destroyHardwareRenderer() { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 6845 | ThreadedRenderer hardwareRenderer = mAttachInfo.mThreadedRenderer; |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6846 | |
| 6847 | if (hardwareRenderer != null) { |
| 6848 | if (mView != null) { |
| 6849 | hardwareRenderer.destroyHardwareResources(mView); |
| 6850 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 6851 | hardwareRenderer.destroy(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6852 | hardwareRenderer.setRequested(false); |
| 6853 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 6854 | mAttachInfo.mThreadedRenderer = null; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6855 | mAttachInfo.mHardwareAccelerated = false; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 6856 | } |
| 6857 | } |
| 6858 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 6859 | @UnsupportedAppUsage |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6860 | private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6861 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6862 | MergedConfiguration mergedConfiguration, Rect backDropFrame, boolean forceLayout, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 6863 | boolean alwaysConsumeNavBar, int displayId, |
| 6864 | DisplayCutout.ParcelableWrapper displayCutout) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6865 | if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString() |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6866 | + " contentInsets=" + contentInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | + " visibleInsets=" + visibleInsets.toShortString() |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 6868 | + " reportDraw=" + reportDraw |
| 6869 | + " backDropFrame=" + backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 6870 | |
| 6871 | // Tell all listeners that we are resizing the window so that the chrome can get |
| 6872 | // updated as fast as possible on a separate thread, |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 6873 | if (mDragResizing && mUseMTRenderer) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 6874 | boolean fullscreen = frame.equals(backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 6875 | synchronized (mWindowCallbacks) { |
| 6876 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 6877 | mWindowCallbacks.get(i).onWindowSizeIsChanging(backDropFrame, fullscreen, |
| 6878 | visibleInsets, stableInsets); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 6879 | } |
| 6880 | } |
| 6881 | } |
| 6882 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6883 | Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6884 | if (mTranslator != null) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6885 | mTranslator.translateRectInScreenToAppWindow(frame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6886 | mTranslator.translateRectInScreenToAppWindow(overscanInsets); |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 6887 | mTranslator.translateRectInScreenToAppWindow(contentInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6888 | mTranslator.translateRectInScreenToAppWindow(visibleInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6889 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6890 | SomeArgs args = SomeArgs.obtain(); |
| 6891 | final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid()); |
| 6892 | args.arg1 = sameProcessCall ? new Rect(frame) : frame; |
| 6893 | args.arg2 = sameProcessCall ? new Rect(contentInsets) : contentInsets; |
| 6894 | args.arg3 = sameProcessCall ? new Rect(visibleInsets) : visibleInsets; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6895 | args.arg4 = sameProcessCall && mergedConfiguration != null |
Wale Ogunwale | cdc8ada | 2017-03-30 13:55:36 -0700 | [diff] [blame] | 6896 | ? new MergedConfiguration(mergedConfiguration) : mergedConfiguration; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6897 | args.arg5 = sameProcessCall ? new Rect(overscanInsets) : overscanInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 6898 | args.arg6 = sameProcessCall ? new Rect(stableInsets) : stableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6899 | args.arg7 = sameProcessCall ? new Rect(outsets) : outsets; |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 6900 | args.arg8 = sameProcessCall ? new Rect(backDropFrame) : backDropFrame; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 6901 | args.arg9 = displayCutout.get(); // DisplayCutout is immutable. |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 6902 | args.argi1 = forceLayout ? 1 : 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6903 | args.argi2 = alwaysConsumeNavBar ? 1 : 0; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6904 | args.argi3 = displayId; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6905 | msg.obj = args; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6906 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6907 | } |
Chet Haase | 1f4786b | 2011-11-02 10:51:52 -0700 | [diff] [blame] | 6908 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 6909 | public void dispatchMoved(int newX, int newY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6910 | if (DEBUG_LAYOUT) Log.v(mTag, "Window moved " + this + ": newX=" + newX + " newY=" + newY); |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 6911 | if (mTranslator != null) { |
| 6912 | PointF point = new PointF(newX, newY); |
| 6913 | mTranslator.translatePointInScreenToAppWindow(point); |
| 6914 | newX = (int) (point.x + 0.5); |
| 6915 | newY = (int) (point.y + 0.5); |
| 6916 | } |
| 6917 | Message msg = mHandler.obtainMessage(MSG_WINDOW_MOVED, newX, newY); |
| 6918 | mHandler.sendMessage(msg); |
| 6919 | } |
| 6920 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6921 | /** |
| 6922 | * Represents a pending input event that is waiting in a queue. |
| 6923 | * |
| 6924 | * Input events are processed in serial order by the timestamp specified by |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 6925 | * {@link InputEvent#getEventTimeNano()}. In general, the input dispatcher delivers |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6926 | * one input event to the application at a time and waits for the application |
| 6927 | * to finish handling it before delivering the next one. |
| 6928 | * |
| 6929 | * However, because the application or IME can synthesize and inject multiple |
| 6930 | * key events at a time without going through the input dispatcher, we end up |
| 6931 | * needing a queue on the application's side. |
| 6932 | */ |
| 6933 | private static final class QueuedInputEvent { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6934 | public static final int FLAG_DELIVER_POST_IME = 1 << 0; |
| 6935 | public static final int FLAG_DEFERRED = 1 << 1; |
| 6936 | public static final int FLAG_FINISHED = 1 << 2; |
| 6937 | public static final int FLAG_FINISHED_HANDLED = 1 << 3; |
| 6938 | public static final int FLAG_RESYNTHESIZED = 1 << 4; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6939 | public static final int FLAG_UNHANDLED = 1 << 5; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6940 | |
| 6941 | public QueuedInputEvent mNext; |
| 6942 | |
| 6943 | public InputEvent mEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6944 | public InputEventReceiver mReceiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6945 | public int mFlags; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6946 | |
| 6947 | public boolean shouldSkipIme() { |
| 6948 | if ((mFlags & FLAG_DELIVER_POST_IME) != 0) { |
| 6949 | return true; |
| 6950 | } |
| 6951 | return mEvent instanceof MotionEvent |
Prashant Malani | fecbc67 | 2016-07-22 15:38:05 -0700 | [diff] [blame] | 6952 | && (mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER) |
| 6953 | || mEvent.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6954 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6955 | |
| 6956 | public boolean shouldSendToSynthesizer() { |
| 6957 | if ((mFlags & FLAG_UNHANDLED) != 0) { |
| 6958 | return true; |
| 6959 | } |
| 6960 | |
| 6961 | return false; |
| 6962 | } |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 6963 | |
| 6964 | @Override |
| 6965 | public String toString() { |
| 6966 | StringBuilder sb = new StringBuilder("QueuedInputEvent{flags="); |
| 6967 | boolean hasPrevious = false; |
| 6968 | hasPrevious = flagToString("DELIVER_POST_IME", FLAG_DELIVER_POST_IME, hasPrevious, sb); |
| 6969 | hasPrevious = flagToString("DEFERRED", FLAG_DEFERRED, hasPrevious, sb); |
| 6970 | hasPrevious = flagToString("FINISHED", FLAG_FINISHED, hasPrevious, sb); |
| 6971 | hasPrevious = flagToString("FINISHED_HANDLED", FLAG_FINISHED_HANDLED, hasPrevious, sb); |
| 6972 | hasPrevious = flagToString("RESYNTHESIZED", FLAG_RESYNTHESIZED, hasPrevious, sb); |
| 6973 | hasPrevious = flagToString("UNHANDLED", FLAG_UNHANDLED, hasPrevious, sb); |
| 6974 | if (!hasPrevious) { |
| 6975 | sb.append("0"); |
| 6976 | } |
| 6977 | sb.append(", hasNextQueuedEvent=" + (mEvent != null ? "true" : "false")); |
| 6978 | sb.append(", hasInputEventReceiver=" + (mReceiver != null ? "true" : "false")); |
| 6979 | sb.append(", mEvent=" + mEvent + "}"); |
| 6980 | return sb.toString(); |
| 6981 | } |
| 6982 | |
| 6983 | private boolean flagToString(String name, int flag, |
| 6984 | boolean hasPrevious, StringBuilder sb) { |
| 6985 | if ((mFlags & flag) != 0) { |
| 6986 | if (hasPrevious) { |
| 6987 | sb.append("|"); |
| 6988 | } |
| 6989 | sb.append(name); |
| 6990 | return true; |
| 6991 | } |
| 6992 | return hasPrevious; |
| 6993 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6994 | } |
| 6995 | |
| 6996 | private QueuedInputEvent obtainQueuedInputEvent(InputEvent event, |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6997 | InputEventReceiver receiver, int flags) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6998 | QueuedInputEvent q = mQueuedInputEventPool; |
| 6999 | if (q != null) { |
| 7000 | mQueuedInputEventPoolSize -= 1; |
| 7001 | mQueuedInputEventPool = q.mNext; |
| 7002 | q.mNext = null; |
| 7003 | } else { |
| 7004 | q = new QueuedInputEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7005 | } |
| 7006 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7007 | q.mEvent = event; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7008 | q.mReceiver = receiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7009 | q.mFlags = flags; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7010 | return q; |
| 7011 | } |
| 7012 | |
| 7013 | private void recycleQueuedInputEvent(QueuedInputEvent q) { |
| 7014 | q.mEvent = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7015 | q.mReceiver = null; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7016 | |
| 7017 | if (mQueuedInputEventPoolSize < MAX_QUEUED_INPUT_EVENT_POOL_SIZE) { |
| 7018 | mQueuedInputEventPoolSize += 1; |
| 7019 | q.mNext = mQueuedInputEventPool; |
| 7020 | mQueuedInputEventPool = q; |
| 7021 | } |
| 7022 | } |
| 7023 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7024 | @UnsupportedAppUsage |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 7025 | void enqueueInputEvent(InputEvent event) { |
| 7026 | enqueueInputEvent(event, null, 0, false); |
| 7027 | } |
| 7028 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7029 | @UnsupportedAppUsage |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7030 | void enqueueInputEvent(InputEvent event, |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 7031 | InputEventReceiver receiver, int flags, boolean processImmediately) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 7032 | adjustInputEventForCompatibility(event); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7033 | QueuedInputEvent q = obtainQueuedInputEvent(event, receiver, flags); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7034 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7035 | // Always enqueue the input event in order, regardless of its time stamp. |
| 7036 | // We do this because the application or the IME may inject key events |
| 7037 | // in response to touch events and we want to ensure that the injected keys |
| 7038 | // are processed in the order they were received and we cannot trust that |
| 7039 | // the time stamp of injected events are monotonic. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7040 | QueuedInputEvent last = mPendingInputEventTail; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7041 | if (last == null) { |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7042 | mPendingInputEventHead = q; |
| 7043 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7044 | } else { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7045 | last.mNext = q; |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7046 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7047 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 7048 | mPendingInputEventCount += 1; |
| 7049 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 7050 | mPendingInputEventCount); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7051 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 7052 | if (processImmediately) { |
| 7053 | doProcessInputEvents(); |
| 7054 | } else { |
| 7055 | scheduleProcessInputEvents(); |
| 7056 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7057 | } |
| 7058 | |
| 7059 | private void scheduleProcessInputEvents() { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 7060 | if (!mProcessInputEventsScheduled) { |
| 7061 | mProcessInputEventsScheduled = true; |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7062 | Message msg = mHandler.obtainMessage(MSG_PROCESS_INPUT_EVENTS); |
| 7063 | msg.setAsynchronous(true); |
| 7064 | mHandler.sendMessage(msg); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7065 | } |
| 7066 | } |
| 7067 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7068 | void doProcessInputEvents() { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7069 | // Deliver all pending input events in the queue. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7070 | while (mPendingInputEventHead != null) { |
| 7071 | QueuedInputEvent q = mPendingInputEventHead; |
| 7072 | mPendingInputEventHead = q.mNext; |
| 7073 | if (mPendingInputEventHead == null) { |
| 7074 | mPendingInputEventTail = null; |
| 7075 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7076 | q.mNext = null; |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 7077 | |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 7078 | mPendingInputEventCount -= 1; |
| 7079 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 7080 | mPendingInputEventCount); |
| 7081 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 7082 | long eventTime = q.mEvent.getEventTimeNano(); |
| 7083 | long oldestEventTime = eventTime; |
| 7084 | if (q.mEvent instanceof MotionEvent) { |
| 7085 | MotionEvent me = (MotionEvent)q.mEvent; |
| 7086 | if (me.getHistorySize() > 0) { |
| 7087 | oldestEventTime = me.getHistoricalEventTimeNano(0); |
| 7088 | } |
| 7089 | } |
| 7090 | mChoreographer.mFrameInfo.updateInputEventTime(eventTime, oldestEventTime); |
| 7091 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7092 | deliverInputEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7093 | } |
| 7094 | |
| 7095 | // We are done processing all input events that we can process right now |
| 7096 | // so we can clear the pending flag immediately. |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 7097 | if (mProcessInputEventsScheduled) { |
| 7098 | mProcessInputEventsScheduled = false; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7099 | mHandler.removeMessages(MSG_PROCESS_INPUT_EVENTS); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7100 | } |
| 7101 | } |
| 7102 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7103 | private void deliverInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 7104 | Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 7105 | q.mEvent.getSequenceNumber()); |
| 7106 | if (mInputEventConsistencyVerifier != null) { |
| 7107 | mInputEventConsistencyVerifier.onInputEvent(q.mEvent, 0); |
| 7108 | } |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7109 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7110 | InputStage stage; |
| 7111 | if (q.shouldSendToSynthesizer()) { |
| 7112 | stage = mSyntheticInputStage; |
| 7113 | } else { |
| 7114 | stage = q.shouldSkipIme() ? mFirstPostImeInputStage : mFirstInputStage; |
| 7115 | } |
| 7116 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 7117 | if (q.mEvent instanceof KeyEvent) { |
| 7118 | mUnhandledKeyManager.preDispatch((KeyEvent) q.mEvent); |
| 7119 | } |
| 7120 | |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 7121 | if (stage != null) { |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 7122 | handleWindowFocusChanged(); |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 7123 | stage.deliver(q); |
| 7124 | } else { |
| 7125 | finishInputEvent(q); |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 7126 | } |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 7127 | } |
| 7128 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7129 | private void finishInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 7130 | Trace.asyncTraceEnd(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 7131 | q.mEvent.getSequenceNumber()); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7132 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7133 | if (q.mReceiver != null) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7134 | boolean handled = (q.mFlags & QueuedInputEvent.FLAG_FINISHED_HANDLED) != 0; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7135 | q.mReceiver.finishInputEvent(q.mEvent, handled); |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 7136 | } else { |
| 7137 | q.mEvent.recycleIfNeededAfterDispatch(); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7138 | } |
| 7139 | |
| 7140 | recycleQueuedInputEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 7141 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7142 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 7143 | private void adjustInputEventForCompatibility(InputEvent e) { |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 7144 | if (mTargetSdkVersion < Build.VERSION_CODES.M && e instanceof MotionEvent) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 7145 | MotionEvent motion = (MotionEvent) e; |
| 7146 | final int mask = |
| 7147 | MotionEvent.BUTTON_STYLUS_PRIMARY | MotionEvent.BUTTON_STYLUS_SECONDARY; |
| 7148 | final int buttonState = motion.getButtonState(); |
| 7149 | final int compatButtonState = (buttonState & mask) >> 4; |
| 7150 | if (compatButtonState != 0) { |
| 7151 | motion.setButtonState(buttonState | compatButtonState); |
| 7152 | } |
| 7153 | } |
| 7154 | } |
| 7155 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7156 | static boolean isTerminalInputEvent(InputEvent event) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 7157 | if (event instanceof KeyEvent) { |
| 7158 | final KeyEvent keyEvent = (KeyEvent)event; |
| 7159 | return keyEvent.getAction() == KeyEvent.ACTION_UP; |
| 7160 | } else { |
| 7161 | final MotionEvent motionEvent = (MotionEvent)event; |
| 7162 | final int action = motionEvent.getAction(); |
| 7163 | return action == MotionEvent.ACTION_UP |
| 7164 | || action == MotionEvent.ACTION_CANCEL |
| 7165 | || action == MotionEvent.ACTION_HOVER_EXIT; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7166 | } |
| 7167 | } |
| 7168 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7169 | void scheduleConsumeBatchedInput() { |
| 7170 | if (!mConsumeBatchedInputScheduled) { |
| 7171 | mConsumeBatchedInputScheduled = true; |
| 7172 | mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, |
| 7173 | mConsumedBatchedInputRunnable, null); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 7174 | } |
| 7175 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7176 | |
| 7177 | void unscheduleConsumeBatchedInput() { |
| 7178 | if (mConsumeBatchedInputScheduled) { |
| 7179 | mConsumeBatchedInputScheduled = false; |
| 7180 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT, |
| 7181 | mConsumedBatchedInputRunnable, null); |
| 7182 | } |
| 7183 | } |
| 7184 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7185 | void scheduleConsumeBatchedInputImmediately() { |
| 7186 | if (!mConsumeBatchedInputImmediatelyScheduled) { |
| 7187 | unscheduleConsumeBatchedInput(); |
| 7188 | mConsumeBatchedInputImmediatelyScheduled = true; |
| 7189 | mHandler.post(mConsumeBatchedInputImmediatelyRunnable); |
| 7190 | } |
| 7191 | } |
| 7192 | |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 7193 | void doConsumeBatchedInput(long frameTimeNanos) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7194 | if (mConsumeBatchedInputScheduled) { |
| 7195 | mConsumeBatchedInputScheduled = false; |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 7196 | if (mInputEventReceiver != null) { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7197 | if (mInputEventReceiver.consumeBatchedInputEvents(frameTimeNanos) |
| 7198 | && frameTimeNanos != -1) { |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 7199 | // If we consumed a batch here, we want to go ahead and schedule the |
| 7200 | // consumption of batched input events on the next frame. Otherwise, we would |
| 7201 | // wait until we have more input events pending and might get starved by other |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7202 | // things occurring in the process. If the frame time is -1, however, then |
| 7203 | // we're in a non-batching mode, so there's no need to schedule this. |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 7204 | scheduleConsumeBatchedInput(); |
| 7205 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7206 | } |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 7207 | doProcessInputEvents(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7208 | } |
| 7209 | } |
| 7210 | |
| 7211 | final class TraversalRunnable implements Runnable { |
| 7212 | @Override |
| 7213 | public void run() { |
| 7214 | doTraversal(); |
| 7215 | } |
| 7216 | } |
| 7217 | final TraversalRunnable mTraversalRunnable = new TraversalRunnable(); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 7218 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7219 | final class WindowInputEventReceiver extends InputEventReceiver { |
| 7220 | public WindowInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 7221 | super(inputChannel, looper); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7222 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7223 | |
| 7224 | @Override |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 7225 | public void onInputEvent(InputEvent event, int displayId) { |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 7226 | enqueueInputEvent(event, this, 0, true); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7227 | } |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 7228 | |
| 7229 | @Override |
| 7230 | public void onBatchedInputEventPending() { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7231 | if (mUnbufferedInputDispatch) { |
| 7232 | super.onBatchedInputEventPending(); |
| 7233 | } else { |
| 7234 | scheduleConsumeBatchedInput(); |
| 7235 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7236 | } |
| 7237 | |
| 7238 | @Override |
| 7239 | public void dispose() { |
| 7240 | unscheduleConsumeBatchedInput(); |
| 7241 | super.dispose(); |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 7242 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7243 | } |
| 7244 | WindowInputEventReceiver mInputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7246 | final class ConsumeBatchedInputRunnable implements Runnable { |
| 7247 | @Override |
| 7248 | public void run() { |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 7249 | doConsumeBatchedInput(mChoreographer.getFrameTimeNanos()); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7250 | } |
| 7251 | } |
| 7252 | final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable = |
| 7253 | new ConsumeBatchedInputRunnable(); |
| 7254 | boolean mConsumeBatchedInputScheduled; |
| 7255 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7256 | final class ConsumeBatchedInputImmediatelyRunnable implements Runnable { |
| 7257 | @Override |
| 7258 | public void run() { |
| 7259 | doConsumeBatchedInput(-1); |
| 7260 | } |
| 7261 | } |
| 7262 | final ConsumeBatchedInputImmediatelyRunnable mConsumeBatchedInputImmediatelyRunnable = |
| 7263 | new ConsumeBatchedInputImmediatelyRunnable(); |
| 7264 | boolean mConsumeBatchedInputImmediatelyScheduled; |
| 7265 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7266 | final class InvalidateOnAnimationRunnable implements Runnable { |
| 7267 | private boolean mPosted; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7268 | private final ArrayList<View> mViews = new ArrayList<View>(); |
| 7269 | private final ArrayList<AttachInfo.InvalidateInfo> mViewRects = |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7270 | new ArrayList<AttachInfo.InvalidateInfo>(); |
| 7271 | private View[] mTempViews; |
| 7272 | private AttachInfo.InvalidateInfo[] mTempViewRects; |
| 7273 | |
| 7274 | public void addView(View view) { |
| 7275 | synchronized (this) { |
| 7276 | mViews.add(view); |
| 7277 | postIfNeededLocked(); |
| 7278 | } |
| 7279 | } |
| 7280 | |
| 7281 | public void addViewRect(AttachInfo.InvalidateInfo info) { |
| 7282 | synchronized (this) { |
| 7283 | mViewRects.add(info); |
| 7284 | postIfNeededLocked(); |
| 7285 | } |
| 7286 | } |
| 7287 | |
| 7288 | public void removeView(View view) { |
| 7289 | synchronized (this) { |
| 7290 | mViews.remove(view); |
| 7291 | |
| 7292 | for (int i = mViewRects.size(); i-- > 0; ) { |
| 7293 | AttachInfo.InvalidateInfo info = mViewRects.get(i); |
| 7294 | if (info.target == view) { |
| 7295 | mViewRects.remove(i); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 7296 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7297 | } |
| 7298 | } |
| 7299 | |
| 7300 | if (mPosted && mViews.isEmpty() && mViewRects.isEmpty()) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7301 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7302 | mPosted = false; |
| 7303 | } |
| 7304 | } |
| 7305 | } |
| 7306 | |
| 7307 | @Override |
| 7308 | public void run() { |
| 7309 | final int viewCount; |
| 7310 | final int viewRectCount; |
| 7311 | synchronized (this) { |
| 7312 | mPosted = false; |
| 7313 | |
| 7314 | viewCount = mViews.size(); |
| 7315 | if (viewCount != 0) { |
| 7316 | mTempViews = mViews.toArray(mTempViews != null |
| 7317 | ? mTempViews : new View[viewCount]); |
| 7318 | mViews.clear(); |
| 7319 | } |
| 7320 | |
| 7321 | viewRectCount = mViewRects.size(); |
| 7322 | if (viewRectCount != 0) { |
| 7323 | mTempViewRects = mViewRects.toArray(mTempViewRects != null |
| 7324 | ? mTempViewRects : new AttachInfo.InvalidateInfo[viewRectCount]); |
| 7325 | mViewRects.clear(); |
| 7326 | } |
| 7327 | } |
| 7328 | |
| 7329 | for (int i = 0; i < viewCount; i++) { |
| 7330 | mTempViews[i].invalidate(); |
Adam Powell | 3e3c4ee | 2012-05-16 17:34:21 -0700 | [diff] [blame] | 7331 | mTempViews[i] = null; |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | for (int i = 0; i < viewRectCount; i++) { |
| 7335 | final View.AttachInfo.InvalidateInfo info = mTempViewRects[i]; |
| 7336 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 7337 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7338 | } |
| 7339 | } |
| 7340 | |
| 7341 | private void postIfNeededLocked() { |
| 7342 | if (!mPosted) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7343 | mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7344 | mPosted = true; |
| 7345 | } |
| 7346 | } |
| 7347 | } |
| 7348 | final InvalidateOnAnimationRunnable mInvalidateOnAnimationRunnable = |
| 7349 | new InvalidateOnAnimationRunnable(); |
| 7350 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7351 | public void dispatchInvalidateDelayed(View view, long delayMilliseconds) { |
| 7352 | Message msg = mHandler.obtainMessage(MSG_INVALIDATE, view); |
| 7353 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 7354 | } |
| 7355 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7356 | public void dispatchInvalidateRectDelayed(AttachInfo.InvalidateInfo info, |
| 7357 | long delayMilliseconds) { |
| 7358 | final Message msg = mHandler.obtainMessage(MSG_INVALIDATE_RECT, info); |
| 7359 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 7360 | } |
| 7361 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7362 | public void dispatchInvalidateOnAnimation(View view) { |
| 7363 | mInvalidateOnAnimationRunnable.addView(view); |
| 7364 | } |
| 7365 | |
| 7366 | public void dispatchInvalidateRectOnAnimation(AttachInfo.InvalidateInfo info) { |
| 7367 | mInvalidateOnAnimationRunnable.addViewRect(info); |
| 7368 | } |
| 7369 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7370 | @UnsupportedAppUsage |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7371 | public void cancelInvalidate(View view) { |
| 7372 | mHandler.removeMessages(MSG_INVALIDATE, view); |
| 7373 | // fixme: might leak the AttachInfo.InvalidateInfo objects instead of returning |
| 7374 | // them to the pool |
| 7375 | mHandler.removeMessages(MSG_INVALIDATE_RECT, view); |
| 7376 | mInvalidateOnAnimationRunnable.removeView(view); |
| 7377 | } |
| 7378 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7379 | @UnsupportedAppUsage |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 7380 | public void dispatchInputEvent(InputEvent event) { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 7381 | dispatchInputEvent(event, null); |
| 7382 | } |
| 7383 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7384 | @UnsupportedAppUsage |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 7385 | public void dispatchInputEvent(InputEvent event, InputEventReceiver receiver) { |
| 7386 | SomeArgs args = SomeArgs.obtain(); |
| 7387 | args.arg1 = event; |
| 7388 | args.arg2 = receiver; |
| 7389 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_INPUT_EVENT, args); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 7390 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7391 | mHandler.sendMessage(msg); |
| 7392 | } |
| 7393 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7394 | public void synthesizeInputEvent(InputEvent event) { |
| 7395 | Message msg = mHandler.obtainMessage(MSG_SYNTHESIZE_INPUT_EVENT, event); |
| 7396 | msg.setAsynchronous(true); |
| 7397 | mHandler.sendMessage(msg); |
| 7398 | } |
| 7399 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7400 | @UnsupportedAppUsage |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7401 | public void dispatchKeyFromIme(KeyEvent event) { |
| 7402 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_KEY_FROM_IME, event); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 7403 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7404 | mHandler.sendMessage(msg); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7405 | } |
| 7406 | |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 7407 | public void dispatchKeyFromAutofill(KeyEvent event) { |
| 7408 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_KEY_FROM_AUTOFILL, event); |
| 7409 | msg.setAsynchronous(true); |
| 7410 | mHandler.sendMessage(msg); |
| 7411 | } |
| 7412 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7413 | /** |
| 7414 | * Reinject unhandled {@link InputEvent}s in order to synthesize fallbacks events. |
| 7415 | * |
| 7416 | * Note that it is the responsibility of the caller of this API to recycle the InputEvent it |
| 7417 | * passes in. |
| 7418 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7419 | @UnsupportedAppUsage |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 7420 | public void dispatchUnhandledInputEvent(InputEvent event) { |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7421 | if (event instanceof MotionEvent) { |
| 7422 | event = MotionEvent.obtain((MotionEvent) event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 7423 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7424 | synthesizeInputEvent(event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 7425 | } |
| 7426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | public void dispatchAppVisibility(boolean visible) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7428 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_APP_VISIBILITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7429 | msg.arg1 = visible ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7430 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7431 | } |
| 7432 | |
| 7433 | public void dispatchGetNewSurface() { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7434 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_GET_NEW_SURFACE); |
| 7435 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7436 | } |
| 7437 | |
| 7438 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 7439 | synchronized (this) { |
Dianne Hackborn | 011944c | 2017-12-15 15:44:55 -0800 | [diff] [blame] | 7440 | mWindowFocusChanged = true; |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 7441 | mUpcomingWindowFocus = hasFocus; |
| 7442 | mUpcomingInTouchMode = inTouchMode; |
| 7443 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7444 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7445 | msg.what = MSG_WINDOW_FOCUS_CHANGED; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7446 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7447 | } |
| 7448 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 7449 | public void dispatchWindowShown() { |
| 7450 | mHandler.sendEmptyMessage(MSG_DISPATCH_WINDOW_SHOWN); |
| 7451 | } |
| 7452 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7453 | public void dispatchCloseSystemDialogs(String reason) { |
| 7454 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7455 | msg.what = MSG_CLOSE_SYSTEM_DIALOGS; |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7456 | msg.obj = reason; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7457 | mHandler.sendMessage(msg); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7458 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7459 | |
| 7460 | public void dispatchDragEvent(DragEvent event) { |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 7461 | final int what; |
| 7462 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7463 | what = MSG_DISPATCH_DRAG_LOCATION_EVENT; |
| 7464 | mHandler.removeMessages(what); |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 7465 | } else { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7466 | what = MSG_DISPATCH_DRAG_EVENT; |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 7467 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7468 | Message msg = mHandler.obtainMessage(what, event); |
| 7469 | mHandler.sendMessage(msg); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7470 | } |
| 7471 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 7472 | public void updatePointerIcon(float x, float y) { |
| 7473 | final int what = MSG_UPDATE_POINTER_ICON; |
| 7474 | mHandler.removeMessages(what); |
| 7475 | final long now = SystemClock.uptimeMillis(); |
| 7476 | final MotionEvent event = MotionEvent.obtain( |
| 7477 | 0, now, MotionEvent.ACTION_HOVER_MOVE, x, y, 0); |
| 7478 | Message msg = mHandler.obtainMessage(what, event); |
| 7479 | mHandler.sendMessage(msg); |
| 7480 | } |
| 7481 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7482 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 7483 | int localValue, int localChanges) { |
| 7484 | SystemUiVisibilityInfo args = new SystemUiVisibilityInfo(); |
| 7485 | args.seq = seq; |
| 7486 | args.globalVisibility = globalVisibility; |
| 7487 | args.localValue = localValue; |
| 7488 | args.localChanges = localChanges; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7489 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_SYSTEM_UI_VISIBILITY, args)); |
| 7490 | } |
| 7491 | |
| 7492 | public void dispatchCheckFocus() { |
| 7493 | if (!mHandler.hasMessages(MSG_CHECK_FOCUS)) { |
| 7494 | // This will result in a call to checkFocus() below. |
| 7495 | mHandler.sendEmptyMessage(MSG_CHECK_FOCUS); |
| 7496 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7497 | } |
| 7498 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 7499 | public void dispatchRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 7500 | mHandler.obtainMessage( |
| 7501 | MSG_REQUEST_KEYBOARD_SHORTCUTS, deviceId, 0, receiver).sendToTarget(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 7502 | } |
| 7503 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 7504 | public void dispatchPointerCaptureChanged(boolean on) { |
| 7505 | final int what = MSG_POINTER_CAPTURE_CHANGED; |
| 7506 | mHandler.removeMessages(what); |
| 7507 | Message msg = mHandler.obtainMessage(what); |
| 7508 | msg.arg1 = on ? 1 : 0; |
| 7509 | mHandler.sendMessage(msg); |
| 7510 | } |
| 7511 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 7512 | /** |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7513 | * Post a callback to send a |
| 7514 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7515 | * This event is send at most once every |
| 7516 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7517 | */ |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7518 | private void postSendWindowContentChangedCallback(View source, int changeType) { |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 7519 | if (mSendWindowContentChangedAccessibilityEvent == null) { |
| 7520 | mSendWindowContentChangedAccessibilityEvent = |
| 7521 | new SendWindowContentChangedAccessibilityEvent(); |
| 7522 | } |
| 7523 | mSendWindowContentChangedAccessibilityEvent.runOrPost(source, changeType); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7524 | } |
| 7525 | |
| 7526 | /** |
| 7527 | * Remove a posted callback to send a |
| 7528 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
| 7529 | */ |
| 7530 | private void removeSendWindowContentChangedCallback() { |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 7531 | if (mSendWindowContentChangedAccessibilityEvent != null) { |
| 7532 | mHandler.removeCallbacks(mSendWindowContentChangedAccessibilityEvent); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7533 | } |
| 7534 | } |
| 7535 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7536 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | public boolean showContextMenuForChild(View originalView) { |
| 7538 | return false; |
| 7539 | } |
| 7540 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7541 | @Override |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 7542 | public boolean showContextMenuForChild(View originalView, float x, float y) { |
| 7543 | return false; |
| 7544 | } |
| 7545 | |
| 7546 | @Override |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7547 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { |
| 7548 | return null; |
| 7549 | } |
| 7550 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7551 | @Override |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7552 | public ActionMode startActionModeForChild( |
| 7553 | View originalView, ActionMode.Callback callback, int type) { |
| 7554 | return null; |
| 7555 | } |
| 7556 | |
| 7557 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | public void createContextMenu(ContextMenu menu) { |
| 7559 | } |
| 7560 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7561 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | public void childDrawableStateChanged(View child) { |
| 7563 | } |
| 7564 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7565 | @Override |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7566 | public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 7567 | if (mView == null || mStopped || mPausedForTransition) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7568 | return false; |
| 7569 | } |
Eugene Susla | ccce5c9 | 2017-05-22 13:14:57 -0700 | [diff] [blame] | 7570 | |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 7571 | // Immediately flush pending content changed event (if any) to preserve event order |
| 7572 | if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED |
| 7573 | && mSendWindowContentChangedAccessibilityEvent != null |
| 7574 | && mSendWindowContentChangedAccessibilityEvent.mSource != null) { |
| 7575 | mSendWindowContentChangedAccessibilityEvent.removeCallbacksAndRun(); |
| 7576 | } |
Eugene Susla | ccce5c9 | 2017-05-22 13:14:57 -0700 | [diff] [blame] | 7577 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7578 | // Intercept accessibility focus events fired by virtual nodes to keep |
| 7579 | // track of accessibility focus position in such nodes. |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7580 | final int eventType = event.getEventType(); |
| 7581 | switch (eventType) { |
| 7582 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7583 | final long sourceNodeId = event.getSourceNodeId(); |
| 7584 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 7585 | sourceNodeId); |
| 7586 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 7587 | if (source != null) { |
| 7588 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 7589 | if (provider != null) { |
Svetoslav | b3ba1d4 | 2014-09-26 15:20:40 -0700 | [diff] [blame] | 7590 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 7591 | sourceNodeId); |
| 7592 | final AccessibilityNodeInfo node; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 7593 | node = provider.createAccessibilityNodeInfo(virtualNodeId); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7594 | setAccessibilityFocus(source, node); |
| 7595 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7596 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7597 | } break; |
| 7598 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7599 | final long sourceNodeId = event.getSourceNodeId(); |
| 7600 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 7601 | sourceNodeId); |
| 7602 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 7603 | if (source != null) { |
| 7604 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 7605 | if (provider != null) { |
| 7606 | setAccessibilityFocus(null, null); |
| 7607 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7608 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7609 | } break; |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 7610 | |
| 7611 | |
| 7612 | case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: { |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7613 | handleWindowContentChangedEvent(event); |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 7614 | } break; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7615 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7616 | mAccessibilityManager.sendAccessibilityEvent(event); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7617 | return true; |
| 7618 | } |
| 7619 | |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7620 | /** |
| 7621 | * Updates the focused virtual view, when necessary, in response to a |
| 7622 | * content changed event. |
| 7623 | * <p> |
| 7624 | * This is necessary to get updated bounds after a position change. |
| 7625 | * |
| 7626 | * @param event an accessibility event of type |
| 7627 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} |
| 7628 | */ |
| 7629 | private void handleWindowContentChangedEvent(AccessibilityEvent event) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7630 | final View focusedHost = mAccessibilityFocusedHost; |
| 7631 | if (focusedHost == null || mAccessibilityFocusedVirtualView == null) { |
| 7632 | // No virtual view focused, nothing to do here. |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7633 | return; |
| 7634 | } |
| 7635 | |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7636 | final AccessibilityNodeProvider provider = focusedHost.getAccessibilityNodeProvider(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7637 | if (provider == null) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7638 | // Error state: virtual view with no provider. Clear focus. |
| 7639 | mAccessibilityFocusedHost = null; |
| 7640 | mAccessibilityFocusedVirtualView = null; |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 7641 | focusedHost.clearAccessibilityFocusNoCallbacks(0); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7642 | return; |
| 7643 | } |
| 7644 | |
| 7645 | // We only care about change types that may affect the bounds of the |
| 7646 | // focused virtual view. |
| 7647 | final int changes = event.getContentChangeTypes(); |
| 7648 | if ((changes & AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE) == 0 |
| 7649 | && changes != AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED) { |
| 7650 | return; |
| 7651 | } |
| 7652 | |
| 7653 | final long eventSourceNodeId = event.getSourceNodeId(); |
| 7654 | final int changedViewId = AccessibilityNodeInfo.getAccessibilityViewId(eventSourceNodeId); |
| 7655 | |
| 7656 | // Search up the tree for subtree containment. |
| 7657 | boolean hostInSubtree = false; |
| 7658 | View root = mAccessibilityFocusedHost; |
| 7659 | while (root != null && !hostInSubtree) { |
| 7660 | if (changedViewId == root.getAccessibilityViewId()) { |
| 7661 | hostInSubtree = true; |
| 7662 | } else { |
| 7663 | final ViewParent parent = root.getParent(); |
| 7664 | if (parent instanceof View) { |
| 7665 | root = (View) parent; |
| 7666 | } else { |
| 7667 | root = null; |
| 7668 | } |
| 7669 | } |
| 7670 | } |
| 7671 | |
| 7672 | // We care only about changes in subtrees containing the host view. |
| 7673 | if (!hostInSubtree) { |
| 7674 | return; |
| 7675 | } |
| 7676 | |
| 7677 | final long focusedSourceNodeId = mAccessibilityFocusedVirtualView.getSourceNodeId(); |
| 7678 | int focusedChildId = AccessibilityNodeInfo.getVirtualDescendantId(focusedSourceNodeId); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7679 | |
| 7680 | // Refresh the node for the focused virtual view. |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 7681 | final Rect oldBounds = mTempRect; |
| 7682 | mAccessibilityFocusedVirtualView.getBoundsInScreen(oldBounds); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7683 | mAccessibilityFocusedVirtualView = provider.createAccessibilityNodeInfo(focusedChildId); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7684 | if (mAccessibilityFocusedVirtualView == null) { |
| 7685 | // Error state: The node no longer exists. Clear focus. |
| 7686 | mAccessibilityFocusedHost = null; |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 7687 | focusedHost.clearAccessibilityFocusNoCallbacks(0); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7688 | |
| 7689 | // This will probably fail, but try to keep the provider's internal |
| 7690 | // state consistent by clearing focus. |
| 7691 | provider.performAction(focusedChildId, |
| 7692 | AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), null); |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 7693 | invalidateRectOnScreen(oldBounds); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7694 | } else { |
| 7695 | // The node was refreshed, invalidate bounds if necessary. |
| 7696 | final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen(); |
| 7697 | if (!oldBounds.equals(newBounds)) { |
| 7698 | oldBounds.union(newBounds); |
| 7699 | invalidateRectOnScreen(oldBounds); |
| 7700 | } |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 7701 | } |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7702 | } |
| 7703 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7704 | @Override |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7705 | public void notifySubtreeAccessibilityStateChanged(View child, View source, int changeType) { |
Phil Weaver | 63e4503 | 2017-05-11 10:54:37 -0700 | [diff] [blame] | 7706 | postSendWindowContentChangedCallback(Preconditions.checkNotNull(source), changeType); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7707 | } |
| 7708 | |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 7709 | @Override |
| 7710 | public boolean canResolveLayoutDirection() { |
| 7711 | return true; |
| 7712 | } |
| 7713 | |
| 7714 | @Override |
| 7715 | public boolean isLayoutDirectionResolved() { |
| 7716 | return true; |
| 7717 | } |
| 7718 | |
| 7719 | @Override |
| 7720 | public int getLayoutDirection() { |
| 7721 | return View.LAYOUT_DIRECTION_RESOLVED_DEFAULT; |
| 7722 | } |
| 7723 | |
| 7724 | @Override |
| 7725 | public boolean canResolveTextDirection() { |
| 7726 | return true; |
| 7727 | } |
| 7728 | |
| 7729 | @Override |
| 7730 | public boolean isTextDirectionResolved() { |
| 7731 | return true; |
| 7732 | } |
| 7733 | |
| 7734 | @Override |
| 7735 | public int getTextDirection() { |
| 7736 | return View.TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 7737 | } |
| 7738 | |
| 7739 | @Override |
| 7740 | public boolean canResolveTextAlignment() { |
| 7741 | return true; |
| 7742 | } |
| 7743 | |
| 7744 | @Override |
| 7745 | public boolean isTextAlignmentResolved() { |
| 7746 | return true; |
| 7747 | } |
| 7748 | |
| 7749 | @Override |
| 7750 | public int getTextAlignment() { |
| 7751 | return View.TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 7752 | } |
| 7753 | |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 7754 | private View getCommonPredecessor(View first, View second) { |
| 7755 | if (mTempHashSet == null) { |
| 7756 | mTempHashSet = new HashSet<View>(); |
| 7757 | } |
| 7758 | HashSet<View> seen = mTempHashSet; |
| 7759 | seen.clear(); |
| 7760 | View firstCurrent = first; |
| 7761 | while (firstCurrent != null) { |
| 7762 | seen.add(firstCurrent); |
| 7763 | ViewParent firstCurrentParent = firstCurrent.mParent; |
| 7764 | if (firstCurrentParent instanceof View) { |
| 7765 | firstCurrent = (View) firstCurrentParent; |
| 7766 | } else { |
| 7767 | firstCurrent = null; |
| 7768 | } |
| 7769 | } |
| 7770 | View secondCurrent = second; |
| 7771 | while (secondCurrent != null) { |
| 7772 | if (seen.contains(secondCurrent)) { |
| 7773 | seen.clear(); |
| 7774 | return secondCurrent; |
| 7775 | } |
| 7776 | ViewParent secondCurrentParent = secondCurrent.mParent; |
| 7777 | if (secondCurrentParent instanceof View) { |
| 7778 | secondCurrent = (View) secondCurrentParent; |
| 7779 | } else { |
| 7780 | secondCurrent = null; |
| 7781 | } |
| 7782 | } |
| 7783 | seen.clear(); |
| 7784 | return null; |
| 7785 | } |
| 7786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7787 | void checkThread() { |
| 7788 | if (mThread != Thread.currentThread()) { |
| 7789 | throw new CalledFromWrongThreadException( |
| 7790 | "Only the original thread that created a view hierarchy can touch its views."); |
| 7791 | } |
| 7792 | } |
| 7793 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7794 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7795 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 7796 | // ViewAncestor never intercepts touch event, so this can be a no-op |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7797 | } |
| 7798 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7799 | @Override |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7800 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 7801 | if (rectangle == null) { |
| 7802 | return scrollToRectOrFocus(null, immediate); |
| 7803 | } |
| 7804 | rectangle.offset(child.getLeft() - child.getScrollX(), |
| 7805 | child.getTop() - child.getScrollY()); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7806 | final boolean scrolled = scrollToRectOrFocus(rectangle, immediate); |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 7807 | mTempRect.set(rectangle); |
| 7808 | mTempRect.offset(0, -mCurScrollY); |
| 7809 | mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 7810 | try { |
| 7811 | mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect); |
| 7812 | } catch (RemoteException re) { |
| 7813 | /* ignore */ |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7814 | } |
| 7815 | return scrolled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7816 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7817 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7818 | @Override |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 7819 | public void childHasTransientStateChanged(View child, boolean hasTransientState) { |
| 7820 | // Do nothing. |
| 7821 | } |
| 7822 | |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7823 | @Override |
| 7824 | public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { |
| 7825 | return false; |
| 7826 | } |
| 7827 | |
| 7828 | @Override |
| 7829 | public void onStopNestedScroll(View target) { |
| 7830 | } |
| 7831 | |
| 7832 | @Override |
| 7833 | public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) { |
| 7834 | } |
| 7835 | |
| 7836 | @Override |
| 7837 | public void onNestedScroll(View target, int dxConsumed, int dyConsumed, |
| 7838 | int dxUnconsumed, int dyUnconsumed) { |
| 7839 | } |
| 7840 | |
| 7841 | @Override |
| 7842 | public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { |
| 7843 | } |
| 7844 | |
| 7845 | @Override |
Adam Powell | b36e4f9 | 2014-05-01 10:23:33 -0700 | [diff] [blame] | 7846 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7847 | return false; |
| 7848 | } |
| 7849 | |
Adam Powell | b72be59 | 2014-07-16 21:41:31 -0700 | [diff] [blame] | 7850 | @Override |
| 7851 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) { |
| 7852 | return false; |
| 7853 | } |
| 7854 | |
Adam Powell | b6ab098 | 2015-01-07 17:00:12 -0800 | [diff] [blame] | 7855 | @Override |
| 7856 | public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle args) { |
| 7857 | return false; |
| 7858 | } |
| 7859 | |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 7860 | |
| 7861 | private void reportNextDraw() { |
| 7862 | if (mReportNextDraw == false) { |
| 7863 | drawPending(); |
| 7864 | } |
| 7865 | mReportNextDraw = true; |
| 7866 | } |
| 7867 | |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 7868 | /** |
| 7869 | * Force the window to report its next draw. |
| 7870 | * <p> |
| 7871 | * This method is only supposed to be used to speed up the interaction from SystemUI and window |
| 7872 | * manager when waiting for the first frame to be drawn when turning on the screen. DO NOT USE |
| 7873 | * unless you fully understand this interaction. |
| 7874 | * @hide |
| 7875 | */ |
| 7876 | public void setReportNextDraw() { |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 7877 | reportNextDraw(); |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 7878 | invalidate(); |
| 7879 | } |
| 7880 | |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 7881 | void changeCanvasOpacity(boolean opaque) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 7882 | Log.d(mTag, "changeCanvasOpacity: opaque=" + opaque); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 7883 | if (mAttachInfo.mThreadedRenderer != null) { |
| 7884 | mAttachInfo.mThreadedRenderer.setOpaque(opaque); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 7885 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 7886 | } |
| 7887 | |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 7888 | /** |
| 7889 | * Dispatches a KeyEvent to all registered key fallback handlers. |
| 7890 | * |
| 7891 | * @param event |
| 7892 | * @return {@code true} if the event was handled, {@code false} otherwise. |
| 7893 | */ |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 7894 | public boolean dispatchUnhandledKeyEvent(KeyEvent event) { |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 7895 | return mUnhandledKeyManager.dispatch(mView, event); |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 7896 | } |
| 7897 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7898 | class TakenSurfaceHolder extends BaseSurfaceHolder { |
| 7899 | @Override |
| 7900 | public boolean onAllowLockCanvas() { |
| 7901 | return mDrawingAllowed; |
| 7902 | } |
| 7903 | |
| 7904 | @Override |
| 7905 | public void onRelayoutContainer() { |
| 7906 | // Not currently interesting -- from changing between fixed and layout size. |
| 7907 | } |
| 7908 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7909 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7910 | public void setFormat(int format) { |
| 7911 | ((RootViewSurfaceTaker)mView).setSurfaceFormat(format); |
| 7912 | } |
| 7913 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7914 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7915 | public void setType(int type) { |
| 7916 | ((RootViewSurfaceTaker)mView).setSurfaceType(type); |
| 7917 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7918 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7919 | @Override |
| 7920 | public void onUpdateSurface() { |
| 7921 | // We take care of format and type changes on our own. |
| 7922 | throw new IllegalStateException("Shouldn't be here"); |
| 7923 | } |
| 7924 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7925 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7926 | public boolean isCreating() { |
| 7927 | return mIsCreating; |
| 7928 | } |
| 7929 | |
| 7930 | @Override |
| 7931 | public void setFixedSize(int width, int height) { |
| 7932 | throw new UnsupportedOperationException( |
| 7933 | "Currently only support sizing from layout"); |
| 7934 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7935 | |
| 7936 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7937 | public void setKeepScreenOn(boolean screenOn) { |
| 7938 | ((RootViewSurfaceTaker)mView).setSurfaceKeepScreenOn(screenOn); |
| 7939 | } |
| 7940 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7942 | static class W extends IWindow.Stub { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7943 | private final WeakReference<ViewRootImpl> mViewAncestor; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7944 | private final IWindowSession mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7945 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7946 | W(ViewRootImpl viewAncestor) { |
| 7947 | mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7948 | mWindowSession = viewAncestor.mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7949 | } |
| 7950 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7951 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 7952 | public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 7953 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7954 | MergedConfiguration mergedConfiguration, Rect backDropFrame, boolean forceLayout, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 7955 | boolean alwaysConsumeNavBar, int displayId, |
| 7956 | DisplayCutout.ParcelableWrapper displayCutout) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7957 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7958 | if (viewAncestor != null) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 7959 | viewAncestor.dispatchResized(frame, overscanInsets, contentInsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7960 | visibleInsets, stableInsets, outsets, reportDraw, mergedConfiguration, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 7961 | backDropFrame, forceLayout, alwaysConsumeNavBar, displayId, displayCutout); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7962 | } |
| 7963 | } |
| 7964 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 7965 | @Override |
| 7966 | public void moved(int newX, int newY) { |
| 7967 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7968 | if (viewAncestor != null) { |
| 7969 | viewAncestor.dispatchMoved(newX, newY); |
| 7970 | } |
| 7971 | } |
| 7972 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7973 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | public void dispatchAppVisibility(boolean visible) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7975 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7976 | if (viewAncestor != null) { |
| 7977 | viewAncestor.dispatchAppVisibility(visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7978 | } |
| 7979 | } |
| 7980 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7981 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7982 | public void dispatchGetNewSurface() { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7983 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7984 | if (viewAncestor != null) { |
| 7985 | viewAncestor.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7986 | } |
| 7987 | } |
| 7988 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7989 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7990 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7991 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7992 | if (viewAncestor != null) { |
| 7993 | viewAncestor.windowFocusChanged(hasFocus, inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7994 | } |
| 7995 | } |
| 7996 | |
| 7997 | private static int checkCallingPermission(String permission) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7998 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7999 | return ActivityManager.getService().checkPermission( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8000 | permission, Binder.getCallingPid(), Binder.getCallingUid()); |
| 8001 | } catch (RemoteException e) { |
| 8002 | return PackageManager.PERMISSION_DENIED; |
| 8003 | } |
| 8004 | } |
| 8005 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8006 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8007 | public void executeCommand(String command, String parameters, ParcelFileDescriptor out) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8008 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8009 | if (viewAncestor != null) { |
| 8010 | final View view = viewAncestor.mView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8011 | if (view != null) { |
| 8012 | if (checkCallingPermission(Manifest.permission.DUMP) != |
| 8013 | PackageManager.PERMISSION_GRANTED) { |
| 8014 | throw new SecurityException("Insufficient permissions to invoke" |
| 8015 | + " executeCommand() from pid=" + Binder.getCallingPid() |
| 8016 | + ", uid=" + Binder.getCallingUid()); |
| 8017 | } |
| 8018 | |
| 8019 | OutputStream clientStream = null; |
| 8020 | try { |
| 8021 | clientStream = new ParcelFileDescriptor.AutoCloseOutputStream(out); |
| 8022 | ViewDebug.dispatchCommand(view, command, parameters, clientStream); |
| 8023 | } catch (IOException e) { |
| 8024 | e.printStackTrace(); |
| 8025 | } finally { |
| 8026 | if (clientStream != null) { |
| 8027 | try { |
| 8028 | clientStream.close(); |
| 8029 | } catch (IOException e) { |
| 8030 | e.printStackTrace(); |
| 8031 | } |
| 8032 | } |
| 8033 | } |
| 8034 | } |
| 8035 | } |
| 8036 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8037 | |
| 8038 | @Override |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 8039 | public void closeSystemDialogs(String reason) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8040 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8041 | if (viewAncestor != null) { |
| 8042 | viewAncestor.dispatchCloseSystemDialogs(reason); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 8043 | } |
| 8044 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8045 | |
| 8046 | @Override |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8047 | public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, |
| 8048 | boolean sync) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 8049 | if (sync) { |
| 8050 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 8051 | mWindowSession.wallpaperOffsetsComplete(asBinder()); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 8052 | } catch (RemoteException e) { |
| 8053 | } |
| 8054 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8055 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8056 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8057 | @Override |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 8058 | public void dispatchWallpaperCommand(String action, int x, int y, |
| 8059 | int z, Bundle extras, boolean sync) { |
| 8060 | if (sync) { |
| 8061 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 8062 | mWindowSession.wallpaperCommandComplete(asBinder(), null); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 8063 | } catch (RemoteException e) { |
| 8064 | } |
| 8065 | } |
| 8066 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8067 | |
| 8068 | /* Drag/drop */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8069 | @Override |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8070 | public void dispatchDragEvent(DragEvent event) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8071 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8072 | if (viewAncestor != null) { |
| 8073 | viewAncestor.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8074 | } |
| 8075 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8076 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8077 | @Override |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 8078 | public void updatePointerIcon(float x, float y) { |
| 8079 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 8080 | if (viewAncestor != null) { |
| 8081 | viewAncestor.updatePointerIcon(x, y); |
| 8082 | } |
| 8083 | } |
| 8084 | |
| 8085 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 8086 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 8087 | int localValue, int localChanges) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8088 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8089 | if (viewAncestor != null) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 8090 | viewAncestor.dispatchSystemUiVisibilityChanged(seq, globalVisibility, |
| 8091 | localValue, localChanges); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8092 | } |
| 8093 | } |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 8094 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8095 | @Override |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 8096 | public void dispatchWindowShown() { |
| 8097 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 8098 | if (viewAncestor != null) { |
| 8099 | viewAncestor.dispatchWindowShown(); |
| 8100 | } |
| 8101 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 8102 | |
| 8103 | @Override |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 8104 | public void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 8105 | ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 8106 | if (viewAncestor != null) { |
| 8107 | viewAncestor.dispatchRequestKeyboardShortcuts(receiver, deviceId); |
| 8108 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 8109 | } |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 8110 | |
| 8111 | @Override |
| 8112 | public void dispatchPointerCaptureChanged(boolean hasCapture) { |
| 8113 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 8114 | if (viewAncestor != null) { |
| 8115 | viewAncestor.dispatchPointerCaptureChanged(hasCapture); |
| 8116 | } |
| 8117 | } |
| 8118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8119 | } |
| 8120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8121 | public static final class CalledFromWrongThreadException extends AndroidRuntimeException { |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 8122 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8123 | public CalledFromWrongThreadException(String msg) { |
| 8124 | super(msg); |
| 8125 | } |
| 8126 | } |
| 8127 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 8128 | static HandlerActionQueue getRunQueue() { |
| 8129 | HandlerActionQueue rq = sRunQueues.get(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8130 | if (rq != null) { |
| 8131 | return rq; |
| 8132 | } |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 8133 | rq = new HandlerActionQueue(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | sRunQueues.set(rq); |
| 8135 | return rq; |
| 8136 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 8137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8138 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8139 | * Start a drag resizing which will inform all listeners that a window resize is taking place. |
| 8140 | */ |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 8141 | private void startDragResizing(Rect initialBounds, boolean fullscreen, Rect systemInsets, |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 8142 | Rect stableInsets, int resizeMode) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8143 | if (!mDragResizing) { |
| 8144 | mDragResizing = true; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8145 | if (mUseMTRenderer) { |
| 8146 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 8147 | mWindowCallbacks.get(i).onWindowDragResizeStart( |
| 8148 | initialBounds, fullscreen, systemInsets, stableInsets, resizeMode); |
| 8149 | } |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8150 | } |
| 8151 | mFullRedrawNeeded = true; |
| 8152 | } |
| 8153 | } |
| 8154 | |
| 8155 | /** |
| 8156 | * End a drag resize which will inform all listeners that a window resize has ended. |
| 8157 | */ |
| 8158 | private void endDragResizing() { |
| 8159 | if (mDragResizing) { |
| 8160 | mDragResizing = false; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8161 | if (mUseMTRenderer) { |
| 8162 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 8163 | mWindowCallbacks.get(i).onWindowDragResizeEnd(); |
| 8164 | } |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8165 | } |
| 8166 | mFullRedrawNeeded = true; |
| 8167 | } |
| 8168 | } |
| 8169 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 8170 | private boolean updateContentDrawBounds() { |
| 8171 | boolean updated = false; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8172 | if (mUseMTRenderer) { |
| 8173 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 8174 | updated |= |
| 8175 | mWindowCallbacks.get(i).onContentDrawn(mWindowAttributes.surfaceInsets.left, |
| 8176 | mWindowAttributes.surfaceInsets.top, mWidth, mHeight); |
| 8177 | } |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 8178 | } |
| 8179 | return updated | (mDragResizing && mReportNextDraw); |
| 8180 | } |
| 8181 | |
| 8182 | private void requestDrawWindow() { |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8183 | if (!mUseMTRenderer) { |
| 8184 | return; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 8185 | } |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8186 | mWindowDrawCountDown = new CountDownLatch(mWindowCallbacks.size()); |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 8187 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 8188 | mWindowCallbacks.get(i).onRequestDraw(mReportNextDraw); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 8189 | } |
| 8190 | } |
| 8191 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8192 | /** |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 8193 | * Tells this instance that its corresponding activity has just relaunched. In this case, we |
| 8194 | * need to force a relayout of the window to make sure we get the correct bounds from window |
| 8195 | * manager. |
| 8196 | */ |
| 8197 | public void reportActivityRelaunched() { |
| 8198 | mActivityRelaunched = true; |
| 8199 | } |
| 8200 | |
| 8201 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8202 | * Class for managing the accessibility interaction connection |
| 8203 | * based on the global accessibility state. |
| 8204 | */ |
| 8205 | final class AccessibilityInteractionConnectionManager |
| 8206 | implements AccessibilityStateChangeListener { |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8207 | @Override |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8208 | public void onAccessibilityStateChanged(boolean enabled) { |
| 8209 | if (enabled) { |
| 8210 | ensureConnection(); |
Phil Weaver | 05a2982 | 2017-09-22 11:03:06 -0700 | [diff] [blame] | 8211 | if (mAttachInfo.mHasWindowFocus && (mView != null)) { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 8212 | mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 8213 | View focusedView = mView.findFocus(); |
| 8214 | if (focusedView != null && focusedView != mView) { |
| 8215 | focusedView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 8216 | } |
| 8217 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8218 | } else { |
| 8219 | ensureNoConnection(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 8220 | mHandler.obtainMessage(MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST).sendToTarget(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8221 | } |
| 8222 | } |
| 8223 | |
| 8224 | public void ensureConnection() { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 8225 | final boolean registered = mAttachInfo.mAccessibilityWindowId |
| 8226 | != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8227 | if (!registered) { |
| 8228 | mAttachInfo.mAccessibilityWindowId = |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 8229 | mAccessibilityManager.addAccessibilityInteractionConnection(mWindow, |
Svet Ganov | 240aed9 | 2017-12-02 12:32:23 -0800 | [diff] [blame] | 8230 | mContext.getPackageName(), |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 8231 | new AccessibilityInteractionConnection(ViewRootImpl.this)); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8232 | } |
| 8233 | } |
| 8234 | |
| 8235 | public void ensureNoConnection() { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 8236 | final boolean registered = mAttachInfo.mAccessibilityWindowId |
| 8237 | != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8238 | if (registered) { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 8239 | mAttachInfo.mAccessibilityWindowId = AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8240 | mAccessibilityManager.removeAccessibilityInteractionConnection(mWindow); |
| 8241 | } |
| 8242 | } |
| 8243 | } |
| 8244 | |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8245 | final class HighContrastTextManager implements HighTextContrastChangeListener { |
| 8246 | HighContrastTextManager() { |
John Reck | 938e884 | 2017-08-24 13:41:59 -0700 | [diff] [blame] | 8247 | ThreadedRenderer.setHighContrastText(mAccessibilityManager.isHighTextContrastEnabled()); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8248 | } |
| 8249 | @Override |
| 8250 | public void onHighTextContrastStateChanged(boolean enabled) { |
John Reck | 938e884 | 2017-08-24 13:41:59 -0700 | [diff] [blame] | 8251 | ThreadedRenderer.setHighContrastText(enabled); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8252 | |
| 8253 | // Destroy Displaylists so they can be recreated with high contrast recordings |
| 8254 | destroyHardwareResources(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 8255 | |
| 8256 | // Schedule redraw, which will rerecord + redraw all text |
| 8257 | invalidate(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8258 | } |
| 8259 | } |
| 8260 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8261 | /** |
| 8262 | * This class is an interface this ViewAncestor provides to the |
| 8263 | * AccessibilityManagerService to the latter can interact with |
| 8264 | * the view hierarchy in this ViewAncestor. |
| 8265 | */ |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 8266 | static final class AccessibilityInteractionConnection |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8267 | extends IAccessibilityInteractionConnection.Stub { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8268 | private final WeakReference<ViewRootImpl> mViewRootImpl; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8269 | |
Svetoslav Ganov | f79f476 | 2011-10-28 15:40:32 -0700 | [diff] [blame] | 8270 | AccessibilityInteractionConnection(ViewRootImpl viewRootImpl) { |
| 8271 | mViewRootImpl = new WeakReference<ViewRootImpl>(viewRootImpl); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8272 | } |
| 8273 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8274 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8275 | public void findAccessibilityNodeInfoByAccessibilityId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8276 | Region interactiveRegion, int interactionId, |
| 8277 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 8278 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec, Bundle args) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8279 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8280 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 8281 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8282 | .findAccessibilityNodeInfoByAccessibilityIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8283 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 8284 | interrogatingTid, spec, args); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8285 | } else { |
| 8286 | // We cannot make the call and notify the caller so it does not wait. |
| 8287 | try { |
| 8288 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 8289 | } catch (RemoteException re) { |
| 8290 | /* best effort - ignore */ |
| 8291 | } |
Svetoslav Ganov | 601ad80 | 2011-06-09 14:47:38 -0700 | [diff] [blame] | 8292 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8293 | } |
| 8294 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8295 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8296 | public void performAccessibilityAction(long accessibilityNodeId, int action, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 8297 | Bundle arguments, int interactionId, |
| 8298 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 8299 | int interrogatingPid, long interrogatingTid) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8300 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8301 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 8302 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 8303 | .performAccessibilityActionClientThread(accessibilityNodeId, action, arguments, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 8304 | interactionId, callback, flags, interrogatingPid, interrogatingTid); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8305 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8306 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8307 | try { |
| 8308 | callback.setPerformAccessibilityActionResult(false, interactionId); |
| 8309 | } catch (RemoteException re) { |
| 8310 | /* best effort - ignore */ |
| 8311 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8312 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8313 | } |
| 8314 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8315 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 8316 | public void findAccessibilityNodeInfosByViewId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8317 | String viewId, Region interactiveRegion, int interactionId, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 8318 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 8319 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8320 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8321 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 8322 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 8323 | .findAccessibilityNodeInfosByViewIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8324 | viewId, interactiveRegion, interactionId, callback, flags, |
| 8325 | interrogatingPid, interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8326 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8327 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8328 | try { |
| 8329 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
| 8330 | } catch (RemoteException re) { |
| 8331 | /* best effort - ignore */ |
| 8332 | } |
| 8333 | } |
| 8334 | } |
| 8335 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8336 | @Override |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8337 | public void findAccessibilityNodeInfosByText(long accessibilityNodeId, String text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8338 | Region interactiveRegion, int interactionId, |
| 8339 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 8340 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8341 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8342 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 8343 | viewRootImpl.getAccessibilityInteractionController() |
| 8344 | .findAccessibilityNodeInfosByTextClientThread(accessibilityNodeId, text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8345 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 8346 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8347 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8348 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8349 | try { |
| 8350 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 8351 | } catch (RemoteException re) { |
| 8352 | /* best effort - ignore */ |
| 8353 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8354 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8355 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8356 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8357 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8358 | public void findFocus(long accessibilityNodeId, int focusType, Region interactiveRegion, |
| 8359 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 8360 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8361 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8362 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 8363 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8364 | .findFocusClientThread(accessibilityNodeId, focusType, interactiveRegion, |
| 8365 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 8366 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 8367 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8368 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8369 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8370 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8371 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8372 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8373 | } |
| 8374 | } |
| 8375 | } |
| 8376 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8377 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8378 | public void focusSearch(long accessibilityNodeId, int direction, Region interactiveRegion, |
| 8379 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 8380 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8381 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8382 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 8383 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8384 | .focusSearchClientThread(accessibilityNodeId, direction, interactiveRegion, |
| 8385 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 8386 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 8387 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8388 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8389 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8390 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8391 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8392 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8393 | } |
| 8394 | } |
| 8395 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8396 | } |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 8397 | |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8398 | private class SendWindowContentChangedAccessibilityEvent implements Runnable { |
| 8399 | private int mChangeTypes = 0; |
| 8400 | |
| 8401 | public View mSource; |
| 8402 | public long mLastEventTimeMillis; |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8403 | /** |
| 8404 | * Override for {@link AccessibilityEvent#originStackTrace} to provide the stack trace |
| 8405 | * of the original {@link #runOrPost} call instead of one for sending the delayed event |
| 8406 | * from a looper. |
| 8407 | */ |
| 8408 | public StackTraceElement[] mOrigin; |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8409 | |
| 8410 | @Override |
| 8411 | public void run() { |
| 8412 | // Protect against re-entrant code and attempt to do the right thing in the case that |
| 8413 | // we're multithreaded. |
| 8414 | View source = mSource; |
| 8415 | mSource = null; |
| 8416 | if (source == null) { |
| 8417 | Log.e(TAG, "Accessibility content change has no source"); |
| 8418 | return; |
| 8419 | } |
| 8420 | // The accessibility may be turned off while we were waiting so check again. |
| 8421 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8422 | mLastEventTimeMillis = SystemClock.uptimeMillis(); |
| 8423 | AccessibilityEvent event = AccessibilityEvent.obtain(); |
| 8424 | event.setEventType(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
| 8425 | event.setContentChangeTypes(mChangeTypes); |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8426 | if (AccessibilityEvent.DEBUG_ORIGIN) event.originStackTrace = mOrigin; |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8427 | source.sendAccessibilityEventUnchecked(event); |
| 8428 | } else { |
| 8429 | mLastEventTimeMillis = 0; |
| 8430 | } |
| 8431 | // In any case reset to initial state. |
| 8432 | source.resetSubtreeAccessibilityStateChanged(); |
| 8433 | mChangeTypes = 0; |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8434 | if (AccessibilityEvent.DEBUG_ORIGIN) mOrigin = null; |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8435 | } |
| 8436 | |
| 8437 | public void runOrPost(View source, int changeType) { |
| 8438 | if (mHandler.getLooper() != Looper.myLooper()) { |
| 8439 | CalledFromWrongThreadException e = new CalledFromWrongThreadException("Only the " |
| 8440 | + "original thread that created a view hierarchy can touch its views."); |
| 8441 | // TODO: Throw the exception |
| 8442 | Log.e(TAG, "Accessibility content change on non-UI thread. Future Android " |
| 8443 | + "versions will throw an exception.", e); |
| 8444 | // Attempt to recover. This code does not eliminate the thread safety issue, but |
| 8445 | // it should force any issues to happen near the above log. |
| 8446 | mHandler.removeCallbacks(this); |
| 8447 | if (mSource != null) { |
| 8448 | // Dispatch whatever was pending. It's still possible that the runnable started |
| 8449 | // just before we removed the callbacks, and bad things will happen, but at |
| 8450 | // least they should happen very close to the logged error. |
| 8451 | run(); |
| 8452 | } |
| 8453 | } |
| 8454 | if (mSource != null) { |
| 8455 | // If there is no common predecessor, then mSource points to |
| 8456 | // a removed view, hence in this case always prefer the source. |
| 8457 | View predecessor = getCommonPredecessor(mSource, source); |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8458 | if (predecessor != null) { |
| 8459 | predecessor = predecessor.getSelfOrParentImportantForA11y(); |
| 8460 | } |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8461 | mSource = (predecessor != null) ? predecessor : source; |
| 8462 | mChangeTypes |= changeType; |
| 8463 | return; |
| 8464 | } |
| 8465 | mSource = source; |
| 8466 | mChangeTypes = changeType; |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8467 | if (AccessibilityEvent.DEBUG_ORIGIN) { |
| 8468 | mOrigin = Thread.currentThread().getStackTrace(); |
| 8469 | } |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8470 | final long timeSinceLastMillis = SystemClock.uptimeMillis() - mLastEventTimeMillis; |
| 8471 | final long minEventIntevalMillis = |
| 8472 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval(); |
| 8473 | if (timeSinceLastMillis >= minEventIntevalMillis) { |
| 8474 | removeCallbacksAndRun(); |
| 8475 | } else { |
| 8476 | mHandler.postDelayed(this, minEventIntevalMillis - timeSinceLastMillis); |
| 8477 | } |
| 8478 | } |
| 8479 | |
| 8480 | public void removeCallbacksAndRun() { |
| 8481 | mHandler.removeCallbacks(this); |
| 8482 | run(); |
| 8483 | } |
| 8484 | } |
| 8485 | |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8486 | private static class UnhandledKeyManager { |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8487 | // This is used to ensure that unhandled events are only dispatched once. We attempt |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8488 | // to dispatch more than once in order to achieve a certain order. Specifically, if we |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8489 | // are in an Activity or Dialog (and have a Window.Callback), the unhandled events should |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8490 | // be dispatched after the view hierarchy, but before the Callback. However, if we aren't |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8491 | // in an activity, we still want unhandled keys to be dispatched. |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8492 | private boolean mDispatched = true; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8493 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8494 | // Keeps track of which Views have unhandled key focus for which keys. This doesn't |
| 8495 | // include modifiers. |
| 8496 | private final SparseArray<WeakReference<View>> mCapturedKeys = new SparseArray<>(); |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8497 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8498 | // The current receiver. This value is transient and used between the pre-dispatch and |
| 8499 | // pre-view phase to ensure that other input-stages don't interfere with tracking. |
| 8500 | private WeakReference<View> mCurrentReceiver = null; |
| 8501 | |
| 8502 | boolean dispatch(View root, KeyEvent event) { |
| 8503 | if (mDispatched) { |
| 8504 | return false; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8505 | } |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8506 | View consumer; |
| 8507 | try { |
| 8508 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "UnhandledKeyEvent dispatch"); |
| 8509 | mDispatched = true; |
| 8510 | |
| 8511 | consumer = root.dispatchUnhandledKeyEvent(event); |
| 8512 | |
| 8513 | // If an unhandled listener handles one, then keep track of it so that the |
| 8514 | // consuming view is first to receive its repeats and release as well. |
| 8515 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 8516 | int keycode = event.getKeyCode(); |
| 8517 | if (consumer != null && !KeyEvent.isModifierKey(keycode)) { |
| 8518 | mCapturedKeys.put(keycode, new WeakReference<>(consumer)); |
| 8519 | } |
| 8520 | } |
| 8521 | } finally { |
| 8522 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 8523 | } |
| 8524 | return consumer != null; |
| 8525 | } |
| 8526 | |
| 8527 | /** |
| 8528 | * Called before the event gets dispatched to anything |
| 8529 | */ |
| 8530 | void preDispatch(KeyEvent event) { |
| 8531 | // Always clean-up 'up' events since it's possible for earlier dispatch stages to |
| 8532 | // consume them without consuming the corresponding 'down' event. |
| 8533 | mCurrentReceiver = null; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8534 | if (event.getAction() == KeyEvent.ACTION_UP) { |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8535 | int idx = mCapturedKeys.indexOfKey(event.getKeyCode()); |
| 8536 | if (idx >= 0) { |
| 8537 | mCurrentReceiver = mCapturedKeys.valueAt(idx); |
| 8538 | mCapturedKeys.removeAt(idx); |
| 8539 | } |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8540 | } |
| 8541 | } |
| 8542 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8543 | /** |
| 8544 | * Called before the event gets dispatched to the view hierarchy |
| 8545 | * @return {@code true} if an unhandled handler has focus and consumed the event |
| 8546 | */ |
| 8547 | boolean preViewDispatch(KeyEvent event) { |
| 8548 | mDispatched = false; |
| 8549 | if (mCurrentReceiver == null) { |
| 8550 | mCurrentReceiver = mCapturedKeys.get(event.getKeyCode()); |
| 8551 | } |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8552 | if (mCurrentReceiver != null) { |
| 8553 | View target = mCurrentReceiver.get(); |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8554 | if (event.getAction() == KeyEvent.ACTION_UP) { |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8555 | mCurrentReceiver = null; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8556 | } |
| 8557 | if (target != null && target.isAttachedToWindow()) { |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8558 | target.onUnhandledKeyEvent(event); |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8559 | } |
| 8560 | // consume anyways so that we don't feed uncaptured key events to other views |
| 8561 | return true; |
| 8562 | } |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8563 | return false; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8564 | } |
| 8565 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8566 | } |