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) { |
Vishnu Nair | 47d2d1e | 2019-01-24 13:01:24 -0800 | [diff] [blame] | 1379 | if (mSurfaceHolder != null) { |
| 1380 | notifySurfaceDestroyed(); |
| 1381 | } |
Robert Carr | 6858bb9 | 2018-04-16 11:09:49 -0700 | [diff] [blame] | 1382 | mSurface.release(); |
| 1383 | } |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1384 | } |
| 1385 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1387 | /** |
| 1388 | * Block the input events during an Activity Transition. The KEYCODE_BACK event is allowed |
| 1389 | * through to allow quick reversal of the Activity Transition. |
| 1390 | * |
| 1391 | * @param paused true to pause, false to resume. |
| 1392 | */ |
| 1393 | public void setPausedForTransition(boolean paused) { |
| 1394 | mPausedForTransition = paused; |
| 1395 | } |
| 1396 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1397 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1398 | public ViewParent getParent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | return null; |
| 1400 | } |
| 1401 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1402 | @Override |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1403 | 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] | 1404 | if (child != mView) { |
| 1405 | throw new RuntimeException("child is not mine, honest!"); |
| 1406 | } |
| 1407 | // Note: don't apply scroll offset, because we want to know its |
| 1408 | // visibility in the virtual canvas being given to the view hierarchy. |
| 1409 | return r.intersect(0, 0, mWidth, mHeight); |
| 1410 | } |
| 1411 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1412 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | public void bringChildToFront(View child) { |
| 1414 | } |
| 1415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1416 | int getHostVisibility() { |
Bryce Lee | 16e5089 | 2017-04-11 01:59:37 +0000 | [diff] [blame] | 1417 | return (mAppVisible || mForceDecorViewVisibility) ? mView.getVisibility() : View.GONE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1419 | |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 1420 | /** |
| 1421 | * Add LayoutTransition to the list of transitions to be started in the next traversal. |
| 1422 | * This list will be cleared after the transitions on the list are start()'ed. These |
| 1423 | * transitionsa re added by LayoutTransition itself when it sets up animations. The setup |
| 1424 | * happens during the layout phase of traversal, which we want to complete before any of the |
| 1425 | * animations are started (because those animations may side-effect properties that layout |
| 1426 | * depends upon, like the bounding rectangles of the affected views). So we add the transition |
| 1427 | * to the list and it is started just prior to starting the drawing phase of traversal. |
| 1428 | * |
| 1429 | * @param transition The LayoutTransition to be started on the next traversal. |
| 1430 | * |
| 1431 | * @hide |
| 1432 | */ |
| 1433 | public void requestTransitionStart(LayoutTransition transition) { |
| 1434 | if (mPendingTransitions == null || !mPendingTransitions.contains(transition)) { |
| 1435 | if (mPendingTransitions == null) { |
| 1436 | mPendingTransitions = new ArrayList<LayoutTransition>(); |
| 1437 | } |
| 1438 | mPendingTransitions.add(transition); |
| 1439 | } |
| 1440 | } |
| 1441 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1442 | /** |
| 1443 | * Notifies the HardwareRenderer that a new frame will be coming soon. |
| 1444 | * Currently only {@link ThreadedRenderer} cares about this, and uses |
| 1445 | * this knowledge to adjust the scheduling of off-thread animations |
| 1446 | */ |
| 1447 | void notifyRendererOfFramePending() { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1448 | if (mAttachInfo.mThreadedRenderer != null) { |
| 1449 | mAttachInfo.mThreadedRenderer.notifyFramePending(); |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1450 | } |
| 1451 | } |
| 1452 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 1453 | @UnsupportedAppUsage |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1454 | void scheduleTraversals() { |
| 1455 | if (!mTraversalScheduled) { |
| 1456 | mTraversalScheduled = true; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1457 | mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1458 | mChoreographer.postCallback( |
| 1459 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 1460 | if (!mUnbufferedInputDispatch) { |
| 1461 | scheduleConsumeBatchedInput(); |
| 1462 | } |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1463 | notifyRendererOfFramePending(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1464 | pokeDrawLockIfNeeded(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1465 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1466 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1467 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1468 | void unscheduleTraversals() { |
| 1469 | if (mTraversalScheduled) { |
| 1470 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1471 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1472 | mChoreographer.removeCallbacks( |
| 1473 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
| 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | void doTraversal() { |
| 1478 | if (mTraversalScheduled) { |
| 1479 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1480 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1481 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1482 | if (mProfile) { |
| 1483 | Debug.startMethodTracing("ViewAncestor"); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1484 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1485 | |
Chris Craik | e22c59b | 2015-05-21 18:33:37 -0700 | [diff] [blame] | 1486 | performTraversals(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1487 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1488 | if (mProfile) { |
| 1489 | Debug.stopMethodTracing(); |
| 1490 | mProfile = false; |
| 1491 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1495 | private void applyKeepScreenOnFlag(WindowManager.LayoutParams params) { |
| 1496 | // Update window's global keep screen on flag: if a view has requested |
| 1497 | // that the screen be kept on, then it is always set; otherwise, it is |
| 1498 | // set to whatever the client last requested for the global state. |
| 1499 | if (mAttachInfo.mKeepScreenOn) { |
| 1500 | params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 1501 | } else { |
| 1502 | params.flags = (params.flags&~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) |
| 1503 | | (mClientWindowLayoutFlags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1504 | } |
| 1505 | } |
| 1506 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1507 | private boolean collectViewAttributes() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1508 | if (mAttachInfo.mRecomputeGlobalAttributes) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1509 | //Log.i(mTag, "Computing view hierarchy attributes!"); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1510 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 1511 | boolean oldScreenOn = mAttachInfo.mKeepScreenOn; |
| 1512 | mAttachInfo.mKeepScreenOn = false; |
| 1513 | mAttachInfo.mSystemUiVisibility = 0; |
| 1514 | mAttachInfo.mHasSystemUiListeners = false; |
| 1515 | mView.dispatchCollectViewAttributes(mAttachInfo, 0); |
| 1516 | mAttachInfo.mSystemUiVisibility &= ~mAttachInfo.mDisabledSystemUiVisibility; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 1517 | WindowManager.LayoutParams params = mWindowAttributes; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1518 | mAttachInfo.mSystemUiVisibility |= getImpliedSystemUiVisibility(params); |
| 1519 | if (mAttachInfo.mKeepScreenOn != oldScreenOn |
| 1520 | || mAttachInfo.mSystemUiVisibility != params.subtreeSystemUiVisibility |
| 1521 | || mAttachInfo.mHasSystemUiListeners != params.hasSystemUiListeners) { |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1522 | applyKeepScreenOnFlag(params); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1523 | params.subtreeSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
| 1524 | params.hasSystemUiListeners = mAttachInfo.mHasSystemUiListeners; |
| 1525 | mView.dispatchWindowSystemUiVisiblityChanged(mAttachInfo.mSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1526 | return true; |
| 1527 | } |
| 1528 | } |
| 1529 | return false; |
| 1530 | } |
| 1531 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1532 | private int getImpliedSystemUiVisibility(WindowManager.LayoutParams params) { |
| 1533 | int vis = 0; |
| 1534 | // Translucent decor window flags imply stable system ui visibility. |
| 1535 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0) { |
| 1536 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 1537 | } |
| 1538 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) { |
| 1539 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1540 | } |
| 1541 | return vis; |
| 1542 | } |
| 1543 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1544 | private boolean measureHierarchy(final View host, final WindowManager.LayoutParams lp, |
| 1545 | final Resources res, final int desiredWindowWidth, final int desiredWindowHeight) { |
| 1546 | int childWidthMeasureSpec; |
| 1547 | int childHeightMeasureSpec; |
| 1548 | boolean windowSizeMayChange = false; |
| 1549 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1550 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1551 | "Measuring " + host + " in display " + desiredWindowWidth |
| 1552 | + "x" + desiredWindowHeight + "..."); |
| 1553 | |
| 1554 | boolean goodMeasure = false; |
| 1555 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) { |
| 1556 | // On large screens, we don't want to allow dialogs to just |
| 1557 | // stretch to fill the entire width of the screen to display |
| 1558 | // one line of text. First try doing the layout at a smaller |
| 1559 | // size to see if it will fit. |
| 1560 | final DisplayMetrics packageMetrics = res.getDisplayMetrics(); |
| 1561 | res.getValue(com.android.internal.R.dimen.config_prefDialogWidth, mTmpValue, true); |
| 1562 | int baseSize = 0; |
| 1563 | if (mTmpValue.type == TypedValue.TYPE_DIMENSION) { |
| 1564 | baseSize = (int)mTmpValue.getDimension(packageMetrics); |
| 1565 | } |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1566 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": baseSize=" + baseSize |
| 1567 | + ", desiredWindowWidth=" + desiredWindowWidth); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1568 | if (baseSize != 0 && desiredWindowWidth > baseSize) { |
| 1569 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
| 1570 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1571 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1572 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1573 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() |
| 1574 | + ") from width spec: " + MeasureSpec.toString(childWidthMeasureSpec) |
| 1575 | + " and height spec: " + MeasureSpec.toString(childHeightMeasureSpec)); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1576 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
| 1577 | goodMeasure = true; |
| 1578 | } else { |
| 1579 | // Didn't fit in that size... try expanding a bit. |
| 1580 | baseSize = (baseSize+desiredWindowWidth)/2; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1581 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": next baseSize=" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1582 | + baseSize); |
| 1583 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1584 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1585 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1586 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")"); |
| 1587 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1588 | if (DEBUG_DIALOG) Log.v(mTag, "Good!"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1589 | goodMeasure = true; |
| 1590 | } |
| 1591 | } |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | if (!goodMeasure) { |
| 1596 | childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width); |
| 1597 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1598 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1599 | if (mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) { |
| 1600 | windowSizeMayChange = true; |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | if (DBG) { |
| 1605 | System.out.println("======================================"); |
| 1606 | System.out.println("performTraversals -- after measure"); |
| 1607 | host.debug(); |
| 1608 | } |
| 1609 | |
| 1610 | return windowSizeMayChange; |
| 1611 | } |
| 1612 | |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1613 | /** |
| 1614 | * Modifies the input matrix such that it maps view-local coordinates to |
| 1615 | * on-screen coordinates. |
| 1616 | * |
| 1617 | * @param m input matrix to modify |
| 1618 | */ |
| 1619 | void transformMatrixToGlobal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1620 | m.preTranslate(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | /** |
| 1624 | * Modifies the input matrix such that it maps on-screen coordinates to |
| 1625 | * view-local coordinates. |
| 1626 | * |
| 1627 | * @param m input matrix to modify |
| 1628 | */ |
| 1629 | void transformMatrixToLocal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1630 | m.postTranslate(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1631 | } |
| 1632 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1633 | /* package */ WindowInsets getWindowInsets(boolean forceConstruct) { |
| 1634 | if (mLastWindowInsets == null || forceConstruct) { |
| 1635 | mDispatchContentInsets.set(mAttachInfo.mContentInsets); |
| 1636 | mDispatchStableInsets.set(mAttachInfo.mStableInsets); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1637 | mDispatchDisplayCutout = mAttachInfo.mDisplayCutout.get(); |
| 1638 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1639 | Rect contentInsets = mDispatchContentInsets; |
| 1640 | Rect stableInsets = mDispatchStableInsets; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1641 | DisplayCutout displayCutout = mDispatchDisplayCutout; |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1642 | // For dispatch we preserve old logic, but for direct requests from Views we allow to |
| 1643 | // immediately use pending insets. |
| 1644 | if (!forceConstruct |
| 1645 | && (!mPendingContentInsets.equals(contentInsets) || |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1646 | !mPendingStableInsets.equals(stableInsets) || |
| 1647 | !mPendingDisplayCutout.get().equals(displayCutout))) { |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1648 | contentInsets = mPendingContentInsets; |
| 1649 | stableInsets = mPendingStableInsets; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1650 | displayCutout = mPendingDisplayCutout.get(); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1651 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1652 | Rect outsets = mAttachInfo.mOutsets; |
| 1653 | if (outsets.left > 0 || outsets.top > 0 || outsets.right > 0 || outsets.bottom > 0) { |
| 1654 | contentInsets = new Rect(contentInsets.left + outsets.left, |
| 1655 | contentInsets.top + outsets.top, contentInsets.right + outsets.right, |
| 1656 | contentInsets.bottom + outsets.bottom); |
| 1657 | } |
Adrian Roos | 7419a17 | 2018-05-24 18:20:51 +0200 | [diff] [blame] | 1658 | contentInsets = ensureInsetsNonNegative(contentInsets, "content"); |
| 1659 | stableInsets = ensureInsetsNonNegative(stableInsets, "stable"); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1660 | mLastWindowInsets = new WindowInsets(contentInsets, |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1661 | null /* windowDecorInsets */, stableInsets, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1662 | mContext.getResources().getConfiguration().isScreenRound(), |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1663 | mAttachInfo.mAlwaysConsumeNavBar, displayCutout); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1664 | } |
| 1665 | return mLastWindowInsets; |
| 1666 | } |
| 1667 | |
Adrian Roos | 7419a17 | 2018-05-24 18:20:51 +0200 | [diff] [blame] | 1668 | private Rect ensureInsetsNonNegative(Rect insets, String kind) { |
| 1669 | 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] | 1670 | return new Rect(Math.max(0, insets.left), |
| 1671 | Math.max(0, insets.top), |
| 1672 | Math.max(0, insets.right), |
| 1673 | Math.max(0, insets.bottom)); |
| 1674 | } |
| 1675 | return insets; |
| 1676 | } |
| 1677 | |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1678 | void dispatchApplyInsets(View host) { |
Adrian Roos | 2b0dcb3 | 2017-12-12 16:07:55 +0100 | [diff] [blame] | 1679 | WindowInsets insets = getWindowInsets(true /* forceConstruct */); |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 1680 | final boolean dispatchCutout = (mWindowAttributes.layoutInDisplayCutoutMode |
| 1681 | == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS); |
| 1682 | if (!dispatchCutout) { |
Adrian Roos | 2b0dcb3 | 2017-12-12 16:07:55 +0100 | [diff] [blame] | 1683 | // Window is either not laid out in cutout or the status bar inset takes care of |
| 1684 | // 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] | 1685 | insets = insets.consumeDisplayCutout(); |
Adrian Roos | 2b0dcb3 | 2017-12-12 16:07:55 +0100 | [diff] [blame] | 1686 | } |
| 1687 | host.dispatchApplyWindowInsets(insets); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1690 | private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { |
| 1691 | return lp.type == TYPE_STATUS_BAR_PANEL |
| 1692 | || lp.type == TYPE_INPUT_METHOD |
| 1693 | || lp.type == TYPE_VOLUME_OVERLAY; |
| 1694 | } |
| 1695 | |
| 1696 | private int dipToPx(int dip) { |
| 1697 | final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); |
| 1698 | return (int) (displayMetrics.density * dip + 0.5f); |
| 1699 | } |
| 1700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | private void performTraversals() { |
| 1702 | // cache mView since it is used so much below... |
| 1703 | final View host = mView; |
| 1704 | |
| 1705 | if (DBG) { |
| 1706 | System.out.println("======================================"); |
| 1707 | System.out.println("performTraversals"); |
| 1708 | host.debug(); |
| 1709 | } |
| 1710 | |
| 1711 | if (host == null || !mAdded) |
| 1712 | return; |
| 1713 | |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 1714 | mIsInTraversal = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1715 | mWillDrawSoon = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1716 | boolean windowSizeMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1717 | boolean newSurface = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1718 | boolean surfaceChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1719 | WindowManager.LayoutParams lp = mWindowAttributes; |
| 1720 | |
| 1721 | int desiredWindowWidth; |
| 1722 | int desiredWindowHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1724 | final int viewVisibility = getHostVisibility(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1725 | final boolean viewVisibilityChanged = !mFirst |
Andrii Kulian | 74b561a | 2017-08-11 09:06:46 -0700 | [diff] [blame] | 1726 | && (mViewVisibility != viewVisibility || mNewSurfaceNeeded |
| 1727 | // Also check for possible double visibility update, which will make current |
| 1728 | // viewVisibility value equal to mViewVisibility and we may miss it. |
| 1729 | || mAppVisibilityChanged); |
| 1730 | mAppVisibilityChanged = false; |
Adam Powell | 06f9eb8 | 2016-08-24 17:09:01 -0700 | [diff] [blame] | 1731 | final boolean viewUserVisibilityChanged = !mFirst && |
| 1732 | ((mViewVisibility == View.VISIBLE) != (viewVisibility == View.VISIBLE)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | |
| 1734 | WindowManager.LayoutParams params = null; |
| 1735 | if (mWindowAttributesChanged) { |
| 1736 | mWindowAttributesChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1737 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1738 | params = lp; |
| 1739 | } |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 1740 | CompatibilityInfo compatibilityInfo = |
| 1741 | mDisplay.getDisplayAdjustments().getCompatibilityInfo(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1742 | if (compatibilityInfo.supportsScreen() == mLastInCompatMode) { |
| 1743 | params = lp; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1744 | mFullRedrawNeeded = true; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1745 | mLayoutRequested = true; |
| 1746 | if (mLastInCompatMode) { |
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 = false; |
| 1749 | } else { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1750 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1751 | mLastInCompatMode = true; |
| 1752 | } |
| 1753 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1754 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 1755 | mWindowAttributesChangesFlag = 0; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1756 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1757 | Rect frame = mWinFrame; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1758 | if (mFirst) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1759 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1760 | mLayoutRequested = true; |
| 1761 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1762 | final Configuration config = mContext.getResources().getConfiguration(); |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1763 | if (shouldUseDisplaySize(lp)) { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1764 | // NOTE -- system code, won't try to do compat mode. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1765 | Point size = new Point(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1766 | mDisplay.getRealSize(size); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1767 | desiredWindowWidth = size.x; |
| 1768 | desiredWindowHeight = size.y; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1769 | } else { |
Adrian Roos | 9e370f2 | 2018-03-06 18:19:45 +0100 | [diff] [blame] | 1770 | desiredWindowWidth = mWinFrame.width(); |
| 1771 | desiredWindowHeight = mWinFrame.height(); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1772 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1773 | |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 1774 | // We used to use the following condition to choose 32 bits drawing caches: |
| 1775 | // PixelFormat.hasAlpha(lp.format) || lp.format == PixelFormat.RGBX_8888 |
| 1776 | // 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] | 1777 | mAttachInfo.mUse32BitDrawingCache = true; |
| 1778 | mAttachInfo.mHasWindowFocus = false; |
| 1779 | mAttachInfo.mWindowVisibility = viewVisibility; |
| 1780 | mAttachInfo.mRecomputeGlobalAttributes = false; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1781 | mLastConfigurationFromResources.setTo(config); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1782 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1783 | // Set the layout direction if it has not been set before (inherit is the default) |
| 1784 | if (mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1785 | host.setLayoutDirection(config.getLayoutDirection()); |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1786 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1787 | host.dispatchAttachedToWindow(mAttachInfo, 0); |
| 1788 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1789 | dispatchApplyInsets(host); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | } else { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1791 | desiredWindowWidth = frame.width(); |
| 1792 | desiredWindowHeight = frame.height(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | if (desiredWindowWidth != mWidth || desiredWindowHeight != mHeight) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1794 | if (DEBUG_ORIENTATION) Log.v(mTag, "View " + host + " resized to: " + frame); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1795 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | mLayoutRequested = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1797 | windowSizeMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | if (viewVisibilityChanged) { |
Bryce Lee | 16e5089 | 2017-04-11 01:59:37 +0000 | [diff] [blame] | 1802 | mAttachInfo.mWindowVisibility = viewVisibility; |
| 1803 | host.dispatchWindowVisibilityChanged(viewVisibility); |
Adam Powell | 06f9eb8 | 2016-08-24 17:09:01 -0700 | [diff] [blame] | 1804 | if (viewUserVisibilityChanged) { |
Adam Powell | 64e1ba4 | 2016-08-22 09:09:44 -0700 | [diff] [blame] | 1805 | host.dispatchVisibilityAggregated(viewVisibility == View.VISIBLE); |
| 1806 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | if (viewVisibility != View.VISIBLE || mNewSurfaceNeeded) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1808 | endDragResizing(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1809 | destroyHardwareResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1810 | } |
| 1811 | if (viewVisibility == View.GONE) { |
| 1812 | // After making a window gone, we will count it as being |
| 1813 | // shown for the first time the next time it gets focus. |
| 1814 | mHasHadWindowFocus = false; |
| 1815 | } |
| 1816 | } |
| 1817 | |
Alan Viverette | 7dbc3bf | 2015-01-28 16:14:36 -0800 | [diff] [blame] | 1818 | // Non-visible windows can't hold accessibility focus. |
| 1819 | if (mAttachInfo.mWindowVisibility != View.VISIBLE) { |
| 1820 | host.clearAccessibilityFocus(); |
| 1821 | } |
| 1822 | |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1823 | // 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] | 1824 | getRunQueue().executeActions(mAttachInfo.mHandler); |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1826 | boolean insetsChanged = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1827 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1828 | boolean layoutRequested = mLayoutRequested && (!mStopped || mReportNextDraw); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1829 | if (layoutRequested) { |
Romain Guy | 15df670 | 2009-08-17 20:17:30 -0700 | [diff] [blame] | 1830 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1831 | final Resources res = mView.getContext().getResources(); |
| 1832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1833 | if (mFirst) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | // make sure touch mode code executes by setting cached value |
| 1835 | // to opposite of the added touch mode. |
| 1836 | mAttachInfo.mInTouchMode = !mAddedTouchMode; |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 1837 | ensureTouchModeLocally(mAddedTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1839 | if (!mPendingOverscanInsets.equals(mAttachInfo.mOverscanInsets)) { |
| 1840 | insetsChanged = true; |
| 1841 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1842 | if (!mPendingContentInsets.equals(mAttachInfo.mContentInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1843 | insetsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1844 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1845 | if (!mPendingStableInsets.equals(mAttachInfo.mStableInsets)) { |
| 1846 | insetsChanged = true; |
| 1847 | } |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 1848 | if (!mPendingDisplayCutout.equals(mAttachInfo.mDisplayCutout)) { |
| 1849 | insetsChanged = true; |
| 1850 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1851 | if (!mPendingVisibleInsets.equals(mAttachInfo.mVisibleInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1853 | 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] | 1854 | + mAttachInfo.mVisibleInsets); |
| 1855 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1856 | if (!mPendingOutsets.equals(mAttachInfo.mOutsets)) { |
| 1857 | insetsChanged = true; |
| 1858 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1859 | if (mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar) { |
| 1860 | insetsChanged = true; |
| 1861 | } |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1862 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT |
| 1863 | || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) { |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1864 | windowSizeMayChange = true; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1865 | |
| 1866 | if (shouldUseDisplaySize(lp)) { |
| 1867 | // NOTE -- system code, won't try to do compat mode. |
| 1868 | Point size = new Point(); |
| 1869 | mDisplay.getRealSize(size); |
| 1870 | desiredWindowWidth = size.x; |
| 1871 | desiredWindowHeight = size.y; |
| 1872 | } else { |
| 1873 | Configuration config = res.getConfiguration(); |
| 1874 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1875 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
| 1876 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | // Ask host how big it wants to be |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1881 | windowSizeMayChange |= measureHierarchy(host, lp, res, |
| 1882 | desiredWindowWidth, desiredWindowHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1883 | } |
| 1884 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1885 | if (collectViewAttributes()) { |
| 1886 | params = lp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1887 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1888 | if (mAttachInfo.mForceReportNewAttributes) { |
| 1889 | mAttachInfo.mForceReportNewAttributes = false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1890 | params = lp; |
| 1891 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1893 | if (mFirst || mAttachInfo.mViewVisibilityChanged) { |
| 1894 | mAttachInfo.mViewVisibilityChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1895 | int resizeMode = mSoftInputMode & |
| 1896 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 1897 | // If we are in auto resize mode, then we need to determine |
| 1898 | // what mode to use now. |
| 1899 | if (resizeMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1900 | final int N = mAttachInfo.mScrollContainers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1901 | for (int i=0; i<N; i++) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1902 | if (mAttachInfo.mScrollContainers.get(i).isShown()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1903 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 1904 | } |
| 1905 | } |
| 1906 | if (resizeMode == 0) { |
| 1907 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN; |
| 1908 | } |
| 1909 | if ((lp.softInputMode & |
| 1910 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) != resizeMode) { |
| 1911 | lp.softInputMode = (lp.softInputMode & |
| 1912 | ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) | |
| 1913 | resizeMode; |
| 1914 | params = lp; |
| 1915 | } |
| 1916 | } |
| 1917 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1918 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1919 | if (params != null) { |
| 1920 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 1921 | if (!PixelFormat.formatHasAlpha(params.format)) { |
| 1922 | params.format = PixelFormat.TRANSLUCENT; |
| 1923 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1925 | mAttachInfo.mOverscanRequested = (params.flags |
| 1926 | & WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | } |
| 1928 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1929 | if (mApplyInsetsRequested) { |
| 1930 | mApplyInsetsRequested = false; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1931 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1932 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1933 | if (mLayoutRequested) { |
| 1934 | // Short-circuit catching a new layout request here, so |
| 1935 | // we don't need to go through two layout passes when things |
| 1936 | // change due to fitting system windows, which can happen a lot. |
| 1937 | windowSizeMayChange |= measureHierarchy(host, lp, |
| 1938 | mView.getContext().getResources(), |
| 1939 | desiredWindowWidth, desiredWindowHeight); |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | if (layoutRequested) { |
| 1944 | // Clear this now, so that if anything requests a layout in the |
| 1945 | // rest of this function we will catch it and re-run a full |
| 1946 | // layout pass. |
| 1947 | mLayoutRequested = false; |
| 1948 | } |
| 1949 | |
| 1950 | boolean windowShouldResize = layoutRequested && windowSizeMayChange |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1951 | && ((mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) |
Romain Guy | 2e4f426 | 2010-04-06 11:07:52 -0700 | [diff] [blame] | 1952 | || (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1953 | frame.width() < desiredWindowWidth && frame.width() != mWidth) |
| 1954 | || (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1955 | frame.height() < desiredWindowHeight && frame.height() != mHeight)); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1956 | windowShouldResize |= mDragResizing && mResizeMode == RESIZE_MODE_FREEFORM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1958 | // If the activity was just relaunched, it might have unfrozen the task bounds (while |
| 1959 | // relaunching), so we need to force a call into window manager to pick up the latest |
| 1960 | // bounds. |
| 1961 | windowShouldResize |= mActivityRelaunched; |
| 1962 | |
Jeff Brown | 2e05ec3 | 2013-09-30 15:57:43 -0700 | [diff] [blame] | 1963 | // Determine whether to compute insets. |
| 1964 | // If there are no inset listeners remaining then we may still need to compute |
| 1965 | // 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] | 1966 | final boolean computesInternalInsets = |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1967 | mAttachInfo.mTreeObserver.hasComputeInternalInsetsListeners() |
| 1968 | || mAttachInfo.mHasNonEmptyGivenInternalInsets; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | boolean insetsPending = false; |
| 1971 | int relayoutResult = 0; |
Chet Haase | d86fb2c | 2016-05-04 07:26:02 -0700 | [diff] [blame] | 1972 | boolean updatedConfiguration = false; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1973 | |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 1974 | final int surfaceGenerationId = mSurface.getGenerationId(); |
| 1975 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1976 | final boolean isViewVisible = viewVisibility == View.VISIBLE; |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 1977 | final boolean windowRelayoutWasForced = mForceNextWindowRelayout; |
Bryce Lee | 46b0165 | 2017-06-07 23:01:56 +0000 | [diff] [blame] | 1978 | if (mFirst || windowShouldResize || insetsChanged || |
| 1979 | viewVisibilityChanged || params != null || mForceNextWindowRelayout) { |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 1980 | mForceNextWindowRelayout = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 1982 | if (isViewVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | // If this window is giving internal insets to the window |
| 1984 | // manager, and it is being added or changing its visibility, |
| 1985 | // then we want to first give the window manager "fake" |
| 1986 | // insets to cause it to effectively ignore the content of |
| 1987 | // the window during layout. This avoids it briefly causing |
| 1988 | // other windows to resize/move based on the raw frame of the |
| 1989 | // window, waiting until we can finish laying out this window |
| 1990 | // and get back to the window manager with the ultimately |
| 1991 | // computed insets. |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1992 | insetsPending = computesInternalInsets && (mFirst || viewVisibilityChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | } |
| 1994 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1995 | if (mSurfaceHolder != null) { |
| 1996 | mSurfaceHolder.mSurfaceLock.lock(); |
| 1997 | mDrawingAllowed = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1998 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1999 | |
Romain Guy | c361da8 | 2010-10-25 15:29:10 -0700 | [diff] [blame] | 2000 | boolean hwInitialized = false; |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 2001 | boolean contentInsetsChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2002 | boolean hadSurface = mSurface.isValid(); |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2004 | try { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 2005 | if (DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2006 | Log.i(mTag, "host=w:" + host.getMeasuredWidth() + ", h:" + |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 2007 | host.getMeasuredHeight() + ", params=" + params); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 2008 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 2009 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2010 | if (mAttachInfo.mThreadedRenderer != null) { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 2011 | // relayoutWindow may decide to destroy mSurface. As that decision |
| 2012 | // happens in WindowManager service, we need to be defensive here |
| 2013 | // and stop using the surface in case it gets destroyed. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2014 | if (mAttachInfo.mThreadedRenderer.pauseSurface(mSurface)) { |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 2015 | // Animations were running so we need to push a frame |
| 2016 | // to resume them |
| 2017 | mDirty.set(0, 0, mWidth, mHeight); |
| 2018 | } |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 2019 | mChoreographer.mFrameInfo.addFlags(FrameInfo.FLAG_WINDOW_LAYOUT_CHANGED); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 2020 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 2021 | relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); |
| 2022 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2023 | if (DEBUG_LAYOUT) Log.v(mTag, "relayout: frame=" + frame.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2024 | + " overscan=" + mPendingOverscanInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2025 | + " content=" + mPendingContentInsets.toShortString() |
| 2026 | + " visible=" + mPendingVisibleInsets.toShortString() |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 2027 | + " stable=" + mPendingStableInsets.toShortString() |
| 2028 | + " cutout=" + mPendingDisplayCutout.get().toString() |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 2029 | + " outsets=" + mPendingOutsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | + " surface=" + mSurface); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2031 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2032 | // If the pending {@link MergedConfiguration} handed back from |
| 2033 | // {@link #relayoutWindow} does not match the one last reported, |
| 2034 | // WindowManagerService has reported back a frame from a configuration not yet |
| 2035 | // handled by the client. In this case, we need to accept the configuration so we |
| 2036 | // do not lay out and draw with the wrong configuration. |
| 2037 | if (!mPendingMergedConfiguration.equals(mLastReportedMergedConfiguration)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2038 | if (DEBUG_CONFIGURATION) Log.v(mTag, "Visible with new config: " |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2039 | + mPendingMergedConfiguration.getMergedConfiguration()); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 2040 | performConfigurationChange(mPendingMergedConfiguration, !mFirst, |
| 2041 | INVALID_DISPLAY /* same display */); |
Chet Haase | d86fb2c | 2016-05-04 07:26:02 -0700 | [diff] [blame] | 2042 | updatedConfiguration = true; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2043 | } |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 2044 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2045 | final boolean overscanInsetsChanged = !mPendingOverscanInsets.equals( |
| 2046 | mAttachInfo.mOverscanInsets); |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 2047 | contentInsetsChanged = !mPendingContentInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2048 | mAttachInfo.mContentInsets); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2049 | final boolean visibleInsetsChanged = !mPendingVisibleInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2050 | mAttachInfo.mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2051 | final boolean stableInsetsChanged = !mPendingStableInsets.equals( |
| 2052 | mAttachInfo.mStableInsets); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 2053 | final boolean cutoutChanged = !mPendingDisplayCutout.equals( |
| 2054 | mAttachInfo.mDisplayCutout); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2055 | final boolean outsetsChanged = !mPendingOutsets.equals(mAttachInfo.mOutsets); |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 2056 | final boolean surfaceSizeChanged = (relayoutResult |
| 2057 | & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0; |
Adrian Roos | dcf50a4f | 2018-01-29 18:31:34 +0100 | [diff] [blame] | 2058 | surfaceChanged |= surfaceSizeChanged; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 2059 | final boolean alwaysConsumeNavBarChanged = |
| 2060 | mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2061 | if (contentInsetsChanged) { |
| 2062 | mAttachInfo.mContentInsets.set(mPendingContentInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2063 | 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] | 2064 | + mAttachInfo.mContentInsets); |
| 2065 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2066 | if (overscanInsetsChanged) { |
| 2067 | mAttachInfo.mOverscanInsets.set(mPendingOverscanInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2068 | if (DEBUG_LAYOUT) Log.v(mTag, "Overscan insets changing to: " |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2069 | + mAttachInfo.mOverscanInsets); |
| 2070 | // Need to relayout with content insets. |
| 2071 | contentInsetsChanged = true; |
| 2072 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2073 | if (stableInsetsChanged) { |
| 2074 | mAttachInfo.mStableInsets.set(mPendingStableInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2075 | if (DEBUG_LAYOUT) Log.v(mTag, "Decor insets changing to: " |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2076 | + mAttachInfo.mStableInsets); |
| 2077 | // Need to relayout with content insets. |
| 2078 | contentInsetsChanged = true; |
| 2079 | } |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 2080 | if (cutoutChanged) { |
| 2081 | mAttachInfo.mDisplayCutout.set(mPendingDisplayCutout); |
| 2082 | if (DEBUG_LAYOUT) { |
| 2083 | Log.v(mTag, "DisplayCutout changing to: " + mAttachInfo.mDisplayCutout); |
| 2084 | } |
| 2085 | // Need to relayout with content insets. |
| 2086 | contentInsetsChanged = true; |
| 2087 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 2088 | if (alwaysConsumeNavBarChanged) { |
| 2089 | mAttachInfo.mAlwaysConsumeNavBar = mPendingAlwaysConsumeNavBar; |
| 2090 | contentInsetsChanged = true; |
| 2091 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2092 | if (contentInsetsChanged || mLastSystemUiVisibility != |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2093 | mAttachInfo.mSystemUiVisibility || mApplyInsetsRequested |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2094 | || mLastOverscanRequested != mAttachInfo.mOverscanRequested |
| 2095 | || outsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2096 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2097 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2098 | mAttachInfo.mOutsets.set(mPendingOutsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2099 | mApplyInsetsRequested = false; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 2100 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2101 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | if (visibleInsetsChanged) { |
| 2103 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2104 | 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] | 2105 | + mAttachInfo.mVisibleInsets); |
| 2106 | } |
| 2107 | |
| 2108 | if (!hadSurface) { |
| 2109 | if (mSurface.isValid()) { |
| 2110 | // If we are creating a new surface, then we need to |
| 2111 | // completely redraw it. Also, when we get to the |
| 2112 | // point of drawing it we will hold off and schedule |
| 2113 | // a new traversal instead. This is so we can tell the |
| 2114 | // window manager about all of the windows being displayed |
| 2115 | // before actually drawing them, so it can display then |
| 2116 | // all at once. |
| 2117 | newSurface = true; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2118 | mFullRedrawNeeded = true; |
Jack Palevich | 61a6e68 | 2009-10-09 17:37:50 -0700 | [diff] [blame] | 2119 | mPreviousTransparentRegion.setEmpty(); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2120 | |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 2121 | // Only initialize up-front if transparent regions are not |
| 2122 | // requested, otherwise defer to see if the entire window |
| 2123 | // will be transparent |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2124 | if (mAttachInfo.mThreadedRenderer != null) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2125 | try { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2126 | hwInitialized = mAttachInfo.mThreadedRenderer.initialize( |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 2127 | mSurface); |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 2128 | if (hwInitialized && (host.mPrivateFlags |
| 2129 | & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) { |
| 2130 | // Don't pre-allocate if transparent regions |
| 2131 | // are requested as they may not be needed |
Jorim Jaggi | 7823ee7 | 2018-07-17 15:24:16 +0200 | [diff] [blame] | 2132 | mAttachInfo.mThreadedRenderer.allocateBuffers(mSurface); |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 2133 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2134 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2135 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2136 | return; |
| 2137 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | } else if (!mSurface.isValid()) { |
| 2141 | // If the surface has been removed, then reset the scroll |
| 2142 | // positions. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2143 | if (mLastScrolledFocus != null) { |
| 2144 | mLastScrolledFocus.clear(); |
| 2145 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | mScrollY = mCurScrollY = 0; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 2147 | if (mView instanceof RootViewSurfaceTaker) { |
| 2148 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 2149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | if (mScroller != null) { |
| 2151 | mScroller.abortAnimation(); |
| 2152 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 2153 | // Our surface is gone |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2154 | if (mAttachInfo.mThreadedRenderer != null && |
| 2155 | mAttachInfo.mThreadedRenderer.isEnabled()) { |
| 2156 | mAttachInfo.mThreadedRenderer.destroy(); |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 2157 | } |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 2158 | } else if ((surfaceGenerationId != mSurface.getGenerationId() |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 2159 | || surfaceSizeChanged || windowRelayoutWasForced) |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 2160 | && mSurfaceHolder == null |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2161 | && mAttachInfo.mThreadedRenderer != null) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2162 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2163 | try { |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 2164 | // Need to do updateSurface (which leads to CanvasContext::setSurface and |
| 2165 | // re-create the EGLSurface) if either the Surface changed (as indicated by |
| 2166 | // generation id), or WindowManager changed the surface size. The latter is |
| 2167 | // because on some chips, changing the consumer side's BufferQueue size may |
| 2168 | // not take effect immediately unless we create a new EGLSurface. |
| 2169 | // Note that frame size change doesn't always imply surface size change (eg. |
| 2170 | // drag resizing uses fullscreen surface), need to check surfaceSizeChanged |
| 2171 | // flag from WindowManager. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2172 | mAttachInfo.mThreadedRenderer.updateSurface(mSurface); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2173 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2174 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2175 | return; |
| 2176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2178 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2179 | final boolean freeformResizing = (relayoutResult |
| 2180 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; |
| 2181 | final boolean dockedResizing = (relayoutResult |
| 2182 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; |
| 2183 | final boolean dragResizing = freeformResizing || dockedResizing; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2184 | if (mDragResizing != dragResizing) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 2185 | if (dragResizing) { |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2186 | mResizeMode = freeformResizing |
| 2187 | ? RESIZE_MODE_FREEFORM |
| 2188 | : RESIZE_MODE_DOCKED_DIVIDER; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 2189 | // TODO: Need cutout? |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2190 | startDragResizing(mPendingBackDropFrame, |
| 2191 | mWinFrame.equals(mPendingBackDropFrame), mPendingVisibleInsets, |
| 2192 | mPendingStableInsets, mResizeMode); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 2193 | } else { |
| 2194 | // We shouldn't come here, but if we come we should end the resize. |
| 2195 | endDragResizing(); |
| 2196 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2197 | } |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 2198 | if (!mUseMTRenderer) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 2199 | if (dragResizing) { |
| 2200 | mCanvasOffsetX = mWinFrame.left; |
| 2201 | mCanvasOffsetY = mWinFrame.top; |
| 2202 | } else { |
| 2203 | mCanvasOffsetX = mCanvasOffsetY = 0; |
| 2204 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2205 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | } catch (RemoteException e) { |
| 2207 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 2208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | if (DEBUG_ORIENTATION) Log.v( |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2210 | TAG, "Relayout returned: frame=" + frame + ", surface=" + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2212 | mAttachInfo.mWindowLeft = frame.left; |
| 2213 | mAttachInfo.mWindowTop = frame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | |
| 2215 | // !!FIXME!! This next section handles the case where we did not get the |
| 2216 | // window size we asked for. We should avoid this by getting a maximum size from |
| 2217 | // the window session beforehand. |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 2218 | if (mWidth != frame.width() || mHeight != frame.height()) { |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 2219 | mWidth = frame.width(); |
| 2220 | mHeight = frame.height(); |
| 2221 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2222 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2223 | if (mSurfaceHolder != null) { |
| 2224 | // The app owns the surface; tell it about what is going on. |
| 2225 | if (mSurface.isValid()) { |
| 2226 | // XXX .copyFrom() doesn't work! |
| 2227 | //mSurfaceHolder.mSurface.copyFrom(mSurface); |
| 2228 | mSurfaceHolder.mSurface = mSurface; |
| 2229 | } |
Jeff Brown | 30bc34f | 2011-01-25 12:56:56 -0800 | [diff] [blame] | 2230 | mSurfaceHolder.setSurfaceFrameSize(mWidth, mHeight); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2231 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 2232 | if (mSurface.isValid()) { |
John Reck | 208c47c | 2016-06-09 16:26:21 -0700 | [diff] [blame] | 2233 | if (!hadSurface) { |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2234 | mSurfaceHolder.ungetCallbacks(); |
| 2235 | |
| 2236 | mIsCreating = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2237 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2238 | if (callbacks != null) { |
| 2239 | for (SurfaceHolder.Callback c : callbacks) { |
| 2240 | c.surfaceCreated(mSurfaceHolder); |
| 2241 | } |
| 2242 | } |
| 2243 | surfaceChanged = true; |
| 2244 | } |
John Reck | 208c47c | 2016-06-09 16:26:21 -0700 | [diff] [blame] | 2245 | if (surfaceChanged || surfaceGenerationId != mSurface.getGenerationId()) { |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2246 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2247 | if (callbacks != null) { |
| 2248 | for (SurfaceHolder.Callback c : callbacks) { |
| 2249 | c.surfaceChanged(mSurfaceHolder, lp.format, |
| 2250 | mWidth, mHeight); |
| 2251 | } |
| 2252 | } |
| 2253 | } |
| 2254 | mIsCreating = false; |
| 2255 | } else if (hadSurface) { |
Vishnu Nair | 47d2d1e | 2019-01-24 13:01:24 -0800 | [diff] [blame] | 2256 | notifySurfaceDestroyed(); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2257 | mSurfaceHolder.mSurfaceLock.lock(); |
Jozef BABJAK | 93c5b6a | 2011-02-22 09:33:19 +0100 | [diff] [blame] | 2258 | try { |
| 2259 | mSurfaceHolder.mSurface = new Surface(); |
| 2260 | } finally { |
| 2261 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 2262 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2263 | } |
| 2264 | } |
Romain Guy | 53389bd | 2010-09-07 17:16:32 -0700 | [diff] [blame] | 2265 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2266 | final ThreadedRenderer threadedRenderer = mAttachInfo.mThreadedRenderer; |
| 2267 | if (threadedRenderer != null && threadedRenderer.isEnabled()) { |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2268 | if (hwInitialized |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2269 | || mWidth != threadedRenderer.getWidth() |
| 2270 | || mHeight != threadedRenderer.getHeight() |
| 2271 | || mNeedsRendererSetup) { |
| 2272 | threadedRenderer.setup(mWidth, mHeight, mAttachInfo, |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2273 | mWindowAttributes.surfaceInsets); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2274 | mNeedsRendererSetup = false; |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 2275 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2276 | } |
| 2277 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 2278 | if (!mStopped || mReportNextDraw) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2279 | boolean focusChangedDueToTouchMode = ensureTouchModeLocally( |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2280 | (relayoutResult&WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE) != 0); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2281 | if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth() |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 2282 | || mHeight != host.getMeasuredHeight() || contentInsetsChanged || |
Chet Haase | d86fb2c | 2016-05-04 07:26:02 -0700 | [diff] [blame] | 2283 | updatedConfiguration) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2284 | int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width); |
| 2285 | int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2286 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2287 | if (DEBUG_LAYOUT) Log.v(mTag, "Ooops, something changed! mWidth=" |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2288 | + mWidth + " measuredWidth=" + host.getMeasuredWidth() |
| 2289 | + " mHeight=" + mHeight |
| 2290 | + " measuredHeight=" + host.getMeasuredHeight() |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 2291 | + " coveredInsetsChanged=" + contentInsetsChanged); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2292 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2293 | // Ask host how big it wants to be |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2294 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
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 | // Implementation of weights from WindowManager.LayoutParams |
| 2297 | // We just grow the dimensions as needed and re-measure if |
| 2298 | // needs be |
| 2299 | int width = host.getMeasuredWidth(); |
| 2300 | int height = host.getMeasuredHeight(); |
| 2301 | boolean measureAgain = false; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2302 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2303 | if (lp.horizontalWeight > 0.0f) { |
| 2304 | width += (int) ((mWidth - width) * lp.horizontalWeight); |
| 2305 | childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, |
| 2306 | MeasureSpec.EXACTLY); |
| 2307 | measureAgain = true; |
| 2308 | } |
| 2309 | if (lp.verticalWeight > 0.0f) { |
| 2310 | height += (int) ((mHeight - height) * lp.verticalWeight); |
| 2311 | childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, |
| 2312 | MeasureSpec.EXACTLY); |
| 2313 | measureAgain = true; |
| 2314 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2315 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2316 | if (measureAgain) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2317 | if (DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2318 | "And hey let's measure once more: width=" + width |
| 2319 | + " height=" + height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2320 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2321 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2322 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2323 | layoutRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2324 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | } |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2326 | } else { |
| 2327 | // Not the first pass and no window/insets/visibility change but the window |
| 2328 | // may have moved and we need check that and if so to update the left and right |
| 2329 | // in the attach info. We translate only the window frame since on window move |
| 2330 | // the window manager tells us only for the new frame but the insets are the |
| 2331 | // same and we do not want to translate them more than once. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2332 | maybeHandleWindowMove(frame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2333 | } |
| 2334 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 2335 | final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2336 | boolean triggerGlobalLayoutListener = didLayout |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2337 | || mAttachInfo.mRecomputeGlobalAttributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2338 | if (didLayout) { |
Jorim Jaggi | 26d02d2 | 2016-02-24 18:37:51 -0500 | [diff] [blame] | 2339 | performLayout(lp, mWidth, mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2340 | |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 2341 | // 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] | 2342 | // We can compute the transparent area |
| 2343 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2344 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2345 | // start out transparent |
| 2346 | // TODO: AVOID THAT CALL BY CACHING THE RESULT? |
| 2347 | host.getLocationInWindow(mTmpLocation); |
| 2348 | mTransparentRegion.set(mTmpLocation[0], mTmpLocation[1], |
| 2349 | mTmpLocation[0] + host.mRight - host.mLeft, |
| 2350 | mTmpLocation[1] + host.mBottom - host.mTop); |
| 2351 | |
| 2352 | host.gatherTransparentRegion(mTransparentRegion); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 2353 | if (mTranslator != null) { |
| 2354 | mTranslator.translateRegionInWindowToScreen(mTransparentRegion); |
| 2355 | } |
| 2356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | if (!mTransparentRegion.equals(mPreviousTransparentRegion)) { |
| 2358 | mPreviousTransparentRegion.set(mTransparentRegion); |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 2359 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | // reconfigure window manager |
| 2361 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2362 | mWindowSession.setTransparentRegion(mWindow, mTransparentRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2363 | } catch (RemoteException e) { |
| 2364 | } |
| 2365 | } |
| 2366 | } |
| 2367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | if (DBG) { |
| 2369 | System.out.println("======================================"); |
Chet Haase | 4610eef | 2015-12-03 07:38:11 -0800 | [diff] [blame] | 2370 | System.out.println("performTraversals -- after setFrame"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | host.debug(); |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | if (triggerGlobalLayoutListener) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2376 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 2377 | mAttachInfo.mTreeObserver.dispatchOnGlobalLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | if (computesInternalInsets) { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2381 | // Clear the original insets. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2382 | final ViewTreeObserver.InternalInsetsInfo insets = mAttachInfo.mGivenInternalInsets; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2383 | insets.reset(); |
| 2384 | |
| 2385 | // Compute new insets in place. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2386 | mAttachInfo.mTreeObserver.dispatchOnComputeInternalInsets(insets); |
| 2387 | mAttachInfo.mHasNonEmptyGivenInternalInsets = !insets.isEmpty(); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2388 | |
| 2389 | // Tell the window manager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | if (insetsPending || !mLastGivenInsets.equals(insets)) { |
| 2391 | mLastGivenInsets.set(insets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2392 | |
| 2393 | // Translate insets to screen coordinates if needed. |
| 2394 | final Rect contentInsets; |
| 2395 | final Rect visibleInsets; |
| 2396 | final Region touchableRegion; |
| 2397 | if (mTranslator != null) { |
| 2398 | contentInsets = mTranslator.getTranslatedContentInsets(insets.contentInsets); |
| 2399 | visibleInsets = mTranslator.getTranslatedVisibleInsets(insets.visibleInsets); |
| 2400 | touchableRegion = mTranslator.getTranslatedTouchableArea(insets.touchableRegion); |
| 2401 | } else { |
| 2402 | contentInsets = insets.contentInsets; |
| 2403 | visibleInsets = insets.visibleInsets; |
| 2404 | touchableRegion = insets.touchableRegion; |
| 2405 | } |
| 2406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2408 | mWindowSession.setInsets(mWindow, insets.mTouchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2409 | contentInsets, visibleInsets, touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | } catch (RemoteException e) { |
| 2411 | } |
| 2412 | } |
| 2413 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2414 | |
Evan Rosky | adf5bec | 2017-10-19 10:24:07 -0700 | [diff] [blame] | 2415 | if (mFirst) { |
Evan Rosky | bdc66cb | 2017-09-08 14:27:24 -0700 | [diff] [blame] | 2416 | if (sAlwaysAssignFocus || !isInTouchMode()) { |
Evan Rosky | adf5bec | 2017-10-19 10:24:07 -0700 | [diff] [blame] | 2417 | // handle first focus request |
| 2418 | if (DEBUG_INPUT_RESIZE) { |
| 2419 | Log.v(mTag, "First: mView.hasFocus()=" + mView.hasFocus()); |
| 2420 | } |
| 2421 | if (mView != null) { |
| 2422 | if (!mView.hasFocus()) { |
| 2423 | mView.restoreDefaultFocus(); |
| 2424 | if (DEBUG_INPUT_RESIZE) { |
| 2425 | Log.v(mTag, "First: requested focused view=" + mView.findFocus()); |
| 2426 | } |
| 2427 | } else { |
| 2428 | if (DEBUG_INPUT_RESIZE) { |
| 2429 | Log.v(mTag, "First: existing focused view=" + mView.findFocus()); |
| 2430 | } |
| 2431 | } |
| 2432 | } |
| 2433 | } else { |
| 2434 | // Some views (like ScrollView) won't hand focus to descendants that aren't within |
| 2435 | // their viewport. Before layout, there's a good change these views are size 0 |
| 2436 | // which means no children can get focus. After layout, this view now has size, but |
| 2437 | // is not guaranteed to hand-off focus to a focusable child (specifically, the edge- |
| 2438 | // case where the child has a size prior to layout and thus won't trigger |
| 2439 | // focusableViewAvailable). |
| 2440 | View focused = mView.findFocus(); |
| 2441 | if (focused instanceof ViewGroup |
| 2442 | && ((ViewGroup) focused).getDescendantFocusability() |
| 2443 | == ViewGroup.FOCUS_AFTER_DESCENDANTS) { |
| 2444 | focused.restoreDefaultFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2445 | } |
| 2446 | } |
| 2447 | } |
| 2448 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2449 | final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible; |
| 2450 | final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible; |
| 2451 | final boolean regainedFocus = hasWindowFocus && mLostWindowFocus; |
| 2452 | if (regainedFocus) { |
| 2453 | mLostWindowFocus = false; |
| 2454 | } else if (!hasWindowFocus && mHadWindowFocus) { |
| 2455 | mLostWindowFocus = true; |
| 2456 | } |
| 2457 | |
| 2458 | if (changedVisibility || regainedFocus) { |
Phil Weaver | 532c799 | 2016-08-29 15:59:03 -0700 | [diff] [blame] | 2459 | // Toasts are presented as notifications - don't present them as windows as well |
| 2460 | boolean isToast = (mWindowAttributes == null) ? false |
| 2461 | : (mWindowAttributes.type == WindowManager.LayoutParams.TYPE_TOAST); |
| 2462 | if (!isToast) { |
| 2463 | host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2464 | } |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2465 | } |
| 2466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | mFirst = false; |
| 2468 | mWillDrawSoon = false; |
| 2469 | mNewSurfaceNeeded = false; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2470 | mActivityRelaunched = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2471 | mViewVisibility = viewVisibility; |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2472 | mHadWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2473 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2474 | if (hasWindowFocus && !isInLocalFocusMode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2475 | final boolean imTarget = WindowManager.LayoutParams |
| 2476 | .mayUseInputMethod(mWindowAttributes.flags); |
| 2477 | if (imTarget != mLastWasImTarget) { |
| 2478 | mLastWasImTarget = imTarget; |
| 2479 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 2480 | if (imm != null && imTarget) { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2481 | imm.onPreWindowFocus(mView, hasWindowFocus); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 2482 | imm.onPostWindowFocus(mView, mView.findFocus(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | mWindowAttributes.softInputMode, |
| 2484 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 2485 | } |
| 2486 | } |
| 2487 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2488 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2489 | // Remember if we must report the next draw. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2490 | if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 2491 | reportNextDraw(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2492 | } |
| 2493 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2494 | boolean cancelDraw = mAttachInfo.mTreeObserver.dispatchOnPreDraw() || !isViewVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2495 | |
Jorim Jaggi | 75c21ca | 2016-03-28 19:26:09 -0400 | [diff] [blame] | 2496 | if (!cancelDraw && !newSurface) { |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2497 | if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
| 2498 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2499 | mPendingTransitions.get(i).startChangingAnimations(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2500 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2501 | mPendingTransitions.clear(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2502 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2503 | |
| 2504 | performDraw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | } else { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2506 | if (isViewVisible) { |
Chris Wren | 78cb7cf | 2012-05-15 12:36:44 -0400 | [diff] [blame] | 2507 | // Try again |
| 2508 | scheduleTraversals(); |
| 2509 | } else if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2510 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2511 | mPendingTransitions.get(i).endChangingAnimations(); |
| 2512 | } |
| 2513 | mPendingTransitions.clear(); |
| 2514 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2515 | } |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 2516 | |
| 2517 | mIsInTraversal = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2518 | } |
| 2519 | |
Vishnu Nair | 47d2d1e | 2019-01-24 13:01:24 -0800 | [diff] [blame] | 2520 | private void notifySurfaceDestroyed() { |
| 2521 | mSurfaceHolder.ungetCallbacks(); |
| 2522 | SurfaceHolder.Callback[] callbacks = mSurfaceHolder.getCallbacks(); |
| 2523 | if (callbacks != null) { |
| 2524 | for (SurfaceHolder.Callback c : callbacks) { |
| 2525 | c.surfaceDestroyed(mSurfaceHolder); |
| 2526 | } |
| 2527 | } |
| 2528 | } |
| 2529 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2530 | private void maybeHandleWindowMove(Rect frame) { |
| 2531 | |
| 2532 | // TODO: Well, we are checking whether the frame has changed similarly |
| 2533 | // to how this is done for the insets. This is however incorrect since |
| 2534 | // the insets and the frame are translated. For example, the old frame |
| 2535 | // was (1, 1 - 1, 1) and was translated to say (2, 2 - 2, 2), now the new |
| 2536 | // reported frame is (2, 2 - 2, 2) which implies no change but this is not |
| 2537 | // true since we are comparing a not translated value to a translated one. |
| 2538 | // This scenario is rare but we may want to fix that. |
| 2539 | |
| 2540 | final boolean windowMoved = mAttachInfo.mWindowLeft != frame.left |
| 2541 | || mAttachInfo.mWindowTop != frame.top; |
| 2542 | if (windowMoved) { |
| 2543 | if (mTranslator != null) { |
| 2544 | mTranslator.translateRectInScreenToAppWinFrame(frame); |
| 2545 | } |
| 2546 | mAttachInfo.mWindowLeft = frame.left; |
| 2547 | mAttachInfo.mWindowTop = frame.top; |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 2548 | } |
| 2549 | if (windowMoved || mAttachInfo.mNeedsUpdateLightCenter) { |
| 2550 | // Update the light position for the new offsets. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2551 | if (mAttachInfo.mThreadedRenderer != null) { |
| 2552 | mAttachInfo.mThreadedRenderer.setLightCenter(mAttachInfo); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2553 | } |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 2554 | mAttachInfo.mNeedsUpdateLightCenter = false; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2555 | } |
| 2556 | } |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 2557 | |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 2558 | private void handleWindowFocusChanged() { |
| 2559 | final boolean hasWindowFocus; |
| 2560 | final boolean inTouchMode; |
| 2561 | synchronized (this) { |
Dianne Hackborn | 011944c | 2017-12-15 15:44:55 -0800 | [diff] [blame] | 2562 | if (!mWindowFocusChanged) { |
| 2563 | return; |
| 2564 | } |
| 2565 | mWindowFocusChanged = false; |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 2566 | hasWindowFocus = mUpcomingWindowFocus; |
| 2567 | inTouchMode = mUpcomingInTouchMode; |
| 2568 | } |
| 2569 | |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 2570 | if (mAdded) { |
| 2571 | profileRendering(hasWindowFocus); |
| 2572 | |
| 2573 | if (hasWindowFocus) { |
| 2574 | ensureTouchModeLocally(inTouchMode); |
| 2575 | if (mAttachInfo.mThreadedRenderer != null && mSurface.isValid()) { |
| 2576 | mFullRedrawNeeded = true; |
| 2577 | try { |
| 2578 | final WindowManager.LayoutParams lp = mWindowAttributes; |
| 2579 | final Rect surfaceInsets = lp != null ? lp.surfaceInsets : null; |
| 2580 | mAttachInfo.mThreadedRenderer.initializeIfNeeded( |
| 2581 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
| 2582 | } catch (OutOfResourcesException e) { |
| 2583 | Log.e(mTag, "OutOfResourcesException locking surface", e); |
| 2584 | try { |
| 2585 | if (!mWindowSession.outOfMemory(mWindow)) { |
| 2586 | Slog.w(mTag, "No processes killed for memory;" |
| 2587 | + " killing self"); |
| 2588 | Process.killProcess(Process.myPid()); |
| 2589 | } |
| 2590 | } catch (RemoteException ex) { |
| 2591 | } |
| 2592 | // Retry in a bit. |
| 2593 | mHandler.sendMessageDelayed(mHandler.obtainMessage( |
| 2594 | MSG_WINDOW_FOCUS_CHANGED), 500); |
| 2595 | return; |
| 2596 | } |
| 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | mAttachInfo.mHasWindowFocus = hasWindowFocus; |
| 2601 | |
| 2602 | mLastWasImTarget = WindowManager.LayoutParams |
| 2603 | .mayUseInputMethod(mWindowAttributes.flags); |
| 2604 | |
| 2605 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 2606 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
| 2607 | imm.onPreWindowFocus(mView, hasWindowFocus); |
| 2608 | } |
| 2609 | if (mView != null) { |
| 2610 | mAttachInfo.mKeyDispatchState.reset(); |
| 2611 | mView.dispatchWindowFocusChanged(hasWindowFocus); |
| 2612 | mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus); |
| 2613 | |
| 2614 | if (mAttachInfo.mTooltipHost != null) { |
| 2615 | mAttachInfo.mTooltipHost.hideTooltip(); |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | // Note: must be done after the focus change callbacks, |
| 2620 | // so all of the view state is set up correctly. |
| 2621 | if (hasWindowFocus) { |
| 2622 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
| 2623 | imm.onPostWindowFocus(mView, mView.findFocus(), |
| 2624 | mWindowAttributes.softInputMode, |
| 2625 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 2626 | } |
| 2627 | // Clear the forward bit. We can just do this directly, since |
| 2628 | // the window manager doesn't care about it. |
| 2629 | mWindowAttributes.softInputMode &= |
| 2630 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
| 2631 | ((WindowManager.LayoutParams) mView.getLayoutParams()) |
| 2632 | .softInputMode &= |
| 2633 | ~WindowManager.LayoutParams |
| 2634 | .SOFT_INPUT_IS_FORWARD_NAVIGATION; |
| 2635 | mHasHadWindowFocus = true; |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 2636 | |
| 2637 | // Refocusing a window that has a focused view should fire a |
| 2638 | // focus event for the view since the global focused view changed. |
| 2639 | fireAccessibilityFocusEventIfHasFocusedNode(); |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 2640 | } else { |
| 2641 | if (mPointerCapture) { |
| 2642 | handlePointerCaptureChanged(false); |
| 2643 | } |
| 2644 | } |
| 2645 | } |
| 2646 | mFirstInputStage.onWindowFocusChanged(hasWindowFocus); |
| 2647 | } |
| 2648 | |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 2649 | private void fireAccessibilityFocusEventIfHasFocusedNode() { |
| 2650 | if (!AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 2651 | return; |
| 2652 | } |
| 2653 | final View focusedView = mView.findFocus(); |
| 2654 | if (focusedView == null) { |
| 2655 | return; |
| 2656 | } |
| 2657 | final AccessibilityNodeProvider provider = focusedView.getAccessibilityNodeProvider(); |
| 2658 | if (provider == null) { |
| 2659 | focusedView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 2660 | } else { |
| 2661 | final AccessibilityNodeInfo focusedNode = findFocusedVirtualNode(provider); |
| 2662 | if (focusedNode != null) { |
| 2663 | final int virtualId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 2664 | focusedNode.getSourceNodeId()); |
| 2665 | // This is a best effort since clearing and setting the focus via the |
| 2666 | // provider APIs could have side effects. We don't have a provider API |
| 2667 | // similar to that on View to ask a given event to be fired. |
| 2668 | final AccessibilityEvent event = AccessibilityEvent.obtain( |
| 2669 | AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 2670 | event.setSource(focusedView, virtualId); |
| 2671 | event.setPackageName(focusedNode.getPackageName()); |
| 2672 | event.setChecked(focusedNode.isChecked()); |
| 2673 | event.setContentDescription(focusedNode.getContentDescription()); |
| 2674 | event.setPassword(focusedNode.isPassword()); |
| 2675 | event.getText().add(focusedNode.getText()); |
| 2676 | event.setEnabled(focusedNode.isEnabled()); |
| 2677 | focusedView.getParent().requestSendAccessibilityEvent(focusedView, event); |
| 2678 | focusedNode.recycle(); |
| 2679 | } |
| 2680 | } |
| 2681 | } |
| 2682 | |
| 2683 | private AccessibilityNodeInfo findFocusedVirtualNode(AccessibilityNodeProvider provider) { |
| 2684 | AccessibilityNodeInfo focusedNode = provider.findFocus( |
| 2685 | AccessibilityNodeInfo.FOCUS_INPUT); |
| 2686 | if (focusedNode != null) { |
| 2687 | return focusedNode; |
| 2688 | } |
| 2689 | |
| 2690 | if (!mContext.isAutofillCompatibilityEnabled()) { |
| 2691 | return null; |
| 2692 | } |
| 2693 | |
| 2694 | // Unfortunately some provider implementations don't properly |
| 2695 | // implement AccessibilityNodeProvider#findFocus |
| 2696 | AccessibilityNodeInfo current = provider.createAccessibilityNodeInfo( |
| 2697 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 2698 | if (current.isFocused()) { |
| 2699 | return current; |
| 2700 | } |
| 2701 | |
| 2702 | final Queue<AccessibilityNodeInfo> fringe = new LinkedList<>(); |
| 2703 | fringe.offer(current); |
| 2704 | |
| 2705 | while (!fringe.isEmpty()) { |
| 2706 | current = fringe.poll(); |
| 2707 | final LongArray childNodeIds = current.getChildNodeIds(); |
| 2708 | if (childNodeIds== null || childNodeIds.size() <= 0) { |
| 2709 | continue; |
| 2710 | } |
| 2711 | final int childCount = childNodeIds.size(); |
| 2712 | for (int i = 0; i < childCount; i++) { |
| 2713 | final int virtualId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 2714 | childNodeIds.get(i)); |
| 2715 | final AccessibilityNodeInfo child = provider.createAccessibilityNodeInfo(virtualId); |
| 2716 | if (child != null) { |
| 2717 | if (child.isFocused()) { |
| 2718 | return child; |
| 2719 | } |
| 2720 | fringe.offer(child); |
| 2721 | } |
| 2722 | } |
| 2723 | current.recycle(); |
| 2724 | } |
| 2725 | |
| 2726 | return null; |
| 2727 | } |
| 2728 | |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2729 | private void handleOutOfResourcesException(Surface.OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2730 | Log.e(mTag, "OutOfResourcesException initializing HW surface", e); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2731 | try { |
| 2732 | if (!mWindowSession.outOfMemory(mWindow) && |
| 2733 | Process.myUid() != Process.SYSTEM_UID) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2734 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2735 | Process.killProcess(Process.myPid()); |
| 2736 | } |
| 2737 | } catch (RemoteException ex) { |
| 2738 | } |
| 2739 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2740 | } |
| 2741 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2742 | private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) { |
Robert Carr | 001e55a | 2017-05-15 17:21:38 -0700 | [diff] [blame] | 2743 | if (mView == null) { |
| 2744 | return; |
| 2745 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2746 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "measure"); |
| 2747 | try { |
| 2748 | mView.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 2749 | } finally { |
| 2750 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2751 | } |
| 2752 | } |
| 2753 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2754 | /** |
| 2755 | * Called by {@link android.view.View#isInLayout()} to determine whether the view hierarchy |
| 2756 | * is currently undergoing a layout pass. |
| 2757 | * |
| 2758 | * @return whether the view hierarchy is currently undergoing a layout pass |
| 2759 | */ |
| 2760 | boolean isInLayout() { |
| 2761 | return mInLayout; |
| 2762 | } |
| 2763 | |
| 2764 | /** |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2765 | * Called by {@link android.view.View#requestLayout()} if the view hierarchy is currently |
| 2766 | * undergoing a layout pass. requestLayout() should not generally be called during layout, |
| 2767 | * unless the container hierarchy knows what it is doing (i.e., it is fine as long as |
| 2768 | * all children in that container hierarchy are measured and laid out at the end of the layout |
| 2769 | * pass for that container). If requestLayout() is called anyway, we handle it correctly |
| 2770 | * by registering all requesters during a frame as it proceeds. At the end of the frame, |
| 2771 | * we check all of those views to see if any still have pending layout requests, which |
| 2772 | * indicates that they were not correctly handled by their container hierarchy. If that is |
| 2773 | * the case, we clear all such flags in the tree, to remove the buggy flag state that leads |
| 2774 | * 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] | 2775 | * 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] | 2776 | * requests to the next frame to avoid possible infinite loops. |
| 2777 | * |
| 2778 | * <p>The return value from this method indicates whether the request should proceed |
| 2779 | * (if it is a request during the first layout pass) or should be skipped and posted to the |
| 2780 | * 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] | 2781 | * |
| 2782 | * @param view the view that requested the layout. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2783 | * |
| 2784 | * @return true if request should proceed, false otherwise. |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2785 | */ |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2786 | boolean requestLayoutDuringLayout(final View view) { |
| 2787 | if (view.mParent == null || view.mAttachInfo == null) { |
| 2788 | // Would not normally trigger another layout, so just let it pass through as usual |
| 2789 | return true; |
| 2790 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2791 | if (!mLayoutRequesters.contains(view)) { |
| 2792 | mLayoutRequesters.add(view); |
| 2793 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2794 | if (!mHandlingLayoutInLayoutRequest) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2795 | // Let the request proceed normally; it will be processed in a second layout pass |
| 2796 | // if necessary |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2797 | return true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2798 | } else { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2799 | // Don't let the request proceed during the second layout pass. |
| 2800 | // It will post to the next frame instead. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2801 | return false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2802 | } |
| 2803 | } |
| 2804 | |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 2805 | private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth, |
| 2806 | int desiredWindowHeight) { |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2807 | mLayoutRequested = false; |
| 2808 | mScrollMayChange = true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2809 | mInLayout = true; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2810 | |
| 2811 | final View host = mView; |
Robert Carr | 32f37ab | 2017-06-15 12:39:34 -0700 | [diff] [blame] | 2812 | if (host == null) { |
| 2813 | return; |
| 2814 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2815 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2816 | Log.v(mTag, "Laying out " + host + " to (" + |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2817 | host.getMeasuredWidth() + ", " + host.getMeasuredHeight() + ")"); |
| 2818 | } |
| 2819 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2820 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "layout"); |
| 2821 | try { |
| 2822 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2823 | |
Chet Haase | d5a8352 | 2012-11-21 16:24:44 -0800 | [diff] [blame] | 2824 | mInLayout = false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2825 | int numViewsRequestingLayout = mLayoutRequesters.size(); |
| 2826 | if (numViewsRequestingLayout > 0) { |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2827 | // requestLayout() was called during layout. |
| 2828 | // If no layout-request flags are set on the requesting views, there is no problem. |
| 2829 | // If some requests are still pending, then we need to clear those flags and do |
| 2830 | // a full request/measure/layout pass to handle this situation. |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2831 | ArrayList<View> validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, |
| 2832 | false); |
| 2833 | if (validLayoutRequesters != null) { |
| 2834 | // Set this flag to indicate that any further requests are happening during |
| 2835 | // the second pass, which may result in posting those requests to the next |
| 2836 | // frame instead |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2837 | mHandlingLayoutInLayoutRequest = true; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2838 | |
| 2839 | // Process fresh layout requests, then measure and layout |
| 2840 | int numValidRequests = validLayoutRequesters.size(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2841 | for (int i = 0; i < numValidRequests; ++i) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2842 | final View view = validLayoutRequesters.get(i); |
| 2843 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2844 | " during layout: running second layout pass"); |
| 2845 | view.requestLayout(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2846 | } |
| 2847 | measureHierarchy(host, lp, mView.getContext().getResources(), |
| 2848 | desiredWindowWidth, desiredWindowHeight); |
| 2849 | mInLayout = true; |
| 2850 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2851 | |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2852 | mHandlingLayoutInLayoutRequest = false; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2853 | |
| 2854 | // Check the valid requests again, this time without checking/clearing the |
| 2855 | // layout flags, since requests happening during the second pass get noop'd |
| 2856 | validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, true); |
| 2857 | if (validLayoutRequesters != null) { |
| 2858 | final ArrayList<View> finalRequesters = validLayoutRequesters; |
| 2859 | // Post second-pass requests to the next frame |
| 2860 | getRunQueue().post(new Runnable() { |
| 2861 | @Override |
| 2862 | public void run() { |
| 2863 | int numValidRequests = finalRequesters.size(); |
| 2864 | for (int i = 0; i < numValidRequests; ++i) { |
| 2865 | final View view = finalRequesters.get(i); |
| 2866 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2867 | " during second layout pass: posting in next frame"); |
| 2868 | view.requestLayout(); |
| 2869 | } |
| 2870 | } |
| 2871 | }); |
| 2872 | } |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2873 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2874 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2875 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2876 | } finally { |
| 2877 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2878 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2879 | mInLayout = false; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2880 | } |
| 2881 | |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2882 | /** |
| 2883 | * This method is called during layout when there have been calls to requestLayout() during |
| 2884 | * layout. It walks through the list of views that requested layout to determine which ones |
| 2885 | * still need it, based on visibility in the hierarchy and whether they have already been |
| 2886 | * handled (as is usually the case with ListView children). |
| 2887 | * |
| 2888 | * @param layoutRequesters The list of views that requested layout during layout |
| 2889 | * @param secondLayoutRequests Whether the requests were issued during the second layout pass. |
| 2890 | * If so, the FORCE_LAYOUT flag was not set on requesters. |
| 2891 | * @return A list of the actual views that still need to be laid out. |
| 2892 | */ |
| 2893 | private ArrayList<View> getValidLayoutRequesters(ArrayList<View> layoutRequesters, |
| 2894 | boolean secondLayoutRequests) { |
| 2895 | |
| 2896 | int numViewsRequestingLayout = layoutRequesters.size(); |
| 2897 | ArrayList<View> validLayoutRequesters = null; |
| 2898 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2899 | View view = layoutRequesters.get(i); |
| 2900 | if (view != null && view.mAttachInfo != null && view.mParent != null && |
| 2901 | (secondLayoutRequests || (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) == |
| 2902 | View.PFLAG_FORCE_LAYOUT)) { |
| 2903 | boolean gone = false; |
| 2904 | View parent = view; |
| 2905 | // Only trigger new requests for views in a non-GONE hierarchy |
| 2906 | while (parent != null) { |
| 2907 | if ((parent.mViewFlags & View.VISIBILITY_MASK) == View.GONE) { |
| 2908 | gone = true; |
| 2909 | break; |
| 2910 | } |
| 2911 | if (parent.mParent instanceof View) { |
| 2912 | parent = (View) parent.mParent; |
| 2913 | } else { |
| 2914 | parent = null; |
| 2915 | } |
| 2916 | } |
| 2917 | if (!gone) { |
| 2918 | if (validLayoutRequesters == null) { |
| 2919 | validLayoutRequesters = new ArrayList<View>(); |
| 2920 | } |
| 2921 | validLayoutRequesters.add(view); |
| 2922 | } |
| 2923 | } |
| 2924 | } |
| 2925 | if (!secondLayoutRequests) { |
| 2926 | // If we're checking the layout flags, then we need to clean them up also |
| 2927 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2928 | View view = layoutRequesters.get(i); |
| 2929 | while (view != null && |
| 2930 | (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) != 0) { |
| 2931 | view.mPrivateFlags &= ~View.PFLAG_FORCE_LAYOUT; |
| 2932 | if (view.mParent instanceof View) { |
| 2933 | view = (View) view.mParent; |
| 2934 | } else { |
| 2935 | view = null; |
| 2936 | } |
| 2937 | } |
| 2938 | } |
| 2939 | } |
| 2940 | layoutRequesters.clear(); |
| 2941 | return validLayoutRequesters; |
| 2942 | } |
| 2943 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2944 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2945 | public void requestTransparentRegion(View child) { |
| 2946 | // the test below should not fail unless someone is messing with us |
| 2947 | checkThread(); |
| 2948 | if (mView == child) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2949 | mView.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2950 | // Need to make sure we re-evaluate the window attributes next |
| 2951 | // time around, to ensure the window has the correct format. |
| 2952 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 2953 | mWindowAttributesChangesFlag = 0; |
Mathias Agopian | 1bd80ad | 2010-11-04 17:13:39 -0700 | [diff] [blame] | 2954 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | /** |
| 2959 | * Figures out the measure spec for the root view in a window based on it's |
| 2960 | * layout params. |
| 2961 | * |
| 2962 | * @param windowSize |
| 2963 | * The available width or height of the window |
| 2964 | * |
| 2965 | * @param rootDimension |
| 2966 | * The layout params for one dimension (width or height) of the |
| 2967 | * window. |
| 2968 | * |
| 2969 | * @return The measure spec to use to measure the root view. |
| 2970 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 2971 | private static int getRootMeasureSpec(int windowSize, int rootDimension) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2972 | int measureSpec; |
| 2973 | switch (rootDimension) { |
| 2974 | |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 2975 | case ViewGroup.LayoutParams.MATCH_PARENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | // Window can't resize. Force root view to be windowSize. |
| 2977 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY); |
| 2978 | break; |
| 2979 | case ViewGroup.LayoutParams.WRAP_CONTENT: |
| 2980 | // Window can resize. Set max size for root view. |
| 2981 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST); |
| 2982 | break; |
| 2983 | default: |
| 2984 | // Window wants to be an exact size. Force root view to be that size. |
| 2985 | measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY); |
| 2986 | break; |
| 2987 | } |
| 2988 | return measureSpec; |
| 2989 | } |
| 2990 | |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2991 | int mHardwareXOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2992 | int mHardwareYOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2993 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2994 | @Override |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2995 | public void onPreDraw(DisplayListCanvas canvas) { |
John Reck | 3e04f09 | 2017-06-02 15:50:09 -0700 | [diff] [blame] | 2996 | // If mCurScrollY is not 0 then this influences the hardwareYOffset. The end result is we |
| 2997 | // can apply offsets that are not handled by anything else, resulting in underdraw as |
| 2998 | // the View is shifted (thus shifting the window background) exposing unpainted |
| 2999 | // content. To handle this with minimal glitches we just clear to BLACK if the window |
| 3000 | // is opaque. If it's not opaque then HWUI already internally does a glClear to |
| 3001 | // transparent, so there's no risk of underdraw on non-opaque surfaces. |
| 3002 | if (mCurScrollY != 0 && mHardwareYOffset != 0 && mAttachInfo.mThreadedRenderer.isOpaque()) { |
| 3003 | canvas.drawColor(Color.BLACK); |
| 3004 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3005 | canvas.translate(-mHardwareXOffset, -mHardwareYOffset); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3006 | } |
| 3007 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3008 | @Override |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3009 | public void onPostDraw(DisplayListCanvas canvas) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3010 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3011 | if (mUseMTRenderer) { |
| 3012 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 3013 | mWindowCallbacks.get(i).onPostDraw(canvas); |
| 3014 | } |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 3015 | } |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3016 | } |
| 3017 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 3018 | /** |
| 3019 | * @hide |
| 3020 | */ |
| 3021 | void outputDisplayList(View view) { |
Chris Craik | 356b5fe | 2015-07-07 10:39:36 -0700 | [diff] [blame] | 3022 | view.mRenderNode.output(); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3023 | if (mAttachInfo.mThreadedRenderer != null) { |
John Reck | 3e04f09 | 2017-06-02 15:50:09 -0700 | [diff] [blame] | 3024 | mAttachInfo.mThreadedRenderer.serializeDisplayListTree(); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 3025 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | /** |
| 3029 | * @see #PROPERTY_PROFILE_RENDERING |
| 3030 | */ |
| 3031 | private void profileRendering(boolean enabled) { |
| 3032 | if (mProfileRendering) { |
| 3033 | mRenderProfilingEnabled = enabled; |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 3034 | |
| 3035 | if (mRenderProfiler != null) { |
| 3036 | mChoreographer.removeFrameCallback(mRenderProfiler); |
| 3037 | } |
| 3038 | if (mRenderProfilingEnabled) { |
| 3039 | if (mRenderProfiler == null) { |
| 3040 | mRenderProfiler = new Choreographer.FrameCallback() { |
| 3041 | @Override |
| 3042 | public void doFrame(long frameTimeNanos) { |
| 3043 | mDirty.set(0, 0, mWidth, mHeight); |
| 3044 | scheduleTraversals(); |
| 3045 | if (mRenderProfilingEnabled) { |
| 3046 | mChoreographer.postFrameCallback(mRenderProfiler); |
| 3047 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3048 | } |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 3049 | }; |
| 3050 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 3051 | mChoreographer.postFrameCallback(mRenderProfiler); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3052 | } else { |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3053 | mRenderProfiler = null; |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 3054 | } |
| 3055 | } |
| 3056 | } |
| 3057 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 3058 | /** |
| 3059 | * Called from draw() when DEBUG_FPS is enabled |
| 3060 | */ |
| 3061 | private void trackFPS() { |
| 3062 | // Tracks frames per second drawn. First value in a series of draws may be bogus |
| 3063 | // because it down not account for the intervening idle time |
| 3064 | long nowTime = System.currentTimeMillis(); |
| 3065 | if (mFpsStartTime < 0) { |
| 3066 | mFpsStartTime = mFpsPrevTime = nowTime; |
| 3067 | mFpsNumFrames = 0; |
| 3068 | } else { |
| 3069 | ++mFpsNumFrames; |
| 3070 | String thisHash = Integer.toHexString(System.identityHashCode(this)); |
| 3071 | long frameTime = nowTime - mFpsPrevTime; |
| 3072 | long totalTime = nowTime - mFpsStartTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3073 | Log.v(mTag, "0x" + thisHash + "\tFrame time:\t" + frameTime); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 3074 | mFpsPrevTime = nowTime; |
| 3075 | if (totalTime > 1000) { |
| 3076 | float fps = (float) mFpsNumFrames * 1000 / totalTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3077 | Log.v(mTag, "0x" + thisHash + "\tFPS:\t" + fps); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 3078 | mFpsStartTime = nowTime; |
| 3079 | mFpsNumFrames = 0; |
| 3080 | } |
| 3081 | } |
| 3082 | } |
| 3083 | |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3084 | /** |
| 3085 | * A count of the number of calls to pendingDrawFinished we |
| 3086 | * require to notify the WM drawing is complete. |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3087 | */ |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 3088 | int mDrawsNeededToReport = 0; |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3089 | |
| 3090 | /** |
| 3091 | * Delay notifying WM of draw finished until |
| 3092 | * a balanced call to pendingDrawFinished. |
| 3093 | */ |
| 3094 | void drawPending() { |
| 3095 | mDrawsNeededToReport++; |
| 3096 | } |
| 3097 | |
| 3098 | void pendingDrawFinished() { |
| 3099 | if (mDrawsNeededToReport == 0) { |
| 3100 | throw new RuntimeException("Unbalanced drawPending/pendingDrawFinished calls"); |
| 3101 | } |
| 3102 | mDrawsNeededToReport--; |
| 3103 | if (mDrawsNeededToReport == 0) { |
| 3104 | reportDrawFinished(); |
| 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | private void postDrawFinished() { |
| 3109 | mHandler.sendEmptyMessage(MSG_DRAW_FINISHED); |
| 3110 | } |
| 3111 | |
| 3112 | private void reportDrawFinished() { |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 3113 | try { |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 3114 | mDrawsNeededToReport = 0; |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 3115 | mWindowSession.finishDrawing(mWindow); |
| 3116 | } catch (RemoteException e) { |
| 3117 | // Have fun! |
| 3118 | } |
| 3119 | } |
| 3120 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3121 | private void performDraw() { |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 3122 | if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) { |
Craig Mautner | 006f0e4 | 2012-03-21 11:00:32 -0700 | [diff] [blame] | 3123 | return; |
Robert Carr | 32f37ab | 2017-06-15 12:39:34 -0700 | [diff] [blame] | 3124 | } else if (mView == null) { |
| 3125 | return; |
Craig Mautner | 006f0e4 | 2012-03-21 11:00:32 -0700 | [diff] [blame] | 3126 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 3127 | |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3128 | final boolean fullRedrawNeeded = mFullRedrawNeeded || mReportNextDraw; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3129 | mFullRedrawNeeded = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3130 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 3131 | mIsDrawing = true; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3132 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "draw"); |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3133 | |
| 3134 | boolean usingAsyncReport = false; |
| 3135 | if (mReportNextDraw && mAttachInfo.mThreadedRenderer != null |
| 3136 | && mAttachInfo.mThreadedRenderer.isEnabled()) { |
| 3137 | usingAsyncReport = true; |
| 3138 | mAttachInfo.mThreadedRenderer.setFrameCompleteCallback((long frameNr) -> { |
| 3139 | // TODO: Use the frame number |
| 3140 | pendingDrawFinished(); |
| 3141 | }); |
| 3142 | } |
| 3143 | |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3144 | try { |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3145 | boolean canUseAsync = draw(fullRedrawNeeded); |
| 3146 | if (usingAsyncReport && !canUseAsync) { |
| 3147 | mAttachInfo.mThreadedRenderer.setFrameCompleteCallback(null); |
| 3148 | usingAsyncReport = false; |
| 3149 | } |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3150 | } finally { |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 3151 | mIsDrawing = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 3152 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 3153 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3154 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 3155 | // For whatever reason we didn't create a HardwareRenderer, end any |
| 3156 | // hardware animations that are now dangling |
| 3157 | if (mAttachInfo.mPendingAnimatingRenderNodes != null) { |
| 3158 | final int count = mAttachInfo.mPendingAnimatingRenderNodes.size(); |
| 3159 | for (int i = 0; i < count; i++) { |
| 3160 | mAttachInfo.mPendingAnimatingRenderNodes.get(i).endAllAnimators(); |
| 3161 | } |
| 3162 | mAttachInfo.mPendingAnimatingRenderNodes.clear(); |
| 3163 | } |
| 3164 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3165 | if (mReportNextDraw) { |
| 3166 | mReportNextDraw = false; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 3167 | |
| 3168 | // if we're using multi-thread renderer, wait for the window frame draws |
| 3169 | if (mWindowDrawCountDown != null) { |
| 3170 | try { |
| 3171 | mWindowDrawCountDown.await(); |
| 3172 | } catch (InterruptedException e) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 3173 | Log.e(mTag, "Window redraw count down interrupted!"); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 3174 | } |
| 3175 | mWindowDrawCountDown = null; |
| 3176 | } |
| 3177 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3178 | if (mAttachInfo.mThreadedRenderer != null) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3179 | mAttachInfo.mThreadedRenderer.setStopped(mStopped); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 3180 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3181 | |
| 3182 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3183 | Log.v(mTag, "FINISHED DRAWING: " + mWindowAttributes.getTitle()); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3184 | } |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 3185 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3186 | if (mSurfaceHolder != null && mSurface.isValid()) { |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3187 | SurfaceCallbackHelper sch = new SurfaceCallbackHelper(this::postDrawFinished); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3188 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 3189 | |
| 3190 | sch.dispatchSurfaceRedrawNeededAsync(mSurfaceHolder, callbacks); |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3191 | } else if (!usingAsyncReport) { |
| 3192 | if (mAttachInfo.mThreadedRenderer != null) { |
| 3193 | mAttachInfo.mThreadedRenderer.fence(); |
| 3194 | } |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 3195 | pendingDrawFinished(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3196 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3197 | } |
| 3198 | } |
| 3199 | |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3200 | private boolean draw(boolean fullRedrawNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | Surface surface = mSurface; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3202 | if (!surface.isValid()) { |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3203 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3204 | } |
| 3205 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 3206 | if (DEBUG_FPS) { |
| 3207 | trackFPS(); |
| 3208 | } |
| 3209 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3210 | if (!sFirstDrawComplete) { |
| 3211 | synchronized (sFirstDrawHandlers) { |
| 3212 | sFirstDrawComplete = true; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 3213 | final int count = sFirstDrawHandlers.size(); |
| 3214 | for (int i = 0; i< count; i++) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3215 | mHandler.post(sFirstDrawHandlers.get(i)); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 3216 | } |
| 3217 | } |
| 3218 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | scrollToRectOrFocus(null, false); |
| 3221 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3222 | if (mAttachInfo.mViewScrollChanged) { |
| 3223 | mAttachInfo.mViewScrollChanged = false; |
| 3224 | mAttachInfo.mTreeObserver.dispatchOnScrollChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3226 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3227 | boolean animating = mScroller != null && mScroller.computeScrollOffset(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3228 | final int curScrollY; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3229 | if (animating) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3230 | curScrollY = mScroller.getCurrY(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3231 | } else { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3232 | curScrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3234 | if (mCurScrollY != curScrollY) { |
| 3235 | mCurScrollY = curScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | fullRedrawNeeded = true; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 3237 | if (mView instanceof RootViewSurfaceTaker) { |
| 3238 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 3239 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3240 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3241 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3242 | final float appScale = mAttachInfo.mApplicationScale; |
| 3243 | final boolean scalingRequired = mAttachInfo.mScalingRequired; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3244 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3245 | final Rect dirty = mDirty; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 3246 | if (mSurfaceHolder != null) { |
| 3247 | // The app owns the surface, we won't draw. |
| 3248 | dirty.setEmpty(); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 3249 | if (animating && mScroller != null) { |
| 3250 | mScroller.abortAnimation(); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3251 | } |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3252 | return false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 3253 | } |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 3254 | |
| 3255 | if (fullRedrawNeeded) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3256 | mAttachInfo.mIgnoreDirtyState = true; |
Romain Guy | c3166e1 | 2011-08-08 15:00:03 -0700 | [diff] [blame] | 3257 | 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] | 3258 | } |
Chet Haase | ad4f703 | 2011-06-22 09:18:31 -0700 | [diff] [blame] | 3259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3260 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3261 | Log.v(mTag, "Draw " + mView + "/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3262 | + mWindowAttributes.getTitle() |
| 3263 | + ": dirty={" + dirty.left + "," + dirty.top |
| 3264 | + "," + dirty.right + "," + dirty.bottom + "} surface=" |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 3265 | + surface + " surface.isValid()=" + surface.isValid() + ", appScale:" + |
| 3266 | appScale + ", width=" + mWidth + ", height=" + mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | } |
| 3268 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3269 | mAttachInfo.mTreeObserver.dispatchOnDraw(); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3270 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 3271 | int xOffset = -mCanvasOffsetX; |
| 3272 | int yOffset = -mCanvasOffsetY + curScrollY; |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 3273 | final WindowManager.LayoutParams params = mWindowAttributes; |
| 3274 | final Rect surfaceInsets = params != null ? params.surfaceInsets : null; |
| 3275 | if (surfaceInsets != null) { |
| 3276 | xOffset -= surfaceInsets.left; |
| 3277 | yOffset -= surfaceInsets.top; |
| 3278 | |
| 3279 | // Offset dirty rect for surface insets. |
| 3280 | dirty.offset(surfaceInsets.left, surfaceInsets.right); |
| 3281 | } |
| 3282 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3283 | boolean accessibilityFocusDirty = false; |
| 3284 | final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable; |
| 3285 | if (drawable != null) { |
| 3286 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 3287 | final boolean hasFocus = getAccessibilityFocusedRect(bounds); |
| 3288 | if (!hasFocus) { |
| 3289 | bounds.setEmpty(); |
| 3290 | } |
| 3291 | if (!bounds.equals(drawable.getBounds())) { |
| 3292 | accessibilityFocusDirty = true; |
| 3293 | } |
| 3294 | } |
| 3295 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 3296 | mAttachInfo.mDrawingTime = |
| 3297 | mChoreographer.getFrameTimeNanos() / TimeUtils.NANOS_PER_MS; |
| 3298 | |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3299 | boolean useAsyncReport = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3300 | if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3301 | if (mAttachInfo.mThreadedRenderer != null && mAttachInfo.mThreadedRenderer.isEnabled()) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3302 | // If accessibility focus moved, always invalidate the root. |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 3303 | boolean invalidateRoot = accessibilityFocusDirty || mInvalidateRootRequested; |
| 3304 | mInvalidateRootRequested = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3305 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3306 | // Draw with hardware renderer. |
| 3307 | mIsAnimating = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3308 | |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3309 | if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) { |
| 3310 | mHardwareYOffset = yOffset; |
| 3311 | mHardwareXOffset = xOffset; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3312 | invalidateRoot = true; |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 3313 | } |
| 3314 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3315 | if (invalidateRoot) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3316 | mAttachInfo.mThreadedRenderer.invalidateRoot(); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3319 | dirty.setEmpty(); |
| 3320 | |
Skuhne | 980ee47 | 2015-10-06 11:31:31 -0700 | [diff] [blame] | 3321 | // Stage the content drawn size now. It will be transferred to the renderer |
| 3322 | // shortly before the draw commands get send to the renderer. |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 3323 | final boolean updated = updateContentDrawBounds(); |
| 3324 | |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 3325 | if (mReportNextDraw) { |
| 3326 | // report next draw overrides setStopped() |
| 3327 | // This value is re-sync'd to the value of mStopped |
| 3328 | // in the handling of mReportNextDraw post-draw. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3329 | mAttachInfo.mThreadedRenderer.setStopped(false); |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 3330 | } |
| 3331 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 3332 | if (updated) { |
| 3333 | requestDrawWindow(); |
| 3334 | } |
Jorim Jaggi | 0d6222d | 2016-04-18 20:42:10 -0700 | [diff] [blame] | 3335 | |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3336 | useAsyncReport = true; |
Jorim Jaggi | e6a026b | 2018-06-06 18:42:16 +0200 | [diff] [blame] | 3337 | |
| 3338 | // draw(...) might invoke post-draw, which might register the next callback already. |
| 3339 | final FrameDrawingCallback callback = mNextRtFrameCallback; |
Jorim Jaggi | 64be98d | 2018-04-26 23:23:29 +0200 | [diff] [blame] | 3340 | mNextRtFrameCallback = null; |
Jorim Jaggi | e6a026b | 2018-06-06 18:42:16 +0200 | [diff] [blame] | 3341 | mAttachInfo.mThreadedRenderer.draw(mView, mAttachInfo, this, callback); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3342 | } else { |
| 3343 | // If we get here with a disabled & requested hardware renderer, something went |
| 3344 | // wrong (an invalidate posted right before we destroyed the hardware surface |
| 3345 | // for instance) so we should just bail out. Locking the surface with software |
| 3346 | // rendering at this point would lock it forever and prevent hardware renderer |
| 3347 | // from doing its job when it comes back. |
| 3348 | // Before we request a new frame we must however attempt to reinitiliaze the |
| 3349 | // hardware renderer if it's in requested state. This would happen after an |
| 3350 | // eglTerminate() for instance. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3351 | if (mAttachInfo.mThreadedRenderer != null && |
| 3352 | !mAttachInfo.mThreadedRenderer.isEnabled() && |
Robert Carr | 80923d5 | 2018-04-19 13:05:08 -0700 | [diff] [blame] | 3353 | mAttachInfo.mThreadedRenderer.isRequested() && |
| 3354 | mSurface.isValid()) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3355 | |
| 3356 | try { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3357 | mAttachInfo.mThreadedRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 3358 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3359 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3360 | handleOutOfResourcesException(e); |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3361 | return false; |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | mFullRedrawNeeded = true; |
| 3365 | scheduleTraversals(); |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3366 | return false; |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3367 | } |
| 3368 | |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3369 | if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, |
| 3370 | scalingRequired, dirty, surfaceInsets)) { |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3371 | return false; |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3372 | } |
Jeff Brown | 95db2b2 | 2011-11-30 19:54:41 -0800 | [diff] [blame] | 3373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3375 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 3376 | if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | mFullRedrawNeeded = true; |
| 3378 | scheduleTraversals(); |
| 3379 | } |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 3380 | return useAsyncReport; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3381 | } |
| 3382 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3383 | /** |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3384 | * @return true if drawing was successful, false if an error occurred |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3385 | */ |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3386 | private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, int yoff, |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3387 | boolean scalingRequired, Rect dirty, Rect surfaceInsets) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3388 | |
| 3389 | // Draw with software renderer. |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 3390 | final Canvas canvas; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3391 | |
| 3392 | // We already have the offset of surfaceInsets in xoff, yoff and dirty region, |
| 3393 | // therefore we need to add it back when moving the dirty region. |
| 3394 | int dirtyXOffset = xoff; |
| 3395 | int dirtyYOffset = yoff; |
| 3396 | if (surfaceInsets != null) { |
| 3397 | dirtyXOffset += surfaceInsets.left; |
| 3398 | dirtyYOffset += surfaceInsets.top; |
| 3399 | } |
| 3400 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3401 | try { |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3402 | dirty.offset(-dirtyXOffset, -dirtyYOffset); |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 3403 | final int left = dirty.left; |
| 3404 | final int top = dirty.top; |
| 3405 | final int right = dirty.right; |
| 3406 | final int bottom = dirty.bottom; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3407 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3408 | canvas = mSurface.lockCanvas(dirty); |
| 3409 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 3410 | // The dirty rectangle can be modified by Surface.lockCanvas() |
| 3411 | //noinspection ConstantConditions |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 3412 | if (left != dirty.left || top != dirty.top || right != dirty.right |
| 3413 | || bottom != dirty.bottom) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3414 | attachInfo.mIgnoreDirtyState = true; |
| 3415 | } |
| 3416 | |
| 3417 | // TODO: Do this in native |
| 3418 | canvas.setDensity(mDensity); |
| 3419 | } catch (Surface.OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3420 | handleOutOfResourcesException(e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3421 | return false; |
| 3422 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3423 | Log.e(mTag, "Could not lock surface", e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3424 | // Don't assume this is due to out of memory, it could be |
| 3425 | // something else, and if it is something else then we could |
| 3426 | // kill stuff (or ourself) for no reason. |
| 3427 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 3428 | return false; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 3429 | } finally { |
| 3430 | dirty.offset(dirtyXOffset, dirtyYOffset); // Reset to the original value. |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | try { |
| 3434 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3435 | Log.v(mTag, "Surface " + surface + " drawing to bitmap w=" |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3436 | + canvas.getWidth() + ", h=" + canvas.getHeight()); |
| 3437 | //canvas.drawARGB(255, 255, 0, 0); |
| 3438 | } |
| 3439 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3440 | // If this bitmap's format includes an alpha channel, we |
| 3441 | // need to clear it before drawing so that the child will |
| 3442 | // properly re-composite its drawing on a transparent |
| 3443 | // background. This automatically respects the clip/dirty region |
| 3444 | // or |
| 3445 | // If we are applying an offset, we need to clear the area |
| 3446 | // where the offset doesn't appear to avoid having garbage |
| 3447 | // left in the blank areas. |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3448 | if (!canvas.isOpaque() || yoff != 0 || xoff != 0) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3449 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 3450 | } |
| 3451 | |
| 3452 | dirty.setEmpty(); |
| 3453 | mIsAnimating = false; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3454 | mView.mPrivateFlags |= View.PFLAG_DRAWN; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3455 | |
| 3456 | if (DEBUG_DRAW) { |
| 3457 | Context cxt = mView.getContext(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3458 | Log.i(mTag, "Drawing: package:" + cxt.getPackageName() + |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3459 | ", metrics=" + cxt.getResources().getDisplayMetrics() + |
| 3460 | ", compatibilityInfo=" + cxt.getResources().getCompatibilityInfo()); |
| 3461 | } |
| 3462 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3463 | canvas.translate(-xoff, -yoff); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3464 | if (mTranslator != null) { |
| 3465 | mTranslator.translateCanvas(canvas); |
| 3466 | } |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3467 | canvas.setScreenDensity(scalingRequired ? mNoncompatDensity : 0); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3468 | attachInfo.mSetIgnoreDirtyState = false; |
| 3469 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3470 | mView.draw(canvas); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3471 | |
| 3472 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3473 | } finally { |
| 3474 | if (!attachInfo.mSetIgnoreDirtyState) { |
| 3475 | // Only clear the flag if it was not set during the mView.draw() call |
| 3476 | attachInfo.mIgnoreDirtyState = false; |
| 3477 | } |
| 3478 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3479 | } finally { |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 3480 | try { |
| 3481 | surface.unlockCanvasAndPost(canvas); |
| 3482 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3483 | Log.e(mTag, "Could not unlock surface", e); |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 3484 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 3485 | //noinspection ReturnInsideFinallyBlock |
| 3486 | return false; |
| 3487 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3488 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3489 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3490 | Log.v(mTag, "Surface " + surface + " unlockCanvasAndPost"); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3491 | } |
| 3492 | } |
| 3493 | return true; |
| 3494 | } |
| 3495 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3496 | /** |
| 3497 | * We want to draw a highlight around the current accessibility focused. |
| 3498 | * Since adding a style for all possible view is not a viable option we |
| 3499 | * have this specialized drawing method. |
| 3500 | * |
| 3501 | * Note: We are doing this here to be able to draw the highlight for |
| 3502 | * virtual views in addition to real ones. |
| 3503 | * |
| 3504 | * @param canvas The canvas on which to draw. |
| 3505 | */ |
| 3506 | private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) { |
| 3507 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 3508 | if (getAccessibilityFocusedRect(bounds)) { |
| 3509 | final Drawable drawable = getAccessibilityFocusedDrawable(); |
| 3510 | if (drawable != null) { |
| 3511 | drawable.setBounds(bounds); |
| 3512 | drawable.draw(canvas); |
| 3513 | } |
| 3514 | } else if (mAttachInfo.mAccessibilityFocusDrawable != null) { |
| 3515 | mAttachInfo.mAccessibilityFocusDrawable.setBounds(0, 0, 0, 0); |
| 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | private boolean getAccessibilityFocusedRect(Rect bounds) { |
| 3520 | final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext); |
| 3521 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
| 3522 | return false; |
| 3523 | } |
| 3524 | |
| 3525 | final View host = mAccessibilityFocusedHost; |
| 3526 | if (host == null || host.mAttachInfo == null) { |
| 3527 | return false; |
| 3528 | } |
| 3529 | |
| 3530 | final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 3531 | if (provider == null) { |
Svetoslav | ded133c | 2015-01-30 20:28:41 -0800 | [diff] [blame] | 3532 | host.getBoundsOnScreen(bounds, true); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3533 | } else if (mAccessibilityFocusedVirtualView != null) { |
| 3534 | mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds); |
| 3535 | } else { |
| 3536 | return false; |
| 3537 | } |
| 3538 | |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 3539 | // Transform the rect into window-relative coordinates. |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3540 | final AttachInfo attachInfo = mAttachInfo; |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 3541 | bounds.offset(0, attachInfo.mViewRootImpl.mScrollY); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3542 | bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop); |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 3543 | if (!bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, |
| 3544 | attachInfo.mViewRootImpl.mHeight)) { |
| 3545 | // If no intersection, set bounds to empty. |
| 3546 | bounds.setEmpty(); |
| 3547 | } |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3548 | return !bounds.isEmpty(); |
| 3549 | } |
| 3550 | |
| 3551 | private Drawable getAccessibilityFocusedDrawable() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3552 | // Lazily load the accessibility focus drawable. |
| 3553 | if (mAttachInfo.mAccessibilityFocusDrawable == null) { |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 3554 | final TypedValue value = new TypedValue(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3555 | final boolean resolved = mView.mContext.getTheme().resolveAttribute( |
| 3556 | R.attr.accessibilityFocusedDrawable, value, true); |
| 3557 | if (resolved) { |
| 3558 | mAttachInfo.mAccessibilityFocusDrawable = |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 3559 | mView.mContext.getDrawable(value.resourceId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3560 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3561 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3562 | return mAttachInfo.mAccessibilityFocusDrawable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3563 | } |
| 3564 | |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 3565 | /** |
| 3566 | * Requests that the root render node is invalidated next time we perform a draw, such that |
| 3567 | * {@link WindowCallbacks#onPostDraw} gets called. |
| 3568 | */ |
| 3569 | public void requestInvalidateRootRenderNode() { |
| 3570 | mInvalidateRootRequested = true; |
| 3571 | } |
| 3572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3573 | boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3574 | final Rect ci = mAttachInfo.mContentInsets; |
| 3575 | final Rect vi = mAttachInfo.mVisibleInsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3576 | int scrollY = 0; |
| 3577 | boolean handled = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3579 | if (vi.left > ci.left || vi.top > ci.top |
| 3580 | || vi.right > ci.right || vi.bottom > ci.bottom) { |
| 3581 | // We'll assume that we aren't going to change the scroll |
| 3582 | // offset, since we want to avoid that unless it is actually |
| 3583 | // going to make the focus visible... otherwise we scroll |
| 3584 | // all over the place. |
| 3585 | scrollY = mScrollY; |
| 3586 | // We can be called for two different situations: during a draw, |
| 3587 | // to update the scroll position if the focus has changed (in which |
| 3588 | // case 'rectangle' is null), or in response to a |
| 3589 | // requestChildRectangleOnScreen() call (in which case 'rectangle' |
| 3590 | // is non-null and we just want to scroll to whatever that |
| 3591 | // rectangle is). |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 3592 | final View focus = mView.findFocus(); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3593 | if (focus == null) { |
Romain Guy | e8b1652 | 2009-07-14 13:06:42 -0700 | [diff] [blame] | 3594 | return false; |
| 3595 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3596 | View lastScrolledFocus = (mLastScrolledFocus != null) ? mLastScrolledFocus.get() : null; |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 3597 | if (focus != lastScrolledFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | // If the focus has changed, then ignore any requests to scroll |
| 3599 | // to a rectangle; first we want to make sure the entire focus |
| 3600 | // view is visible. |
| 3601 | rectangle = null; |
| 3602 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3603 | 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] | 3604 | + " rectangle=" + rectangle + " ci=" + ci |
| 3605 | + " vi=" + vi); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3606 | if (focus == lastScrolledFocus && !mScrollMayChange && rectangle == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3607 | // Optimization: if the focus hasn't changed since last |
| 3608 | // time, and no layout has happened, then just leave things |
| 3609 | // as they are. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3610 | 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] | 3611 | + mScrollY + " vi=" + vi.toShortString()); |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 3612 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | // We need to determine if the currently focused view is |
| 3614 | // within the visible part of the window and, if not, apply |
| 3615 | // a pan so it can be seen. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3616 | mLastScrolledFocus = new WeakReference<View>(focus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3617 | mScrollMayChange = false; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3618 | 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] | 3619 | // Try to find the rectangle from the focus view. |
| 3620 | if (focus.getGlobalVisibleRect(mVisRect, null)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3621 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Root w=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | + mView.getWidth() + " h=" + mView.getHeight() |
| 3623 | + " ci=" + ci.toShortString() |
| 3624 | + " vi=" + vi.toShortString()); |
| 3625 | if (rectangle == null) { |
| 3626 | focus.getFocusedRect(mTempRect); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3627 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Focus " + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3628 | + ": focusRect=" + mTempRect.toShortString()); |
Dianne Hackborn | 1c6a894 | 2010-03-23 16:34:20 -0700 | [diff] [blame] | 3629 | if (mView instanceof ViewGroup) { |
| 3630 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 3631 | focus, mTempRect); |
| 3632 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3633 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3634 | "Focus in window: focusRect=" |
| 3635 | + mTempRect.toShortString() |
| 3636 | + " visRect=" + mVisRect.toShortString()); |
| 3637 | } else { |
| 3638 | mTempRect.set(rectangle); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3639 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3640 | "Request scroll to rect: " |
| 3641 | + mTempRect.toShortString() |
| 3642 | + " visRect=" + mVisRect.toShortString()); |
| 3643 | } |
| 3644 | if (mTempRect.intersect(mVisRect)) { |
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 | "Focus window visible rect: " |
| 3647 | + mTempRect.toShortString()); |
| 3648 | if (mTempRect.height() > |
| 3649 | (mView.getHeight()-vi.top-vi.bottom)) { |
| 3650 | // If the focus simply is not going to fit, then |
| 3651 | // best is probably just to leave things as-is. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3652 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | "Too tall; leaving scrollY=" + scrollY); |
Chong Zhang | 6725472 | 2016-06-02 12:56:54 -0700 | [diff] [blame] | 3654 | } |
| 3655 | // Next, check whether top or bottom is covered based on the non-scrolled |
| 3656 | // position, and calculate new scrollY (or set it to 0). |
| 3657 | // We can't keep using mScrollY here. For example mScrollY is non-zero |
| 3658 | // due to IME, then IME goes away. The current value of mScrollY leaves top |
| 3659 | // and bottom both visible, but we still need to scroll it back to 0. |
| 3660 | else if (mTempRect.top < vi.top) { |
| 3661 | scrollY = mTempRect.top - vi.top; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3662 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | "Top covered; scrollY=" + scrollY); |
Chong Zhang | 6725472 | 2016-06-02 12:56:54 -0700 | [diff] [blame] | 3664 | } else if (mTempRect.bottom > (mView.getHeight()-vi.bottom)) { |
| 3665 | scrollY = mTempRect.bottom - (mView.getHeight()-vi.bottom); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3666 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | "Bottom covered; scrollY=" + scrollY); |
Chong Zhang | 6725472 | 2016-06-02 12:56:54 -0700 | [diff] [blame] | 3668 | } else { |
| 3669 | scrollY = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | } |
| 3671 | handled = true; |
| 3672 | } |
| 3673 | } |
| 3674 | } |
| 3675 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | if (scrollY != mScrollY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3678 | 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] | 3679 | + mScrollY + " , new=" + scrollY); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 3680 | if (!immediate) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3681 | if (mScroller == null) { |
| 3682 | mScroller = new Scroller(mView.getContext()); |
| 3683 | } |
| 3684 | mScroller.startScroll(0, mScrollY, 0, scrollY-mScrollY); |
| 3685 | } else if (mScroller != null) { |
| 3686 | mScroller.abortAnimation(); |
| 3687 | } |
| 3688 | mScrollY = scrollY; |
| 3689 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | return handled; |
| 3692 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3693 | |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3694 | /** |
| 3695 | * @hide |
| 3696 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 3697 | @UnsupportedAppUsage |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3698 | public View getAccessibilityFocusedHost() { |
| 3699 | return mAccessibilityFocusedHost; |
| 3700 | } |
| 3701 | |
| 3702 | /** |
| 3703 | * @hide |
| 3704 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 3705 | @UnsupportedAppUsage |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3706 | public AccessibilityNodeInfo getAccessibilityFocusedVirtualView() { |
| 3707 | return mAccessibilityFocusedVirtualView; |
| 3708 | } |
| 3709 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3710 | void setAccessibilityFocus(View view, AccessibilityNodeInfo node) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3711 | // If we have a virtual view with accessibility focus we need |
| 3712 | // to clear the focus and invalidate the virtual view bounds. |
| 3713 | if (mAccessibilityFocusedVirtualView != null) { |
| 3714 | |
| 3715 | AccessibilityNodeInfo focusNode = mAccessibilityFocusedVirtualView; |
| 3716 | View focusHost = mAccessibilityFocusedHost; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3717 | |
| 3718 | // Wipe the state of the current accessibility focus since |
| 3719 | // the call into the provider to clear accessibility focus |
| 3720 | // will fire an accessibility event which will end up calling |
| 3721 | // this method and we want to have clean state when this |
| 3722 | // invocation happens. |
| 3723 | mAccessibilityFocusedHost = null; |
| 3724 | mAccessibilityFocusedVirtualView = null; |
| 3725 | |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3726 | // Clear accessibility focus on the host after clearing state since |
| 3727 | // this method may be reentrant. |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 3728 | focusHost.clearAccessibilityFocusNoCallbacks( |
| 3729 | AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3730 | |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3731 | AccessibilityNodeProvider provider = focusHost.getAccessibilityNodeProvider(); |
| 3732 | if (provider != null) { |
| 3733 | // Invalidate the area of the cleared accessibility focus. |
| 3734 | focusNode.getBoundsInParent(mTempRect); |
| 3735 | focusHost.invalidate(mTempRect); |
| 3736 | // Clear accessibility focus in the virtual node. |
| 3737 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 3738 | focusNode.getSourceNodeId()); |
| 3739 | provider.performAction(virtualNodeId, |
| 3740 | AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); |
| 3741 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3742 | focusNode.recycle(); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3743 | } |
Phil Weaver | da46927 | 2016-06-24 18:17:21 -0700 | [diff] [blame] | 3744 | if ((mAccessibilityFocusedHost != null) && (mAccessibilityFocusedHost != view)) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3745 | // Clear accessibility focus in the view. |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 3746 | mAccessibilityFocusedHost.clearAccessibilityFocusNoCallbacks( |
| 3747 | AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3748 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3749 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3750 | // Set the new focus host and node. |
| 3751 | mAccessibilityFocusedHost = view; |
| 3752 | mAccessibilityFocusedVirtualView = node; |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3753 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3754 | if (mAttachInfo.mThreadedRenderer != null) { |
| 3755 | mAttachInfo.mThreadedRenderer.invalidateRoot(); |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3756 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3757 | } |
| 3758 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 3759 | boolean hasPointerCapture() { |
| 3760 | return mPointerCapture; |
| 3761 | } |
| 3762 | |
| 3763 | void requestPointerCapture(boolean enabled) { |
| 3764 | if (mPointerCapture == enabled) { |
| 3765 | return; |
| 3766 | } |
| 3767 | InputManager.getInstance().requestPointerCapture(mAttachInfo.mWindowToken, enabled); |
| 3768 | } |
| 3769 | |
| 3770 | private void handlePointerCaptureChanged(boolean hasCapture) { |
| 3771 | if (mPointerCapture == hasCapture) { |
| 3772 | return; |
| 3773 | } |
| 3774 | mPointerCapture = hasCapture; |
| 3775 | if (mView != null) { |
| 3776 | mView.dispatchPointerCaptureChanged(hasCapture); |
| 3777 | } |
| 3778 | } |
| 3779 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3780 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3781 | public void requestChildFocus(View child, View focused) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3782 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3783 | Log.v(mTag, "Request child focus: focus now " + focused); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3785 | checkThread(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3786 | scheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3787 | } |
| 3788 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3789 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | public void clearChildFocus(View child) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3791 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3792 | Log.v(mTag, "Clearing child focus"); |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3793 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3794 | checkThread(); |
| 3795 | scheduleTraversals(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3796 | } |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3797 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3798 | @Override |
| 3799 | public ViewParent getParentForAccessibility() { |
| 3800 | return null; |
| 3801 | } |
| 3802 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3803 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3804 | public void focusableViewAvailable(View v) { |
| 3805 | checkThread(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3806 | if (mView != null) { |
| 3807 | if (!mView.hasFocus()) { |
Evan Rosky | 2888404 | 2018-04-03 13:21:55 -0700 | [diff] [blame] | 3808 | if (sAlwaysAssignFocus || !mAttachInfo.mInTouchMode) { |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 3809 | v.requestFocus(); |
| 3810 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3811 | } else { |
| 3812 | // the one case where will transfer focus away from the current one |
| 3813 | // is if the current view is a view group that prefers to give focus |
| 3814 | // to its children first AND the view is a descendant of it. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3815 | View focused = mView.findFocus(); |
| 3816 | if (focused instanceof ViewGroup) { |
| 3817 | ViewGroup group = (ViewGroup) focused; |
| 3818 | if (group.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3819 | && isViewDescendantOf(v, focused)) { |
| 3820 | v.requestFocus(); |
| 3821 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3822 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3823 | } |
| 3824 | } |
| 3825 | } |
| 3826 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3827 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3828 | public void recomputeViewAttributes(View child) { |
| 3829 | checkThread(); |
| 3830 | if (mView == child) { |
| 3831 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 3832 | if (!mWillDrawSoon) { |
| 3833 | scheduleTraversals(); |
| 3834 | } |
| 3835 | } |
| 3836 | } |
| 3837 | |
| 3838 | void dispatchDetachedFromWindow() { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 3839 | mFirstInputStage.onDetachedFromWindow(); |
Romain Guy | 90fc03b | 2011-01-16 13:07:15 -0800 | [diff] [blame] | 3840 | if (mView != null && mView.mAttachInfo != null) { |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3841 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3842 | mView.dispatchDetachedFromWindow(); |
| 3843 | } |
| 3844 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3845 | mAccessibilityInteractionConnectionManager.ensureNoConnection(); |
| 3846 | mAccessibilityManager.removeAccessibilityStateChangeListener( |
| 3847 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 3848 | mAccessibilityManager.removeHighTextContrastStateChangeListener( |
| 3849 | mHighContrastTextManager); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3850 | removeSendWindowContentChangedCallback(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3851 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3852 | destroyHardwareRenderer(); |
| 3853 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3854 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3855 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 3856 | mView.assignParent(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3857 | mView = null; |
| 3858 | mAttachInfo.mRootView = null; |
| 3859 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 3860 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3861 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3862 | if (mInputQueueCallback != null && mInputQueue != null) { |
| 3863 | mInputQueueCallback.onInputQueueDestroyed(mInputQueue); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3864 | mInputQueue.dispose(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3865 | mInputQueueCallback = null; |
| 3866 | mInputQueue = null; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3867 | } |
| 3868 | if (mInputEventReceiver != null) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3869 | mInputEventReceiver.dispose(); |
| 3870 | mInputEventReceiver = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3871 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3873 | mWindowSession.remove(mWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | } catch (RemoteException e) { |
| 3875 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3876 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3877 | // Dispose the input channel after removing the window so the Window Manager |
| 3878 | // doesn't interpret the input channel being closed as an abnormal termination. |
| 3879 | if (mInputChannel != null) { |
| 3880 | mInputChannel.dispose(); |
| 3881 | mInputChannel = null; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3882 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3883 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 3884 | mDisplayManager.unregisterDisplayListener(mDisplayListener); |
| 3885 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 3886 | unscheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3887 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3888 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3889 | /** |
| 3890 | * Notifies all callbacks that configuration and/or display has changed and updates internal |
| 3891 | * state. |
| 3892 | * @param mergedConfiguration New global and override config in {@link MergedConfiguration} |
| 3893 | * container. |
| 3894 | * @param force Flag indicating if we should force apply the config. |
| 3895 | * @param newDisplayId Id of new display if moved, {@link Display#INVALID_DISPLAY} if not |
| 3896 | * changed. |
| 3897 | */ |
| 3898 | private void performConfigurationChange(MergedConfiguration mergedConfiguration, boolean force, |
| 3899 | int newDisplayId) { |
| 3900 | if (mergedConfiguration == null) { |
| 3901 | throw new IllegalArgumentException("No merged config provided."); |
| 3902 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3903 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3904 | Configuration globalConfig = mergedConfiguration.getGlobalConfiguration(); |
| 3905 | final Configuration overrideConfig = mergedConfiguration.getOverrideConfiguration(); |
| 3906 | if (DEBUG_CONFIGURATION) Log.v(mTag, |
| 3907 | "Applying new config to window " + mWindowAttributes.getTitle() |
| 3908 | + ", globalConfig: " + globalConfig |
| 3909 | + ", overrideConfig: " + overrideConfig); |
| 3910 | |
| 3911 | final CompatibilityInfo ci = mDisplay.getDisplayAdjustments().getCompatibilityInfo(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3912 | if (!ci.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3913 | globalConfig = new Configuration(globalConfig); |
| 3914 | ci.applyToConfiguration(mNoncompatDensity, globalConfig); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3915 | } |
| 3916 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3917 | synchronized (sConfigCallbacks) { |
| 3918 | for (int i=sConfigCallbacks.size()-1; i>=0; i--) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3919 | sConfigCallbacks.get(i).onConfigurationChanged(globalConfig); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3920 | } |
| 3921 | } |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 3922 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3923 | mLastReportedMergedConfiguration.setConfiguration(globalConfig, overrideConfig); |
| 3924 | |
| 3925 | mForceNextConfigUpdate = force; |
| 3926 | if (mActivityConfigCallback != null) { |
| 3927 | // An activity callback is set - notify it about override configuration update. |
| 3928 | // This basically initiates a round trip to ActivityThread and back, which will ensure |
| 3929 | // that corresponding activity and resources are updated before updating inner state of |
| 3930 | // ViewRootImpl. Eventually it will call #updateConfiguration(). |
| 3931 | mActivityConfigCallback.onConfigurationChanged(overrideConfig, newDisplayId); |
| 3932 | } else { |
| 3933 | // There is no activity callback - update the configuration right away. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3934 | updateConfiguration(newDisplayId); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3935 | } |
| 3936 | mForceNextConfigUpdate = false; |
| 3937 | } |
| 3938 | |
| 3939 | /** |
| 3940 | * Update display and views if last applied merged configuration changed. |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3941 | * @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] | 3942 | */ |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3943 | public void updateConfiguration(int newDisplayId) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3944 | if (mView == null) { |
| 3945 | return; |
| 3946 | } |
| 3947 | |
| 3948 | // At this point the resources have been updated to |
| 3949 | // have the most recent config, whatever that is. Use |
| 3950 | // the one in them which may be newer. |
| 3951 | final Resources localResources = mView.getResources(); |
| 3952 | final Configuration config = localResources.getConfiguration(); |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3953 | |
| 3954 | // Handle move to display. |
| 3955 | if (newDisplayId != INVALID_DISPLAY) { |
| 3956 | onMovedToDisplay(newDisplayId, config); |
| 3957 | } |
| 3958 | |
| 3959 | // Handle configuration change. |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3960 | if (mForceNextConfigUpdate || mLastConfigurationFromResources.diff(config) != 0) { |
| 3961 | // Update the display with new DisplayAdjustments. |
| 3962 | mDisplay = ResourcesManager.getInstance().getAdjustedDisplay( |
| 3963 | mDisplay.getDisplayId(), localResources); |
| 3964 | |
| 3965 | final int lastLayoutDirection = mLastConfigurationFromResources.getLayoutDirection(); |
| 3966 | final int currentLayoutDirection = config.getLayoutDirection(); |
| 3967 | mLastConfigurationFromResources.setTo(config); |
| 3968 | if (lastLayoutDirection != currentLayoutDirection |
| 3969 | && mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
| 3970 | mView.setLayoutDirection(currentLayoutDirection); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3971 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3972 | mView.dispatchConfigurationChanged(config); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 3973 | |
| 3974 | // We could have gotten this {@link Configuration} update after we called |
| 3975 | // {@link #performTraversals} with an older {@link Configuration}. As a result, our |
| 3976 | // window frame may be stale. We must ensure the next pass of {@link #performTraversals} |
| 3977 | // catches this. |
| 3978 | mForceNextWindowRelayout = true; |
| 3979 | requestLayout(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3980 | } |
| 3981 | } |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 3982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3983 | /** |
| 3984 | * Return true if child is an ancestor of parent, (or equal to the parent). |
| 3985 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3986 | public static boolean isViewDescendantOf(View child, View parent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | if (child == parent) { |
| 3988 | return true; |
| 3989 | } |
| 3990 | |
| 3991 | final ViewParent theParent = child.getParent(); |
| 3992 | return (theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent); |
| 3993 | } |
| 3994 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3995 | private static void forceLayout(View view) { |
| 3996 | view.forceLayout(); |
| 3997 | if (view instanceof ViewGroup) { |
| 3998 | ViewGroup group = (ViewGroup) view; |
| 3999 | final int count = group.getChildCount(); |
| 4000 | for (int i = 0; i < count; i++) { |
| 4001 | forceLayout(group.getChildAt(i)); |
| 4002 | } |
| 4003 | } |
| 4004 | } |
| 4005 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4006 | private final static int MSG_INVALIDATE = 1; |
| 4007 | private final static int MSG_INVALIDATE_RECT = 2; |
| 4008 | private final static int MSG_DIE = 3; |
| 4009 | private final static int MSG_RESIZED = 4; |
| 4010 | private final static int MSG_RESIZED_REPORT = 5; |
| 4011 | private final static int MSG_WINDOW_FOCUS_CHANGED = 6; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4012 | private final static int MSG_DISPATCH_INPUT_EVENT = 7; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4013 | private final static int MSG_DISPATCH_APP_VISIBILITY = 8; |
| 4014 | private final static int MSG_DISPATCH_GET_NEW_SURFACE = 9; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4015 | private final static int MSG_DISPATCH_KEY_FROM_IME = 11; |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4016 | private final static int MSG_DISPATCH_KEY_FROM_AUTOFILL = 12; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4017 | private final static int MSG_CHECK_FOCUS = 13; |
| 4018 | private final static int MSG_CLOSE_SYSTEM_DIALOGS = 14; |
| 4019 | private final static int MSG_DISPATCH_DRAG_EVENT = 15; |
| 4020 | private final static int MSG_DISPATCH_DRAG_LOCATION_EVENT = 16; |
| 4021 | private final static int MSG_DISPATCH_SYSTEM_UI_VISIBILITY = 17; |
| 4022 | private final static int MSG_UPDATE_CONFIGURATION = 18; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4023 | private final static int MSG_PROCESS_INPUT_EVENTS = 19; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 4024 | private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 21; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 4025 | private final static int MSG_INVALIDATE_WORLD = 22; |
| 4026 | private final static int MSG_WINDOW_MOVED = 23; |
| 4027 | private final static int MSG_SYNTHESIZE_INPUT_EVENT = 24; |
| 4028 | private final static int MSG_DISPATCH_WINDOW_SHOWN = 25; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 4029 | private final static int MSG_REQUEST_KEYBOARD_SHORTCUTS = 26; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4030 | private final static int MSG_UPDATE_POINTER_ICON = 27; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 4031 | private final static int MSG_POINTER_CAPTURE_CHANGED = 28; |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 4032 | private final static int MSG_DRAW_FINISHED = 29; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4033 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4034 | final class ViewRootHandler extends Handler { |
| 4035 | @Override |
| 4036 | public String getMessageName(Message message) { |
| 4037 | switch (message.what) { |
| 4038 | case MSG_INVALIDATE: |
| 4039 | return "MSG_INVALIDATE"; |
| 4040 | case MSG_INVALIDATE_RECT: |
| 4041 | return "MSG_INVALIDATE_RECT"; |
| 4042 | case MSG_DIE: |
| 4043 | return "MSG_DIE"; |
| 4044 | case MSG_RESIZED: |
| 4045 | return "MSG_RESIZED"; |
| 4046 | case MSG_RESIZED_REPORT: |
| 4047 | return "MSG_RESIZED_REPORT"; |
| 4048 | case MSG_WINDOW_FOCUS_CHANGED: |
| 4049 | return "MSG_WINDOW_FOCUS_CHANGED"; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4050 | case MSG_DISPATCH_INPUT_EVENT: |
| 4051 | return "MSG_DISPATCH_INPUT_EVENT"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4052 | case MSG_DISPATCH_APP_VISIBILITY: |
| 4053 | return "MSG_DISPATCH_APP_VISIBILITY"; |
| 4054 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 4055 | return "MSG_DISPATCH_GET_NEW_SURFACE"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4056 | case MSG_DISPATCH_KEY_FROM_IME: |
| 4057 | return "MSG_DISPATCH_KEY_FROM_IME"; |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4058 | case MSG_DISPATCH_KEY_FROM_AUTOFILL: |
| 4059 | return "MSG_DISPATCH_KEY_FROM_AUTOFILL"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4060 | case MSG_CHECK_FOCUS: |
| 4061 | return "MSG_CHECK_FOCUS"; |
| 4062 | case MSG_CLOSE_SYSTEM_DIALOGS: |
| 4063 | return "MSG_CLOSE_SYSTEM_DIALOGS"; |
| 4064 | case MSG_DISPATCH_DRAG_EVENT: |
| 4065 | return "MSG_DISPATCH_DRAG_EVENT"; |
| 4066 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: |
| 4067 | return "MSG_DISPATCH_DRAG_LOCATION_EVENT"; |
| 4068 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: |
| 4069 | return "MSG_DISPATCH_SYSTEM_UI_VISIBILITY"; |
| 4070 | case MSG_UPDATE_CONFIGURATION: |
| 4071 | return "MSG_UPDATE_CONFIGURATION"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4072 | case MSG_PROCESS_INPUT_EVENTS: |
| 4073 | return "MSG_PROCESS_INPUT_EVENTS"; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 4074 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: |
| 4075 | return "MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST"; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 4076 | case MSG_WINDOW_MOVED: |
| 4077 | return "MSG_WINDOW_MOVED"; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4078 | case MSG_SYNTHESIZE_INPUT_EVENT: |
| 4079 | return "MSG_SYNTHESIZE_INPUT_EVENT"; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 4080 | case MSG_DISPATCH_WINDOW_SHOWN: |
| 4081 | return "MSG_DISPATCH_WINDOW_SHOWN"; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4082 | case MSG_UPDATE_POINTER_ICON: |
| 4083 | return "MSG_UPDATE_POINTER_ICON"; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 4084 | case MSG_POINTER_CAPTURE_CHANGED: |
| 4085 | return "MSG_POINTER_CAPTURE_CHANGED"; |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame] | 4086 | case MSG_DRAW_FINISHED: |
| 4087 | return "MSG_DRAW_FINISHED"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4088 | } |
| 4089 | return super.getMessageName(message); |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 4090 | } |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 4091 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4092 | @Override |
Michael Wright | 53b854a | 2016-04-12 19:22:41 -0400 | [diff] [blame] | 4093 | public boolean sendMessageAtTime(Message msg, long uptimeMillis) { |
| 4094 | if (msg.what == MSG_REQUEST_KEYBOARD_SHORTCUTS && msg.obj == null) { |
| 4095 | // Debugging for b/27963013 |
| 4096 | throw new NullPointerException( |
| 4097 | "Attempted to call MSG_REQUEST_KEYBOARD_SHORTCUTS with null receiver:"); |
| 4098 | } |
| 4099 | return super.sendMessageAtTime(msg, uptimeMillis); |
| 4100 | } |
| 4101 | |
| 4102 | @Override |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4103 | public void handleMessage(Message msg) { |
| 4104 | switch (msg.what) { |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4105 | case MSG_INVALIDATE: |
| 4106 | ((View) msg.obj).invalidate(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4107 | break; |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4108 | case MSG_INVALIDATE_RECT: |
| 4109 | final View.AttachInfo.InvalidateInfo info = |
| 4110 | (View.AttachInfo.InvalidateInfo) msg.obj; |
| 4111 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
| 4112 | info.recycle(); |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 4113 | break; |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4114 | case MSG_PROCESS_INPUT_EVENTS: |
| 4115 | mProcessInputEventsScheduled = false; |
| 4116 | doProcessInputEvents(); |
| 4117 | break; |
| 4118 | case MSG_DISPATCH_APP_VISIBILITY: |
| 4119 | handleAppVisibility(msg.arg1 != 0); |
| 4120 | break; |
| 4121 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 4122 | handleGetNewSurface(); |
| 4123 | break; |
| 4124 | case MSG_RESIZED: { |
| 4125 | // Recycled in the fall through... |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4126 | SomeArgs args = (SomeArgs) msg.obj; |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4127 | if (mWinFrame.equals(args.arg1) |
| 4128 | && mPendingOverscanInsets.equals(args.arg5) |
| 4129 | && mPendingContentInsets.equals(args.arg2) |
| 4130 | && mPendingStableInsets.equals(args.arg6) |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 4131 | && mPendingDisplayCutout.get().equals(args.arg9) |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4132 | && mPendingVisibleInsets.equals(args.arg3) |
| 4133 | && mPendingOutsets.equals(args.arg7) |
| 4134 | && mPendingBackDropFrame.equals(args.arg8) |
| 4135 | && args.arg4 == null |
| 4136 | && args.argi1 == 0 |
| 4137 | && mDisplay.getDisplayId() == args.argi3) { |
| 4138 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4139 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4140 | } // fall through... |
| 4141 | case MSG_RESIZED_REPORT: |
| 4142 | if (mAdded) { |
| 4143 | SomeArgs args = (SomeArgs) msg.obj; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4144 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4145 | final int displayId = args.argi3; |
| 4146 | MergedConfiguration mergedConfiguration = (MergedConfiguration) args.arg4; |
| 4147 | final boolean displayChanged = mDisplay.getDisplayId() != displayId; |
Jorim Jaggi | 26952d7 | 2016-04-01 17:43:14 -0700 | [diff] [blame] | 4148 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4149 | if (!mLastReportedMergedConfiguration.equals(mergedConfiguration)) { |
| 4150 | // If configuration changed - notify about that and, maybe, |
| 4151 | // about move to display. |
| 4152 | performConfigurationChange(mergedConfiguration, false /* force */, |
| 4153 | displayChanged |
| 4154 | ? displayId : INVALID_DISPLAY /* same display */); |
| 4155 | } else if (displayChanged) { |
| 4156 | // Moved to display without config change - report last applied one. |
| 4157 | onMovedToDisplay(displayId, mLastConfigurationFromResources); |
| 4158 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4159 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4160 | final boolean framesChanged = !mWinFrame.equals(args.arg1) |
| 4161 | || !mPendingOverscanInsets.equals(args.arg5) |
| 4162 | || !mPendingContentInsets.equals(args.arg2) |
| 4163 | || !mPendingStableInsets.equals(args.arg6) |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 4164 | || !mPendingDisplayCutout.get().equals(args.arg9) |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4165 | || !mPendingVisibleInsets.equals(args.arg3) |
| 4166 | || !mPendingOutsets.equals(args.arg7); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4167 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4168 | mWinFrame.set((Rect) args.arg1); |
| 4169 | mPendingOverscanInsets.set((Rect) args.arg5); |
| 4170 | mPendingContentInsets.set((Rect) args.arg2); |
| 4171 | mPendingStableInsets.set((Rect) args.arg6); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 4172 | mPendingDisplayCutout.set((DisplayCutout) args.arg9); |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4173 | mPendingVisibleInsets.set((Rect) args.arg3); |
| 4174 | mPendingOutsets.set((Rect) args.arg7); |
| 4175 | mPendingBackDropFrame.set((Rect) args.arg8); |
| 4176 | mForceNextWindowRelayout = args.argi1 != 0; |
| 4177 | mPendingAlwaysConsumeNavBar = args.argi2 != 0; |
| 4178 | |
| 4179 | args.recycle(); |
| 4180 | |
| 4181 | if (msg.what == MSG_RESIZED_REPORT) { |
| 4182 | reportNextDraw(); |
| 4183 | } |
| 4184 | |
| 4185 | if (mView != null && framesChanged) { |
| 4186 | forceLayout(mView); |
| 4187 | } |
| 4188 | requestLayout(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4189 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4190 | break; |
| 4191 | case MSG_WINDOW_MOVED: |
| 4192 | if (mAdded) { |
| 4193 | final int w = mWinFrame.width(); |
| 4194 | final int h = mWinFrame.height(); |
| 4195 | final int l = msg.arg1; |
| 4196 | final int t = msg.arg2; |
| 4197 | mWinFrame.left = l; |
| 4198 | mWinFrame.right = l + w; |
| 4199 | mWinFrame.top = t; |
| 4200 | mWinFrame.bottom = t + h; |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 4201 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4202 | mPendingBackDropFrame.set(mWinFrame); |
| 4203 | maybeHandleWindowMove(mWinFrame); |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 4204 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4205 | break; |
| 4206 | case MSG_WINDOW_FOCUS_CHANGED: { |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 4207 | handleWindowFocusChanged(); |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4208 | } break; |
| 4209 | case MSG_DIE: |
| 4210 | doDie(); |
| 4211 | break; |
| 4212 | case MSG_DISPATCH_INPUT_EVENT: { |
| 4213 | SomeArgs args = (SomeArgs) msg.obj; |
| 4214 | InputEvent event = (InputEvent) args.arg1; |
| 4215 | InputEventReceiver receiver = (InputEventReceiver) args.arg2; |
| 4216 | enqueueInputEvent(event, receiver, 0, true); |
| 4217 | args.recycle(); |
| 4218 | } break; |
| 4219 | case MSG_SYNTHESIZE_INPUT_EVENT: { |
| 4220 | InputEvent event = (InputEvent) msg.obj; |
| 4221 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_UNHANDLED, true); |
| 4222 | } break; |
| 4223 | case MSG_DISPATCH_KEY_FROM_IME: { |
| 4224 | if (LOCAL_LOGV) { |
| 4225 | Log.v(TAG, "Dispatching key " + msg.obj + " from IME to " + mView); |
| 4226 | } |
| 4227 | KeyEvent event = (KeyEvent) msg.obj; |
| 4228 | if ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) != 0) { |
| 4229 | // The IME is trying to say this event is from the |
| 4230 | // system! Bad bad bad! |
| 4231 | //noinspection UnusedAssignment |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 4232 | event = KeyEvent.changeFlags(event, |
| 4233 | event.getFlags() & ~KeyEvent.FLAG_FROM_SYSTEM); |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4234 | } |
| 4235 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_DELIVER_POST_IME, true); |
| 4236 | } break; |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4237 | case MSG_DISPATCH_KEY_FROM_AUTOFILL: { |
| 4238 | if (LOCAL_LOGV) { |
| 4239 | Log.v(TAG, "Dispatching key " + msg.obj + " from Autofill to " + mView); |
| 4240 | } |
| 4241 | KeyEvent event = (KeyEvent) msg.obj; |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 4242 | enqueueInputEvent(event, null, 0, true); |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4243 | } break; |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4244 | case MSG_CHECK_FOCUS: { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4245 | InputMethodManager imm = InputMethodManager.peekInstance(); |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4246 | if (imm != null) { |
| 4247 | imm.checkFocus(); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 4248 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4249 | } break; |
| 4250 | case MSG_CLOSE_SYSTEM_DIALOGS: { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4251 | if (mView != null) { |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4252 | mView.onCloseSystemDialogs((String) msg.obj); |
| 4253 | } |
| 4254 | } break; |
| 4255 | case MSG_DISPATCH_DRAG_EVENT: { |
| 4256 | } // fall through |
| 4257 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: { |
| 4258 | DragEvent event = (DragEvent) msg.obj; |
| 4259 | // only present when this app called startDrag() |
| 4260 | event.mLocalState = mLocalDragState; |
| 4261 | handleDragEvent(event); |
| 4262 | } break; |
| 4263 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: { |
| 4264 | handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo) msg.obj); |
| 4265 | } break; |
| 4266 | case MSG_UPDATE_CONFIGURATION: { |
| 4267 | Configuration config = (Configuration) msg.obj; |
| 4268 | if (config.isOtherSeqNewer( |
| 4269 | mLastReportedMergedConfiguration.getMergedConfiguration())) { |
| 4270 | // If we already have a newer merged config applied - use its global part. |
| 4271 | config = mLastReportedMergedConfiguration.getGlobalConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4272 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4273 | |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4274 | // Use the newer global config and last reported override config. |
| 4275 | mPendingMergedConfiguration.setConfiguration(config, |
| 4276 | mLastReportedMergedConfiguration.getOverrideConfiguration()); |
| 4277 | |
| 4278 | performConfigurationChange(mPendingMergedConfiguration, false /* force */, |
| 4279 | INVALID_DISPLAY /* same display */); |
| 4280 | } break; |
| 4281 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: { |
| 4282 | setAccessibilityFocus(null, null); |
| 4283 | } break; |
| 4284 | case MSG_INVALIDATE_WORLD: { |
| 4285 | if (mView != null) { |
| 4286 | invalidateWorld(mView); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4287 | } |
Siarhei Vishniakou | 27358ef | 2017-10-12 11:00:35 -0700 | [diff] [blame] | 4288 | } break; |
| 4289 | case MSG_DISPATCH_WINDOW_SHOWN: { |
| 4290 | handleDispatchWindowShown(); |
| 4291 | } break; |
| 4292 | case MSG_REQUEST_KEYBOARD_SHORTCUTS: { |
| 4293 | final IResultReceiver receiver = (IResultReceiver) msg.obj; |
| 4294 | final int deviceId = msg.arg1; |
| 4295 | handleRequestKeyboardShortcuts(receiver, deviceId); |
| 4296 | } break; |
| 4297 | case MSG_UPDATE_POINTER_ICON: { |
| 4298 | MotionEvent event = (MotionEvent) msg.obj; |
| 4299 | resetPointerIcon(event); |
| 4300 | } break; |
| 4301 | case MSG_POINTER_CAPTURE_CHANGED: { |
| 4302 | final boolean hasCapture = msg.arg1 != 0; |
| 4303 | handlePointerCaptureChanged(hasCapture); |
| 4304 | } break; |
| 4305 | case MSG_DRAW_FINISHED: { |
| 4306 | pendingDrawFinished(); |
| 4307 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | } |
| 4310 | } |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 4311 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 4312 | final ViewRootHandler mHandler = new ViewRootHandler(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4314 | /** |
| 4315 | * Something in the current window tells us we need to change the touch mode. For |
| 4316 | * example, we are not in touch mode, and the user touches the screen. |
| 4317 | * |
| 4318 | * If the touch mode has changed, tell the window manager, and handle it locally. |
| 4319 | * |
| 4320 | * @param inTouchMode Whether we want to be in touch mode. |
| 4321 | * @return True if the touch mode changed and focus changed was changed as a result |
| 4322 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 4323 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | boolean ensureTouchMode(boolean inTouchMode) { |
| 4325 | if (DBG) Log.d("touchmode", "ensureTouchMode(" + inTouchMode + "), current " |
| 4326 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 4327 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 4328 | |
| 4329 | // tell the window manager |
| 4330 | try { |
Matt Wu | d6bc96d | 2016-01-14 12:59:24 -0800 | [diff] [blame] | 4331 | mWindowSession.setInTouchMode(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | } catch (RemoteException e) { |
| 4333 | throw new RuntimeException(e); |
| 4334 | } |
| 4335 | |
| 4336 | // handle the change |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 4337 | return ensureTouchModeLocally(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | /** |
| 4341 | * Ensure that the touch mode for this window is set, and if it is changing, |
| 4342 | * take the appropriate action. |
| 4343 | * @param inTouchMode Whether we want to be in touch mode. |
| 4344 | * @return True if the touch mode changed and focus changed was changed as a result |
| 4345 | */ |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 4346 | private boolean ensureTouchModeLocally(boolean inTouchMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4347 | if (DBG) Log.d("touchmode", "ensureTouchModeLocally(" + inTouchMode + "), current " |
| 4348 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 4349 | |
| 4350 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 4351 | |
| 4352 | mAttachInfo.mInTouchMode = inTouchMode; |
| 4353 | mAttachInfo.mTreeObserver.dispatchOnTouchModeChanged(inTouchMode); |
| 4354 | |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 4355 | return (inTouchMode) ? enterTouchMode() : leaveTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | private boolean enterTouchMode() { |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 4359 | if (mView != null && mView.hasFocus()) { |
| 4360 | // note: not relying on mFocusedView here because this could |
| 4361 | // be when the window is first being added, and mFocused isn't |
| 4362 | // set yet. |
| 4363 | final View focused = mView.findFocus(); |
| 4364 | if (focused != null && !focused.isFocusableInTouchMode()) { |
| 4365 | final ViewGroup ancestorToTakeFocus = findAncestorToTakeFocusInTouchMode(focused); |
| 4366 | if (ancestorToTakeFocus != null) { |
| 4367 | // there is an ancestor that wants focus after its |
| 4368 | // descendants that is focusable in touch mode.. give it |
| 4369 | // focus |
| 4370 | return ancestorToTakeFocus.requestFocus(); |
| 4371 | } else { |
Alan Viverette | 973f3b4 | 2013-08-13 16:57:28 -0700 | [diff] [blame] | 4372 | // There's nothing to focus. Clear and propagate through the |
| 4373 | // hierarchy, but don't attempt to place new focus. |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 4374 | focused.clearFocusInternal(null, true, false); |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 4375 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | } |
| 4379 | return false; |
| 4380 | } |
| 4381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4382 | /** |
| 4383 | * Find an ancestor of focused that wants focus after its descendants and is |
| 4384 | * focusable in touch mode. |
| 4385 | * @param focused The currently focused view. |
| 4386 | * @return An appropriate view, or null if no such view exists. |
| 4387 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4388 | private static ViewGroup findAncestorToTakeFocusInTouchMode(View focused) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4389 | ViewParent parent = focused.getParent(); |
| 4390 | while (parent instanceof ViewGroup) { |
| 4391 | final ViewGroup vgParent = (ViewGroup) parent; |
| 4392 | if (vgParent.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 4393 | && vgParent.isFocusableInTouchMode()) { |
| 4394 | return vgParent; |
| 4395 | } |
| 4396 | if (vgParent.isRootNamespace()) { |
| 4397 | return null; |
| 4398 | } else { |
| 4399 | parent = vgParent.getParent(); |
| 4400 | } |
| 4401 | } |
| 4402 | return null; |
| 4403 | } |
| 4404 | |
| 4405 | private boolean leaveTouchMode() { |
| 4406 | if (mView != null) { |
| 4407 | if (mView.hasFocus()) { |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4408 | View focusedView = mView.findFocus(); |
| 4409 | if (!(focusedView instanceof ViewGroup)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | // some view has focus, let it keep it |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 4411 | return false; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4412 | } else if (((ViewGroup) focusedView).getDescendantFocusability() != |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4413 | ViewGroup.FOCUS_AFTER_DESCENDANTS) { |
| 4414 | // some view group has focus, and doesn't prefer its children |
| 4415 | // over itself for focus, so let them keep it. |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 4416 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | } |
| 4418 | } |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 4419 | |
| 4420 | // find the best view to give focus to in this brave new non-touch-mode |
| 4421 | // world |
Evan Rosky | bdc66cb | 2017-09-08 14:27:24 -0700 | [diff] [blame] | 4422 | return mView.restoreDefaultFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | } |
| 4424 | return false; |
| 4425 | } |
| 4426 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4427 | /** |
| 4428 | * Base class for implementing a stage in the chain of responsibility |
| 4429 | * for processing input events. |
| 4430 | * <p> |
| 4431 | * Events are delivered to the stage by the {@link #deliver} method. The stage |
| 4432 | * then has the choice of finishing the event or forwarding it to the next stage. |
| 4433 | * </p> |
| 4434 | */ |
| 4435 | abstract class InputStage { |
| 4436 | private final InputStage mNext; |
| 4437 | |
| 4438 | protected static final int FORWARD = 0; |
| 4439 | protected static final int FINISH_HANDLED = 1; |
| 4440 | protected static final int FINISH_NOT_HANDLED = 2; |
| 4441 | |
| 4442 | /** |
| 4443 | * Creates an input stage. |
| 4444 | * @param next The next stage to which events should be forwarded. |
| 4445 | */ |
| 4446 | public InputStage(InputStage next) { |
| 4447 | mNext = next; |
| 4448 | } |
| 4449 | |
| 4450 | /** |
| 4451 | * Delivers an event to be processed. |
| 4452 | */ |
| 4453 | public final void deliver(QueuedInputEvent q) { |
| 4454 | if ((q.mFlags & QueuedInputEvent.FLAG_FINISHED) != 0) { |
| 4455 | forward(q); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4456 | } else if (shouldDropInputEvent(q)) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4457 | finish(q, false); |
| 4458 | } else { |
| 4459 | apply(q, onProcess(q)); |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | /** |
| 4464 | * Marks the the input event as finished then forwards it to the next stage. |
| 4465 | */ |
| 4466 | protected void finish(QueuedInputEvent q, boolean handled) { |
| 4467 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED; |
| 4468 | if (handled) { |
| 4469 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED_HANDLED; |
| 4470 | } |
| 4471 | forward(q); |
| 4472 | } |
| 4473 | |
| 4474 | /** |
| 4475 | * Forwards the event to the next stage. |
| 4476 | */ |
| 4477 | protected void forward(QueuedInputEvent q) { |
| 4478 | onDeliverToNext(q); |
| 4479 | } |
| 4480 | |
| 4481 | /** |
| 4482 | * Applies a result code from {@link #onProcess} to the specified event. |
| 4483 | */ |
| 4484 | protected void apply(QueuedInputEvent q, int result) { |
| 4485 | if (result == FORWARD) { |
| 4486 | forward(q); |
| 4487 | } else if (result == FINISH_HANDLED) { |
| 4488 | finish(q, true); |
| 4489 | } else if (result == FINISH_NOT_HANDLED) { |
| 4490 | finish(q, false); |
| 4491 | } else { |
| 4492 | throw new IllegalArgumentException("Invalid result: " + result); |
| 4493 | } |
| 4494 | } |
| 4495 | |
| 4496 | /** |
| 4497 | * Called when an event is ready to be processed. |
| 4498 | * @return A result code indicating how the event was handled. |
| 4499 | */ |
| 4500 | protected int onProcess(QueuedInputEvent q) { |
| 4501 | return FORWARD; |
| 4502 | } |
| 4503 | |
| 4504 | /** |
| 4505 | * Called when an event is being delivered to the next stage. |
| 4506 | */ |
| 4507 | protected void onDeliverToNext(QueuedInputEvent q) { |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 4508 | if (DEBUG_INPUT_STAGES) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4509 | Log.v(mTag, "Done with " + getClass().getSimpleName() + ". " + q); |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 4510 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4511 | if (mNext != null) { |
| 4512 | mNext.deliver(q); |
| 4513 | } else { |
| 4514 | finishInputEvent(q); |
| 4515 | } |
| 4516 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4517 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 4518 | protected void onWindowFocusChanged(boolean hasWindowFocus) { |
| 4519 | if (mNext != null) { |
| 4520 | mNext.onWindowFocusChanged(hasWindowFocus); |
| 4521 | } |
| 4522 | } |
| 4523 | |
| 4524 | protected void onDetachedFromWindow() { |
| 4525 | if (mNext != null) { |
| 4526 | mNext.onDetachedFromWindow(); |
| 4527 | } |
| 4528 | } |
| 4529 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4530 | protected boolean shouldDropInputEvent(QueuedInputEvent q) { |
| 4531 | if (mView == null || !mAdded) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4532 | 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] | 4533 | return true; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4534 | } else if ((!mAttachInfo.mHasWindowFocus |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 4535 | && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER) |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 4536 | && !isAutofillUiShowing()) || mStopped |
Joe LaPenna | 90776de | 2016-01-22 07:11:49 -0800 | [diff] [blame] | 4537 | || (mIsAmbientMode && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_BUTTON)) |
| 4538 | || (mPausedForTransition && !isBack(q.mEvent))) { |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 4539 | // This is a focus event and the window doesn't currently have input focus or |
| 4540 | // has stopped. This could be an event that came back from the previous stage |
| 4541 | // but the window has lost focus or stopped in the meantime. |
| 4542 | if (isTerminalInputEvent(q.mEvent)) { |
| 4543 | // Don't drop terminal input events, however mark them as canceled. |
| 4544 | q.mEvent.cancel(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4545 | Slog.w(mTag, "Cancelling event due to no window focus: " + q.mEvent); |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 4546 | return false; |
| 4547 | } |
| 4548 | |
| 4549 | // Drop non-terminal input events. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4550 | Slog.w(mTag, "Dropping event due to no window focus: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4551 | return true; |
| 4552 | } |
| 4553 | return false; |
| 4554 | } |
| 4555 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4556 | void dump(String prefix, PrintWriter writer) { |
| 4557 | if (mNext != null) { |
| 4558 | mNext.dump(prefix, writer); |
| 4559 | } |
| 4560 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4561 | |
| 4562 | private boolean isBack(InputEvent event) { |
| 4563 | if (event instanceof KeyEvent) { |
| 4564 | return ((KeyEvent) event).getKeyCode() == KeyEvent.KEYCODE_BACK; |
| 4565 | } else { |
| 4566 | return false; |
| 4567 | } |
| 4568 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | /** |
| 4572 | * Base class for implementing an input pipeline stage that supports |
| 4573 | * asynchronous and out-of-order processing of input events. |
| 4574 | * <p> |
| 4575 | * In addition to what a normal input stage can do, an asynchronous |
| 4576 | * input stage may also defer an input event that has been delivered to it |
| 4577 | * and finish or forward it later. |
| 4578 | * </p> |
| 4579 | */ |
| 4580 | abstract class AsyncInputStage extends InputStage { |
| 4581 | private final String mTraceCounter; |
| 4582 | |
| 4583 | private QueuedInputEvent mQueueHead; |
| 4584 | private QueuedInputEvent mQueueTail; |
| 4585 | private int mQueueLength; |
| 4586 | |
| 4587 | protected static final int DEFER = 3; |
| 4588 | |
| 4589 | /** |
| 4590 | * Creates an asynchronous input stage. |
| 4591 | * @param next The next stage to which events should be forwarded. |
| 4592 | * @param traceCounter The name of a counter to record the size of |
| 4593 | * the queue of pending events. |
| 4594 | */ |
| 4595 | public AsyncInputStage(InputStage next, String traceCounter) { |
| 4596 | super(next); |
| 4597 | mTraceCounter = traceCounter; |
| 4598 | } |
| 4599 | |
| 4600 | /** |
| 4601 | * Marks the event as deferred, which is to say that it will be handled |
| 4602 | * asynchronously. The caller is responsible for calling {@link #forward} |
| 4603 | * or {@link #finish} later when it is done handling the event. |
| 4604 | */ |
| 4605 | protected void defer(QueuedInputEvent q) { |
| 4606 | q.mFlags |= QueuedInputEvent.FLAG_DEFERRED; |
| 4607 | enqueue(q); |
| 4608 | } |
| 4609 | |
| 4610 | @Override |
| 4611 | protected void forward(QueuedInputEvent q) { |
| 4612 | // Clear the deferred flag. |
| 4613 | q.mFlags &= ~QueuedInputEvent.FLAG_DEFERRED; |
| 4614 | |
| 4615 | // Fast path if the queue is empty. |
| 4616 | QueuedInputEvent curr = mQueueHead; |
| 4617 | if (curr == null) { |
| 4618 | super.forward(q); |
| 4619 | return; |
| 4620 | } |
| 4621 | |
| 4622 | // Determine whether the event must be serialized behind any others |
| 4623 | // before it can be delivered to the next stage. This is done because |
| 4624 | // deferred events might be handled out of order by the stage. |
| 4625 | final int deviceId = q.mEvent.getDeviceId(); |
| 4626 | QueuedInputEvent prev = null; |
| 4627 | boolean blocked = false; |
| 4628 | while (curr != null && curr != q) { |
| 4629 | if (!blocked && deviceId == curr.mEvent.getDeviceId()) { |
| 4630 | blocked = true; |
| 4631 | } |
| 4632 | prev = curr; |
| 4633 | curr = curr.mNext; |
| 4634 | } |
| 4635 | |
| 4636 | // If the event is blocked, then leave it in the queue to be delivered later. |
| 4637 | // Note that the event might not yet be in the queue if it was not previously |
| 4638 | // deferred so we will enqueue it if needed. |
| 4639 | if (blocked) { |
| 4640 | if (curr == null) { |
| 4641 | enqueue(q); |
| 4642 | } |
| 4643 | return; |
| 4644 | } |
| 4645 | |
| 4646 | // The event is not blocked. Deliver it immediately. |
| 4647 | if (curr != null) { |
| 4648 | curr = curr.mNext; |
| 4649 | dequeue(q, prev); |
| 4650 | } |
| 4651 | super.forward(q); |
| 4652 | |
| 4653 | // Dequeuing this event may have unblocked successors. Deliver them. |
| 4654 | while (curr != null) { |
| 4655 | if (deviceId == curr.mEvent.getDeviceId()) { |
| 4656 | if ((curr.mFlags & QueuedInputEvent.FLAG_DEFERRED) != 0) { |
| 4657 | break; |
| 4658 | } |
| 4659 | QueuedInputEvent next = curr.mNext; |
| 4660 | dequeue(curr, prev); |
| 4661 | super.forward(curr); |
| 4662 | curr = next; |
| 4663 | } else { |
| 4664 | prev = curr; |
| 4665 | curr = curr.mNext; |
| 4666 | } |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | @Override |
| 4671 | protected void apply(QueuedInputEvent q, int result) { |
| 4672 | if (result == DEFER) { |
| 4673 | defer(q); |
| 4674 | } else { |
| 4675 | super.apply(q, result); |
| 4676 | } |
| 4677 | } |
| 4678 | |
| 4679 | private void enqueue(QueuedInputEvent q) { |
| 4680 | if (mQueueTail == null) { |
| 4681 | mQueueHead = q; |
| 4682 | mQueueTail = q; |
| 4683 | } else { |
| 4684 | mQueueTail.mNext = q; |
| 4685 | mQueueTail = q; |
| 4686 | } |
| 4687 | |
| 4688 | mQueueLength += 1; |
| 4689 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 4690 | } |
| 4691 | |
| 4692 | private void dequeue(QueuedInputEvent q, QueuedInputEvent prev) { |
| 4693 | if (prev == null) { |
| 4694 | mQueueHead = q.mNext; |
| 4695 | } else { |
| 4696 | prev.mNext = q.mNext; |
| 4697 | } |
| 4698 | if (mQueueTail == q) { |
| 4699 | mQueueTail = prev; |
| 4700 | } |
| 4701 | q.mNext = null; |
| 4702 | |
| 4703 | mQueueLength -= 1; |
| 4704 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 4705 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4706 | |
| 4707 | @Override |
| 4708 | void dump(String prefix, PrintWriter writer) { |
| 4709 | writer.print(prefix); |
| 4710 | writer.print(getClass().getName()); |
| 4711 | writer.print(": mQueueLength="); |
| 4712 | writer.println(mQueueLength); |
| 4713 | |
| 4714 | super.dump(prefix, writer); |
| 4715 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | /** |
| 4719 | * Delivers pre-ime input events to a native activity. |
| 4720 | * Does not support pointer events. |
| 4721 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4722 | final class NativePreImeInputStage extends AsyncInputStage |
| 4723 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4724 | public NativePreImeInputStage(InputStage next, String traceCounter) { |
| 4725 | super(next, traceCounter); |
| 4726 | } |
| 4727 | |
| 4728 | @Override |
| 4729 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4730 | if (mInputQueue != null && q.mEvent instanceof KeyEvent) { |
| 4731 | mInputQueue.sendInputEvent(q.mEvent, q, true, this); |
| 4732 | return DEFER; |
| 4733 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4734 | return FORWARD; |
| 4735 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4736 | |
| 4737 | @Override |
| 4738 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4739 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4740 | if (handled) { |
| 4741 | finish(q, true); |
| 4742 | return; |
| 4743 | } |
| 4744 | forward(q); |
| 4745 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | /** |
| 4749 | * Delivers pre-ime input events to the view hierarchy. |
| 4750 | * Does not support pointer events. |
| 4751 | */ |
| 4752 | final class ViewPreImeInputStage extends InputStage { |
| 4753 | public ViewPreImeInputStage(InputStage next) { |
| 4754 | super(next); |
| 4755 | } |
| 4756 | |
| 4757 | @Override |
| 4758 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4759 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4760 | return processKeyEvent(q); |
| 4761 | } |
| 4762 | return FORWARD; |
| 4763 | } |
| 4764 | |
| 4765 | private int processKeyEvent(QueuedInputEvent q) { |
| 4766 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4767 | if (mView.dispatchKeyEventPreIme(event)) { |
| 4768 | return FINISH_HANDLED; |
| 4769 | } |
| 4770 | return FORWARD; |
| 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | /** |
| 4775 | * Delivers input events to the ime. |
| 4776 | * Does not support pointer events. |
| 4777 | */ |
| 4778 | final class ImeInputStage extends AsyncInputStage |
| 4779 | implements InputMethodManager.FinishedInputEventCallback { |
| 4780 | public ImeInputStage(InputStage next, String traceCounter) { |
| 4781 | super(next, traceCounter); |
| 4782 | } |
| 4783 | |
| 4784 | @Override |
| 4785 | protected int onProcess(QueuedInputEvent q) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4786 | if (mLastWasImTarget && !isInLocalFocusMode()) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4787 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4788 | if (imm != null) { |
| 4789 | final InputEvent event = q.mEvent; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4790 | if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4791 | int result = imm.dispatchInputEvent(event, q, this, mHandler); |
| 4792 | if (result == InputMethodManager.DISPATCH_HANDLED) { |
| 4793 | return FINISH_HANDLED; |
| 4794 | } else if (result == InputMethodManager.DISPATCH_NOT_HANDLED) { |
Adam Lesinski | c0f6eed | 2013-10-28 16:03:19 -0700 | [diff] [blame] | 4795 | // The IME could not handle it, so skip along to the next InputStage |
| 4796 | return FORWARD; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4797 | } else { |
| 4798 | return DEFER; // callback will be invoked later |
| 4799 | } |
| 4800 | } |
| 4801 | } |
| 4802 | return FORWARD; |
| 4803 | } |
| 4804 | |
| 4805 | @Override |
| 4806 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4807 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4808 | if (handled) { |
| 4809 | finish(q, true); |
| 4810 | return; |
| 4811 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4812 | forward(q); |
| 4813 | } |
| 4814 | } |
| 4815 | |
| 4816 | /** |
| 4817 | * Performs early processing of post-ime input events. |
| 4818 | */ |
| 4819 | final class EarlyPostImeInputStage extends InputStage { |
| 4820 | public EarlyPostImeInputStage(InputStage next) { |
| 4821 | super(next); |
| 4822 | } |
| 4823 | |
| 4824 | @Override |
| 4825 | protected int onProcess(QueuedInputEvent q) { |
| 4826 | if (q.mEvent instanceof KeyEvent) { |
| 4827 | return processKeyEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4828 | } else { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4829 | final int source = q.mEvent.getSource(); |
| 4830 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4831 | return processPointerEvent(q); |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4832 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4833 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4834 | return FORWARD; |
| 4835 | } |
| 4836 | |
| 4837 | private int processKeyEvent(QueuedInputEvent q) { |
| 4838 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4839 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 4840 | if (mAttachInfo.mTooltipHost != null) { |
| 4841 | mAttachInfo.mTooltipHost.handleTooltipKey(event); |
| 4842 | } |
| 4843 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4844 | // If the key's purpose is to exit touch mode then we consume it |
| 4845 | // and consider it handled. |
| 4846 | if (checkForLeavingTouchModeAndConsume(event)) { |
| 4847 | return FINISH_HANDLED; |
| 4848 | } |
| 4849 | |
| 4850 | // Make sure the fallback event policy sees all keys that will be |
| 4851 | // delivered to the view hierarchy. |
| 4852 | mFallbackEventHandler.preDispatchKeyEvent(event); |
| 4853 | return FORWARD; |
| 4854 | } |
| 4855 | |
| 4856 | private int processPointerEvent(QueuedInputEvent q) { |
| 4857 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4858 | |
| 4859 | // Translate the pointer event for compatibility, if needed. |
| 4860 | if (mTranslator != null) { |
| 4861 | mTranslator.translateEventInScreenToAppWindow(event); |
| 4862 | } |
| 4863 | |
Vladislav Kaznacheev | 7614cdf | 2017-02-21 11:57:59 -0800 | [diff] [blame] | 4864 | // Enter touch mode on down or scroll, if it is coming from a touch screen device, |
| 4865 | // exit otherwise. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4866 | final int action = event.getAction(); |
Vladislav Kaznacheev | 7614cdf | 2017-02-21 11:57:59 -0800 | [diff] [blame] | 4867 | if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_SCROLL) { |
| 4868 | ensureTouchMode(event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 4871 | if (action == MotionEvent.ACTION_DOWN) { |
Dake Gu | b0fa378 | 2018-02-26 12:25:14 -0800 | [diff] [blame] | 4872 | // Upon motion event within app window, close autofill ui. |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 4873 | AutofillManager afm = getAutofillManager(); |
| 4874 | if (afm != null) { |
| 4875 | afm.requestHideFillUi(); |
Dake Gu | b0fa378 | 2018-02-26 12:25:14 -0800 | [diff] [blame] | 4876 | } |
| 4877 | } |
| 4878 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 4879 | if (action == MotionEvent.ACTION_DOWN && mAttachInfo.mTooltipHost != null) { |
| 4880 | mAttachInfo.mTooltipHost.hideTooltip(); |
| 4881 | } |
| 4882 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4883 | // Offset the scroll position. |
| 4884 | if (mCurScrollY != 0) { |
| 4885 | event.offsetLocation(0, mCurScrollY); |
| 4886 | } |
| 4887 | |
| 4888 | // Remember the touch position for possible drag-initiation. |
| 4889 | if (event.isTouchEvent()) { |
| 4890 | mLastTouchPoint.x = event.getRawX(); |
| 4891 | mLastTouchPoint.y = event.getRawY(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 4892 | mLastTouchSource = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4893 | } |
| 4894 | return FORWARD; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4895 | } |
| 4896 | } |
| 4897 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4898 | /** |
| 4899 | * Delivers post-ime input events to a native activity. |
| 4900 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4901 | final class NativePostImeInputStage extends AsyncInputStage |
| 4902 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4903 | public NativePostImeInputStage(InputStage next, String traceCounter) { |
| 4904 | super(next, traceCounter); |
| 4905 | } |
| 4906 | |
| 4907 | @Override |
| 4908 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4909 | if (mInputQueue != null) { |
| 4910 | mInputQueue.sendInputEvent(q.mEvent, q, false, this); |
| 4911 | return DEFER; |
| 4912 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4913 | return FORWARD; |
| 4914 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4915 | |
| 4916 | @Override |
| 4917 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4918 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4919 | if (handled) { |
| 4920 | finish(q, true); |
| 4921 | return; |
| 4922 | } |
| 4923 | forward(q); |
| 4924 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | /** |
| 4928 | * Delivers post-ime input events to the view hierarchy. |
| 4929 | */ |
| 4930 | final class ViewPostImeInputStage extends InputStage { |
| 4931 | public ViewPostImeInputStage(InputStage next) { |
| 4932 | super(next); |
| 4933 | } |
| 4934 | |
| 4935 | @Override |
| 4936 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4937 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4938 | return processKeyEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4939 | } else { |
| 4940 | final int source = q.mEvent.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4941 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4942 | return processPointerEvent(q); |
| 4943 | } else if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
| 4944 | return processTrackballEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4945 | } else { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4946 | return processGenericMotionEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4947 | } |
| 4948 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4949 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4950 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4951 | @Override |
| 4952 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4953 | if (mUnbufferedInputDispatch |
| 4954 | && q.mEvent instanceof MotionEvent |
| 4955 | && ((MotionEvent)q.mEvent).isTouchEvent() |
| 4956 | && isTerminalInputEvent(q.mEvent)) { |
| 4957 | mUnbufferedInputDispatch = false; |
| 4958 | scheduleConsumeBatchedInput(); |
| 4959 | } |
| 4960 | super.onDeliverToNext(q); |
| 4961 | } |
| 4962 | |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4963 | private boolean performFocusNavigation(KeyEvent event) { |
| 4964 | int direction = 0; |
| 4965 | switch (event.getKeyCode()) { |
| 4966 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 4967 | if (event.hasNoModifiers()) { |
| 4968 | direction = View.FOCUS_LEFT; |
| 4969 | } |
| 4970 | break; |
| 4971 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 4972 | if (event.hasNoModifiers()) { |
| 4973 | direction = View.FOCUS_RIGHT; |
| 4974 | } |
| 4975 | break; |
| 4976 | case KeyEvent.KEYCODE_DPAD_UP: |
| 4977 | if (event.hasNoModifiers()) { |
| 4978 | direction = View.FOCUS_UP; |
| 4979 | } |
| 4980 | break; |
| 4981 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 4982 | if (event.hasNoModifiers()) { |
| 4983 | direction = View.FOCUS_DOWN; |
| 4984 | } |
| 4985 | break; |
| 4986 | case KeyEvent.KEYCODE_TAB: |
| 4987 | if (event.hasNoModifiers()) { |
| 4988 | direction = View.FOCUS_FORWARD; |
| 4989 | } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { |
| 4990 | direction = View.FOCUS_BACKWARD; |
| 4991 | } |
| 4992 | break; |
| 4993 | } |
| 4994 | if (direction != 0) { |
| 4995 | View focused = mView.findFocus(); |
| 4996 | if (focused != null) { |
| 4997 | View v = focused.focusSearch(direction); |
| 4998 | if (v != null && v != focused) { |
| 4999 | // do the math the get the interesting rect |
| 5000 | // of previous focused into the coord system of |
| 5001 | // newly focused view |
| 5002 | focused.getFocusedRect(mTempRect); |
| 5003 | if (mView instanceof ViewGroup) { |
| 5004 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 5005 | focused, mTempRect); |
| 5006 | ((ViewGroup) mView).offsetRectIntoDescendantCoords( |
| 5007 | v, mTempRect); |
| 5008 | } |
| 5009 | if (v.requestFocus(direction, mTempRect)) { |
| 5010 | playSoundEffect(SoundEffectConstants |
| 5011 | .getContantForFocusDirection(direction)); |
| 5012 | return true; |
| 5013 | } |
| 5014 | } |
| 5015 | |
| 5016 | // Give the focused view a last chance to handle the dpad key. |
| 5017 | if (mView.dispatchUnhandledMove(focused, direction)) { |
| 5018 | return true; |
| 5019 | } |
| 5020 | } else { |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 5021 | if (mView.restoreDefaultFocus()) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5022 | return true; |
| 5023 | } |
| 5024 | } |
| 5025 | } |
| 5026 | return false; |
| 5027 | } |
| 5028 | |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 5029 | private boolean performKeyboardGroupNavigation(int direction) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5030 | final View focused = mView.findFocus(); |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 5031 | if (focused == null && mView.restoreDefaultFocus()) { |
| 5032 | return true; |
| 5033 | } |
Evan Rosky | 5b86071 | 2017-04-17 16:40:16 -0700 | [diff] [blame] | 5034 | View cluster = focused == null ? keyboardNavigationClusterSearch(null, direction) |
| 5035 | : focused.keyboardNavigationClusterSearch(null, direction); |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5036 | |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5037 | // Since requestFocus only takes "real" focus directions (and therefore also |
| 5038 | // restoreFocusInCluster), convert forward/backward focus into FOCUS_DOWN. |
| 5039 | int realDirection = direction; |
| 5040 | if (direction == View.FOCUS_FORWARD || direction == View.FOCUS_BACKWARD) { |
| 5041 | realDirection = View.FOCUS_DOWN; |
| 5042 | } |
| 5043 | |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 5044 | if (cluster != null && cluster.isRootNamespace()) { |
| 5045 | // the default cluster. Try to find a non-clustered view to focus. |
| 5046 | if (cluster.restoreFocusNotInCluster()) { |
Evan Rosky | bd10c52 | 2017-03-27 15:50:38 -0700 | [diff] [blame] | 5047 | playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction)); |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 5048 | return true; |
| 5049 | } |
| 5050 | // otherwise skip to next actual cluster |
| 5051 | cluster = keyboardNavigationClusterSearch(null, direction); |
| 5052 | } |
| 5053 | |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5054 | if (cluster != null && cluster.restoreFocusInCluster(realDirection)) { |
Evan Rosky | bd10c52 | 2017-03-27 15:50:38 -0700 | [diff] [blame] | 5055 | playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction)); |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5056 | return true; |
| 5057 | } |
| 5058 | |
| 5059 | return false; |
| 5060 | } |
| 5061 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5062 | private int processKeyEvent(QueuedInputEvent q) { |
| 5063 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 5064 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 5065 | if (mUnhandledKeyManager.preViewDispatch(event)) { |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 5066 | return FINISH_HANDLED; |
| 5067 | } |
| 5068 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5069 | // Deliver the key to the view hierarchy. |
| 5070 | if (mView.dispatchKeyEvent(event)) { |
| 5071 | return FINISH_HANDLED; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5072 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5073 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 5074 | if (shouldDropInputEvent(q)) { |
| 5075 | return FINISH_NOT_HANDLED; |
| 5076 | } |
| 5077 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 5078 | // This dispatch is for windows that don't have a Window.Callback. Otherwise, |
| 5079 | // the Window.Callback usually will have already called this (see |
| 5080 | // DecorView.superDispatchKeyEvent) leaving this call a no-op. |
| 5081 | if (mUnhandledKeyManager.dispatch(mView, event)) { |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 5082 | return FINISH_HANDLED; |
| 5083 | } |
| 5084 | |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5085 | int groupNavigationDirection = 0; |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5086 | |
Evan Rosky | 516f9e6 | 2017-01-23 16:43:52 -0800 | [diff] [blame] | 5087 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 5088 | && event.getKeyCode() == KeyEvent.KEYCODE_TAB) { |
| 5089 | if (KeyEvent.metaStateHasModifiers(event.getMetaState(), KeyEvent.META_META_ON)) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5090 | groupNavigationDirection = View.FOCUS_FORWARD; |
Evan Rosky | 516f9e6 | 2017-01-23 16:43:52 -0800 | [diff] [blame] | 5091 | } else if (KeyEvent.metaStateHasModifiers(event.getMetaState(), |
| 5092 | KeyEvent.META_META_ON | KeyEvent.META_SHIFT_ON)) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5093 | groupNavigationDirection = View.FOCUS_BACKWARD; |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5094 | } |
| 5095 | } |
| 5096 | |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 5097 | // 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] | 5098 | if (event.getAction() == KeyEvent.ACTION_DOWN |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 5099 | && !KeyEvent.metaStateHasNoModifiers(event.getMetaState()) |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5100 | && event.getRepeatCount() == 0 |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5101 | && !KeyEvent.isModifierKey(event.getKeyCode()) |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5102 | && groupNavigationDirection == 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5103 | if (mView.dispatchKeyShortcutEvent(event)) { |
| 5104 | return FINISH_HANDLED; |
| 5105 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 5106 | if (shouldDropInputEvent(q)) { |
| 5107 | return FINISH_NOT_HANDLED; |
| 5108 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | // Apply the fallback event policy. |
| 5112 | if (mFallbackEventHandler.dispatchKeyEvent(event)) { |
| 5113 | return FINISH_HANDLED; |
| 5114 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 5115 | if (shouldDropInputEvent(q)) { |
| 5116 | return FINISH_NOT_HANDLED; |
| 5117 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5118 | |
| 5119 | // Handle automatic focus changes. |
| 5120 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 5121 | if (groupNavigationDirection != 0) { |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 5122 | if (performKeyboardGroupNavigation(groupNavigationDirection)) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 5123 | return FINISH_HANDLED; |
| 5124 | } |
| 5125 | } else { |
| 5126 | if (performFocusNavigation(event)) { |
| 5127 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5128 | } |
| 5129 | } |
| 5130 | } |
| 5131 | return FORWARD; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5132 | } |
| 5133 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5134 | private int processPointerEvent(QueuedInputEvent q) { |
| 5135 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 5136 | |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 5137 | mAttachInfo.mUnbufferedDispatchRequested = false; |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 5138 | mAttachInfo.mHandlingPointerEvent = true; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 5139 | boolean handled = mView.dispatchPointerEvent(event); |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 5140 | maybeUpdatePointerIcon(event); |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 5141 | maybeUpdateTooltip(event); |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 5142 | mAttachInfo.mHandlingPointerEvent = false; |
| 5143 | if (mAttachInfo.mUnbufferedDispatchRequested && !mUnbufferedInputDispatch) { |
| 5144 | mUnbufferedInputDispatch = true; |
| 5145 | if (mConsumeBatchedInputScheduled) { |
| 5146 | scheduleConsumeBatchedInputImmediately(); |
| 5147 | } |
| 5148 | } |
| 5149 | return handled ? FINISH_HANDLED : FORWARD; |
| 5150 | } |
| 5151 | |
| 5152 | private void maybeUpdatePointerIcon(MotionEvent event) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5153 | if (event.getPointerCount() == 1 && event.isFromSource(InputDevice.SOURCE_MOUSE)) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 5154 | if (event.getActionMasked() == MotionEvent.ACTION_HOVER_ENTER |
| 5155 | || event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5156 | // Other apps or the window manager may change the icon type outside of |
| 5157 | // this app, therefore the icon type has to be reset on enter/exit event. |
| 5158 | mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5161 | if (event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT) { |
| 5162 | if (!updatePointerIcon(event) && |
| 5163 | event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5164 | mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 5165 | } |
| 5166 | } |
| 5167 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5168 | } |
| 5169 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5170 | private int processTrackballEvent(QueuedInputEvent q) { |
| 5171 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 5172 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 5173 | if (event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)) { |
| 5174 | if (!hasPointerCapture() || mView.dispatchCapturedPointerEvent(event)) { |
| 5175 | return FINISH_HANDLED; |
| 5176 | } |
| 5177 | } |
| 5178 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5179 | if (mView.dispatchTrackballEvent(event)) { |
| 5180 | return FINISH_HANDLED; |
| 5181 | } |
| 5182 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | } |
| 5184 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5185 | private int processGenericMotionEvent(QueuedInputEvent q) { |
| 5186 | final MotionEvent event = (MotionEvent)q.mEvent; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5187 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5188 | // Deliver the event to the view. |
| 5189 | if (mView.dispatchGenericMotionEvent(event)) { |
| 5190 | return FINISH_HANDLED; |
| 5191 | } |
| 5192 | return FORWARD; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5193 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5194 | } |
| 5195 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5196 | private void resetPointerIcon(MotionEvent event) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5197 | mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5198 | updatePointerIcon(event); |
| 5199 | } |
| 5200 | |
| 5201 | private boolean updatePointerIcon(MotionEvent event) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5202 | final int pointerIndex = 0; |
| 5203 | final float x = event.getX(pointerIndex); |
| 5204 | final float y = event.getY(pointerIndex); |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 5205 | if (mView == null) { |
| 5206 | // E.g. click outside a popup to dismiss it |
| 5207 | Slog.d(mTag, "updatePointerIcon called after view was removed"); |
| 5208 | return false; |
| 5209 | } |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5210 | if (x < 0 || x >= mView.getWidth() || y < 0 || y >= mView.getHeight()) { |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 5211 | // E.g. when moving window divider with mouse |
| 5212 | Slog.d(mTag, "updatePointerIcon called with position out of bounds"); |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5213 | return false; |
| 5214 | } |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5215 | final PointerIcon pointerIcon = mView.onResolvePointerIcon(event, pointerIndex); |
| 5216 | final int pointerType = (pointerIcon != null) ? |
| 5217 | pointerIcon.getType() : PointerIcon.TYPE_DEFAULT; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5218 | |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5219 | if (mPointerIconType != pointerType) { |
| 5220 | mPointerIconType = pointerType; |
Vladislav Kaznacheev | e40fb27 | 2017-01-03 16:45:42 -0800 | [diff] [blame] | 5221 | mCustomPointerIcon = null; |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5222 | if (mPointerIconType != PointerIcon.TYPE_CUSTOM) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5223 | InputManager.getInstance().setPointerIconType(pointerType); |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5224 | return true; |
| 5225 | } |
| 5226 | } |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 5227 | if (mPointerIconType == PointerIcon.TYPE_CUSTOM && |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 5228 | !pointerIcon.equals(mCustomPointerIcon)) { |
| 5229 | mCustomPointerIcon = pointerIcon; |
| 5230 | InputManager.getInstance().setCustomPointerIcon(mCustomPointerIcon); |
| 5231 | } |
| 5232 | return true; |
| 5233 | } |
| 5234 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 5235 | private void maybeUpdateTooltip(MotionEvent event) { |
| 5236 | if (event.getPointerCount() != 1) { |
| 5237 | return; |
| 5238 | } |
| 5239 | final int action = event.getActionMasked(); |
| 5240 | if (action != MotionEvent.ACTION_HOVER_ENTER |
| 5241 | && action != MotionEvent.ACTION_HOVER_MOVE |
| 5242 | && action != MotionEvent.ACTION_HOVER_EXIT) { |
| 5243 | return; |
| 5244 | } |
| 5245 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 5246 | if (manager.isEnabled() && manager.isTouchExplorationEnabled()) { |
| 5247 | return; |
| 5248 | } |
| 5249 | if (mView == null) { |
| 5250 | Slog.d(mTag, "maybeUpdateTooltip called after view was removed"); |
| 5251 | return; |
| 5252 | } |
| 5253 | mView.dispatchTooltipHoverEvent(event); |
| 5254 | } |
| 5255 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5256 | /** |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5257 | * Performs synthesis of new input events from unhandled input events. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5258 | */ |
| 5259 | final class SyntheticInputStage extends InputStage { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5260 | private final SyntheticTrackballHandler mTrackball = new SyntheticTrackballHandler(); |
| 5261 | private final SyntheticJoystickHandler mJoystick = new SyntheticJoystickHandler(); |
| 5262 | private final SyntheticTouchNavigationHandler mTouchNavigation = |
| 5263 | new SyntheticTouchNavigationHandler(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5264 | private final SyntheticKeyboardHandler mKeyboard = new SyntheticKeyboardHandler(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5265 | |
| 5266 | public SyntheticInputStage() { |
| 5267 | super(null); |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5268 | } |
| 5269 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5270 | @Override |
| 5271 | protected int onProcess(QueuedInputEvent q) { |
| 5272 | q.mFlags |= QueuedInputEvent.FLAG_RESYNTHESIZED; |
| 5273 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5274 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 5275 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5276 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5277 | mTrackball.process(event); |
| 5278 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5279 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5280 | mJoystick.process(event); |
| 5281 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5282 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 5283 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5284 | mTouchNavigation.process(event); |
| 5285 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5286 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5287 | } else if ((q.mFlags & QueuedInputEvent.FLAG_UNHANDLED) != 0) { |
| 5288 | mKeyboard.process((KeyEvent)q.mEvent); |
| 5289 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5290 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5291 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5292 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5293 | } |
| 5294 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5295 | @Override |
| 5296 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 5297 | if ((q.mFlags & QueuedInputEvent.FLAG_RESYNTHESIZED) == 0) { |
| 5298 | // Cancel related synthetic events if any prior stage has handled the event. |
| 5299 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5300 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 5301 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5302 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5303 | mTrackball.cancel(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5304 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5305 | mJoystick.cancel(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5306 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 5307 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5308 | mTouchNavigation.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5309 | } |
| 5310 | } |
| 5311 | } |
| 5312 | super.onDeliverToNext(q); |
| 5313 | } |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5314 | |
| 5315 | @Override |
| 5316 | protected void onWindowFocusChanged(boolean hasWindowFocus) { |
| 5317 | if (!hasWindowFocus) { |
| 5318 | mJoystick.cancel(); |
| 5319 | } |
| 5320 | } |
| 5321 | |
| 5322 | @Override |
| 5323 | protected void onDetachedFromWindow() { |
| 5324 | mJoystick.cancel(); |
| 5325 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5326 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5327 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5328 | /** |
| 5329 | * Creates dpad events from unhandled trackball movements. |
| 5330 | */ |
| 5331 | final class SyntheticTrackballHandler { |
| 5332 | private final TrackballAxis mX = new TrackballAxis(); |
| 5333 | private final TrackballAxis mY = new TrackballAxis(); |
| 5334 | private long mLastTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5335 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5336 | public void process(MotionEvent event) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5337 | // Translate the trackball event into DPAD keys and try to deliver those. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5338 | long curTime = SystemClock.uptimeMillis(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5339 | if ((mLastTime + MAX_TRACKBALL_DELAY) < curTime) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5340 | // It has been too long since the last movement, |
| 5341 | // so restart at the beginning. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5342 | mX.reset(0); |
| 5343 | mY.reset(0); |
| 5344 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | final int action = event.getAction(); |
| 5348 | final int metaState = event.getMetaState(); |
| 5349 | switch (action) { |
| 5350 | case MotionEvent.ACTION_DOWN: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5351 | mX.reset(2); |
| 5352 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5353 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5354 | KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 5355 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5356 | InputDevice.SOURCE_KEYBOARD)); |
| 5357 | break; |
| 5358 | case MotionEvent.ACTION_UP: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5359 | mX.reset(2); |
| 5360 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5361 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5362 | KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 5363 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5364 | InputDevice.SOURCE_KEYBOARD)); |
| 5365 | break; |
| 5366 | } |
| 5367 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5368 | if (DEBUG_TRACKBALL) Log.v(mTag, "TB X=" + mX.position + " step=" |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5369 | + mX.step + " dir=" + mX.dir + " acc=" + mX.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5370 | + " move=" + event.getX() |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5371 | + " / Y=" + mY.position + " step=" |
| 5372 | + mY.step + " dir=" + mY.dir + " acc=" + mY.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5373 | + " move=" + event.getY()); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5374 | final float xOff = mX.collect(event.getX(), event.getEventTime(), "X"); |
| 5375 | final float yOff = mY.collect(event.getY(), event.getEventTime(), "Y"); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5376 | |
| 5377 | // Generate DPAD events based on the trackball movement. |
| 5378 | // We pick the axis that has moved the most as the direction of |
| 5379 | // the DPAD. When we generate DPAD events for one axis, then the |
| 5380 | // other axis is reset -- we don't want to perform DPAD jumps due |
| 5381 | // to slight movements in the trackball when making major movements |
| 5382 | // along the other axis. |
| 5383 | int keycode = 0; |
| 5384 | int movement = 0; |
| 5385 | float accel = 1; |
| 5386 | if (xOff > yOff) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5387 | movement = mX.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5388 | if (movement != 0) { |
| 5389 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_RIGHT |
| 5390 | : KeyEvent.KEYCODE_DPAD_LEFT; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5391 | accel = mX.acceleration; |
| 5392 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5393 | } |
| 5394 | } else if (yOff > 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5395 | movement = mY.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5396 | if (movement != 0) { |
| 5397 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_DOWN |
| 5398 | : KeyEvent.KEYCODE_DPAD_UP; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5399 | accel = mY.acceleration; |
| 5400 | mX.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5401 | } |
| 5402 | } |
| 5403 | |
| 5404 | if (keycode != 0) { |
| 5405 | if (movement < 0) movement = -movement; |
| 5406 | int accelMovement = (int)(movement * accel); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5407 | if (DEBUG_TRACKBALL) Log.v(mTag, "Move: movement=" + movement |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5408 | + " accelMovement=" + accelMovement |
| 5409 | + " accel=" + accel); |
| 5410 | if (accelMovement > movement) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5411 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5412 | + keycode); |
| 5413 | movement--; |
| 5414 | int repeatCount = accelMovement - movement; |
| 5415 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5416 | KeyEvent.ACTION_MULTIPLE, keycode, repeatCount, metaState, |
| 5417 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5418 | InputDevice.SOURCE_KEYBOARD)); |
| 5419 | } |
| 5420 | while (movement > 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5421 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5422 | + keycode); |
| 5423 | movement--; |
| 5424 | curTime = SystemClock.uptimeMillis(); |
| 5425 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5426 | KeyEvent.ACTION_DOWN, keycode, 0, metaState, |
| 5427 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5428 | InputDevice.SOURCE_KEYBOARD)); |
| 5429 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5430 | KeyEvent.ACTION_UP, keycode, 0, metaState, |
| 5431 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5432 | InputDevice.SOURCE_KEYBOARD)); |
| 5433 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5434 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5435 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5436 | } |
| 5437 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5438 | public void cancel() { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5439 | mLastTime = Integer.MIN_VALUE; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5440 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5441 | // If we reach this, we consumed a trackball event. |
| 5442 | // Because we will not translate the trackball event into a key event, |
| 5443 | // touch mode will not exit, so we exit touch mode here. |
| 5444 | if (mView != null && mAdded) { |
| 5445 | ensureTouchMode(false); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5446 | } |
| 5447 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5448 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5449 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5450 | /** |
| 5451 | * Maintains state information for a single trackball axis, generating |
| 5452 | * discrete (DPAD) movements based on raw trackball motion. |
| 5453 | */ |
| 5454 | static final class TrackballAxis { |
| 5455 | /** |
| 5456 | * The maximum amount of acceleration we will apply. |
| 5457 | */ |
| 5458 | static final float MAX_ACCELERATION = 20; |
| 5459 | |
| 5460 | /** |
| 5461 | * The maximum amount of time (in milliseconds) between events in order |
| 5462 | * for us to consider the user to be doing fast trackball movements, |
| 5463 | * and thus apply an acceleration. |
| 5464 | */ |
| 5465 | static final long FAST_MOVE_TIME = 150; |
| 5466 | |
| 5467 | /** |
| 5468 | * Scaling factor to the time (in milliseconds) between events to how |
| 5469 | * much to multiple/divide the current acceleration. When movement |
| 5470 | * is < FAST_MOVE_TIME this multiplies the acceleration; when > |
| 5471 | * FAST_MOVE_TIME it divides it. |
| 5472 | */ |
| 5473 | static final float ACCEL_MOVE_SCALING_FACTOR = (1.0f/40); |
| 5474 | |
| 5475 | static final float FIRST_MOVEMENT_THRESHOLD = 0.5f; |
| 5476 | static final float SECOND_CUMULATIVE_MOVEMENT_THRESHOLD = 2.0f; |
| 5477 | static final float SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD = 1.0f; |
| 5478 | |
| 5479 | float position; |
| 5480 | float acceleration = 1; |
| 5481 | long lastMoveTime = 0; |
| 5482 | int step; |
| 5483 | int dir; |
| 5484 | int nonAccelMovement; |
| 5485 | |
| 5486 | void reset(int _step) { |
| 5487 | position = 0; |
| 5488 | acceleration = 1; |
| 5489 | lastMoveTime = 0; |
| 5490 | step = _step; |
| 5491 | dir = 0; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 5492 | } |
| 5493 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5494 | /** |
| 5495 | * Add trackball movement into the state. If the direction of movement |
| 5496 | * has been reversed, the state is reset before adding the |
| 5497 | * movement (so that you don't have to compensate for any previously |
| 5498 | * collected movement before see the result of the movement in the |
| 5499 | * new direction). |
| 5500 | * |
| 5501 | * @return Returns the absolute value of the amount of movement |
| 5502 | * collected so far. |
| 5503 | */ |
| 5504 | float collect(float off, long time, String axis) { |
| 5505 | long normTime; |
| 5506 | if (off > 0) { |
| 5507 | normTime = (long)(off * FAST_MOVE_TIME); |
| 5508 | if (dir < 0) { |
| 5509 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to positive!"); |
| 5510 | position = 0; |
| 5511 | step = 0; |
| 5512 | acceleration = 1; |
| 5513 | lastMoveTime = 0; |
| 5514 | } |
| 5515 | dir = 1; |
| 5516 | } else if (off < 0) { |
| 5517 | normTime = (long)((-off) * FAST_MOVE_TIME); |
| 5518 | if (dir > 0) { |
| 5519 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to negative!"); |
| 5520 | position = 0; |
| 5521 | step = 0; |
| 5522 | acceleration = 1; |
| 5523 | lastMoveTime = 0; |
| 5524 | } |
| 5525 | dir = -1; |
| 5526 | } else { |
| 5527 | normTime = 0; |
| 5528 | } |
| 5529 | |
| 5530 | // The number of milliseconds between each movement that is |
| 5531 | // considered "normal" and will not result in any acceleration |
| 5532 | // or deceleration, scaled by the offset we have here. |
| 5533 | if (normTime > 0) { |
| 5534 | long delta = time - lastMoveTime; |
| 5535 | lastMoveTime = time; |
| 5536 | float acc = acceleration; |
| 5537 | if (delta < normTime) { |
| 5538 | // The user is scrolling rapidly, so increase acceleration. |
| 5539 | float scale = (normTime-delta) * ACCEL_MOVE_SCALING_FACTOR; |
| 5540 | if (scale > 1) acc *= scale; |
| 5541 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " accelerate: off=" |
| 5542 | + off + " normTime=" + normTime + " delta=" + delta |
| 5543 | + " scale=" + scale + " acc=" + acc); |
| 5544 | acceleration = acc < MAX_ACCELERATION ? acc : MAX_ACCELERATION; |
| 5545 | } else { |
| 5546 | // The user is scrolling slowly, so decrease acceleration. |
| 5547 | float scale = (delta-normTime) * ACCEL_MOVE_SCALING_FACTOR; |
| 5548 | if (scale > 1) acc /= scale; |
| 5549 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " deccelerate: off=" |
| 5550 | + off + " normTime=" + normTime + " delta=" + delta |
| 5551 | + " scale=" + scale + " acc=" + acc); |
| 5552 | acceleration = acc > 1 ? acc : 1; |
| 5553 | } |
| 5554 | } |
| 5555 | position += off; |
| 5556 | return Math.abs(position); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 5557 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5558 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5559 | /** |
| 5560 | * Generate the number of discrete movement events appropriate for |
| 5561 | * the currently collected trackball movement. |
| 5562 | * |
| 5563 | * @return Returns the number of discrete movements, either positive |
| 5564 | * or negative, or 0 if there is not enough trackball movement yet |
| 5565 | * for a discrete movement. |
| 5566 | */ |
| 5567 | int generate() { |
| 5568 | int movement = 0; |
| 5569 | nonAccelMovement = 0; |
| 5570 | do { |
| 5571 | final int dir = position >= 0 ? 1 : -1; |
| 5572 | switch (step) { |
| 5573 | // If we are going to execute the first step, then we want |
| 5574 | // to do this as soon as possible instead of waiting for |
| 5575 | // a full movement, in order to make things look responsive. |
| 5576 | case 0: |
| 5577 | if (Math.abs(position) < FIRST_MOVEMENT_THRESHOLD) { |
| 5578 | return movement; |
| 5579 | } |
| 5580 | movement += dir; |
| 5581 | nonAccelMovement += dir; |
| 5582 | step = 1; |
| 5583 | break; |
| 5584 | // If we have generated the first movement, then we need |
| 5585 | // to wait for the second complete trackball motion before |
| 5586 | // generating the second discrete movement. |
| 5587 | case 1: |
| 5588 | if (Math.abs(position) < SECOND_CUMULATIVE_MOVEMENT_THRESHOLD) { |
| 5589 | return movement; |
| 5590 | } |
| 5591 | movement += dir; |
| 5592 | nonAccelMovement += dir; |
| 5593 | position -= SECOND_CUMULATIVE_MOVEMENT_THRESHOLD * dir; |
| 5594 | step = 2; |
| 5595 | break; |
| 5596 | // After the first two, we generate discrete movements |
| 5597 | // consistently with the trackball, applying an acceleration |
| 5598 | // if the trackball is moving quickly. This is a simple |
| 5599 | // acceleration on top of what we already compute based |
| 5600 | // on how quickly the wheel is being turned, to apply |
| 5601 | // a longer increasing acceleration to continuous movement |
| 5602 | // in one direction. |
| 5603 | default: |
| 5604 | if (Math.abs(position) < SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD) { |
| 5605 | return movement; |
| 5606 | } |
| 5607 | movement += dir; |
| 5608 | position -= dir * SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD; |
| 5609 | float acc = acceleration; |
| 5610 | acc *= 1.1f; |
| 5611 | acceleration = acc < MAX_ACCELERATION ? acc : acceleration; |
| 5612 | break; |
| 5613 | } |
| 5614 | } while (true); |
| 5615 | } |
| 5616 | } |
| 5617 | |
| 5618 | /** |
| 5619 | * Creates dpad events from unhandled joystick movements. |
| 5620 | */ |
| 5621 | final class SyntheticJoystickHandler extends Handler { |
| 5622 | private final static int MSG_ENQUEUE_X_AXIS_KEY_REPEAT = 1; |
| 5623 | private final static int MSG_ENQUEUE_Y_AXIS_KEY_REPEAT = 2; |
| 5624 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5625 | private final JoystickAxesState mJoystickAxesState = new JoystickAxesState(); |
| 5626 | private final SparseArray<KeyEvent> mDeviceKeyEvents = new SparseArray<>(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5627 | |
| 5628 | public SyntheticJoystickHandler() { |
| 5629 | super(true); |
| 5630 | } |
| 5631 | |
| 5632 | @Override |
| 5633 | public void handleMessage(Message msg) { |
| 5634 | switch (msg.what) { |
| 5635 | case MSG_ENQUEUE_X_AXIS_KEY_REPEAT: |
| 5636 | case MSG_ENQUEUE_Y_AXIS_KEY_REPEAT: { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5637 | if (mAttachInfo.mHasWindowFocus) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5638 | KeyEvent oldEvent = (KeyEvent) msg.obj; |
| 5639 | KeyEvent e = KeyEvent.changeTimeRepeat(oldEvent, |
| 5640 | SystemClock.uptimeMillis(), oldEvent.getRepeatCount() + 1); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5641 | enqueueInputEvent(e); |
| 5642 | Message m = obtainMessage(msg.what, e); |
| 5643 | m.setAsynchronous(true); |
| 5644 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatDelay()); |
| 5645 | } |
| 5646 | } break; |
| 5647 | } |
| 5648 | } |
| 5649 | |
| 5650 | public void process(MotionEvent event) { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5651 | switch(event.getActionMasked()) { |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5652 | case MotionEvent.ACTION_CANCEL: |
| 5653 | cancel(); |
| 5654 | break; |
| 5655 | case MotionEvent.ACTION_MOVE: |
| 5656 | update(event); |
| 5657 | break; |
| 5658 | default: |
| 5659 | Log.w(mTag, "Unexpected action: " + event.getActionMasked()); |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5660 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5661 | } |
| 5662 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5663 | private void cancel() { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5664 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
| 5665 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5666 | for (int i = 0; i < mDeviceKeyEvents.size(); i++) { |
| 5667 | final KeyEvent keyEvent = mDeviceKeyEvents.valueAt(i); |
| 5668 | if (keyEvent != null) { |
| 5669 | enqueueInputEvent(KeyEvent.changeTimeRepeat(keyEvent, |
| 5670 | SystemClock.uptimeMillis(), 0)); |
| 5671 | } |
| 5672 | } |
| 5673 | mDeviceKeyEvents.clear(); |
| 5674 | mJoystickAxesState.resetState(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5675 | } |
| 5676 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5677 | private void update(MotionEvent event) { |
| 5678 | final int historySize = event.getHistorySize(); |
| 5679 | for (int h = 0; h < historySize; h++) { |
| 5680 | final long time = event.getHistoricalEventTime(h); |
| 5681 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_X, |
| 5682 | event.getHistoricalAxisValue(MotionEvent.AXIS_X, 0, h)); |
| 5683 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_Y, |
| 5684 | event.getHistoricalAxisValue(MotionEvent.AXIS_Y, 0, h)); |
| 5685 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_HAT_X, |
| 5686 | event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_X, 0, h)); |
| 5687 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_HAT_Y, |
| 5688 | event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_Y, 0, h)); |
| 5689 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5690 | final long time = event.getEventTime(); |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5691 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_X, |
| 5692 | event.getAxisValue(MotionEvent.AXIS_X)); |
| 5693 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_Y, |
| 5694 | event.getAxisValue(MotionEvent.AXIS_Y)); |
| 5695 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_HAT_X, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5696 | event.getAxisValue(MotionEvent.AXIS_HAT_X)); |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5697 | mJoystickAxesState.updateStateForAxis(event, time, MotionEvent.AXIS_HAT_Y, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5698 | event.getAxisValue(MotionEvent.AXIS_HAT_Y)); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5699 | } |
| 5700 | |
Siarhei Vishniakou | 461faf9 | 2017-06-26 11:24:25 -0700 | [diff] [blame] | 5701 | final class JoystickAxesState { |
| 5702 | // State machine: from neutral state (no button press) can go into |
| 5703 | // button STATE_UP_OR_LEFT or STATE_DOWN_OR_RIGHT state, emitting an ACTION_DOWN event. |
| 5704 | // From STATE_UP_OR_LEFT or STATE_DOWN_OR_RIGHT state can go into neutral state, |
| 5705 | // emitting an ACTION_UP event. |
| 5706 | private static final int STATE_UP_OR_LEFT = -1; |
| 5707 | private static final int STATE_NEUTRAL = 0; |
| 5708 | private static final int STATE_DOWN_OR_RIGHT = 1; |
| 5709 | |
| 5710 | final int[] mAxisStatesHat = {STATE_NEUTRAL, STATE_NEUTRAL}; // {AXIS_HAT_X, AXIS_HAT_Y} |
| 5711 | final int[] mAxisStatesStick = {STATE_NEUTRAL, STATE_NEUTRAL}; // {AXIS_X, AXIS_Y} |
| 5712 | |
| 5713 | void resetState() { |
| 5714 | mAxisStatesHat[0] = STATE_NEUTRAL; |
| 5715 | mAxisStatesHat[1] = STATE_NEUTRAL; |
| 5716 | mAxisStatesStick[0] = STATE_NEUTRAL; |
| 5717 | mAxisStatesStick[1] = STATE_NEUTRAL; |
| 5718 | } |
| 5719 | |
| 5720 | void updateStateForAxis(MotionEvent event, long time, int axis, float value) { |
| 5721 | // Emit KeyEvent if necessary |
| 5722 | // axis can be AXIS_X, AXIS_Y, AXIS_HAT_X, AXIS_HAT_Y |
| 5723 | final int axisStateIndex; |
| 5724 | final int repeatMessage; |
| 5725 | if (isXAxis(axis)) { |
| 5726 | axisStateIndex = 0; |
| 5727 | repeatMessage = MSG_ENQUEUE_X_AXIS_KEY_REPEAT; |
| 5728 | } else if (isYAxis(axis)) { |
| 5729 | axisStateIndex = 1; |
| 5730 | repeatMessage = MSG_ENQUEUE_Y_AXIS_KEY_REPEAT; |
| 5731 | } else { |
| 5732 | Log.e(mTag, "Unexpected axis " + axis + " in updateStateForAxis!"); |
| 5733 | return; |
| 5734 | } |
| 5735 | final int newState = joystickAxisValueToState(value); |
| 5736 | |
| 5737 | final int currentState; |
| 5738 | if (axis == MotionEvent.AXIS_X || axis == MotionEvent.AXIS_Y) { |
| 5739 | currentState = mAxisStatesStick[axisStateIndex]; |
| 5740 | } else { |
| 5741 | currentState = mAxisStatesHat[axisStateIndex]; |
| 5742 | } |
| 5743 | |
| 5744 | if (currentState == newState) { |
| 5745 | return; |
| 5746 | } |
| 5747 | |
| 5748 | final int metaState = event.getMetaState(); |
| 5749 | final int deviceId = event.getDeviceId(); |
| 5750 | final int source = event.getSource(); |
| 5751 | |
| 5752 | if (currentState == STATE_DOWN_OR_RIGHT || currentState == STATE_UP_OR_LEFT) { |
| 5753 | // send a button release event |
| 5754 | final int keyCode = joystickAxisAndStateToKeycode(axis, currentState); |
| 5755 | if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 5756 | enqueueInputEvent(new KeyEvent(time, time, KeyEvent.ACTION_UP, keyCode, |
| 5757 | 0, metaState, deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
| 5758 | // remove the corresponding pending UP event if focus lost/view detached |
| 5759 | mDeviceKeyEvents.put(deviceId, null); |
| 5760 | } |
| 5761 | removeMessages(repeatMessage); |
| 5762 | } |
| 5763 | |
| 5764 | if (newState == STATE_DOWN_OR_RIGHT || newState == STATE_UP_OR_LEFT) { |
| 5765 | // send a button down event |
| 5766 | final int keyCode = joystickAxisAndStateToKeycode(axis, newState); |
| 5767 | if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 5768 | KeyEvent keyEvent = new KeyEvent(time, time, KeyEvent.ACTION_DOWN, keyCode, |
| 5769 | 0, metaState, deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 5770 | enqueueInputEvent(keyEvent); |
| 5771 | Message m = obtainMessage(repeatMessage, keyEvent); |
| 5772 | m.setAsynchronous(true); |
| 5773 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
| 5774 | // store the corresponding ACTION_UP event so that it can be sent |
| 5775 | // if focus is lost or root view is removed |
| 5776 | mDeviceKeyEvents.put(deviceId, |
| 5777 | new KeyEvent(time, time, KeyEvent.ACTION_UP, keyCode, |
| 5778 | 0, metaState, deviceId, 0, |
| 5779 | KeyEvent.FLAG_FALLBACK | KeyEvent.FLAG_CANCELED, |
| 5780 | source)); |
| 5781 | } |
| 5782 | } |
| 5783 | if (axis == MotionEvent.AXIS_X || axis == MotionEvent.AXIS_Y) { |
| 5784 | mAxisStatesStick[axisStateIndex] = newState; |
| 5785 | } else { |
| 5786 | mAxisStatesHat[axisStateIndex] = newState; |
| 5787 | } |
| 5788 | } |
| 5789 | |
| 5790 | private boolean isXAxis(int axis) { |
| 5791 | return axis == MotionEvent.AXIS_X || axis == MotionEvent.AXIS_HAT_X; |
| 5792 | } |
| 5793 | private boolean isYAxis(int axis) { |
| 5794 | return axis == MotionEvent.AXIS_Y || axis == MotionEvent.AXIS_HAT_Y; |
| 5795 | } |
| 5796 | |
| 5797 | private int joystickAxisAndStateToKeycode(int axis, int state) { |
| 5798 | if (isXAxis(axis) && state == STATE_UP_OR_LEFT) { |
| 5799 | return KeyEvent.KEYCODE_DPAD_LEFT; |
| 5800 | } |
| 5801 | if (isXAxis(axis) && state == STATE_DOWN_OR_RIGHT) { |
| 5802 | return KeyEvent.KEYCODE_DPAD_RIGHT; |
| 5803 | } |
| 5804 | if (isYAxis(axis) && state == STATE_UP_OR_LEFT) { |
| 5805 | return KeyEvent.KEYCODE_DPAD_UP; |
| 5806 | } |
| 5807 | if (isYAxis(axis) && state == STATE_DOWN_OR_RIGHT) { |
| 5808 | return KeyEvent.KEYCODE_DPAD_DOWN; |
| 5809 | } |
| 5810 | Log.e(mTag, "Unknown axis " + axis + " or direction " + state); |
| 5811 | return KeyEvent.KEYCODE_UNKNOWN; // should never happen |
| 5812 | } |
| 5813 | |
| 5814 | private int joystickAxisValueToState(float value) { |
| 5815 | if (value >= 0.5f) { |
| 5816 | return STATE_DOWN_OR_RIGHT; |
| 5817 | } else if (value <= -0.5f) { |
| 5818 | return STATE_UP_OR_LEFT; |
| 5819 | } else { |
| 5820 | return STATE_NEUTRAL; |
| 5821 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5822 | } |
| 5823 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5824 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5825 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5826 | /** |
| 5827 | * Creates dpad events from unhandled touch navigation movements. |
| 5828 | */ |
| 5829 | final class SyntheticTouchNavigationHandler extends Handler { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5830 | private static final String LOCAL_TAG = "SyntheticTouchNavigationHandler"; |
| 5831 | private static final boolean LOCAL_DEBUG = false; |
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 | // Assumed nominal width and height in millimeters of a touch navigation pad, |
| 5834 | // if no resolution information is available from the input system. |
| 5835 | private static final float DEFAULT_WIDTH_MILLIMETERS = 48; |
| 5836 | private static final float DEFAULT_HEIGHT_MILLIMETERS = 48; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5837 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5838 | /* TODO: These constants should eventually be moved to ViewConfiguration. */ |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5839 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5840 | // The nominal distance traveled to move by one unit. |
| 5841 | private static final int TICK_DISTANCE_MILLIMETERS = 12; |
| 5842 | |
| 5843 | // Minimum and maximum fling velocity in ticks per second. |
| 5844 | // The minimum velocity should be set such that we perform enough ticks per |
| 5845 | // second that the fling appears to be fluid. For example, if we set the minimum |
| 5846 | // to 2 ticks per second, then there may be up to half a second delay between the next |
| 5847 | // to last and last ticks which is noticeably discrete and jerky. This value should |
| 5848 | // probably not be set to anything less than about 4. |
| 5849 | // If fling accuracy is a problem then consider tuning the tick distance instead. |
| 5850 | private static final float MIN_FLING_VELOCITY_TICKS_PER_SECOND = 6f; |
| 5851 | private static final float MAX_FLING_VELOCITY_TICKS_PER_SECOND = 20f; |
| 5852 | |
| 5853 | // Fling velocity decay factor applied after each new key is emitted. |
| 5854 | // This parameter controls the deceleration and overall duration of the fling. |
| 5855 | // The fling stops automatically when its velocity drops below the minimum |
| 5856 | // fling velocity defined above. |
| 5857 | private static final float FLING_TICK_DECAY = 0.8f; |
| 5858 | |
| 5859 | /* The input device that we are tracking. */ |
| 5860 | |
| 5861 | private int mCurrentDeviceId = -1; |
| 5862 | private int mCurrentSource; |
| 5863 | private boolean mCurrentDeviceSupported; |
| 5864 | |
| 5865 | /* Configuration for the current input device. */ |
| 5866 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5867 | // The scaled tick distance. A movement of this amount should generally translate |
| 5868 | // into a single dpad event in a given direction. |
| 5869 | private float mConfigTickDistance; |
| 5870 | |
| 5871 | // The minimum and maximum scaled fling velocity. |
| 5872 | private float mConfigMinFlingVelocity; |
| 5873 | private float mConfigMaxFlingVelocity; |
| 5874 | |
| 5875 | /* Tracking state. */ |
| 5876 | |
| 5877 | // The velocity tracker for detecting flings. |
| 5878 | private VelocityTracker mVelocityTracker; |
| 5879 | |
| 5880 | // The active pointer id, or -1 if none. |
| 5881 | private int mActivePointerId = -1; |
| 5882 | |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 5883 | // Location where tracking started. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5884 | private float mStartX; |
| 5885 | private float mStartY; |
| 5886 | |
| 5887 | // Most recently observed position. |
| 5888 | private float mLastX; |
| 5889 | private float mLastY; |
| 5890 | |
| 5891 | // Accumulated movement delta since the last direction key was sent. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5892 | private float mAccumulatedX; |
| 5893 | private float mAccumulatedY; |
| 5894 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5895 | // Set to true if any movement was delivered to the app. |
| 5896 | // Implies that tap slop was exceeded. |
| 5897 | private boolean mConsumedMovement; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5898 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5899 | // The most recently sent key down event. |
| 5900 | // The keycode remains set until the direction changes or a fling ends |
| 5901 | // so that repeated key events may be generated as required. |
| 5902 | private long mPendingKeyDownTime; |
| 5903 | private int mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5904 | private int mPendingKeyRepeatCount; |
| 5905 | private int mPendingKeyMetaState; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5906 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5907 | // The current fling velocity while a fling is in progress. |
| 5908 | private boolean mFlinging; |
| 5909 | private float mFlingVelocity; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5910 | |
| 5911 | public SyntheticTouchNavigationHandler() { |
| 5912 | super(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | public void process(MotionEvent event) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5916 | // Update the current device information. |
| 5917 | final long time = event.getEventTime(); |
| 5918 | final int deviceId = event.getDeviceId(); |
| 5919 | final int source = event.getSource(); |
| 5920 | if (mCurrentDeviceId != deviceId || mCurrentSource != source) { |
| 5921 | finishKeys(time); |
| 5922 | finishTracking(time); |
| 5923 | mCurrentDeviceId = deviceId; |
| 5924 | mCurrentSource = source; |
| 5925 | mCurrentDeviceSupported = false; |
| 5926 | InputDevice device = event.getDevice(); |
| 5927 | if (device != null) { |
| 5928 | // In order to support an input device, we must know certain |
| 5929 | // characteristics about it, such as its size and resolution. |
| 5930 | InputDevice.MotionRange xRange = device.getMotionRange(MotionEvent.AXIS_X); |
| 5931 | InputDevice.MotionRange yRange = device.getMotionRange(MotionEvent.AXIS_Y); |
| 5932 | if (xRange != null && yRange != null) { |
| 5933 | mCurrentDeviceSupported = true; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5934 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5935 | // Infer the resolution if it not actually known. |
| 5936 | float xRes = xRange.getResolution(); |
| 5937 | if (xRes <= 0) { |
| 5938 | xRes = xRange.getRange() / DEFAULT_WIDTH_MILLIMETERS; |
| 5939 | } |
| 5940 | float yRes = yRange.getResolution(); |
| 5941 | if (yRes <= 0) { |
| 5942 | yRes = yRange.getRange() / DEFAULT_HEIGHT_MILLIMETERS; |
| 5943 | } |
| 5944 | float nominalRes = (xRes + yRes) * 0.5f; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5945 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5946 | // Precompute all of the configuration thresholds we will need. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5947 | mConfigTickDistance = TICK_DISTANCE_MILLIMETERS * nominalRes; |
| 5948 | mConfigMinFlingVelocity = |
| 5949 | MIN_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5950 | mConfigMaxFlingVelocity = |
| 5951 | MAX_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5952 | |
| 5953 | if (LOCAL_DEBUG) { |
| 5954 | Log.d(LOCAL_TAG, "Configured device " + mCurrentDeviceId |
| 5955 | + " (" + Integer.toHexString(mCurrentSource) + "): " |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5956 | + ", mConfigTickDistance=" + mConfigTickDistance |
| 5957 | + ", mConfigMinFlingVelocity=" + mConfigMinFlingVelocity |
| 5958 | + ", mConfigMaxFlingVelocity=" + mConfigMaxFlingVelocity); |
| 5959 | } |
| 5960 | } |
| 5961 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5962 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5963 | if (!mCurrentDeviceSupported) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5964 | return; |
| 5965 | } |
| 5966 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5967 | // Handle the event. |
| 5968 | final int action = event.getActionMasked(); |
| 5969 | switch (action) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5970 | case MotionEvent.ACTION_DOWN: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5971 | boolean caughtFling = mFlinging; |
| 5972 | finishKeys(time); |
| 5973 | finishTracking(time); |
| 5974 | mActivePointerId = event.getPointerId(0); |
| 5975 | mVelocityTracker = VelocityTracker.obtain(); |
| 5976 | mVelocityTracker.addMovement(event); |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5977 | mStartX = event.getX(); |
| 5978 | mStartY = event.getY(); |
| 5979 | mLastX = mStartX; |
| 5980 | mLastY = mStartY; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5981 | mAccumulatedX = 0; |
| 5982 | mAccumulatedY = 0; |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5983 | |
| 5984 | // If we caught a fling, then pretend that the tap slop has already |
| 5985 | // been exceeded to suppress taps whose only purpose is to stop the fling. |
| 5986 | mConsumedMovement = caughtFling; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5987 | break; |
| 5988 | } |
| 5989 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5990 | case MotionEvent.ACTION_MOVE: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5991 | case MotionEvent.ACTION_UP: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5992 | if (mActivePointerId < 0) { |
| 5993 | break; |
| 5994 | } |
| 5995 | final int index = event.findPointerIndex(mActivePointerId); |
| 5996 | if (index < 0) { |
| 5997 | finishKeys(time); |
| 5998 | finishTracking(time); |
| 5999 | break; |
| 6000 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 6001 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 6002 | mVelocityTracker.addMovement(event); |
| 6003 | final float x = event.getX(index); |
| 6004 | final float y = event.getY(index); |
| 6005 | mAccumulatedX += x - mLastX; |
| 6006 | mAccumulatedY += y - mLastY; |
| 6007 | mLastX = x; |
| 6008 | mLastY = y; |
| 6009 | |
| 6010 | // Consume any accumulated movement so far. |
| 6011 | final int metaState = event.getMetaState(); |
| 6012 | consumeAccumulatedMovement(time, metaState); |
| 6013 | |
| 6014 | // Detect taps and flings. |
| 6015 | if (action == MotionEvent.ACTION_UP) { |
Michael Wright | 88d7f79 | 2013-08-27 15:45:42 -0700 | [diff] [blame] | 6016 | if (mConsumedMovement && mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 6017 | // It might be a fling. |
| 6018 | mVelocityTracker.computeCurrentVelocity(1000, mConfigMaxFlingVelocity); |
| 6019 | final float vx = mVelocityTracker.getXVelocity(mActivePointerId); |
| 6020 | final float vy = mVelocityTracker.getYVelocity(mActivePointerId); |
| 6021 | if (!startFling(time, vx, vy)) { |
| 6022 | finishKeys(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 6023 | } |
| 6024 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 6025 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 6026 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 6027 | break; |
| 6028 | } |
| 6029 | |
| 6030 | case MotionEvent.ACTION_CANCEL: { |
| 6031 | finishKeys(time); |
| 6032 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 6033 | break; |
| 6034 | } |
| 6035 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6036 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 6037 | |
| 6038 | public void cancel(MotionEvent event) { |
| 6039 | if (mCurrentDeviceId == event.getDeviceId() |
| 6040 | && mCurrentSource == event.getSource()) { |
| 6041 | final long time = event.getEventTime(); |
| 6042 | finishKeys(time); |
| 6043 | finishTracking(time); |
| 6044 | } |
| 6045 | } |
| 6046 | |
| 6047 | private void finishKeys(long time) { |
| 6048 | cancelFling(); |
| 6049 | sendKeyUp(time); |
| 6050 | } |
| 6051 | |
| 6052 | private void finishTracking(long time) { |
| 6053 | if (mActivePointerId >= 0) { |
| 6054 | mActivePointerId = -1; |
| 6055 | mVelocityTracker.recycle(); |
| 6056 | mVelocityTracker = null; |
| 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | private void consumeAccumulatedMovement(long time, int metaState) { |
| 6061 | final float absX = Math.abs(mAccumulatedX); |
| 6062 | final float absY = Math.abs(mAccumulatedY); |
| 6063 | if (absX >= absY) { |
| 6064 | if (absX >= mConfigTickDistance) { |
| 6065 | mAccumulatedX = consumeAccumulatedMovement(time, metaState, mAccumulatedX, |
| 6066 | KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT); |
| 6067 | mAccumulatedY = 0; |
| 6068 | mConsumedMovement = true; |
| 6069 | } |
| 6070 | } else { |
| 6071 | if (absY >= mConfigTickDistance) { |
| 6072 | mAccumulatedY = consumeAccumulatedMovement(time, metaState, mAccumulatedY, |
| 6073 | KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN); |
| 6074 | mAccumulatedX = 0; |
| 6075 | mConsumedMovement = true; |
| 6076 | } |
| 6077 | } |
| 6078 | } |
| 6079 | |
| 6080 | private float consumeAccumulatedMovement(long time, int metaState, |
| 6081 | float accumulator, int negativeKeyCode, int positiveKeyCode) { |
| 6082 | while (accumulator <= -mConfigTickDistance) { |
| 6083 | sendKeyDownOrRepeat(time, negativeKeyCode, metaState); |
| 6084 | accumulator += mConfigTickDistance; |
| 6085 | } |
| 6086 | while (accumulator >= mConfigTickDistance) { |
| 6087 | sendKeyDownOrRepeat(time, positiveKeyCode, metaState); |
| 6088 | accumulator -= mConfigTickDistance; |
| 6089 | } |
| 6090 | return accumulator; |
| 6091 | } |
| 6092 | |
| 6093 | private void sendKeyDownOrRepeat(long time, int keyCode, int metaState) { |
| 6094 | if (mPendingKeyCode != keyCode) { |
| 6095 | sendKeyUp(time); |
| 6096 | mPendingKeyDownTime = time; |
| 6097 | mPendingKeyCode = keyCode; |
| 6098 | mPendingKeyRepeatCount = 0; |
| 6099 | } else { |
| 6100 | mPendingKeyRepeatCount += 1; |
| 6101 | } |
| 6102 | mPendingKeyMetaState = metaState; |
| 6103 | |
| 6104 | // Note: Normally we would pass FLAG_LONG_PRESS when the repeat count is 1 |
| 6105 | // but it doesn't quite make sense when simulating the events in this way. |
| 6106 | if (LOCAL_DEBUG) { |
| 6107 | Log.d(LOCAL_TAG, "Sending key down: keyCode=" + mPendingKeyCode |
| 6108 | + ", repeatCount=" + mPendingKeyRepeatCount |
| 6109 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 6110 | } |
| 6111 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 6112 | KeyEvent.ACTION_DOWN, mPendingKeyCode, mPendingKeyRepeatCount, |
| 6113 | mPendingKeyMetaState, mCurrentDeviceId, |
| 6114 | KeyEvent.FLAG_FALLBACK, mCurrentSource)); |
| 6115 | } |
| 6116 | |
| 6117 | private void sendKeyUp(long time) { |
| 6118 | if (mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 6119 | if (LOCAL_DEBUG) { |
| 6120 | Log.d(LOCAL_TAG, "Sending key up: keyCode=" + mPendingKeyCode |
| 6121 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 6122 | } |
| 6123 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 6124 | KeyEvent.ACTION_UP, mPendingKeyCode, 0, mPendingKeyMetaState, |
| 6125 | mCurrentDeviceId, 0, KeyEvent.FLAG_FALLBACK, |
| 6126 | mCurrentSource)); |
| 6127 | mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 6128 | } |
| 6129 | } |
| 6130 | |
| 6131 | private boolean startFling(long time, float vx, float vy) { |
| 6132 | if (LOCAL_DEBUG) { |
| 6133 | Log.d(LOCAL_TAG, "Considering fling: vx=" + vx + ", vy=" + vy |
| 6134 | + ", min=" + mConfigMinFlingVelocity); |
| 6135 | } |
| 6136 | |
| 6137 | // Flings must be oriented in the same direction as the preceding movements. |
| 6138 | switch (mPendingKeyCode) { |
| 6139 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 6140 | if (-vx >= mConfigMinFlingVelocity |
| 6141 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 6142 | mFlingVelocity = -vx; |
| 6143 | break; |
| 6144 | } |
| 6145 | return false; |
| 6146 | |
| 6147 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 6148 | if (vx >= mConfigMinFlingVelocity |
| 6149 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 6150 | mFlingVelocity = vx; |
| 6151 | break; |
| 6152 | } |
| 6153 | return false; |
| 6154 | |
| 6155 | case KeyEvent.KEYCODE_DPAD_UP: |
| 6156 | if (-vy >= mConfigMinFlingVelocity |
| 6157 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 6158 | mFlingVelocity = -vy; |
| 6159 | break; |
| 6160 | } |
| 6161 | return false; |
| 6162 | |
| 6163 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 6164 | if (vy >= mConfigMinFlingVelocity |
| 6165 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 6166 | mFlingVelocity = vy; |
| 6167 | break; |
| 6168 | } |
| 6169 | return false; |
| 6170 | } |
| 6171 | |
| 6172 | // Post the first fling event. |
| 6173 | mFlinging = postFling(time); |
| 6174 | return mFlinging; |
| 6175 | } |
| 6176 | |
| 6177 | private boolean postFling(long time) { |
| 6178 | // The idea here is to estimate the time when the pointer would have |
| 6179 | // traveled one tick distance unit given the current fling velocity. |
| 6180 | // This effect creates continuity of motion. |
| 6181 | if (mFlingVelocity >= mConfigMinFlingVelocity) { |
| 6182 | long delay = (long)(mConfigTickDistance / mFlingVelocity * 1000); |
| 6183 | postAtTime(mFlingRunnable, time + delay); |
| 6184 | if (LOCAL_DEBUG) { |
| 6185 | Log.d(LOCAL_TAG, "Posted fling: velocity=" |
| 6186 | + mFlingVelocity + ", delay=" + delay |
| 6187 | + ", keyCode=" + mPendingKeyCode); |
| 6188 | } |
| 6189 | return true; |
| 6190 | } |
| 6191 | return false; |
| 6192 | } |
| 6193 | |
| 6194 | private void cancelFling() { |
| 6195 | if (mFlinging) { |
| 6196 | removeCallbacks(mFlingRunnable); |
| 6197 | mFlinging = false; |
| 6198 | } |
| 6199 | } |
| 6200 | |
| 6201 | private final Runnable mFlingRunnable = new Runnable() { |
| 6202 | @Override |
| 6203 | public void run() { |
| 6204 | final long time = SystemClock.uptimeMillis(); |
| 6205 | sendKeyDownOrRepeat(time, mPendingKeyCode, mPendingKeyMetaState); |
| 6206 | mFlingVelocity *= FLING_TICK_DECAY; |
| 6207 | if (!postFling(time)) { |
| 6208 | mFlinging = false; |
| 6209 | finishKeys(time); |
| 6210 | } |
| 6211 | } |
| 6212 | }; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6213 | } |
| 6214 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6215 | final class SyntheticKeyboardHandler { |
| 6216 | public void process(KeyEvent event) { |
| 6217 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) != 0) { |
| 6218 | return; |
| 6219 | } |
| 6220 | |
| 6221 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 6222 | final int keyCode = event.getKeyCode(); |
| 6223 | final int metaState = event.getMetaState(); |
| 6224 | |
| 6225 | // Check for fallback actions specified by the key character map. |
| 6226 | KeyCharacterMap.FallbackAction fallbackAction = |
| 6227 | kcm.getFallbackAction(keyCode, metaState); |
| 6228 | if (fallbackAction != null) { |
| 6229 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 6230 | KeyEvent fallbackEvent = KeyEvent.obtain( |
| 6231 | event.getDownTime(), event.getEventTime(), |
| 6232 | event.getAction(), fallbackAction.keyCode, |
| 6233 | event.getRepeatCount(), fallbackAction.metaState, |
| 6234 | event.getDeviceId(), event.getScanCode(), |
| 6235 | flags, event.getSource(), null); |
| 6236 | fallbackAction.recycle(); |
| 6237 | enqueueInputEvent(fallbackEvent); |
| 6238 | } |
| 6239 | } |
| 6240 | } |
| 6241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6242 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6243 | * Returns true if the key is used for keyboard navigation. |
| 6244 | * @param keyEvent The key event. |
| 6245 | * @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] | 6246 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6247 | private static boolean isNavigationKey(KeyEvent keyEvent) { |
| 6248 | switch (keyEvent.getKeyCode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6249 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 6250 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 6251 | case KeyEvent.KEYCODE_DPAD_UP: |
| 6252 | case KeyEvent.KEYCODE_DPAD_DOWN: |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6253 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6254 | case KeyEvent.KEYCODE_PAGE_UP: |
| 6255 | case KeyEvent.KEYCODE_PAGE_DOWN: |
| 6256 | case KeyEvent.KEYCODE_MOVE_HOME: |
| 6257 | case KeyEvent.KEYCODE_MOVE_END: |
| 6258 | case KeyEvent.KEYCODE_TAB: |
| 6259 | case KeyEvent.KEYCODE_SPACE: |
| 6260 | case KeyEvent.KEYCODE_ENTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6261 | return true; |
| 6262 | } |
| 6263 | return false; |
| 6264 | } |
| 6265 | |
| 6266 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6267 | * Returns true if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6268 | * @param keyEvent The key event. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6269 | * @return True if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6270 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6271 | private static boolean isTypingKey(KeyEvent keyEvent) { |
| 6272 | return keyEvent.getUnicodeChar() > 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6273 | } |
| 6274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6275 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6276 | * 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] | 6277 | * @param event The key event. |
| 6278 | * @return Whether this key event should be consumed (meaning the act of |
| 6279 | * leaving touch mode alone is considered the event). |
| 6280 | */ |
| 6281 | private boolean checkForLeavingTouchModeAndConsume(KeyEvent event) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6282 | // Only relevant in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6283 | if (!mAttachInfo.mInTouchMode) { |
| 6284 | return false; |
| 6285 | } |
| 6286 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6287 | // Only consider leaving touch mode on DOWN or MULTIPLE actions, never on UP. |
| 6288 | final int action = event.getAction(); |
| 6289 | if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_MULTIPLE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6290 | return false; |
| 6291 | } |
| 6292 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6293 | // Don't leave touch mode if the IME told us not to. |
| 6294 | if ((event.getFlags() & KeyEvent.FLAG_KEEP_TOUCH_MODE) != 0) { |
| 6295 | return false; |
| 6296 | } |
| 6297 | |
| 6298 | // If the key can be used for keyboard navigation then leave touch mode |
| 6299 | // and select a focused view if needed (in ensureTouchMode). |
| 6300 | // When a new focused view is selected, we consume the navigation key because |
| 6301 | // navigation doesn't make much sense unless a view already has focus so |
| 6302 | // the key's purpose is to set focus. |
| 6303 | if (isNavigationKey(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | return ensureTouchMode(false); |
| 6305 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6306 | |
| 6307 | // If the key can be used for typing then leave touch mode |
| 6308 | // and select a focused view if needed (in ensureTouchMode). |
| 6309 | // Always allow the view to process the typing key. |
| 6310 | if (isTypingKey(event)) { |
| 6311 | ensureTouchMode(false); |
| 6312 | return false; |
| 6313 | } |
| 6314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6315 | return false; |
| 6316 | } |
| 6317 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6318 | /* drag/drop */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 6319 | @UnsupportedAppUsage |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6320 | void setLocalDragState(Object obj) { |
| 6321 | mLocalDragState = obj; |
| 6322 | } |
| 6323 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6324 | private void handleDragEvent(DragEvent event) { |
| 6325 | // From the root, only drag start/end/location are dispatched. entered/exited |
| 6326 | // are determined and dispatched by the viewgroup hierarchy, who then report |
| 6327 | // that back here for ultimate reporting back to the framework. |
| 6328 | if (mView != null && mAdded) { |
| 6329 | final int what = event.mAction; |
| 6330 | |
Vladislav Kaznacheev | 7fe1f79 | 2016-07-14 17:15:02 -0700 | [diff] [blame] | 6331 | // Cache the drag description when the operation starts, then fill it in |
| 6332 | // on subsequent calls as a convenience |
| 6333 | if (what == DragEvent.ACTION_DRAG_STARTED) { |
| 6334 | mCurrentDragView = null; // Start the current-recipient tracking |
| 6335 | mDragDescription = event.mClipDescription; |
| 6336 | } else { |
Vladislav Kaznacheev | cd84cfa | 2016-07-26 15:17:49 -0700 | [diff] [blame] | 6337 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
| 6338 | mDragDescription = null; |
| 6339 | } |
Vladislav Kaznacheev | 7fe1f79 | 2016-07-14 17:15:02 -0700 | [diff] [blame] | 6340 | event.mClipDescription = mDragDescription; |
| 6341 | } |
| 6342 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6343 | if (what == DragEvent.ACTION_DRAG_EXITED) { |
| 6344 | // A direct EXITED event means that the window manager knows we've just crossed |
| 6345 | // 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] | 6346 | // 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] | 6347 | if (View.sCascadedDragDrop) { |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 6348 | mView.dispatchDragEnterExitInPreN(event); |
| 6349 | } |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6350 | setDragFocus(null, event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6351 | } else { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6352 | // For events with a [screen] location, translate into window coordinates |
| 6353 | if ((what == DragEvent.ACTION_DRAG_LOCATION) || (what == DragEvent.ACTION_DROP)) { |
| 6354 | mDragPoint.set(event.mX, event.mY); |
| 6355 | if (mTranslator != null) { |
| 6356 | mTranslator.translatePointInScreenToAppWindow(mDragPoint); |
| 6357 | } |
| 6358 | |
| 6359 | if (mCurScrollY != 0) { |
| 6360 | mDragPoint.offset(0, mCurScrollY); |
| 6361 | } |
| 6362 | |
| 6363 | event.mX = mDragPoint.x; |
| 6364 | event.mY = mDragPoint.y; |
| 6365 | } |
| 6366 | |
| 6367 | // Remember who the current drag target is pre-dispatch |
| 6368 | final View prevDragView = mCurrentDragView; |
| 6369 | |
Vadim Tryshev | 6973317 | 2016-09-30 17:25:30 -0700 | [diff] [blame] | 6370 | if (what == DragEvent.ACTION_DROP && event.mClipData != null) { |
| 6371 | event.mClipData.prepareToEnterProcess(); |
Vladislav Kaznacheev | 854d3f2 | 2016-08-11 10:19:36 -0700 | [diff] [blame] | 6372 | } |
| 6373 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6374 | // Now dispatch the drag/drop event |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6375 | boolean result = mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6376 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6377 | if (what == DragEvent.ACTION_DRAG_LOCATION && !event.mEventHandlerWasCalled) { |
| 6378 | // If the LOCATION event wasn't delivered to any handler, no view now has a drag |
| 6379 | // focus. |
| 6380 | setDragFocus(null, event); |
| 6381 | } |
| 6382 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6383 | // If we changed apparent drag target, tell the OS about it |
| 6384 | if (prevDragView != mCurrentDragView) { |
| 6385 | try { |
| 6386 | if (prevDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6387 | mWindowSession.dragRecipientExited(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6388 | } |
| 6389 | if (mCurrentDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6390 | mWindowSession.dragRecipientEntered(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6391 | } |
| 6392 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6393 | Slog.e(mTag, "Unable to note drag target change"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6394 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6395 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6396 | |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6397 | // Report the drop result when we're done |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6398 | if (what == DragEvent.ACTION_DROP) { |
| 6399 | try { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6400 | Log.i(mTag, "Reporting drop result: " + result); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6401 | mWindowSession.reportDropResult(mWindow, result); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6402 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6403 | Log.e(mTag, "Unable to report drop result"); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6404 | } |
| 6405 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6406 | |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 6407 | // When the drag operation ends, reset drag-related state |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6408 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6409 | mCurrentDragView = null; |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6410 | setLocalDragState(null); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 6411 | mAttachInfo.mDragToken = null; |
Vladislav Kaznacheev | 4f63974 | 2015-11-18 13:21:35 -0800 | [diff] [blame] | 6412 | if (mAttachInfo.mDragSurface != null) { |
| 6413 | mAttachInfo.mDragSurface.release(); |
| 6414 | mAttachInfo.mDragSurface = null; |
| 6415 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 6416 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6417 | } |
| 6418 | } |
| 6419 | event.recycle(); |
| 6420 | } |
| 6421 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6422 | public void handleDispatchSystemUiVisibilityChanged(SystemUiVisibilityInfo args) { |
| 6423 | if (mSeq != args.seq) { |
| 6424 | // The sequence has changed, so we need to update our value and make |
| 6425 | // sure to do a traversal afterward so the window manager is given our |
| 6426 | // most recent data. |
| 6427 | mSeq = args.seq; |
| 6428 | mAttachInfo.mForceReportNewAttributes = true; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6429 | scheduleTraversals(); |
Joe Onorato | 14782f7 | 2011-01-25 19:53:17 -0800 | [diff] [blame] | 6430 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6431 | if (mView == null) return; |
| 6432 | if (args.localChanges != 0) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6433 | mView.updateLocalSystemUiVisibility(args.localValue, args.localChanges); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6434 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6435 | |
| 6436 | int visibility = args.globalVisibility&View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 6437 | if (visibility != mAttachInfo.mGlobalSystemUiVisibility) { |
| 6438 | mAttachInfo.mGlobalSystemUiVisibility = visibility; |
| 6439 | mView.dispatchSystemUiVisibilityChanged(visibility); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 6440 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6441 | } |
| 6442 | |
Phil Weaver | 964c68e | 2016-10-27 16:22:05 -0700 | [diff] [blame] | 6443 | /** |
| 6444 | * Notify that the window title changed |
| 6445 | */ |
| 6446 | public void onWindowTitleChanged() { |
| 6447 | mAttachInfo.mForceReportNewAttributes = true; |
| 6448 | } |
| 6449 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 6450 | public void handleDispatchWindowShown() { |
| 6451 | mAttachInfo.mTreeObserver.dispatchOnWindowShown(); |
| 6452 | } |
| 6453 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 6454 | public void handleRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6455 | Bundle data = new Bundle(); |
| 6456 | ArrayList<KeyboardShortcutGroup> list = new ArrayList<>(); |
| 6457 | if (mView != null) { |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 6458 | mView.requestKeyboardShortcuts(list, deviceId); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6459 | } |
| 6460 | data.putParcelableArrayList(WindowManager.PARCEL_KEY_SHORTCUTS_ARRAY, list); |
| 6461 | try { |
| 6462 | receiver.send(0, data); |
| 6463 | } catch (RemoteException e) { |
| 6464 | } |
| 6465 | } |
| 6466 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 6467 | @UnsupportedAppUsage |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6468 | public void getLastTouchPoint(Point outLocation) { |
| 6469 | outLocation.x = (int) mLastTouchPoint.x; |
| 6470 | outLocation.y = (int) mLastTouchPoint.y; |
| 6471 | } |
| 6472 | |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 6473 | public int getLastTouchSource() { |
| 6474 | return mLastTouchSource; |
| 6475 | } |
| 6476 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6477 | public void setDragFocus(View newDragTarget, DragEvent event) { |
Vadim Tryshev | 45bee6b | 2016-09-19 11:00:37 -0700 | [diff] [blame] | 6478 | if (mCurrentDragView != newDragTarget && !View.sCascadedDragDrop) { |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6479 | // Send EXITED and ENTERED notifications to the old and new drag focus views. |
| 6480 | |
| 6481 | final float tx = event.mX; |
| 6482 | final float ty = event.mY; |
| 6483 | final int action = event.mAction; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 6484 | final ClipData td = event.mClipData; |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6485 | // Position should not be available for ACTION_DRAG_ENTERED and ACTION_DRAG_EXITED. |
| 6486 | event.mX = 0; |
| 6487 | event.mY = 0; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 6488 | event.mClipData = null; |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6489 | |
| 6490 | if (mCurrentDragView != null) { |
| 6491 | event.mAction = DragEvent.ACTION_DRAG_EXITED; |
| 6492 | mCurrentDragView.callDragEventHandler(event); |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6493 | } |
| 6494 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6495 | if (newDragTarget != null) { |
| 6496 | event.mAction = DragEvent.ACTION_DRAG_ENTERED; |
| 6497 | newDragTarget.callDragEventHandler(event); |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | event.mAction = action; |
| 6501 | event.mX = tx; |
| 6502 | event.mY = ty; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 6503 | event.mClipData = td; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6504 | } |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 6505 | |
| 6506 | mCurrentDragView = newDragTarget; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6507 | } |
| 6508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6509 | private AudioManager getAudioManager() { |
| 6510 | if (mView == null) { |
| 6511 | throw new IllegalStateException("getAudioManager called when there is no mView"); |
| 6512 | } |
| 6513 | if (mAudioManager == null) { |
| 6514 | mAudioManager = (AudioManager) mView.getContext().getSystemService(Context.AUDIO_SERVICE); |
| 6515 | } |
| 6516 | return mAudioManager; |
| 6517 | } |
| 6518 | |
Dake Gu | d9dbd27 | 2018-03-13 11:38:42 -0700 | [diff] [blame] | 6519 | private @Nullable AutofillManager getAutofillManager() { |
| 6520 | if (mView instanceof ViewGroup) { |
| 6521 | ViewGroup decorView = (ViewGroup) mView; |
| 6522 | if (decorView.getChildCount() > 0) { |
| 6523 | // We cannot use decorView's Context for querying AutofillManager: DecorView's |
| 6524 | // context is based on Application Context, it would allocate a different |
| 6525 | // AutofillManager instance. |
| 6526 | return decorView.getChildAt(0).getContext() |
| 6527 | .getSystemService(AutofillManager.class); |
| 6528 | } |
| 6529 | } |
| 6530 | return null; |
| 6531 | } |
| 6532 | |
| 6533 | private boolean isAutofillUiShowing() { |
| 6534 | AutofillManager afm = getAutofillManager(); |
| 6535 | if (afm == null) { |
| 6536 | return false; |
| 6537 | } |
| 6538 | return afm.isAutofillUiShowing(); |
| 6539 | } |
| 6540 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6541 | public AccessibilityInteractionController getAccessibilityInteractionController() { |
| 6542 | if (mView == null) { |
| 6543 | throw new IllegalStateException("getAccessibilityInteractionController" |
| 6544 | + " called when there is no mView"); |
| 6545 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 6546 | if (mAccessibilityInteractionController == null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6547 | mAccessibilityInteractionController = new AccessibilityInteractionController(this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6548 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 6549 | return mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6550 | } |
| 6551 | |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 6552 | private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility, |
| 6553 | boolean insetsPending) throws RemoteException { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6554 | |
| 6555 | float appScale = mAttachInfo.mApplicationScale; |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6556 | boolean restore = false; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6557 | if (params != null && mTranslator != null) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6558 | restore = true; |
| 6559 | params.backup(); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6560 | mTranslator.translateWindowLayout(params); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6561 | } |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 6562 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6563 | if (params != null) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6564 | if (DBG) Log.d(mTag, "WindowLayout in layoutWindow:" + params); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 6565 | |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 6566 | if (mOrigWindowType != params.type) { |
| 6567 | // For compatibility with old apps, don't crash here. |
| 6568 | if (mTargetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
| 6569 | Slog.w(mTag, "Window type can not be changed after " |
| 6570 | + "the window is added; ignoring change of " + mView); |
| 6571 | params.type = mOrigWindowType; |
| 6572 | } |
| 6573 | } |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 6574 | } |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 6575 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 6576 | long frameNumber = -1; |
| 6577 | if (mSurface.isValid()) { |
| 6578 | frameNumber = mSurface.getNextFrameNumber(); |
| 6579 | } |
| 6580 | |
| 6581 | int relayoutResult = mWindowSession.relayout(mWindow, mSeq, params, |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6582 | (int) (mView.getMeasuredWidth() * appScale + 0.5f), |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 6583 | (int) (mView.getMeasuredHeight() * appScale + 0.5f), viewVisibility, |
| 6584 | insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, frameNumber, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6585 | mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 6586 | mPendingStableInsets, mPendingOutsets, mPendingBackDropFrame, mPendingDisplayCutout, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6587 | mPendingMergedConfiguration, mSurface); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6588 | |
| 6589 | mPendingAlwaysConsumeNavBar = |
| 6590 | (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_CONSUME_ALWAYS_NAV_BAR) != 0; |
| 6591 | |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6592 | if (restore) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6593 | params.restore(); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6594 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6595 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6596 | if (mTranslator != null) { |
| 6597 | mTranslator.translateRectInScreenToAppWinFrame(mWinFrame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6598 | mTranslator.translateRectInScreenToAppWindow(mPendingOverscanInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6599 | mTranslator.translateRectInScreenToAppWindow(mPendingContentInsets); |
| 6600 | mTranslator.translateRectInScreenToAppWindow(mPendingVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 6601 | mTranslator.translateRectInScreenToAppWindow(mPendingStableInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6602 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 6603 | return relayoutResult; |
| 6604 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6605 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6606 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6607 | * {@inheritDoc} |
| 6608 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6609 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6610 | public void playSoundEffect(int effectId) { |
| 6611 | checkThread(); |
| 6612 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 6613 | try { |
| 6614 | final AudioManager audioManager = getAudioManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6615 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 6616 | switch (effectId) { |
| 6617 | case SoundEffectConstants.CLICK: |
| 6618 | audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); |
| 6619 | return; |
| 6620 | case SoundEffectConstants.NAVIGATION_DOWN: |
| 6621 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_DOWN); |
| 6622 | return; |
| 6623 | case SoundEffectConstants.NAVIGATION_LEFT: |
| 6624 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_LEFT); |
| 6625 | return; |
| 6626 | case SoundEffectConstants.NAVIGATION_RIGHT: |
| 6627 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_RIGHT); |
| 6628 | return; |
| 6629 | case SoundEffectConstants.NAVIGATION_UP: |
| 6630 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_UP); |
| 6631 | return; |
| 6632 | default: |
| 6633 | throw new IllegalArgumentException("unknown effect id " + effectId + |
| 6634 | " not defined in " + SoundEffectConstants.class.getCanonicalName()); |
| 6635 | } |
| 6636 | } catch (IllegalStateException e) { |
| 6637 | // Exception thrown by getAudioManager() when mView is null |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6638 | 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] | 6639 | e.printStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6640 | } |
| 6641 | } |
| 6642 | |
| 6643 | /** |
| 6644 | * {@inheritDoc} |
| 6645 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6646 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | public boolean performHapticFeedback(int effectId, boolean always) { |
| 6648 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6649 | return mWindowSession.performHapticFeedback(mWindow, effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6650 | } catch (RemoteException e) { |
| 6651 | return false; |
| 6652 | } |
| 6653 | } |
| 6654 | |
| 6655 | /** |
| 6656 | * {@inheritDoc} |
| 6657 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6658 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6659 | public View focusSearch(View focused, int direction) { |
| 6660 | checkThread(); |
| 6661 | if (!(mView instanceof ViewGroup)) { |
| 6662 | return null; |
| 6663 | } |
| 6664 | return FocusFinder.getInstance().findNextFocus((ViewGroup) mView, focused, direction); |
| 6665 | } |
| 6666 | |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 6667 | /** |
| 6668 | * {@inheritDoc} |
| 6669 | */ |
| 6670 | @Override |
Evan Rosky | 5722331 | 2017-02-08 14:42:45 -0800 | [diff] [blame] | 6671 | public View keyboardNavigationClusterSearch(View currentCluster, |
| 6672 | @FocusDirection int direction) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 6673 | checkThread(); |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 6674 | return FocusFinder.getInstance().findNextKeyboardNavigationCluster( |
| 6675 | mView, currentCluster, direction); |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 6676 | } |
| 6677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6678 | public void debug() { |
| 6679 | mView.debug(); |
| 6680 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6681 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6682 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 6683 | String innerPrefix = prefix + " "; |
| 6684 | writer.print(prefix); writer.println("ViewRoot:"); |
| 6685 | writer.print(innerPrefix); writer.print("mAdded="); writer.print(mAdded); |
| 6686 | writer.print(" mRemoved="); writer.println(mRemoved); |
| 6687 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputScheduled="); |
| 6688 | writer.println(mConsumeBatchedInputScheduled); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6689 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputImmediatelyScheduled="); |
| 6690 | writer.println(mConsumeBatchedInputImmediatelyScheduled); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6691 | writer.print(innerPrefix); writer.print("mPendingInputEventCount="); |
| 6692 | writer.println(mPendingInputEventCount); |
| 6693 | writer.print(innerPrefix); writer.print("mProcessInputEventsScheduled="); |
| 6694 | writer.println(mProcessInputEventsScheduled); |
| 6695 | writer.print(innerPrefix); writer.print("mTraversalScheduled="); |
| 6696 | writer.print(mTraversalScheduled); |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 6697 | writer.print(innerPrefix); writer.print("mIsAmbientMode="); |
| 6698 | writer.print(mIsAmbientMode); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6699 | if (mTraversalScheduled) { |
| 6700 | writer.print(" (barrier="); writer.print(mTraversalBarrier); writer.println(")"); |
| 6701 | } else { |
| 6702 | writer.println(); |
| 6703 | } |
| 6704 | mFirstInputStage.dump(innerPrefix, writer); |
| 6705 | |
| 6706 | mChoreographer.dump(prefix, writer); |
| 6707 | |
| 6708 | writer.print(prefix); writer.println("View Hierarchy:"); |
| 6709 | dumpViewHierarchy(innerPrefix, writer, mView); |
| 6710 | } |
| 6711 | |
| 6712 | private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) { |
| 6713 | writer.print(prefix); |
| 6714 | if (view == null) { |
| 6715 | writer.println("null"); |
| 6716 | return; |
| 6717 | } |
| 6718 | writer.println(view.toString()); |
| 6719 | if (!(view instanceof ViewGroup)) { |
| 6720 | return; |
| 6721 | } |
| 6722 | ViewGroup grp = (ViewGroup)view; |
| 6723 | final int N = grp.getChildCount(); |
| 6724 | if (N <= 0) { |
| 6725 | return; |
| 6726 | } |
| 6727 | prefix = prefix + " "; |
| 6728 | for (int i=0; i<N; i++) { |
| 6729 | dumpViewHierarchy(prefix, writer, grp.getChildAt(i)); |
| 6730 | } |
| 6731 | } |
| 6732 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 6733 | public void dumpGfxInfo(int[] info) { |
Romain Guy | 54ab347 | 2012-06-14 12:52:53 -0700 | [diff] [blame] | 6734 | info[0] = info[1] = 0; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6735 | if (mView != null) { |
| 6736 | getGfxInfo(mView, info); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6737 | } |
| 6738 | } |
| 6739 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6740 | private static void getGfxInfo(View view, int[] info) { |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 6741 | RenderNode renderNode = view.mRenderNode; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6742 | info[0]++; |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 6743 | if (renderNode != null) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 6744 | info[1] += renderNode.getDebugSize(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6745 | } |
| 6746 | |
| 6747 | if (view instanceof ViewGroup) { |
| 6748 | ViewGroup group = (ViewGroup) view; |
| 6749 | |
| 6750 | int count = group.getChildCount(); |
| 6751 | for (int i = 0; i < count; i++) { |
| 6752 | getGfxInfo(group.getChildAt(i), info); |
| 6753 | } |
| 6754 | } |
| 6755 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6756 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6757 | /** |
| 6758 | * @param immediate True, do now if not in traversal. False, put on queue and do later. |
| 6759 | * @return True, request has been queued. False, request has been completed. |
| 6760 | */ |
| 6761 | boolean die(boolean immediate) { |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 6762 | // Make sure we do execute immediately if we are in the middle of a traversal or the damage |
| 6763 | // done by dispatchDetachedFromWindow will cause havoc on return. |
| 6764 | if (immediate && !mIsInTraversal) { |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 6765 | doDie(); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6766 | return false; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 6767 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6768 | |
| 6769 | if (!mIsDrawing) { |
| 6770 | destroyHardwareRenderer(); |
| 6771 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6772 | Log.e(mTag, "Attempting to destroy the window while drawing!\n" + |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6773 | " window=" + this + ", title=" + mWindowAttributes.getTitle()); |
| 6774 | } |
| 6775 | mHandler.sendEmptyMessage(MSG_DIE); |
| 6776 | return true; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 6777 | } |
| 6778 | |
| 6779 | void doDie() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6780 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6781 | 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] | 6782 | synchronized (this) { |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6783 | if (mRemoved) { |
| 6784 | return; |
| 6785 | } |
| 6786 | mRemoved = true; |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 6787 | if (mAdded) { |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 6788 | dispatchDetachedFromWindow(); |
| 6789 | } |
| 6790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | if (mAdded && !mFirst) { |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 6792 | destroyHardwareRenderer(); |
| 6793 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6794 | if (mView != null) { |
| 6795 | int viewVisibility = mView.getVisibility(); |
| 6796 | boolean viewVisibilityChanged = mViewVisibility != viewVisibility; |
| 6797 | if (mWindowAttributesChanged || viewVisibilityChanged) { |
| 6798 | // If layout params have been changed, first give them |
| 6799 | // to the window manager to make sure it has the correct |
| 6800 | // animation info. |
| 6801 | try { |
| 6802 | if ((relayoutWindow(mWindowAttributes, viewVisibility, false) |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6803 | & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
| 6804 | mWindowSession.finishDrawing(mWindow); |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6805 | } |
| 6806 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6807 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6808 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6809 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6810 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6811 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6812 | } |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6813 | |
| 6814 | mAdded = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6815 | } |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 6816 | WindowManagerGlobal.getInstance().doRemoveView(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6817 | } |
| 6818 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6819 | public void requestUpdateConfiguration(Configuration config) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6820 | Message msg = mHandler.obtainMessage(MSG_UPDATE_CONFIGURATION, config); |
| 6821 | mHandler.sendMessage(msg); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6822 | } |
| 6823 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 6824 | public void loadSystemProperties() { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6825 | mHandler.post(new Runnable() { |
| 6826 | @Override |
| 6827 | public void run() { |
| 6828 | // Profiling |
| 6829 | mProfileRendering = SystemProperties.getBoolean(PROPERTY_PROFILE_RENDERING, false); |
| 6830 | profileRendering(mAttachInfo.mHasWindowFocus); |
| 6831 | |
| 6832 | // Hardware rendering |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 6833 | if (mAttachInfo.mThreadedRenderer != null) { |
| 6834 | if (mAttachInfo.mThreadedRenderer.loadSystemProperties()) { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6835 | invalidate(); |
| 6836 | } |
| 6837 | } |
| 6838 | |
| 6839 | // Layout debugging |
Kiyoung Kim | 89052d9 | 2018-12-20 18:26:10 +0900 | [diff] [blame] | 6840 | boolean layout = DisplayProperties.debug_layout().orElse(false); |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6841 | if (layout != mAttachInfo.mDebugLayout) { |
| 6842 | mAttachInfo.mDebugLayout = layout; |
| 6843 | if (!mHandler.hasMessages(MSG_INVALIDATE_WORLD)) { |
| 6844 | mHandler.sendEmptyMessageDelayed(MSG_INVALIDATE_WORLD, 200); |
| 6845 | } |
| 6846 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 6847 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6848 | }); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 6849 | } |
| 6850 | |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 6851 | private void destroyHardwareRenderer() { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 6852 | ThreadedRenderer hardwareRenderer = mAttachInfo.mThreadedRenderer; |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6853 | |
| 6854 | if (hardwareRenderer != null) { |
| 6855 | if (mView != null) { |
| 6856 | hardwareRenderer.destroyHardwareResources(mView); |
| 6857 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 6858 | hardwareRenderer.destroy(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6859 | hardwareRenderer.setRequested(false); |
| 6860 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 6861 | mAttachInfo.mThreadedRenderer = null; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6862 | mAttachInfo.mHardwareAccelerated = false; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 6863 | } |
| 6864 | } |
| 6865 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 6866 | @UnsupportedAppUsage |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6867 | private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6868 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6869 | MergedConfiguration mergedConfiguration, Rect backDropFrame, boolean forceLayout, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 6870 | boolean alwaysConsumeNavBar, int displayId, |
| 6871 | DisplayCutout.ParcelableWrapper displayCutout) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6872 | if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString() |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6873 | + " contentInsets=" + contentInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6874 | + " visibleInsets=" + visibleInsets.toShortString() |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 6875 | + " reportDraw=" + reportDraw |
| 6876 | + " backDropFrame=" + backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 6877 | |
| 6878 | // Tell all listeners that we are resizing the window so that the chrome can get |
| 6879 | // updated as fast as possible on a separate thread, |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 6880 | if (mDragResizing && mUseMTRenderer) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 6881 | boolean fullscreen = frame.equals(backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 6882 | synchronized (mWindowCallbacks) { |
| 6883 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 6884 | mWindowCallbacks.get(i).onWindowSizeIsChanging(backDropFrame, fullscreen, |
| 6885 | visibleInsets, stableInsets); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 6886 | } |
| 6887 | } |
| 6888 | } |
| 6889 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6890 | Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6891 | if (mTranslator != null) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6892 | mTranslator.translateRectInScreenToAppWindow(frame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6893 | mTranslator.translateRectInScreenToAppWindow(overscanInsets); |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 6894 | mTranslator.translateRectInScreenToAppWindow(contentInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6895 | mTranslator.translateRectInScreenToAppWindow(visibleInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6896 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6897 | SomeArgs args = SomeArgs.obtain(); |
| 6898 | final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid()); |
| 6899 | args.arg1 = sameProcessCall ? new Rect(frame) : frame; |
| 6900 | args.arg2 = sameProcessCall ? new Rect(contentInsets) : contentInsets; |
| 6901 | args.arg3 = sameProcessCall ? new Rect(visibleInsets) : visibleInsets; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6902 | args.arg4 = sameProcessCall && mergedConfiguration != null |
Wale Ogunwale | cdc8ada | 2017-03-30 13:55:36 -0700 | [diff] [blame] | 6903 | ? new MergedConfiguration(mergedConfiguration) : mergedConfiguration; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6904 | args.arg5 = sameProcessCall ? new Rect(overscanInsets) : overscanInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 6905 | args.arg6 = sameProcessCall ? new Rect(stableInsets) : stableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6906 | args.arg7 = sameProcessCall ? new Rect(outsets) : outsets; |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 6907 | args.arg8 = sameProcessCall ? new Rect(backDropFrame) : backDropFrame; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 6908 | args.arg9 = displayCutout.get(); // DisplayCutout is immutable. |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 6909 | args.argi1 = forceLayout ? 1 : 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6910 | args.argi2 = alwaysConsumeNavBar ? 1 : 0; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6911 | args.argi3 = displayId; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6912 | msg.obj = args; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6913 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6914 | } |
Chet Haase | 1f4786b | 2011-11-02 10:51:52 -0700 | [diff] [blame] | 6915 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 6916 | public void dispatchMoved(int newX, int newY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6917 | 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] | 6918 | if (mTranslator != null) { |
| 6919 | PointF point = new PointF(newX, newY); |
| 6920 | mTranslator.translatePointInScreenToAppWindow(point); |
| 6921 | newX = (int) (point.x + 0.5); |
| 6922 | newY = (int) (point.y + 0.5); |
| 6923 | } |
| 6924 | Message msg = mHandler.obtainMessage(MSG_WINDOW_MOVED, newX, newY); |
| 6925 | mHandler.sendMessage(msg); |
| 6926 | } |
| 6927 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6928 | /** |
| 6929 | * Represents a pending input event that is waiting in a queue. |
| 6930 | * |
| 6931 | * Input events are processed in serial order by the timestamp specified by |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 6932 | * {@link InputEvent#getEventTimeNano()}. In general, the input dispatcher delivers |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6933 | * one input event to the application at a time and waits for the application |
| 6934 | * to finish handling it before delivering the next one. |
| 6935 | * |
| 6936 | * However, because the application or IME can synthesize and inject multiple |
| 6937 | * key events at a time without going through the input dispatcher, we end up |
| 6938 | * needing a queue on the application's side. |
| 6939 | */ |
| 6940 | private static final class QueuedInputEvent { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6941 | public static final int FLAG_DELIVER_POST_IME = 1 << 0; |
| 6942 | public static final int FLAG_DEFERRED = 1 << 1; |
| 6943 | public static final int FLAG_FINISHED = 1 << 2; |
| 6944 | public static final int FLAG_FINISHED_HANDLED = 1 << 3; |
| 6945 | public static final int FLAG_RESYNTHESIZED = 1 << 4; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6946 | public static final int FLAG_UNHANDLED = 1 << 5; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6947 | |
| 6948 | public QueuedInputEvent mNext; |
| 6949 | |
| 6950 | public InputEvent mEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6951 | public InputEventReceiver mReceiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6952 | public int mFlags; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6953 | |
| 6954 | public boolean shouldSkipIme() { |
| 6955 | if ((mFlags & FLAG_DELIVER_POST_IME) != 0) { |
| 6956 | return true; |
| 6957 | } |
| 6958 | return mEvent instanceof MotionEvent |
Prashant Malani | fecbc67 | 2016-07-22 15:38:05 -0700 | [diff] [blame] | 6959 | && (mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER) |
| 6960 | || mEvent.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6961 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6962 | |
| 6963 | public boolean shouldSendToSynthesizer() { |
| 6964 | if ((mFlags & FLAG_UNHANDLED) != 0) { |
| 6965 | return true; |
| 6966 | } |
| 6967 | |
| 6968 | return false; |
| 6969 | } |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 6970 | |
| 6971 | @Override |
| 6972 | public String toString() { |
| 6973 | StringBuilder sb = new StringBuilder("QueuedInputEvent{flags="); |
| 6974 | boolean hasPrevious = false; |
| 6975 | hasPrevious = flagToString("DELIVER_POST_IME", FLAG_DELIVER_POST_IME, hasPrevious, sb); |
| 6976 | hasPrevious = flagToString("DEFERRED", FLAG_DEFERRED, hasPrevious, sb); |
| 6977 | hasPrevious = flagToString("FINISHED", FLAG_FINISHED, hasPrevious, sb); |
| 6978 | hasPrevious = flagToString("FINISHED_HANDLED", FLAG_FINISHED_HANDLED, hasPrevious, sb); |
| 6979 | hasPrevious = flagToString("RESYNTHESIZED", FLAG_RESYNTHESIZED, hasPrevious, sb); |
| 6980 | hasPrevious = flagToString("UNHANDLED", FLAG_UNHANDLED, hasPrevious, sb); |
| 6981 | if (!hasPrevious) { |
| 6982 | sb.append("0"); |
| 6983 | } |
| 6984 | sb.append(", hasNextQueuedEvent=" + (mEvent != null ? "true" : "false")); |
| 6985 | sb.append(", hasInputEventReceiver=" + (mReceiver != null ? "true" : "false")); |
| 6986 | sb.append(", mEvent=" + mEvent + "}"); |
| 6987 | return sb.toString(); |
| 6988 | } |
| 6989 | |
| 6990 | private boolean flagToString(String name, int flag, |
| 6991 | boolean hasPrevious, StringBuilder sb) { |
| 6992 | if ((mFlags & flag) != 0) { |
| 6993 | if (hasPrevious) { |
| 6994 | sb.append("|"); |
| 6995 | } |
| 6996 | sb.append(name); |
| 6997 | return true; |
| 6998 | } |
| 6999 | return hasPrevious; |
| 7000 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7001 | } |
| 7002 | |
| 7003 | private QueuedInputEvent obtainQueuedInputEvent(InputEvent event, |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7004 | InputEventReceiver receiver, int flags) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7005 | QueuedInputEvent q = mQueuedInputEventPool; |
| 7006 | if (q != null) { |
| 7007 | mQueuedInputEventPoolSize -= 1; |
| 7008 | mQueuedInputEventPool = q.mNext; |
| 7009 | q.mNext = null; |
| 7010 | } else { |
| 7011 | q = new QueuedInputEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7012 | } |
| 7013 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7014 | q.mEvent = event; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7015 | q.mReceiver = receiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7016 | q.mFlags = flags; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7017 | return q; |
| 7018 | } |
| 7019 | |
| 7020 | private void recycleQueuedInputEvent(QueuedInputEvent q) { |
| 7021 | q.mEvent = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7022 | q.mReceiver = null; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7023 | |
| 7024 | if (mQueuedInputEventPoolSize < MAX_QUEUED_INPUT_EVENT_POOL_SIZE) { |
| 7025 | mQueuedInputEventPoolSize += 1; |
| 7026 | q.mNext = mQueuedInputEventPool; |
| 7027 | mQueuedInputEventPool = q; |
| 7028 | } |
| 7029 | } |
| 7030 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7031 | @UnsupportedAppUsage |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 7032 | void enqueueInputEvent(InputEvent event) { |
| 7033 | enqueueInputEvent(event, null, 0, false); |
| 7034 | } |
| 7035 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7036 | @UnsupportedAppUsage |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7037 | void enqueueInputEvent(InputEvent event, |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 7038 | InputEventReceiver receiver, int flags, boolean processImmediately) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 7039 | adjustInputEventForCompatibility(event); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7040 | QueuedInputEvent q = obtainQueuedInputEvent(event, receiver, flags); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7041 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7042 | // Always enqueue the input event in order, regardless of its time stamp. |
| 7043 | // We do this because the application or the IME may inject key events |
| 7044 | // in response to touch events and we want to ensure that the injected keys |
| 7045 | // are processed in the order they were received and we cannot trust that |
| 7046 | // the time stamp of injected events are monotonic. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7047 | QueuedInputEvent last = mPendingInputEventTail; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7048 | if (last == null) { |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7049 | mPendingInputEventHead = q; |
| 7050 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7051 | } else { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7052 | last.mNext = q; |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7053 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7054 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 7055 | mPendingInputEventCount += 1; |
| 7056 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 7057 | mPendingInputEventCount); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7058 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 7059 | if (processImmediately) { |
| 7060 | doProcessInputEvents(); |
| 7061 | } else { |
| 7062 | scheduleProcessInputEvents(); |
| 7063 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7064 | } |
| 7065 | |
| 7066 | private void scheduleProcessInputEvents() { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 7067 | if (!mProcessInputEventsScheduled) { |
| 7068 | mProcessInputEventsScheduled = true; |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7069 | Message msg = mHandler.obtainMessage(MSG_PROCESS_INPUT_EVENTS); |
| 7070 | msg.setAsynchronous(true); |
| 7071 | mHandler.sendMessage(msg); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7072 | } |
| 7073 | } |
| 7074 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7075 | void doProcessInputEvents() { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7076 | // Deliver all pending input events in the queue. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7077 | while (mPendingInputEventHead != null) { |
| 7078 | QueuedInputEvent q = mPendingInputEventHead; |
| 7079 | mPendingInputEventHead = q.mNext; |
| 7080 | if (mPendingInputEventHead == null) { |
| 7081 | mPendingInputEventTail = null; |
| 7082 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7083 | q.mNext = null; |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 7084 | |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 7085 | mPendingInputEventCount -= 1; |
| 7086 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 7087 | mPendingInputEventCount); |
| 7088 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 7089 | long eventTime = q.mEvent.getEventTimeNano(); |
| 7090 | long oldestEventTime = eventTime; |
| 7091 | if (q.mEvent instanceof MotionEvent) { |
| 7092 | MotionEvent me = (MotionEvent)q.mEvent; |
| 7093 | if (me.getHistorySize() > 0) { |
| 7094 | oldestEventTime = me.getHistoricalEventTimeNano(0); |
| 7095 | } |
| 7096 | } |
| 7097 | mChoreographer.mFrameInfo.updateInputEventTime(eventTime, oldestEventTime); |
| 7098 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7099 | deliverInputEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | // We are done processing all input events that we can process right now |
| 7103 | // so we can clear the pending flag immediately. |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 7104 | if (mProcessInputEventsScheduled) { |
| 7105 | mProcessInputEventsScheduled = false; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7106 | mHandler.removeMessages(MSG_PROCESS_INPUT_EVENTS); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7107 | } |
| 7108 | } |
| 7109 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7110 | private void deliverInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 7111 | Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 7112 | q.mEvent.getSequenceNumber()); |
| 7113 | if (mInputEventConsistencyVerifier != null) { |
| 7114 | mInputEventConsistencyVerifier.onInputEvent(q.mEvent, 0); |
| 7115 | } |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 7116 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7117 | InputStage stage; |
| 7118 | if (q.shouldSendToSynthesizer()) { |
| 7119 | stage = mSyntheticInputStage; |
| 7120 | } else { |
| 7121 | stage = q.shouldSkipIme() ? mFirstPostImeInputStage : mFirstInputStage; |
| 7122 | } |
| 7123 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 7124 | if (q.mEvent instanceof KeyEvent) { |
| 7125 | mUnhandledKeyManager.preDispatch((KeyEvent) q.mEvent); |
| 7126 | } |
| 7127 | |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 7128 | if (stage != null) { |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 7129 | handleWindowFocusChanged(); |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 7130 | stage.deliver(q); |
| 7131 | } else { |
| 7132 | finishInputEvent(q); |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 7133 | } |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 7134 | } |
| 7135 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7136 | private void finishInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 7137 | Trace.asyncTraceEnd(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 7138 | q.mEvent.getSequenceNumber()); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7139 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7140 | if (q.mReceiver != null) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7141 | boolean handled = (q.mFlags & QueuedInputEvent.FLAG_FINISHED_HANDLED) != 0; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7142 | q.mReceiver.finishInputEvent(q.mEvent, handled); |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 7143 | } else { |
| 7144 | q.mEvent.recycleIfNeededAfterDispatch(); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | recycleQueuedInputEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 7148 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7149 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 7150 | private void adjustInputEventForCompatibility(InputEvent e) { |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 7151 | if (mTargetSdkVersion < Build.VERSION_CODES.M && e instanceof MotionEvent) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 7152 | MotionEvent motion = (MotionEvent) e; |
| 7153 | final int mask = |
| 7154 | MotionEvent.BUTTON_STYLUS_PRIMARY | MotionEvent.BUTTON_STYLUS_SECONDARY; |
| 7155 | final int buttonState = motion.getButtonState(); |
| 7156 | final int compatButtonState = (buttonState & mask) >> 4; |
| 7157 | if (compatButtonState != 0) { |
| 7158 | motion.setButtonState(buttonState | compatButtonState); |
| 7159 | } |
| 7160 | } |
| 7161 | } |
| 7162 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 7163 | static boolean isTerminalInputEvent(InputEvent event) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 7164 | if (event instanceof KeyEvent) { |
| 7165 | final KeyEvent keyEvent = (KeyEvent)event; |
| 7166 | return keyEvent.getAction() == KeyEvent.ACTION_UP; |
| 7167 | } else { |
| 7168 | final MotionEvent motionEvent = (MotionEvent)event; |
| 7169 | final int action = motionEvent.getAction(); |
| 7170 | return action == MotionEvent.ACTION_UP |
| 7171 | || action == MotionEvent.ACTION_CANCEL |
| 7172 | || action == MotionEvent.ACTION_HOVER_EXIT; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 7173 | } |
| 7174 | } |
| 7175 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7176 | void scheduleConsumeBatchedInput() { |
| 7177 | if (!mConsumeBatchedInputScheduled) { |
| 7178 | mConsumeBatchedInputScheduled = true; |
| 7179 | mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, |
| 7180 | mConsumedBatchedInputRunnable, null); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 7181 | } |
| 7182 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7183 | |
| 7184 | void unscheduleConsumeBatchedInput() { |
| 7185 | if (mConsumeBatchedInputScheduled) { |
| 7186 | mConsumeBatchedInputScheduled = false; |
| 7187 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT, |
| 7188 | mConsumedBatchedInputRunnable, null); |
| 7189 | } |
| 7190 | } |
| 7191 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7192 | void scheduleConsumeBatchedInputImmediately() { |
| 7193 | if (!mConsumeBatchedInputImmediatelyScheduled) { |
| 7194 | unscheduleConsumeBatchedInput(); |
| 7195 | mConsumeBatchedInputImmediatelyScheduled = true; |
| 7196 | mHandler.post(mConsumeBatchedInputImmediatelyRunnable); |
| 7197 | } |
| 7198 | } |
| 7199 | |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 7200 | void doConsumeBatchedInput(long frameTimeNanos) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7201 | if (mConsumeBatchedInputScheduled) { |
| 7202 | mConsumeBatchedInputScheduled = false; |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 7203 | if (mInputEventReceiver != null) { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7204 | if (mInputEventReceiver.consumeBatchedInputEvents(frameTimeNanos) |
| 7205 | && frameTimeNanos != -1) { |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 7206 | // If we consumed a batch here, we want to go ahead and schedule the |
| 7207 | // consumption of batched input events on the next frame. Otherwise, we would |
| 7208 | // 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] | 7209 | // things occurring in the process. If the frame time is -1, however, then |
| 7210 | // 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] | 7211 | scheduleConsumeBatchedInput(); |
| 7212 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7213 | } |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 7214 | doProcessInputEvents(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7215 | } |
| 7216 | } |
| 7217 | |
| 7218 | final class TraversalRunnable implements Runnable { |
| 7219 | @Override |
| 7220 | public void run() { |
| 7221 | doTraversal(); |
| 7222 | } |
| 7223 | } |
| 7224 | final TraversalRunnable mTraversalRunnable = new TraversalRunnable(); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 7225 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7226 | final class WindowInputEventReceiver extends InputEventReceiver { |
| 7227 | public WindowInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 7228 | super(inputChannel, looper); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7229 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7230 | |
| 7231 | @Override |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 7232 | public void onInputEvent(InputEvent event, int displayId) { |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 7233 | enqueueInputEvent(event, this, 0, true); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7234 | } |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 7235 | |
| 7236 | @Override |
| 7237 | public void onBatchedInputEventPending() { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7238 | if (mUnbufferedInputDispatch) { |
| 7239 | super.onBatchedInputEventPending(); |
| 7240 | } else { |
| 7241 | scheduleConsumeBatchedInput(); |
| 7242 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7243 | } |
| 7244 | |
| 7245 | @Override |
| 7246 | public void dispose() { |
| 7247 | unscheduleConsumeBatchedInput(); |
| 7248 | super.dispose(); |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 7249 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 7250 | } |
| 7251 | WindowInputEventReceiver mInputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7253 | final class ConsumeBatchedInputRunnable implements Runnable { |
| 7254 | @Override |
| 7255 | public void run() { |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 7256 | doConsumeBatchedInput(mChoreographer.getFrameTimeNanos()); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7257 | } |
| 7258 | } |
| 7259 | final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable = |
| 7260 | new ConsumeBatchedInputRunnable(); |
| 7261 | boolean mConsumeBatchedInputScheduled; |
| 7262 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 7263 | final class ConsumeBatchedInputImmediatelyRunnable implements Runnable { |
| 7264 | @Override |
| 7265 | public void run() { |
| 7266 | doConsumeBatchedInput(-1); |
| 7267 | } |
| 7268 | } |
| 7269 | final ConsumeBatchedInputImmediatelyRunnable mConsumeBatchedInputImmediatelyRunnable = |
| 7270 | new ConsumeBatchedInputImmediatelyRunnable(); |
| 7271 | boolean mConsumeBatchedInputImmediatelyScheduled; |
| 7272 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7273 | final class InvalidateOnAnimationRunnable implements Runnable { |
| 7274 | private boolean mPosted; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7275 | private final ArrayList<View> mViews = new ArrayList<View>(); |
| 7276 | private final ArrayList<AttachInfo.InvalidateInfo> mViewRects = |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7277 | new ArrayList<AttachInfo.InvalidateInfo>(); |
| 7278 | private View[] mTempViews; |
| 7279 | private AttachInfo.InvalidateInfo[] mTempViewRects; |
| 7280 | |
| 7281 | public void addView(View view) { |
| 7282 | synchronized (this) { |
| 7283 | mViews.add(view); |
| 7284 | postIfNeededLocked(); |
| 7285 | } |
| 7286 | } |
| 7287 | |
| 7288 | public void addViewRect(AttachInfo.InvalidateInfo info) { |
| 7289 | synchronized (this) { |
| 7290 | mViewRects.add(info); |
| 7291 | postIfNeededLocked(); |
| 7292 | } |
| 7293 | } |
| 7294 | |
| 7295 | public void removeView(View view) { |
| 7296 | synchronized (this) { |
| 7297 | mViews.remove(view); |
| 7298 | |
| 7299 | for (int i = mViewRects.size(); i-- > 0; ) { |
| 7300 | AttachInfo.InvalidateInfo info = mViewRects.get(i); |
| 7301 | if (info.target == view) { |
| 7302 | mViewRects.remove(i); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 7303 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7304 | } |
| 7305 | } |
| 7306 | |
| 7307 | if (mPosted && mViews.isEmpty() && mViewRects.isEmpty()) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7308 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7309 | mPosted = false; |
| 7310 | } |
| 7311 | } |
| 7312 | } |
| 7313 | |
| 7314 | @Override |
| 7315 | public void run() { |
| 7316 | final int viewCount; |
| 7317 | final int viewRectCount; |
| 7318 | synchronized (this) { |
| 7319 | mPosted = false; |
| 7320 | |
| 7321 | viewCount = mViews.size(); |
| 7322 | if (viewCount != 0) { |
| 7323 | mTempViews = mViews.toArray(mTempViews != null |
| 7324 | ? mTempViews : new View[viewCount]); |
| 7325 | mViews.clear(); |
| 7326 | } |
| 7327 | |
| 7328 | viewRectCount = mViewRects.size(); |
| 7329 | if (viewRectCount != 0) { |
| 7330 | mTempViewRects = mViewRects.toArray(mTempViewRects != null |
| 7331 | ? mTempViewRects : new AttachInfo.InvalidateInfo[viewRectCount]); |
| 7332 | mViewRects.clear(); |
| 7333 | } |
| 7334 | } |
| 7335 | |
| 7336 | for (int i = 0; i < viewCount; i++) { |
| 7337 | mTempViews[i].invalidate(); |
Adam Powell | 3e3c4ee | 2012-05-16 17:34:21 -0700 | [diff] [blame] | 7338 | mTempViews[i] = null; |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7339 | } |
| 7340 | |
| 7341 | for (int i = 0; i < viewRectCount; i++) { |
| 7342 | final View.AttachInfo.InvalidateInfo info = mTempViewRects[i]; |
| 7343 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 7344 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7345 | } |
| 7346 | } |
| 7347 | |
| 7348 | private void postIfNeededLocked() { |
| 7349 | if (!mPosted) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 7350 | mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7351 | mPosted = true; |
| 7352 | } |
| 7353 | } |
| 7354 | } |
| 7355 | final InvalidateOnAnimationRunnable mInvalidateOnAnimationRunnable = |
| 7356 | new InvalidateOnAnimationRunnable(); |
| 7357 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7358 | public void dispatchInvalidateDelayed(View view, long delayMilliseconds) { |
| 7359 | Message msg = mHandler.obtainMessage(MSG_INVALIDATE, view); |
| 7360 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 7361 | } |
| 7362 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7363 | public void dispatchInvalidateRectDelayed(AttachInfo.InvalidateInfo info, |
| 7364 | long delayMilliseconds) { |
| 7365 | final Message msg = mHandler.obtainMessage(MSG_INVALIDATE_RECT, info); |
| 7366 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 7367 | } |
| 7368 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7369 | public void dispatchInvalidateOnAnimation(View view) { |
| 7370 | mInvalidateOnAnimationRunnable.addView(view); |
| 7371 | } |
| 7372 | |
| 7373 | public void dispatchInvalidateRectOnAnimation(AttachInfo.InvalidateInfo info) { |
| 7374 | mInvalidateOnAnimationRunnable.addViewRect(info); |
| 7375 | } |
| 7376 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7377 | @UnsupportedAppUsage |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 7378 | public void cancelInvalidate(View view) { |
| 7379 | mHandler.removeMessages(MSG_INVALIDATE, view); |
| 7380 | // fixme: might leak the AttachInfo.InvalidateInfo objects instead of returning |
| 7381 | // them to the pool |
| 7382 | mHandler.removeMessages(MSG_INVALIDATE_RECT, view); |
| 7383 | mInvalidateOnAnimationRunnable.removeView(view); |
| 7384 | } |
| 7385 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7386 | @UnsupportedAppUsage |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 7387 | public void dispatchInputEvent(InputEvent event) { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 7388 | dispatchInputEvent(event, null); |
| 7389 | } |
| 7390 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7391 | @UnsupportedAppUsage |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 7392 | public void dispatchInputEvent(InputEvent event, InputEventReceiver receiver) { |
| 7393 | SomeArgs args = SomeArgs.obtain(); |
| 7394 | args.arg1 = event; |
| 7395 | args.arg2 = receiver; |
| 7396 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_INPUT_EVENT, args); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 7397 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7398 | mHandler.sendMessage(msg); |
| 7399 | } |
| 7400 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7401 | public void synthesizeInputEvent(InputEvent event) { |
| 7402 | Message msg = mHandler.obtainMessage(MSG_SYNTHESIZE_INPUT_EVENT, event); |
| 7403 | msg.setAsynchronous(true); |
| 7404 | mHandler.sendMessage(msg); |
| 7405 | } |
| 7406 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7407 | @UnsupportedAppUsage |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7408 | public void dispatchKeyFromIme(KeyEvent event) { |
| 7409 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_KEY_FROM_IME, event); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 7410 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7411 | mHandler.sendMessage(msg); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7412 | } |
| 7413 | |
Dake Gu | 6a20a19 | 2018-02-08 12:09:30 -0800 | [diff] [blame] | 7414 | public void dispatchKeyFromAutofill(KeyEvent event) { |
| 7415 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_KEY_FROM_AUTOFILL, event); |
| 7416 | msg.setAsynchronous(true); |
| 7417 | mHandler.sendMessage(msg); |
| 7418 | } |
| 7419 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7420 | /** |
| 7421 | * Reinject unhandled {@link InputEvent}s in order to synthesize fallbacks events. |
| 7422 | * |
| 7423 | * Note that it is the responsibility of the caller of this API to recycle the InputEvent it |
| 7424 | * passes in. |
| 7425 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 7426 | @UnsupportedAppUsage |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 7427 | public void dispatchUnhandledInputEvent(InputEvent event) { |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7428 | if (event instanceof MotionEvent) { |
| 7429 | event = MotionEvent.obtain((MotionEvent) event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 7430 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 7431 | synthesizeInputEvent(event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 7432 | } |
| 7433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7434 | public void dispatchAppVisibility(boolean visible) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7435 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_APP_VISIBILITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7436 | msg.arg1 = visible ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7437 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7438 | } |
| 7439 | |
| 7440 | public void dispatchGetNewSurface() { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7441 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_GET_NEW_SURFACE); |
| 7442 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 7446 | synchronized (this) { |
Dianne Hackborn | 011944c | 2017-12-15 15:44:55 -0800 | [diff] [blame] | 7447 | mWindowFocusChanged = true; |
Dianne Hackborn | 5c3296a | 2017-12-13 17:52:26 -0800 | [diff] [blame] | 7448 | mUpcomingWindowFocus = hasFocus; |
| 7449 | mUpcomingInTouchMode = inTouchMode; |
| 7450 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7451 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7452 | msg.what = MSG_WINDOW_FOCUS_CHANGED; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7453 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7454 | } |
| 7455 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 7456 | public void dispatchWindowShown() { |
| 7457 | mHandler.sendEmptyMessage(MSG_DISPATCH_WINDOW_SHOWN); |
| 7458 | } |
| 7459 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7460 | public void dispatchCloseSystemDialogs(String reason) { |
| 7461 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7462 | msg.what = MSG_CLOSE_SYSTEM_DIALOGS; |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7463 | msg.obj = reason; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7464 | mHandler.sendMessage(msg); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7465 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7466 | |
| 7467 | public void dispatchDragEvent(DragEvent event) { |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 7468 | final int what; |
| 7469 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7470 | what = MSG_DISPATCH_DRAG_LOCATION_EVENT; |
| 7471 | mHandler.removeMessages(what); |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 7472 | } else { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7473 | what = MSG_DISPATCH_DRAG_EVENT; |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 7474 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7475 | Message msg = mHandler.obtainMessage(what, event); |
| 7476 | mHandler.sendMessage(msg); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7477 | } |
| 7478 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 7479 | public void updatePointerIcon(float x, float y) { |
| 7480 | final int what = MSG_UPDATE_POINTER_ICON; |
| 7481 | mHandler.removeMessages(what); |
| 7482 | final long now = SystemClock.uptimeMillis(); |
| 7483 | final MotionEvent event = MotionEvent.obtain( |
| 7484 | 0, now, MotionEvent.ACTION_HOVER_MOVE, x, y, 0); |
| 7485 | Message msg = mHandler.obtainMessage(what, event); |
| 7486 | mHandler.sendMessage(msg); |
| 7487 | } |
| 7488 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7489 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 7490 | int localValue, int localChanges) { |
| 7491 | SystemUiVisibilityInfo args = new SystemUiVisibilityInfo(); |
| 7492 | args.seq = seq; |
| 7493 | args.globalVisibility = globalVisibility; |
| 7494 | args.localValue = localValue; |
| 7495 | args.localChanges = localChanges; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 7496 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_SYSTEM_UI_VISIBILITY, args)); |
| 7497 | } |
| 7498 | |
| 7499 | public void dispatchCheckFocus() { |
| 7500 | if (!mHandler.hasMessages(MSG_CHECK_FOCUS)) { |
| 7501 | // This will result in a call to checkFocus() below. |
| 7502 | mHandler.sendEmptyMessage(MSG_CHECK_FOCUS); |
| 7503 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7504 | } |
| 7505 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 7506 | public void dispatchRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 7507 | mHandler.obtainMessage( |
| 7508 | MSG_REQUEST_KEYBOARD_SHORTCUTS, deviceId, 0, receiver).sendToTarget(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 7509 | } |
| 7510 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 7511 | public void dispatchPointerCaptureChanged(boolean on) { |
| 7512 | final int what = MSG_POINTER_CAPTURE_CHANGED; |
| 7513 | mHandler.removeMessages(what); |
| 7514 | Message msg = mHandler.obtainMessage(what); |
| 7515 | msg.arg1 = on ? 1 : 0; |
| 7516 | mHandler.sendMessage(msg); |
| 7517 | } |
| 7518 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 7519 | /** |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7520 | * Post a callback to send a |
| 7521 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7522 | * This event is send at most once every |
| 7523 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7524 | */ |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7525 | private void postSendWindowContentChangedCallback(View source, int changeType) { |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 7526 | if (mSendWindowContentChangedAccessibilityEvent == null) { |
| 7527 | mSendWindowContentChangedAccessibilityEvent = |
| 7528 | new SendWindowContentChangedAccessibilityEvent(); |
| 7529 | } |
| 7530 | mSendWindowContentChangedAccessibilityEvent.runOrPost(source, changeType); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7531 | } |
| 7532 | |
| 7533 | /** |
| 7534 | * Remove a posted callback to send a |
| 7535 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
| 7536 | */ |
| 7537 | private void removeSendWindowContentChangedCallback() { |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 7538 | if (mSendWindowContentChangedAccessibilityEvent != null) { |
| 7539 | mHandler.removeCallbacks(mSendWindowContentChangedAccessibilityEvent); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7540 | } |
| 7541 | } |
| 7542 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7543 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7544 | public boolean showContextMenuForChild(View originalView) { |
| 7545 | return false; |
| 7546 | } |
| 7547 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7548 | @Override |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 7549 | public boolean showContextMenuForChild(View originalView, float x, float y) { |
| 7550 | return false; |
| 7551 | } |
| 7552 | |
| 7553 | @Override |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7554 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { |
| 7555 | return null; |
| 7556 | } |
| 7557 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7558 | @Override |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7559 | public ActionMode startActionModeForChild( |
| 7560 | View originalView, ActionMode.Callback callback, int type) { |
| 7561 | return null; |
| 7562 | } |
| 7563 | |
| 7564 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | public void createContextMenu(ContextMenu menu) { |
| 7566 | } |
| 7567 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7568 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | public void childDrawableStateChanged(View child) { |
| 7570 | } |
| 7571 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7572 | @Override |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7573 | public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 7574 | if (mView == null || mStopped || mPausedForTransition) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7575 | return false; |
| 7576 | } |
Eugene Susla | ccce5c9 | 2017-05-22 13:14:57 -0700 | [diff] [blame] | 7577 | |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 7578 | // Immediately flush pending content changed event (if any) to preserve event order |
| 7579 | if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED |
| 7580 | && mSendWindowContentChangedAccessibilityEvent != null |
| 7581 | && mSendWindowContentChangedAccessibilityEvent.mSource != null) { |
| 7582 | mSendWindowContentChangedAccessibilityEvent.removeCallbacksAndRun(); |
| 7583 | } |
Eugene Susla | ccce5c9 | 2017-05-22 13:14:57 -0700 | [diff] [blame] | 7584 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7585 | // Intercept accessibility focus events fired by virtual nodes to keep |
| 7586 | // track of accessibility focus position in such nodes. |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7587 | final int eventType = event.getEventType(); |
| 7588 | switch (eventType) { |
| 7589 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7590 | final long sourceNodeId = event.getSourceNodeId(); |
| 7591 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 7592 | sourceNodeId); |
| 7593 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 7594 | if (source != null) { |
| 7595 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 7596 | if (provider != null) { |
Svetoslav | b3ba1d4 | 2014-09-26 15:20:40 -0700 | [diff] [blame] | 7597 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 7598 | sourceNodeId); |
| 7599 | final AccessibilityNodeInfo node; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 7600 | node = provider.createAccessibilityNodeInfo(virtualNodeId); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7601 | setAccessibilityFocus(source, node); |
| 7602 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7603 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7604 | } break; |
| 7605 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7606 | final long sourceNodeId = event.getSourceNodeId(); |
| 7607 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 7608 | sourceNodeId); |
| 7609 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 7610 | if (source != null) { |
| 7611 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 7612 | if (provider != null) { |
| 7613 | setAccessibilityFocus(null, null); |
| 7614 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7615 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7616 | } break; |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 7617 | |
| 7618 | |
| 7619 | case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: { |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7620 | handleWindowContentChangedEvent(event); |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 7621 | } break; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7622 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7623 | mAccessibilityManager.sendAccessibilityEvent(event); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7624 | return true; |
| 7625 | } |
| 7626 | |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7627 | /** |
| 7628 | * Updates the focused virtual view, when necessary, in response to a |
| 7629 | * content changed event. |
| 7630 | * <p> |
| 7631 | * This is necessary to get updated bounds after a position change. |
| 7632 | * |
| 7633 | * @param event an accessibility event of type |
| 7634 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} |
| 7635 | */ |
| 7636 | private void handleWindowContentChangedEvent(AccessibilityEvent event) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7637 | final View focusedHost = mAccessibilityFocusedHost; |
| 7638 | if (focusedHost == null || mAccessibilityFocusedVirtualView == null) { |
| 7639 | // No virtual view focused, nothing to do here. |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7640 | return; |
| 7641 | } |
| 7642 | |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7643 | final AccessibilityNodeProvider provider = focusedHost.getAccessibilityNodeProvider(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7644 | if (provider == null) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7645 | // Error state: virtual view with no provider. Clear focus. |
| 7646 | mAccessibilityFocusedHost = null; |
| 7647 | mAccessibilityFocusedVirtualView = null; |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 7648 | focusedHost.clearAccessibilityFocusNoCallbacks(0); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7649 | return; |
| 7650 | } |
| 7651 | |
| 7652 | // We only care about change types that may affect the bounds of the |
| 7653 | // focused virtual view. |
| 7654 | final int changes = event.getContentChangeTypes(); |
| 7655 | if ((changes & AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE) == 0 |
| 7656 | && changes != AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED) { |
| 7657 | return; |
| 7658 | } |
| 7659 | |
| 7660 | final long eventSourceNodeId = event.getSourceNodeId(); |
| 7661 | final int changedViewId = AccessibilityNodeInfo.getAccessibilityViewId(eventSourceNodeId); |
| 7662 | |
| 7663 | // Search up the tree for subtree containment. |
| 7664 | boolean hostInSubtree = false; |
| 7665 | View root = mAccessibilityFocusedHost; |
| 7666 | while (root != null && !hostInSubtree) { |
| 7667 | if (changedViewId == root.getAccessibilityViewId()) { |
| 7668 | hostInSubtree = true; |
| 7669 | } else { |
| 7670 | final ViewParent parent = root.getParent(); |
| 7671 | if (parent instanceof View) { |
| 7672 | root = (View) parent; |
| 7673 | } else { |
| 7674 | root = null; |
| 7675 | } |
| 7676 | } |
| 7677 | } |
| 7678 | |
| 7679 | // We care only about changes in subtrees containing the host view. |
| 7680 | if (!hostInSubtree) { |
| 7681 | return; |
| 7682 | } |
| 7683 | |
| 7684 | final long focusedSourceNodeId = mAccessibilityFocusedVirtualView.getSourceNodeId(); |
| 7685 | int focusedChildId = AccessibilityNodeInfo.getVirtualDescendantId(focusedSourceNodeId); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7686 | |
| 7687 | // Refresh the node for the focused virtual view. |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 7688 | final Rect oldBounds = mTempRect; |
| 7689 | mAccessibilityFocusedVirtualView.getBoundsInScreen(oldBounds); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7690 | mAccessibilityFocusedVirtualView = provider.createAccessibilityNodeInfo(focusedChildId); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7691 | if (mAccessibilityFocusedVirtualView == null) { |
| 7692 | // Error state: The node no longer exists. Clear focus. |
| 7693 | mAccessibilityFocusedHost = null; |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 7694 | focusedHost.clearAccessibilityFocusNoCallbacks(0); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7695 | |
| 7696 | // This will probably fail, but try to keep the provider's internal |
| 7697 | // state consistent by clearing focus. |
| 7698 | provider.performAction(focusedChildId, |
| 7699 | AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), null); |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 7700 | invalidateRectOnScreen(oldBounds); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7701 | } else { |
| 7702 | // The node was refreshed, invalidate bounds if necessary. |
| 7703 | final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen(); |
| 7704 | if (!oldBounds.equals(newBounds)) { |
| 7705 | oldBounds.union(newBounds); |
| 7706 | invalidateRectOnScreen(oldBounds); |
| 7707 | } |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 7708 | } |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7709 | } |
| 7710 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7711 | @Override |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7712 | public void notifySubtreeAccessibilityStateChanged(View child, View source, int changeType) { |
Phil Weaver | 63e4503 | 2017-05-11 10:54:37 -0700 | [diff] [blame] | 7713 | postSendWindowContentChangedCallback(Preconditions.checkNotNull(source), changeType); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7714 | } |
| 7715 | |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 7716 | @Override |
| 7717 | public boolean canResolveLayoutDirection() { |
| 7718 | return true; |
| 7719 | } |
| 7720 | |
| 7721 | @Override |
| 7722 | public boolean isLayoutDirectionResolved() { |
| 7723 | return true; |
| 7724 | } |
| 7725 | |
| 7726 | @Override |
| 7727 | public int getLayoutDirection() { |
| 7728 | return View.LAYOUT_DIRECTION_RESOLVED_DEFAULT; |
| 7729 | } |
| 7730 | |
| 7731 | @Override |
| 7732 | public boolean canResolveTextDirection() { |
| 7733 | return true; |
| 7734 | } |
| 7735 | |
| 7736 | @Override |
| 7737 | public boolean isTextDirectionResolved() { |
| 7738 | return true; |
| 7739 | } |
| 7740 | |
| 7741 | @Override |
| 7742 | public int getTextDirection() { |
| 7743 | return View.TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 7744 | } |
| 7745 | |
| 7746 | @Override |
| 7747 | public boolean canResolveTextAlignment() { |
| 7748 | return true; |
| 7749 | } |
| 7750 | |
| 7751 | @Override |
| 7752 | public boolean isTextAlignmentResolved() { |
| 7753 | return true; |
| 7754 | } |
| 7755 | |
| 7756 | @Override |
| 7757 | public int getTextAlignment() { |
| 7758 | return View.TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 7759 | } |
| 7760 | |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 7761 | private View getCommonPredecessor(View first, View second) { |
| 7762 | if (mTempHashSet == null) { |
| 7763 | mTempHashSet = new HashSet<View>(); |
| 7764 | } |
| 7765 | HashSet<View> seen = mTempHashSet; |
| 7766 | seen.clear(); |
| 7767 | View firstCurrent = first; |
| 7768 | while (firstCurrent != null) { |
| 7769 | seen.add(firstCurrent); |
| 7770 | ViewParent firstCurrentParent = firstCurrent.mParent; |
| 7771 | if (firstCurrentParent instanceof View) { |
| 7772 | firstCurrent = (View) firstCurrentParent; |
| 7773 | } else { |
| 7774 | firstCurrent = null; |
| 7775 | } |
| 7776 | } |
| 7777 | View secondCurrent = second; |
| 7778 | while (secondCurrent != null) { |
| 7779 | if (seen.contains(secondCurrent)) { |
| 7780 | seen.clear(); |
| 7781 | return secondCurrent; |
| 7782 | } |
| 7783 | ViewParent secondCurrentParent = secondCurrent.mParent; |
| 7784 | if (secondCurrentParent instanceof View) { |
| 7785 | secondCurrent = (View) secondCurrentParent; |
| 7786 | } else { |
| 7787 | secondCurrent = null; |
| 7788 | } |
| 7789 | } |
| 7790 | seen.clear(); |
| 7791 | return null; |
| 7792 | } |
| 7793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7794 | void checkThread() { |
| 7795 | if (mThread != Thread.currentThread()) { |
| 7796 | throw new CalledFromWrongThreadException( |
| 7797 | "Only the original thread that created a view hierarchy can touch its views."); |
| 7798 | } |
| 7799 | } |
| 7800 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7801 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7802 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 7803 | // 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] | 7804 | } |
| 7805 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7806 | @Override |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7807 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 7808 | if (rectangle == null) { |
| 7809 | return scrollToRectOrFocus(null, immediate); |
| 7810 | } |
| 7811 | rectangle.offset(child.getLeft() - child.getScrollX(), |
| 7812 | child.getTop() - child.getScrollY()); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7813 | final boolean scrolled = scrollToRectOrFocus(rectangle, immediate); |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 7814 | mTempRect.set(rectangle); |
| 7815 | mTempRect.offset(0, -mCurScrollY); |
| 7816 | mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 7817 | try { |
| 7818 | mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect); |
| 7819 | } catch (RemoteException re) { |
| 7820 | /* ignore */ |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7821 | } |
| 7822 | return scrolled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7823 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7824 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7825 | @Override |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 7826 | public void childHasTransientStateChanged(View child, boolean hasTransientState) { |
| 7827 | // Do nothing. |
| 7828 | } |
| 7829 | |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7830 | @Override |
| 7831 | public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { |
| 7832 | return false; |
| 7833 | } |
| 7834 | |
| 7835 | @Override |
| 7836 | public void onStopNestedScroll(View target) { |
| 7837 | } |
| 7838 | |
| 7839 | @Override |
| 7840 | public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) { |
| 7841 | } |
| 7842 | |
| 7843 | @Override |
| 7844 | public void onNestedScroll(View target, int dxConsumed, int dyConsumed, |
| 7845 | int dxUnconsumed, int dyUnconsumed) { |
| 7846 | } |
| 7847 | |
| 7848 | @Override |
| 7849 | public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { |
| 7850 | } |
| 7851 | |
| 7852 | @Override |
Adam Powell | b36e4f9 | 2014-05-01 10:23:33 -0700 | [diff] [blame] | 7853 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7854 | return false; |
| 7855 | } |
| 7856 | |
Adam Powell | b72be59 | 2014-07-16 21:41:31 -0700 | [diff] [blame] | 7857 | @Override |
| 7858 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) { |
| 7859 | return false; |
| 7860 | } |
| 7861 | |
Adam Powell | b6ab098 | 2015-01-07 17:00:12 -0800 | [diff] [blame] | 7862 | @Override |
| 7863 | public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle args) { |
| 7864 | return false; |
| 7865 | } |
| 7866 | |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 7867 | |
| 7868 | private void reportNextDraw() { |
| 7869 | if (mReportNextDraw == false) { |
| 7870 | drawPending(); |
| 7871 | } |
| 7872 | mReportNextDraw = true; |
| 7873 | } |
| 7874 | |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 7875 | /** |
| 7876 | * Force the window to report its next draw. |
| 7877 | * <p> |
| 7878 | * This method is only supposed to be used to speed up the interaction from SystemUI and window |
| 7879 | * manager when waiting for the first frame to be drawn when turning on the screen. DO NOT USE |
| 7880 | * unless you fully understand this interaction. |
| 7881 | * @hide |
| 7882 | */ |
| 7883 | public void setReportNextDraw() { |
Robert Carr | 49cd9f8 | 2017-05-25 18:24:42 -0700 | [diff] [blame] | 7884 | reportNextDraw(); |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 7885 | invalidate(); |
| 7886 | } |
| 7887 | |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 7888 | void changeCanvasOpacity(boolean opaque) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 7889 | Log.d(mTag, "changeCanvasOpacity: opaque=" + opaque); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 7890 | if (mAttachInfo.mThreadedRenderer != null) { |
| 7891 | mAttachInfo.mThreadedRenderer.setOpaque(opaque); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 7892 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 7893 | } |
| 7894 | |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 7895 | /** |
| 7896 | * Dispatches a KeyEvent to all registered key fallback handlers. |
| 7897 | * |
| 7898 | * @param event |
| 7899 | * @return {@code true} if the event was handled, {@code false} otherwise. |
| 7900 | */ |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 7901 | public boolean dispatchUnhandledKeyEvent(KeyEvent event) { |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 7902 | return mUnhandledKeyManager.dispatch(mView, event); |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 7903 | } |
| 7904 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7905 | class TakenSurfaceHolder extends BaseSurfaceHolder { |
| 7906 | @Override |
| 7907 | public boolean onAllowLockCanvas() { |
| 7908 | return mDrawingAllowed; |
| 7909 | } |
| 7910 | |
| 7911 | @Override |
| 7912 | public void onRelayoutContainer() { |
| 7913 | // Not currently interesting -- from changing between fixed and layout size. |
| 7914 | } |
| 7915 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7916 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7917 | public void setFormat(int format) { |
| 7918 | ((RootViewSurfaceTaker)mView).setSurfaceFormat(format); |
| 7919 | } |
| 7920 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7921 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7922 | public void setType(int type) { |
| 7923 | ((RootViewSurfaceTaker)mView).setSurfaceType(type); |
| 7924 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7925 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7926 | @Override |
| 7927 | public void onUpdateSurface() { |
| 7928 | // We take care of format and type changes on our own. |
| 7929 | throw new IllegalStateException("Shouldn't be here"); |
| 7930 | } |
| 7931 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7932 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7933 | public boolean isCreating() { |
| 7934 | return mIsCreating; |
| 7935 | } |
| 7936 | |
| 7937 | @Override |
| 7938 | public void setFixedSize(int width, int height) { |
| 7939 | throw new UnsupportedOperationException( |
| 7940 | "Currently only support sizing from layout"); |
| 7941 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7942 | |
| 7943 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7944 | public void setKeepScreenOn(boolean screenOn) { |
| 7945 | ((RootViewSurfaceTaker)mView).setSurfaceKeepScreenOn(screenOn); |
| 7946 | } |
| 7947 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7949 | static class W extends IWindow.Stub { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7950 | private final WeakReference<ViewRootImpl> mViewAncestor; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7951 | private final IWindowSession mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7952 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7953 | W(ViewRootImpl viewAncestor) { |
| 7954 | mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7955 | mWindowSession = viewAncestor.mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7956 | } |
| 7957 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7958 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 7959 | public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 7960 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7961 | MergedConfiguration mergedConfiguration, Rect backDropFrame, boolean forceLayout, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 7962 | boolean alwaysConsumeNavBar, int displayId, |
| 7963 | DisplayCutout.ParcelableWrapper displayCutout) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7964 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7965 | if (viewAncestor != null) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 7966 | viewAncestor.dispatchResized(frame, overscanInsets, contentInsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7967 | visibleInsets, stableInsets, outsets, reportDraw, mergedConfiguration, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 7968 | backDropFrame, forceLayout, alwaysConsumeNavBar, displayId, displayCutout); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7969 | } |
| 7970 | } |
| 7971 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 7972 | @Override |
| 7973 | public void moved(int newX, int newY) { |
| 7974 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7975 | if (viewAncestor != null) { |
| 7976 | viewAncestor.dispatchMoved(newX, newY); |
| 7977 | } |
| 7978 | } |
| 7979 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7980 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7981 | public void dispatchAppVisibility(boolean visible) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7982 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7983 | if (viewAncestor != null) { |
| 7984 | viewAncestor.dispatchAppVisibility(visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7985 | } |
| 7986 | } |
| 7987 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7988 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7989 | public void dispatchGetNewSurface() { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7990 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7991 | if (viewAncestor != null) { |
| 7992 | viewAncestor.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7993 | } |
| 7994 | } |
| 7995 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7996 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7997 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7998 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7999 | if (viewAncestor != null) { |
| 8000 | viewAncestor.windowFocusChanged(hasFocus, inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8001 | } |
| 8002 | } |
| 8003 | |
| 8004 | private static int checkCallingPermission(String permission) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8005 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 8006 | return ActivityManager.getService().checkPermission( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8007 | permission, Binder.getCallingPid(), Binder.getCallingUid()); |
| 8008 | } catch (RemoteException e) { |
| 8009 | return PackageManager.PERMISSION_DENIED; |
| 8010 | } |
| 8011 | } |
| 8012 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8013 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8014 | public void executeCommand(String command, String parameters, ParcelFileDescriptor out) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8015 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8016 | if (viewAncestor != null) { |
| 8017 | final View view = viewAncestor.mView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8018 | if (view != null) { |
| 8019 | if (checkCallingPermission(Manifest.permission.DUMP) != |
| 8020 | PackageManager.PERMISSION_GRANTED) { |
| 8021 | throw new SecurityException("Insufficient permissions to invoke" |
| 8022 | + " executeCommand() from pid=" + Binder.getCallingPid() |
| 8023 | + ", uid=" + Binder.getCallingUid()); |
| 8024 | } |
| 8025 | |
| 8026 | OutputStream clientStream = null; |
| 8027 | try { |
| 8028 | clientStream = new ParcelFileDescriptor.AutoCloseOutputStream(out); |
| 8029 | ViewDebug.dispatchCommand(view, command, parameters, clientStream); |
| 8030 | } catch (IOException e) { |
| 8031 | e.printStackTrace(); |
| 8032 | } finally { |
| 8033 | if (clientStream != null) { |
| 8034 | try { |
| 8035 | clientStream.close(); |
| 8036 | } catch (IOException e) { |
| 8037 | e.printStackTrace(); |
| 8038 | } |
| 8039 | } |
| 8040 | } |
| 8041 | } |
| 8042 | } |
| 8043 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8044 | |
| 8045 | @Override |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 8046 | public void closeSystemDialogs(String reason) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8047 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8048 | if (viewAncestor != null) { |
| 8049 | viewAncestor.dispatchCloseSystemDialogs(reason); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 8050 | } |
| 8051 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8052 | |
| 8053 | @Override |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8054 | public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, |
| 8055 | boolean sync) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 8056 | if (sync) { |
| 8057 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 8058 | mWindowSession.wallpaperOffsetsComplete(asBinder()); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 8059 | } catch (RemoteException e) { |
| 8060 | } |
| 8061 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8062 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8063 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8064 | @Override |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 8065 | public void dispatchWallpaperCommand(String action, int x, int y, |
| 8066 | int z, Bundle extras, boolean sync) { |
| 8067 | if (sync) { |
| 8068 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 8069 | mWindowSession.wallpaperCommandComplete(asBinder(), null); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 8070 | } catch (RemoteException e) { |
| 8071 | } |
| 8072 | } |
| 8073 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8074 | |
| 8075 | /* Drag/drop */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8076 | @Override |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8077 | public void dispatchDragEvent(DragEvent event) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8078 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8079 | if (viewAncestor != null) { |
| 8080 | viewAncestor.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8081 | } |
| 8082 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8083 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8084 | @Override |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 8085 | public void updatePointerIcon(float x, float y) { |
| 8086 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 8087 | if (viewAncestor != null) { |
| 8088 | viewAncestor.updatePointerIcon(x, y); |
| 8089 | } |
| 8090 | } |
| 8091 | |
| 8092 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 8093 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 8094 | int localValue, int localChanges) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8095 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8096 | if (viewAncestor != null) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 8097 | viewAncestor.dispatchSystemUiVisibilityChanged(seq, globalVisibility, |
| 8098 | localValue, localChanges); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8099 | } |
| 8100 | } |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 8101 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8102 | @Override |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 8103 | public void dispatchWindowShown() { |
| 8104 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 8105 | if (viewAncestor != null) { |
| 8106 | viewAncestor.dispatchWindowShown(); |
| 8107 | } |
| 8108 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 8109 | |
| 8110 | @Override |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 8111 | public void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 8112 | ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 8113 | if (viewAncestor != null) { |
| 8114 | viewAncestor.dispatchRequestKeyboardShortcuts(receiver, deviceId); |
| 8115 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 8116 | } |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 8117 | |
| 8118 | @Override |
| 8119 | public void dispatchPointerCaptureChanged(boolean hasCapture) { |
| 8120 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 8121 | if (viewAncestor != null) { |
| 8122 | viewAncestor.dispatchPointerCaptureChanged(hasCapture); |
| 8123 | } |
| 8124 | } |
| 8125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8126 | } |
| 8127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | public static final class CalledFromWrongThreadException extends AndroidRuntimeException { |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 8129 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8130 | public CalledFromWrongThreadException(String msg) { |
| 8131 | super(msg); |
| 8132 | } |
| 8133 | } |
| 8134 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 8135 | static HandlerActionQueue getRunQueue() { |
| 8136 | HandlerActionQueue rq = sRunQueues.get(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8137 | if (rq != null) { |
| 8138 | return rq; |
| 8139 | } |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 8140 | rq = new HandlerActionQueue(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8141 | sRunQueues.set(rq); |
| 8142 | return rq; |
| 8143 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 8144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8145 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8146 | * Start a drag resizing which will inform all listeners that a window resize is taking place. |
| 8147 | */ |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 8148 | private void startDragResizing(Rect initialBounds, boolean fullscreen, Rect systemInsets, |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 8149 | Rect stableInsets, int resizeMode) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8150 | if (!mDragResizing) { |
| 8151 | mDragResizing = true; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8152 | if (mUseMTRenderer) { |
| 8153 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 8154 | mWindowCallbacks.get(i).onWindowDragResizeStart( |
| 8155 | initialBounds, fullscreen, systemInsets, stableInsets, resizeMode); |
| 8156 | } |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8157 | } |
| 8158 | mFullRedrawNeeded = true; |
| 8159 | } |
| 8160 | } |
| 8161 | |
| 8162 | /** |
| 8163 | * End a drag resize which will inform all listeners that a window resize has ended. |
| 8164 | */ |
| 8165 | private void endDragResizing() { |
| 8166 | if (mDragResizing) { |
| 8167 | mDragResizing = false; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8168 | if (mUseMTRenderer) { |
| 8169 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 8170 | mWindowCallbacks.get(i).onWindowDragResizeEnd(); |
| 8171 | } |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8172 | } |
| 8173 | mFullRedrawNeeded = true; |
| 8174 | } |
| 8175 | } |
| 8176 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 8177 | private boolean updateContentDrawBounds() { |
| 8178 | boolean updated = false; |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8179 | if (mUseMTRenderer) { |
| 8180 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 8181 | updated |= |
| 8182 | mWindowCallbacks.get(i).onContentDrawn(mWindowAttributes.surfaceInsets.left, |
| 8183 | mWindowAttributes.surfaceInsets.top, mWidth, mHeight); |
| 8184 | } |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 8185 | } |
| 8186 | return updated | (mDragResizing && mReportNextDraw); |
| 8187 | } |
| 8188 | |
| 8189 | private void requestDrawWindow() { |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8190 | if (!mUseMTRenderer) { |
| 8191 | return; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 8192 | } |
Tomasz Mikolajewski | 711f1f9 | 2017-07-25 12:45:31 +0900 | [diff] [blame] | 8193 | mWindowDrawCountDown = new CountDownLatch(mWindowCallbacks.size()); |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 8194 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 8195 | mWindowCallbacks.get(i).onRequestDraw(mReportNextDraw); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 8196 | } |
| 8197 | } |
| 8198 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 8199 | /** |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 8200 | * Tells this instance that its corresponding activity has just relaunched. In this case, we |
| 8201 | * need to force a relayout of the window to make sure we get the correct bounds from window |
| 8202 | * manager. |
| 8203 | */ |
| 8204 | public void reportActivityRelaunched() { |
| 8205 | mActivityRelaunched = true; |
| 8206 | } |
| 8207 | |
| 8208 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8209 | * Class for managing the accessibility interaction connection |
| 8210 | * based on the global accessibility state. |
| 8211 | */ |
| 8212 | final class AccessibilityInteractionConnectionManager |
| 8213 | implements AccessibilityStateChangeListener { |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 8214 | @Override |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8215 | public void onAccessibilityStateChanged(boolean enabled) { |
| 8216 | if (enabled) { |
| 8217 | ensureConnection(); |
Phil Weaver | 05a2982 | 2017-09-22 11:03:06 -0700 | [diff] [blame] | 8218 | if (mAttachInfo.mHasWindowFocus && (mView != null)) { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 8219 | mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 8220 | View focusedView = mView.findFocus(); |
| 8221 | if (focusedView != null && focusedView != mView) { |
| 8222 | focusedView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 8223 | } |
| 8224 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8225 | } else { |
| 8226 | ensureNoConnection(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 8227 | mHandler.obtainMessage(MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST).sendToTarget(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8228 | } |
| 8229 | } |
| 8230 | |
| 8231 | public void ensureConnection() { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 8232 | final boolean registered = mAttachInfo.mAccessibilityWindowId |
| 8233 | != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8234 | if (!registered) { |
| 8235 | mAttachInfo.mAccessibilityWindowId = |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 8236 | mAccessibilityManager.addAccessibilityInteractionConnection(mWindow, |
Svet Ganov | 240aed9 | 2017-12-02 12:32:23 -0800 | [diff] [blame] | 8237 | mContext.getPackageName(), |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 8238 | new AccessibilityInteractionConnection(ViewRootImpl.this)); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8239 | } |
| 8240 | } |
| 8241 | |
| 8242 | public void ensureNoConnection() { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 8243 | final boolean registered = mAttachInfo.mAccessibilityWindowId |
| 8244 | != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8245 | if (registered) { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 8246 | mAttachInfo.mAccessibilityWindowId = AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8247 | mAccessibilityManager.removeAccessibilityInteractionConnection(mWindow); |
| 8248 | } |
| 8249 | } |
| 8250 | } |
| 8251 | |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8252 | final class HighContrastTextManager implements HighTextContrastChangeListener { |
| 8253 | HighContrastTextManager() { |
John Reck | 938e884 | 2017-08-24 13:41:59 -0700 | [diff] [blame] | 8254 | ThreadedRenderer.setHighContrastText(mAccessibilityManager.isHighTextContrastEnabled()); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8255 | } |
| 8256 | @Override |
| 8257 | public void onHighTextContrastStateChanged(boolean enabled) { |
John Reck | 938e884 | 2017-08-24 13:41:59 -0700 | [diff] [blame] | 8258 | ThreadedRenderer.setHighContrastText(enabled); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8259 | |
| 8260 | // Destroy Displaylists so they can be recreated with high contrast recordings |
| 8261 | destroyHardwareResources(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 8262 | |
| 8263 | // Schedule redraw, which will rerecord + redraw all text |
| 8264 | invalidate(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 8265 | } |
| 8266 | } |
| 8267 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8268 | /** |
| 8269 | * This class is an interface this ViewAncestor provides to the |
| 8270 | * AccessibilityManagerService to the latter can interact with |
| 8271 | * the view hierarchy in this ViewAncestor. |
| 8272 | */ |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 8273 | static final class AccessibilityInteractionConnection |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8274 | extends IAccessibilityInteractionConnection.Stub { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8275 | private final WeakReference<ViewRootImpl> mViewRootImpl; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8276 | |
Svetoslav Ganov | f79f476 | 2011-10-28 15:40:32 -0700 | [diff] [blame] | 8277 | AccessibilityInteractionConnection(ViewRootImpl viewRootImpl) { |
| 8278 | mViewRootImpl = new WeakReference<ViewRootImpl>(viewRootImpl); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8279 | } |
| 8280 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8281 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8282 | public void findAccessibilityNodeInfoByAccessibilityId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8283 | Region interactiveRegion, int interactionId, |
| 8284 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 8285 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec, Bundle args) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8286 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8287 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 8288 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8289 | .findAccessibilityNodeInfoByAccessibilityIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8290 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 8291 | interrogatingTid, spec, args); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8292 | } else { |
| 8293 | // We cannot make the call and notify the caller so it does not wait. |
| 8294 | try { |
| 8295 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 8296 | } catch (RemoteException re) { |
| 8297 | /* best effort - ignore */ |
| 8298 | } |
Svetoslav Ganov | 601ad80 | 2011-06-09 14:47:38 -0700 | [diff] [blame] | 8299 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8300 | } |
| 8301 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8302 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8303 | public void performAccessibilityAction(long accessibilityNodeId, int action, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 8304 | Bundle arguments, int interactionId, |
| 8305 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 8306 | int interrogatingPid, long interrogatingTid) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8307 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8308 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 8309 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 8310 | .performAccessibilityActionClientThread(accessibilityNodeId, action, arguments, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 8311 | interactionId, callback, flags, interrogatingPid, interrogatingTid); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8312 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8313 | // 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] | 8314 | try { |
| 8315 | callback.setPerformAccessibilityActionResult(false, interactionId); |
| 8316 | } catch (RemoteException re) { |
| 8317 | /* best effort - ignore */ |
| 8318 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8319 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8320 | } |
| 8321 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8322 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 8323 | public void findAccessibilityNodeInfosByViewId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8324 | String viewId, Region interactiveRegion, int interactionId, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 8325 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 8326 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 8327 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8328 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 8329 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 8330 | .findAccessibilityNodeInfosByViewIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8331 | viewId, interactiveRegion, interactionId, callback, flags, |
| 8332 | interrogatingPid, interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8333 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8334 | // 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] | 8335 | try { |
| 8336 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
| 8337 | } catch (RemoteException re) { |
| 8338 | /* best effort - ignore */ |
| 8339 | } |
| 8340 | } |
| 8341 | } |
| 8342 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8343 | @Override |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8344 | public void findAccessibilityNodeInfosByText(long accessibilityNodeId, String text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8345 | Region interactiveRegion, int interactionId, |
| 8346 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 8347 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8348 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8349 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 8350 | viewRootImpl.getAccessibilityInteractionController() |
| 8351 | .findAccessibilityNodeInfosByTextClientThread(accessibilityNodeId, text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8352 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 8353 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 8354 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8355 | // 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] | 8356 | try { |
| 8357 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 8358 | } catch (RemoteException re) { |
| 8359 | /* best effort - ignore */ |
| 8360 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8361 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8362 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8363 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8364 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8365 | public void findFocus(long accessibilityNodeId, int focusType, Region interactiveRegion, |
| 8366 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 8367 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8368 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8369 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 8370 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8371 | .findFocusClientThread(accessibilityNodeId, focusType, interactiveRegion, |
| 8372 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 8373 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 8374 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8375 | // 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] | 8376 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8377 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8378 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8379 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8380 | } |
| 8381 | } |
| 8382 | } |
| 8383 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8384 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8385 | public void focusSearch(long accessibilityNodeId, int direction, Region interactiveRegion, |
| 8386 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 8387 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8388 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 8389 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 8390 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 8391 | .focusSearchClientThread(accessibilityNodeId, direction, interactiveRegion, |
| 8392 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 8393 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 8394 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8395 | // 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] | 8396 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8397 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8398 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8399 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8400 | } |
| 8401 | } |
| 8402 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 8403 | } |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 8404 | |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8405 | private class SendWindowContentChangedAccessibilityEvent implements Runnable { |
| 8406 | private int mChangeTypes = 0; |
| 8407 | |
| 8408 | public View mSource; |
| 8409 | public long mLastEventTimeMillis; |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8410 | /** |
| 8411 | * Override for {@link AccessibilityEvent#originStackTrace} to provide the stack trace |
| 8412 | * of the original {@link #runOrPost} call instead of one for sending the delayed event |
| 8413 | * from a looper. |
| 8414 | */ |
| 8415 | public StackTraceElement[] mOrigin; |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8416 | |
| 8417 | @Override |
| 8418 | public void run() { |
| 8419 | // Protect against re-entrant code and attempt to do the right thing in the case that |
| 8420 | // we're multithreaded. |
| 8421 | View source = mSource; |
| 8422 | mSource = null; |
| 8423 | if (source == null) { |
| 8424 | Log.e(TAG, "Accessibility content change has no source"); |
| 8425 | return; |
| 8426 | } |
| 8427 | // The accessibility may be turned off while we were waiting so check again. |
| 8428 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8429 | mLastEventTimeMillis = SystemClock.uptimeMillis(); |
| 8430 | AccessibilityEvent event = AccessibilityEvent.obtain(); |
| 8431 | event.setEventType(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
| 8432 | event.setContentChangeTypes(mChangeTypes); |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8433 | if (AccessibilityEvent.DEBUG_ORIGIN) event.originStackTrace = mOrigin; |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8434 | source.sendAccessibilityEventUnchecked(event); |
| 8435 | } else { |
| 8436 | mLastEventTimeMillis = 0; |
| 8437 | } |
| 8438 | // In any case reset to initial state. |
| 8439 | source.resetSubtreeAccessibilityStateChanged(); |
| 8440 | mChangeTypes = 0; |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8441 | if (AccessibilityEvent.DEBUG_ORIGIN) mOrigin = null; |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8442 | } |
| 8443 | |
| 8444 | public void runOrPost(View source, int changeType) { |
| 8445 | if (mHandler.getLooper() != Looper.myLooper()) { |
| 8446 | CalledFromWrongThreadException e = new CalledFromWrongThreadException("Only the " |
| 8447 | + "original thread that created a view hierarchy can touch its views."); |
| 8448 | // TODO: Throw the exception |
| 8449 | Log.e(TAG, "Accessibility content change on non-UI thread. Future Android " |
| 8450 | + "versions will throw an exception.", e); |
| 8451 | // Attempt to recover. This code does not eliminate the thread safety issue, but |
| 8452 | // it should force any issues to happen near the above log. |
| 8453 | mHandler.removeCallbacks(this); |
| 8454 | if (mSource != null) { |
| 8455 | // Dispatch whatever was pending. It's still possible that the runnable started |
| 8456 | // just before we removed the callbacks, and bad things will happen, but at |
| 8457 | // least they should happen very close to the logged error. |
| 8458 | run(); |
| 8459 | } |
| 8460 | } |
| 8461 | if (mSource != null) { |
| 8462 | // If there is no common predecessor, then mSource points to |
| 8463 | // a removed view, hence in this case always prefer the source. |
| 8464 | View predecessor = getCommonPredecessor(mSource, source); |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8465 | if (predecessor != null) { |
| 8466 | predecessor = predecessor.getSelfOrParentImportantForA11y(); |
| 8467 | } |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8468 | mSource = (predecessor != null) ? predecessor : source; |
| 8469 | mChangeTypes |= changeType; |
| 8470 | return; |
| 8471 | } |
| 8472 | mSource = source; |
| 8473 | mChangeTypes = changeType; |
Eugene Susla | 9af1378c | 2018-03-22 16:29:10 -0700 | [diff] [blame] | 8474 | if (AccessibilityEvent.DEBUG_ORIGIN) { |
| 8475 | mOrigin = Thread.currentThread().getStackTrace(); |
| 8476 | } |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 8477 | final long timeSinceLastMillis = SystemClock.uptimeMillis() - mLastEventTimeMillis; |
| 8478 | final long minEventIntevalMillis = |
| 8479 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval(); |
| 8480 | if (timeSinceLastMillis >= minEventIntevalMillis) { |
| 8481 | removeCallbacksAndRun(); |
| 8482 | } else { |
| 8483 | mHandler.postDelayed(this, minEventIntevalMillis - timeSinceLastMillis); |
| 8484 | } |
| 8485 | } |
| 8486 | |
| 8487 | public void removeCallbacksAndRun() { |
| 8488 | mHandler.removeCallbacks(this); |
| 8489 | run(); |
| 8490 | } |
| 8491 | } |
| 8492 | |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8493 | private static class UnhandledKeyManager { |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8494 | // 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] | 8495 | // 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] | 8496 | // 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] | 8497 | // 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] | 8498 | // in an activity, we still want unhandled keys to be dispatched. |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8499 | private boolean mDispatched = true; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8500 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8501 | // Keeps track of which Views have unhandled key focus for which keys. This doesn't |
| 8502 | // include modifiers. |
| 8503 | private final SparseArray<WeakReference<View>> mCapturedKeys = new SparseArray<>(); |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8504 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8505 | // The current receiver. This value is transient and used between the pre-dispatch and |
| 8506 | // pre-view phase to ensure that other input-stages don't interfere with tracking. |
| 8507 | private WeakReference<View> mCurrentReceiver = null; |
| 8508 | |
| 8509 | boolean dispatch(View root, KeyEvent event) { |
| 8510 | if (mDispatched) { |
| 8511 | return false; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8512 | } |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8513 | View consumer; |
| 8514 | try { |
| 8515 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "UnhandledKeyEvent dispatch"); |
| 8516 | mDispatched = true; |
| 8517 | |
| 8518 | consumer = root.dispatchUnhandledKeyEvent(event); |
| 8519 | |
| 8520 | // If an unhandled listener handles one, then keep track of it so that the |
| 8521 | // consuming view is first to receive its repeats and release as well. |
| 8522 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 8523 | int keycode = event.getKeyCode(); |
| 8524 | if (consumer != null && !KeyEvent.isModifierKey(keycode)) { |
| 8525 | mCapturedKeys.put(keycode, new WeakReference<>(consumer)); |
| 8526 | } |
| 8527 | } |
| 8528 | } finally { |
| 8529 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 8530 | } |
| 8531 | return consumer != null; |
| 8532 | } |
| 8533 | |
| 8534 | /** |
| 8535 | * Called before the event gets dispatched to anything |
| 8536 | */ |
| 8537 | void preDispatch(KeyEvent event) { |
| 8538 | // Always clean-up 'up' events since it's possible for earlier dispatch stages to |
| 8539 | // consume them without consuming the corresponding 'down' event. |
| 8540 | mCurrentReceiver = null; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8541 | if (event.getAction() == KeyEvent.ACTION_UP) { |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8542 | int idx = mCapturedKeys.indexOfKey(event.getKeyCode()); |
| 8543 | if (idx >= 0) { |
| 8544 | mCurrentReceiver = mCapturedKeys.valueAt(idx); |
| 8545 | mCapturedKeys.removeAt(idx); |
| 8546 | } |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8547 | } |
| 8548 | } |
| 8549 | |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8550 | /** |
| 8551 | * Called before the event gets dispatched to the view hierarchy |
| 8552 | * @return {@code true} if an unhandled handler has focus and consumed the event |
| 8553 | */ |
| 8554 | boolean preViewDispatch(KeyEvent event) { |
| 8555 | mDispatched = false; |
| 8556 | if (mCurrentReceiver == null) { |
| 8557 | mCurrentReceiver = mCapturedKeys.get(event.getKeyCode()); |
| 8558 | } |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8559 | if (mCurrentReceiver != null) { |
| 8560 | View target = mCurrentReceiver.get(); |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8561 | if (event.getAction() == KeyEvent.ACTION_UP) { |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8562 | mCurrentReceiver = null; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8563 | } |
| 8564 | if (target != null && target.isAttachedToWindow()) { |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 8565 | target.onUnhandledKeyEvent(event); |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8566 | } |
| 8567 | // consume anyways so that we don't feed uncaptured key events to other views |
| 8568 | return true; |
| 8569 | } |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 8570 | return false; |
Evan Rosky | 5e29c07 | 2017-06-02 17:31:22 -0700 | [diff] [blame] | 8571 | } |
| 8572 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8573 | } |