Fix unexpected crashes during accessibility actions. (#20687)
This commit is contained in:
@@ -135,10 +135,30 @@ namespace Avalonia.Android
|
|||||||
protected override bool OnPerformActionForVirtualView(int virtualViewId, int action, Bundle? arguments)
|
protected override bool OnPerformActionForVirtualView(int virtualViewId, int action, Bundle? arguments)
|
||||||
{
|
{
|
||||||
return (GetNodeInfoProvidersFromVirtualViewId(virtualViewId) ?? [])
|
return (GetNodeInfoProvidersFromVirtualViewId(virtualViewId) ?? [])
|
||||||
.Select(x => x.PerformNodeAction(action, arguments))
|
.Select(x => TryPerformNodeAction(x, action, arguments))
|
||||||
.Aggregate(false, (a, b) => a | b);
|
.Aggregate(false, (a, b) => a | b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool TryPerformNodeAction(INodeInfoProvider nodeInfoProvider, int action, Bundle? arguments)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return nodeInfoProvider.PerformNodeAction(action, arguments);
|
||||||
|
}
|
||||||
|
catch (ElementNotEnabledException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (NotSupportedException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat? nodeInfo)
|
protected override void OnPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat? nodeInfo)
|
||||||
{
|
{
|
||||||
if (nodeInfo is null || !_peers.TryGetValue(virtualViewId, out AutomationPeer? peer))
|
if (nodeInfo is null || !_peers.TryGetValue(virtualViewId, out AutomationPeer? peer))
|
||||||
|
|||||||
Reference in New Issue
Block a user