Bug 51664 - View.PerformAccessibilityAction and other AccessibilityAction methods map to the incorrect enum?
Summary: View.PerformAccessibilityAction and other AccessibilityAction methods map to ...
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 7.1 (C9)
Hardware: PC Windows
: Highest major
Target Milestone: 15.5
Assignee: Atsushi Eno
Depends on:
Reported: 2017-01-20 16:35 UTC by Jon Douglas [MSFT]
Modified: 2017-11-13 10:37 UTC (History)
4 users (show)

Tags: bb
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jon Douglas [MSFT] 2017-01-20 16:35:11 UTC

Based on the current Android documentation for View.performAccessibilityAction, it has a parameter of type "int" named "action". However I believe this mapping might be incorrect.

https://developer.android.com/reference/android/view/View.html#performAccessibilityAction(int, android.os.Bundle)

In the documentation it notes that a default implementation will delegate ACTION_SCROLL_BACKWARD(https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html#ACTION_SCROLL_BACKWARD) and ACTION_SCROLL_FORWARD(https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html#ACTION_SCROLL_FORWARD) to the nested scrolling parents if nested scrolling is enabled on the view. This is clue #1 that this parameter of "int action" should be of C# type "Action" (https://developer.xamarin.com/api/type/Android.Views.Accessibility.Action/)

Instead the same method based on the docs expects an enum of type "GlobalAction"



The reason why this seems off is that the source code of this method in Android seems to specifically have a switch case on these "Action" items.


I believe the culprit is the method mapping here:


I believe that not only this method is wrong, but other methods as well such as 

https://developer.android.com/reference/android/view/View.AccessibilityDelegate.html#performAccessibilityAction(android.view.View, int, android.os.Bundle)



https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeProvider.html#performAction(int, int, android.os.Bundle)

I believe the correct mappings here would be https://developer.xamarin.com/api/type/Android.Views.Accessibility.Action/ for these methods. Please correct me if I'm wrong or if this is intended behavior.


I believe this is the same scenario up to the current master of https://github.com/xamarin/xamarin-android
Comment 2 Tom Opgenorth 2017-06-26 20:23:56 UTC
I agree with Jon Douglas - this is a broken API implementation; the current mapping in Xamarin.Android is incorrect. The int values of GlobalAction don't match the values expected by the Android APIs.

For example,  AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD is 8192 and AccessbilityNodeInfo.ACTION_SCROLL_FORWARD is 4096. GlobalAction only has values in the range of 1 - 7.
Comment 3 Atsushi Eno 2017-09-14 17:16:37 UTC
This kind of mismatching enumification happens at any time due to lack of Android documentation at early phase or anything that *might* be passed via Intent where more than one enum types could apply to one single int.
The only alternative is to totally dump the idea of using enums (which I believe is the way to go).

https://github.com/xamarin/xamarin-android/pull/859 introduces some workarounds and fixes. Old incorrect members cannot be removed for compatiblity. We add method overloads that take the right enums, and introduce getter/setter methods with the right enum for the wrong property (whose type cannot be changed for comparibility).
Comment 4 Atsushi Eno 2017-09-19 11:27:17 UTC
The PR is merged.
Comment 5 Sarang Kanchalwar 2017-11-13 10:37:02 UTC
While verifying the bug, I tried using AccessibilityNodeInfo.ActionScrollBackward.
As the intellisense tool tip shows that AccessibilityNodeInfo.ActionScrollBackward is obsolete & will be removed in future. I am using Android.Views.Accessibility.Action.ScrollBackward as mentioned in tool tip. Also did the same for rest constants/enums.
Expected values for comparison taken from-

I found the expected results.
ACTION_SCROLL_BACKWARD = Action.ScrollBackward = 8192
ACTION_SCROLL_FORWARD = Action.ScrollForward = 4096
ACTION_SELECT = Action.Select = 4
ACTION_SET_SELECTION = Action.SetSelection = 131072
ACTION_SET_TEXT = Action.SetText = 2097152

Following are the build details:
Microsoft Visual Studio Enterprise 2017 
Version 15.5.0 [27109.1.d15rel]
Microsoft .NET Framework
Version 4.7.02046
Installed Version: Enterprise
Xamarin (a773aca)
Xamarin Designer   4.8.152 (5e0da2967)
Xamarin.Android SDK (HEAD/f65f87747)
Xamarin.iOS and Xamarin.Mac SDK (c4240f3)

Complete Build Details: