From db5e2e9492b3a72558a0d58bdef1074ad5635a92 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Sun, 31 Mar 2019 23:21:51 -0700 Subject: [PATCH] Don't access a11y APIs with reflection starting Android P. (flutter/engine#8393) --- .../view/AccessibilityViewEmbedder.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityViewEmbedder.java b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityViewEmbedder.java index fbc2260d26..e1065143d8 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityViewEmbedder.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityViewEmbedder.java @@ -420,25 +420,28 @@ class AccessibilityViewEmbedder { Method getParentNodeId = null; Method getRecordSourceNodeId = null; Method getChildId = null; - try { - getSourceNodeId = AccessibilityNodeInfo.class.getMethod("getSourceNodeId"); - } catch (NoSuchMethodException e) { - Log.w(TAG, "can't invoke AccessibilityNodeInfo#getSourceNodeId with reflection"); - } - try { - getParentNodeId = AccessibilityNodeInfo.class.getMethod("getParentNodeId"); - } catch (NoSuchMethodException e) { - Log.w(TAG, "can't invoke getParentNodeId with reflection"); - } - try { - getRecordSourceNodeId = AccessibilityRecord.class.getMethod("getSourceNodeId"); - } catch (NoSuchMethodException e) { - Log.w(TAG, "can't invoke AccessibiiltyRecord#getSourceNodeId with reflection"); - } - try { - getChildId = AccessibilityNodeInfo.class.getMethod("getChildId", int.class); - } catch (NoSuchMethodException e) { - Log.w(TAG, "can't invoke getChildId with reflection"); + // Reflection access is not allowed starting Android P. + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) { + try { + getSourceNodeId = AccessibilityNodeInfo.class.getMethod("getSourceNodeId"); + } catch (NoSuchMethodException e) { + Log.w(TAG, "can't invoke AccessibilityNodeInfo#getSourceNodeId with reflection"); + } + try { + getParentNodeId = AccessibilityNodeInfo.class.getMethod("getParentNodeId"); + } catch (NoSuchMethodException e) { + Log.w(TAG, "can't invoke getParentNodeId with reflection"); + } + try { + getRecordSourceNodeId = AccessibilityRecord.class.getMethod("getSourceNodeId"); + } catch (NoSuchMethodException e) { + Log.w(TAG, "can't invoke AccessibiiltyRecord#getSourceNodeId with reflection"); + } + try { + getChildId = AccessibilityNodeInfo.class.getMethod("getChildId", int.class); + } catch (NoSuchMethodException e) { + Log.w(TAG, "can't invoke getChildId with reflection"); + } } this.getSourceNodeId = getSourceNodeId; this.getParentNodeId = getParentNodeId;