Remove preferKeepClearAreaForFocusDelay, turn it into a flag
TV PiP repositioning in response to keep clear area changes will be
debounced in SystemUI, so the client side delay in setting a keep clear
area with focus becomes obsolete.
Instead the config is turned into a flag for whether focused views
should automatically be marked as keep clear areas.
Bug: 231309309
Test: atest KeepClearRectsTests
Change-Id: I0ac61e671bb75e22a95b400c9bd8d84004379e43
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 21220c5..9b01247 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -2888,7 +2888,7 @@
method public static int getHoverTooltipHideTimeout();
method public static int getHoverTooltipShowTimeout();
method public static int getLongPressTooltipHideTimeout();
- method public int getPreferKeepClearForFocusDelay();
+ method public boolean isPreferKeepClearForFocusEnabled();
}
public class ViewDebug {
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 387b547..5981992 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -4801,9 +4801,6 @@
@UnsupportedAppUsage
ListenerInfo mListenerInfo;
- private boolean mPreferKeepClearForFocus;
- private Runnable mMarkPreferKeepClearForFocus;
-
private static class TooltipInfo {
/**
* Text to be displayed in a tooltip popup.
@@ -11994,8 +11991,9 @@
@NonNull
List<Rect> collectPreferKeepClearRects() {
ListenerInfo info = mListenerInfo;
- boolean keepBoundsClear =
- (info != null && info.mPreferKeepClear) || mPreferKeepClearForFocus;
+ boolean keepClearForFocus = isFocused()
+ && ViewConfiguration.get(mContext).isPreferKeepClearForFocusEnabled();
+ boolean keepBoundsClear = (info != null && info.mPreferKeepClear) || keepClearForFocus;
boolean hasCustomKeepClearRects = info != null && info.mKeepClearRects != null;
if (!keepBoundsClear && !hasCustomKeepClearRects) {
@@ -12017,31 +12015,10 @@
}
private void updatePreferKeepClearForFocus() {
- if (mMarkPreferKeepClearForFocus != null) {
- removeCallbacks(mMarkPreferKeepClearForFocus);
- mMarkPreferKeepClearForFocus = null;
+ if (ViewConfiguration.get(mContext).isPreferKeepClearForFocusEnabled()) {
+ updatePositionUpdateListener();
+ post(this::updateKeepClearRects);
}
-
- final ViewConfiguration configuration = ViewConfiguration.get(mContext);
- final int delay = configuration.getPreferKeepClearForFocusDelay();
- if (delay >= 0) {
- mMarkPreferKeepClearForFocus = () -> {
- mPreferKeepClearForFocus = isFocused();
- mMarkPreferKeepClearForFocus = null;
-
- updatePositionUpdateListener();
- post(this::updateKeepClearRects);
- };
- postDelayed(mMarkPreferKeepClearForFocus, delay);
- }
- }
-
- private void cancelMarkPreferKeepClearForFocus() {
- if (mMarkPreferKeepClearForFocus != null) {
- removeCallbacks(mMarkPreferKeepClearForFocus);
- mMarkPreferKeepClearForFocus = null;
- }
- mPreferKeepClearForFocus = false;
}
/**
@@ -13865,7 +13842,6 @@
}
invalidate();
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
- updatePreferKeepClearForFocus();
return true;
}
return false;
@@ -21265,7 +21241,6 @@
removePerformClickCallback();
clearAccessibilityThrottles();
stopNestedScroll();
- cancelMarkPreferKeepClearForFocus();
// Anything that started animating right before detach should already
// be in its final state when re-attached.
diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java
index d07560a..8a19a7b 100644
--- a/core/java/android/view/ViewConfiguration.java
+++ b/core/java/android/view/ViewConfiguration.java
@@ -352,7 +352,7 @@
private final long mScreenshotChordKeyTimeout;
private final int mSmartSelectionInitializedTimeout;
private final int mSmartSelectionInitializingTimeout;
- private final int mPreferKeepClearForFocusDelay;
+ private final boolean mPreferKeepClearForFocusEnabled;
private final String mVelocityTrackerStrategy;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915)
@@ -400,7 +400,7 @@
mMinScalingSpan = 0;
mSmartSelectionInitializedTimeout = SMART_SELECTION_INITIALIZED_TIMEOUT_IN_MILLISECOND;
mSmartSelectionInitializingTimeout = SMART_SELECTION_INITIALIZING_TIMEOUT_IN_MILLISECOND;
- mPreferKeepClearForFocusDelay = -1;
+ mPreferKeepClearForFocusEnabled = false;
mVelocityTrackerStrategy = InputManager.getInstance().getVelocityTrackerStrategy();
}
@@ -518,8 +518,8 @@
com.android.internal.R.integer.config_smartSelectionInitializedTimeoutMillis);
mSmartSelectionInitializingTimeout = res.getInteger(
com.android.internal.R.integer.config_smartSelectionInitializingTimeoutMillis);
- mPreferKeepClearForFocusDelay = res.getInteger(
- com.android.internal.R.integer.config_preferKeepClearForFocusDelayMillis);
+ mPreferKeepClearForFocusEnabled = res.getBoolean(
+ com.android.internal.R.bool.config_preferKeepClearForFocus);
mVelocityTrackerStrategy = InputManager.getInstance().getVelocityTrackerStrategy();
}
@@ -1128,13 +1128,13 @@
}
/**
- * @return The delay in milliseconds before focused Views set themselves as preferred to keep
- * clear, or -1 if Views should not set themselves as preferred to keep clear.
+ * @return {@code true} if Views should set themselves as preferred to keep clear when focused,
+ * {@code false} otherwise.
* @hide
*/
@TestApi
- public int getPreferKeepClearForFocusDelay() {
- return mPreferKeepClearForFocusDelay;
+ public boolean isPreferKeepClearForFocusEnabled() {
+ return mPreferKeepClearForFocusEnabled;
}
/**
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index a3a37e3..d96f117 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -5191,9 +5191,8 @@
when TextClassifier has not been initialized. -->
<integer name="config_smartSelectionInitializingTimeoutMillis">500</integer>
- <!-- The delay in milliseconds before focused Views set themselves as preferred to keep clear.
- Set to -1 if Views should not set themselves as preferred to keep clear. -->
- <integer name="config_preferKeepClearForFocusDelayMillis">-1</integer>
+ <!-- If true, Views will declare they prefer to be kept clear from overlays when focused. -->
+ <bool name="config_preferKeepClearForFocus">false</bool>
<!-- Indicates that default fitness tracker app needs to request sensor and location permissions. -->
<bool name="config_trackerAppNeedsPermissions">false</bool>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 99e65f1..db388b3 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -480,7 +480,7 @@
<java-symbol type="bool" name="config_useAssistantVolume" />
<java-symbol type="integer" name="config_smartSelectionInitializedTimeoutMillis" />
<java-symbol type="integer" name="config_smartSelectionInitializingTimeoutMillis" />
- <java-symbol type="integer" name="config_preferKeepClearForFocusDelayMillis" />
+ <java-symbol type="bool" name="config_preferKeepClearForFocus" />
<java-symbol type="bool" name="config_hibernationDeletesOatArtifactsEnabled"/>
<java-symbol type="integer" name="config_defaultAnalogClockSecondsHandFps"/>