This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Guard against NewAPI failures #8048
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,15 @@ | |
|
||
package io.flutter.view; | ||
|
||
import android.annotation.TargetApi; | ||
import android.app.Activity; | ||
import android.graphics.Rect; | ||
import android.opengl.Matrix; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.RequiresApi; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.view.accessibility.AccessibilityEvent; | ||
|
@@ -84,10 +87,12 @@ enum Action { | |
SHOW_ON_SCREEN(1 << 8), | ||
MOVE_CURSOR_FORWARD_BY_CHARACTER(1 << 9), | ||
MOVE_CURSOR_BACKWARD_BY_CHARACTER(1 << 10), | ||
/** These actions are only supported on Android 4.3 and above. */ | ||
SET_SELECTION(1 << 11), | ||
COPY(1 << 12), | ||
CUT(1 << 13), | ||
PASTE(1 << 14), | ||
/** End 4.3 only supported actions. */ | ||
DID_GAIN_ACCESSIBILITY_FOCUS(1 << 15), | ||
DID_LOSE_ACCESSIBILITY_FOCUS(1 << 16), | ||
CUSTOM_ACTION(1 << 17), | ||
|
@@ -233,17 +238,22 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { | |
} | ||
result.setMovementGranularities(granularities); | ||
} | ||
if (object.hasAction(Action.SET_SELECTION)) { | ||
result.addAction(AccessibilityNodeInfo.ACTION_SET_SELECTION); | ||
} | ||
if (object.hasAction(Action.COPY)) { | ||
result.addAction(AccessibilityNodeInfo.ACTION_COPY); | ||
} | ||
if (object.hasAction(Action.CUT)) { | ||
result.addAction(AccessibilityNodeInfo.ACTION_CUT); | ||
} | ||
if (object.hasAction(Action.PASTE)) { | ||
result.addAction(AccessibilityNodeInfo.ACTION_PASTE); | ||
|
||
// These are non-ops on older devices. Attempting to interact with the text will cause Talkback to read the | ||
// contents of the text box instead. | ||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
mklim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (object.hasAction(Action.SET_SELECTION)) { | ||
result.addAction(AccessibilityNodeInfo.ACTION_SET_SELECTION); | ||
} | ||
if (object.hasAction(Action.COPY)) { | ||
result.addAction(AccessibilityNodeInfo.ACTION_COPY); | ||
} | ||
if (object.hasAction(Action.CUT)) { | ||
result.addAction(AccessibilityNodeInfo.ACTION_CUT); | ||
} | ||
if (object.hasAction(Action.PASTE)) { | ||
result.addAction(AccessibilityNodeInfo.ACTION_PASTE); | ||
} | ||
} | ||
|
||
if (object.hasFlag(Flag.IS_BUTTON)) { | ||
|
@@ -312,11 +322,14 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { | |
// We should prefer setCollectionInfo to the class names, as this way we get "In List" | ||
// and "Out of list" announcements. But we don't always know the counts, so we | ||
// can fallback to the generic scroll view class names. | ||
// | ||
// On older APIs, we always fall back to the generic scroll view class names here. | ||
// | ||
// TODO(dnfield): We should add semantics properties for rows and columns in 2 dimensional lists, e.g. | ||
// GridView. Right now, we're only supporting ListViews and only if they have scroll children. | ||
if (object.hasFlag(Flag.HAS_IMPLICIT_SCROLLING)) { | ||
if (object.hasAction(Action.SCROLL_LEFT) || object.hasAction(Action.SCROLL_RIGHT)) { | ||
if (shouldSetCollectionInfo(object)) { | ||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT && shouldSetCollectionInfo(object)) { | ||
mklim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
result.setCollectionInfo(AccessibilityNodeInfo.CollectionInfo.obtain( | ||
0, // rows | ||
object.scrollChildren, // columns | ||
|
@@ -325,7 +338,7 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { | |
result.setClassName("android.widget.HorizontalScrollView"); | ||
} | ||
} else { | ||
if (shouldSetCollectionInfo(object)) { | ||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2 && shouldSetCollectionInfo(object)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and elsewhere, can you add comments about what happens if the SDK versions are not met? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to the inline comments above this block. |
||
result.setCollectionInfo(AccessibilityNodeInfo.CollectionInfo.obtain( | ||
object.scrollChildren, // rows | ||
0, // columns | ||
|
@@ -465,9 +478,21 @@ public boolean performAction(int virtualViewId, int action, Bundle arguments) { | |
return true; | ||
} | ||
case AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY: { | ||
// Text selection APIs aren't available until API 18. We can't handle the case here so return false | ||
// instead. It's extremely unlikely that this case would ever be triggered in the first place in API < | ||
// 18. | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
return false; | ||
} | ||
return performCursorMoveAction(object, virtualViewId, arguments, false); | ||
} | ||
case AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY: { | ||
// Text selection APIs aren't available until API 18. We can't handle the case here so return false | ||
// instead. It's extremely unlikely that this case would ever be triggered in the first place in API < | ||
// 18. | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
return false; | ||
} | ||
return performCursorMoveAction(object, virtualViewId, arguments, true); | ||
} | ||
case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS: { | ||
|
@@ -502,6 +527,12 @@ public boolean performAction(int virtualViewId, int action, Bundle arguments) { | |
return true; | ||
} | ||
case AccessibilityNodeInfo.ACTION_SET_SELECTION: { | ||
// Text selection APIs aren't available until API 18. We can't handle the case here so return false | ||
// instead. It's extremely unlikely that this case would ever be triggered in the first place in API < | ||
// 18. | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { | ||
return false; | ||
} | ||
final Map<String, Integer> selection = new HashMap<>(); | ||
final boolean hasSelection = arguments != null | ||
&& arguments.containsKey( | ||
|
@@ -553,6 +584,8 @@ public boolean performAction(int virtualViewId, int action, Bundle arguments) { | |
return false; | ||
} | ||
|
||
@RequiresApi(18) | ||
@TargetApi(18) | ||
boolean performCursorMoveAction( | ||
SemanticsObject object, int virtualViewId, Bundle arguments, boolean forward) { | ||
final int granularity = | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.