Fix unexpected crashes during accessibility actions. (#20687)

This commit is contained in:
SunnyDesignor
2026-02-16 17:18:07 +08:00
committed by GitHub
parent f4b5dc95b7
commit f8a1f2e2aa
@@ -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))