package io.flutter.view; import android.graphics.Rect; import android.os.Build; import android.os.Bundle; import android.os.Parcel; import android.util.SparseArray; import android.view.MotionEvent; import android.view.View; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeProvider; import android.view.accessibility.AccessibilityRecord; import io.flutter.Log; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; /* loaded from: classes6.dex */ class AccessibilityViewEmbedder { private static final String TAG = "AccessibilityBridge"; private int nextFlutterId; private final View rootAccessibilityView; private final ReflectionAccessors reflectionAccessors = new ReflectionAccessors(); private final SparseArray flutterIdToOrigin = new SparseArray<>(); private final Map originToFlutterId = new HashMap(); private final Map embeddedViewToDisplayBounds = new HashMap(); /* JADX INFO: Access modifiers changed from: package-private */ public AccessibilityViewEmbedder(View view, int i) { this.rootAccessibilityView = view; this.nextFlutterId = i; } public AccessibilityNodeInfo getRootNode(View view, int i, Rect rect) { AccessibilityNodeInfo createAccessibilityNodeInfo = view.createAccessibilityNodeInfo(); Long sourceNodeId = this.reflectionAccessors.getSourceNodeId(createAccessibilityNodeInfo); if (sourceNodeId == null) { return null; } this.embeddedViewToDisplayBounds.put(view, rect); cacheVirtualIdMappings(view, ReflectionAccessors.getVirtualNodeId(sourceNodeId.longValue()), i); return convertToFlutterNode(createAccessibilityNodeInfo, i, view); } public AccessibilityNodeInfo createAccessibilityNodeInfo(int i) { AccessibilityNodeInfo createAccessibilityNodeInfo; ViewAndId viewAndId = this.flutterIdToOrigin.get(i); if (viewAndId == null || !this.embeddedViewToDisplayBounds.containsKey(viewAndId.view) || viewAndId.view.getAccessibilityNodeProvider() == null || (createAccessibilityNodeInfo = viewAndId.view.getAccessibilityNodeProvider().createAccessibilityNodeInfo(viewAndId.id)) == null) { return null; } return convertToFlutterNode(createAccessibilityNodeInfo, i, viewAndId.view); } private AccessibilityNodeInfo convertToFlutterNode(AccessibilityNodeInfo accessibilityNodeInfo, int i, View view) { AccessibilityNodeInfo obtain = AccessibilityNodeInfo.obtain(this.rootAccessibilityView, i); obtain.setPackageName(this.rootAccessibilityView.getContext().getPackageName()); obtain.setSource(this.rootAccessibilityView, i); obtain.setClassName(accessibilityNodeInfo.getClassName()); Rect rect = this.embeddedViewToDisplayBounds.get(view); copyAccessibilityFields(accessibilityNodeInfo, obtain); setFlutterNodesTranslateBounds(accessibilityNodeInfo, rect, obtain); addChildrenToFlutterNode(accessibilityNodeInfo, view, obtain); setFlutterNodeParent(accessibilityNodeInfo, view, obtain); return obtain; } private void setFlutterNodeParent(AccessibilityNodeInfo accessibilityNodeInfo, View view, AccessibilityNodeInfo accessibilityNodeInfo2) { Long parentNodeId = this.reflectionAccessors.getParentNodeId(accessibilityNodeInfo); if (parentNodeId == null) { return; } Integer num = this.originToFlutterId.get(new ViewAndId(view, ReflectionAccessors.getVirtualNodeId(parentNodeId.longValue()))); if (num != null) { accessibilityNodeInfo2.setParent(this.rootAccessibilityView, num.intValue()); } } private void addChildrenToFlutterNode(AccessibilityNodeInfo accessibilityNodeInfo, View view, AccessibilityNodeInfo accessibilityNodeInfo2) { int i; for (int i2 = 0; i2 < accessibilityNodeInfo.getChildCount(); i2++) { Long childId = this.reflectionAccessors.getChildId(accessibilityNodeInfo, i2); if (childId != null) { int virtualNodeId = ReflectionAccessors.getVirtualNodeId(childId.longValue()); ViewAndId viewAndId = new ViewAndId(view, virtualNodeId); if (this.originToFlutterId.containsKey(viewAndId)) { i = this.originToFlutterId.get(viewAndId).intValue(); } else { int i3 = this.nextFlutterId; this.nextFlutterId = i3 + 1; cacheVirtualIdMappings(view, virtualNodeId, i3); i = i3; } accessibilityNodeInfo2.addChild(this.rootAccessibilityView, i); } } } private void cacheVirtualIdMappings(View view, int i, int i2) { ViewAndId viewAndId = new ViewAndId(view, i); this.originToFlutterId.put(viewAndId, Integer.valueOf(i2)); this.flutterIdToOrigin.put(i2, viewAndId); } private void setFlutterNodesTranslateBounds(AccessibilityNodeInfo accessibilityNodeInfo, Rect rect, AccessibilityNodeInfo accessibilityNodeInfo2) { Rect rect2 = new Rect(); accessibilityNodeInfo.getBoundsInParent(rect2); accessibilityNodeInfo2.setBoundsInParent(rect2); Rect rect3 = new Rect(); accessibilityNodeInfo.getBoundsInScreen(rect3); rect3.offset(rect.left, rect.top); accessibilityNodeInfo2.setBoundsInScreen(rect3); } private void copyAccessibilityFields(AccessibilityNodeInfo accessibilityNodeInfo, AccessibilityNodeInfo accessibilityNodeInfo2) { accessibilityNodeInfo2.setAccessibilityFocused(accessibilityNodeInfo.isAccessibilityFocused()); accessibilityNodeInfo2.setCheckable(accessibilityNodeInfo.isCheckable()); accessibilityNodeInfo2.setChecked(accessibilityNodeInfo.isChecked()); accessibilityNodeInfo2.setContentDescription(accessibilityNodeInfo.getContentDescription()); accessibilityNodeInfo2.setEnabled(accessibilityNodeInfo.isEnabled()); accessibilityNodeInfo2.setClickable(accessibilityNodeInfo.isClickable()); accessibilityNodeInfo2.setFocusable(accessibilityNodeInfo.isFocusable()); accessibilityNodeInfo2.setFocused(accessibilityNodeInfo.isFocused()); accessibilityNodeInfo2.setLongClickable(accessibilityNodeInfo.isLongClickable()); accessibilityNodeInfo2.setMovementGranularities(accessibilityNodeInfo.getMovementGranularities()); accessibilityNodeInfo2.setPassword(accessibilityNodeInfo.isPassword()); accessibilityNodeInfo2.setScrollable(accessibilityNodeInfo.isScrollable()); accessibilityNodeInfo2.setSelected(accessibilityNodeInfo.isSelected()); accessibilityNodeInfo2.setText(accessibilityNodeInfo.getText()); accessibilityNodeInfo2.setVisibleToUser(accessibilityNodeInfo.isVisibleToUser()); accessibilityNodeInfo2.setEditable(accessibilityNodeInfo.isEditable()); accessibilityNodeInfo2.setCanOpenPopup(accessibilityNodeInfo.canOpenPopup()); accessibilityNodeInfo2.setCollectionInfo(accessibilityNodeInfo.getCollectionInfo()); accessibilityNodeInfo2.setCollectionItemInfo(accessibilityNodeInfo.getCollectionItemInfo()); accessibilityNodeInfo2.setContentInvalid(accessibilityNodeInfo.isContentInvalid()); accessibilityNodeInfo2.setDismissable(accessibilityNodeInfo.isDismissable()); accessibilityNodeInfo2.setInputType(accessibilityNodeInfo.getInputType()); accessibilityNodeInfo2.setLiveRegion(accessibilityNodeInfo.getLiveRegion()); accessibilityNodeInfo2.setMultiLine(accessibilityNodeInfo.isMultiLine()); accessibilityNodeInfo2.setRangeInfo(accessibilityNodeInfo.getRangeInfo()); accessibilityNodeInfo2.setError(accessibilityNodeInfo.getError()); accessibilityNodeInfo2.setMaxTextLength(accessibilityNodeInfo.getMaxTextLength()); accessibilityNodeInfo2.setContextClickable(accessibilityNodeInfo.isContextClickable()); accessibilityNodeInfo2.setDrawingOrder(accessibilityNodeInfo.getDrawingOrder()); accessibilityNodeInfo2.setImportantForAccessibility(accessibilityNodeInfo.isImportantForAccessibility()); accessibilityNodeInfo2.setAvailableExtraData(accessibilityNodeInfo.getAvailableExtraData()); accessibilityNodeInfo2.setHintText(accessibilityNodeInfo.getHintText()); accessibilityNodeInfo2.setShowingHintText(accessibilityNodeInfo.isShowingHintText()); } public boolean requestSendAccessibilityEvent(View view, View view2, AccessibilityEvent accessibilityEvent) { AccessibilityEvent obtain = AccessibilityEvent.obtain(accessibilityEvent); Long recordSourceNodeId = this.reflectionAccessors.getRecordSourceNodeId(accessibilityEvent); if (recordSourceNodeId == null) { return false; } int virtualNodeId = ReflectionAccessors.getVirtualNodeId(recordSourceNodeId.longValue()); Integer num = this.originToFlutterId.get(new ViewAndId(view, virtualNodeId)); if (num == null) { int i = this.nextFlutterId; this.nextFlutterId = i + 1; num = Integer.valueOf(i); cacheVirtualIdMappings(view, virtualNodeId, num.intValue()); } obtain.setSource(this.rootAccessibilityView, num.intValue()); obtain.setClassName(accessibilityEvent.getClassName()); obtain.setPackageName(accessibilityEvent.getPackageName()); for (int i2 = 0; i2 < obtain.getRecordCount(); i2++) { AccessibilityRecord record = obtain.getRecord(i2); Long recordSourceNodeId2 = this.reflectionAccessors.getRecordSourceNodeId(record); if (recordSourceNodeId2 == null) { return false; } ViewAndId viewAndId = new ViewAndId(view, ReflectionAccessors.getVirtualNodeId(recordSourceNodeId2.longValue())); if (!this.originToFlutterId.containsKey(viewAndId)) { return false; } record.setSource(this.rootAccessibilityView, this.originToFlutterId.get(viewAndId).intValue()); } return this.rootAccessibilityView.getParent().requestSendAccessibilityEvent(view2, obtain); } public boolean performAction(int i, int i2, Bundle bundle) { AccessibilityNodeProvider accessibilityNodeProvider; ViewAndId viewAndId = this.flutterIdToOrigin.get(i); if (viewAndId == null || (accessibilityNodeProvider = viewAndId.view.getAccessibilityNodeProvider()) == null) { return false; } return accessibilityNodeProvider.performAction(viewAndId.id, i2, bundle); } public Integer getRecordFlutterId(View view, AccessibilityRecord accessibilityRecord) { Long recordSourceNodeId = this.reflectionAccessors.getRecordSourceNodeId(accessibilityRecord); if (recordSourceNodeId == null) { return null; } return this.originToFlutterId.get(new ViewAndId(view, ReflectionAccessors.getVirtualNodeId(recordSourceNodeId.longValue()))); } public boolean onAccessibilityHoverEvent(int i, MotionEvent motionEvent) { ViewAndId viewAndId = this.flutterIdToOrigin.get(i); if (viewAndId == null) { return false; } Rect rect = this.embeddedViewToDisplayBounds.get(viewAndId.view); int pointerCount = motionEvent.getPointerCount(); MotionEvent.PointerProperties[] pointerPropertiesArr = new MotionEvent.PointerProperties[pointerCount]; MotionEvent.PointerCoords[] pointerCoordsArr = new MotionEvent.PointerCoords[pointerCount]; for (int i2 = 0; i2 < motionEvent.getPointerCount(); i2++) { MotionEvent.PointerProperties pointerProperties = new MotionEvent.PointerProperties(); pointerPropertiesArr[i2] = pointerProperties; motionEvent.getPointerProperties(i2, pointerProperties); MotionEvent.PointerCoords pointerCoords = new MotionEvent.PointerCoords(); motionEvent.getPointerCoords(i2, pointerCoords); MotionEvent.PointerCoords pointerCoords2 = new MotionEvent.PointerCoords(pointerCoords); pointerCoordsArr[i2] = pointerCoords2; pointerCoords2.x -= rect.left; pointerCoordsArr[i2].y -= rect.top; } return viewAndId.view.dispatchGenericMotionEvent(MotionEvent.obtain(motionEvent.getDownTime(), motionEvent.getEventTime(), motionEvent.getAction(), motionEvent.getPointerCount(), pointerPropertiesArr, pointerCoordsArr, motionEvent.getMetaState(), motionEvent.getButtonState(), motionEvent.getXPrecision(), motionEvent.getYPrecision(), motionEvent.getDeviceId(), motionEvent.getEdgeFlags(), motionEvent.getSource(), motionEvent.getFlags())); } public View platformViewOfNode(int i) { ViewAndId viewAndId = this.flutterIdToOrigin.get(i); if (viewAndId == null) { return null; } return viewAndId.view; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static class ViewAndId { final int id; final View view; private ViewAndId(View view, int i) { this.view = view; this.id = i; } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof ViewAndId)) { return false; } ViewAndId viewAndId = (ViewAndId) obj; return this.id == viewAndId.id && this.view.equals(viewAndId.view); } public int hashCode() { return ((this.view.hashCode() + 31) * 31) + this.id; } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static class ReflectionAccessors { private final Field childNodeIdsField; private final Method getChildId; private final Method getParentNodeId; private final Method getRecordSourceNodeId; private final Method getSourceNodeId; private final Method longArrayGetIndex; /* JADX INFO: Access modifiers changed from: private */ public static int getVirtualNodeId(long j) { return (int) (j >> 32); } private static boolean isBitSet(long j, int i) { return (j & (1 << i)) != 0; } private ReflectionAccessors() { Method method; Method method2; Method method3; Method method4; Field declaredField; Method method5; Method method6 = null; try { method = AccessibilityNodeInfo.class.getMethod("getSourceNodeId", new Class[0]); } catch (NoSuchMethodException unused) { Log.w(AccessibilityViewEmbedder.TAG, "can't invoke AccessibilityNodeInfo#getSourceNodeId with reflection"); method = null; } try { method2 = AccessibilityRecord.class.getMethod("getSourceNodeId", new Class[0]); } catch (NoSuchMethodException unused2) { Log.w(AccessibilityViewEmbedder.TAG, "can't invoke AccessibiiltyRecord#getSourceNodeId with reflection"); method2 = null; } if (Build.VERSION.SDK_INT <= 26) { try { method4 = AccessibilityNodeInfo.class.getMethod("getParentNodeId", new Class[0]); } catch (NoSuchMethodException unused3) { Log.w(AccessibilityViewEmbedder.TAG, "can't invoke getParentNodeId with reflection"); method4 = null; } try { method3 = AccessibilityNodeInfo.class.getMethod("getChildId", Integer.TYPE); } catch (NoSuchMethodException unused4) { Log.w(AccessibilityViewEmbedder.TAG, "can't invoke getChildId with reflection"); method3 = null; } } else { try { declaredField = AccessibilityNodeInfo.class.getDeclaredField("mChildNodeIds"); declaredField.setAccessible(true); method5 = Class.forName("android.util.LongArray").getMethod("get", Integer.TYPE); method3 = null; } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | NullPointerException unused5) { Log.w(AccessibilityViewEmbedder.TAG, "can't access childNodeIdsField with reflection"); method3 = null; method4 = null; } this.getSourceNodeId = method; this.getParentNodeId = method6; this.getRecordSourceNodeId = method2; this.getChildId = method3; this.childNodeIdsField = declaredField; this.longArrayGetIndex = method5; } method5 = null; method6 = method4; declaredField = null; this.getSourceNodeId = method; this.getParentNodeId = method6; this.getRecordSourceNodeId = method2; this.getChildId = method3; this.childNodeIdsField = declaredField; this.longArrayGetIndex = method5; } /* JADX INFO: Access modifiers changed from: private */ public Long getSourceNodeId(AccessibilityNodeInfo accessibilityNodeInfo) { Method method = this.getSourceNodeId; if (method == null) { return null; } try { return (Long) method.invoke(accessibilityNodeInfo, new Object[0]); } catch (IllegalAccessException e) { Log.w(AccessibilityViewEmbedder.TAG, "Failed to access getSourceNodeId method.", e); return null; } catch (InvocationTargetException e2) { Log.w(AccessibilityViewEmbedder.TAG, "The getSourceNodeId method threw an exception when invoked.", e2); return null; } } /* JADX INFO: Access modifiers changed from: private */ public Long getChildId(AccessibilityNodeInfo accessibilityNodeInfo, int i) { Method method = this.getChildId; if (method == null && (this.childNodeIdsField == null || this.longArrayGetIndex == null)) { return null; } if (method != null) { try { return (Long) method.invoke(accessibilityNodeInfo, Integer.valueOf(i)); } catch (IllegalAccessException e) { Log.w(AccessibilityViewEmbedder.TAG, "Failed to access getChildId method.", e); } catch (InvocationTargetException e2) { Log.w(AccessibilityViewEmbedder.TAG, "The getChildId method threw an exception when invoked.", e2); } } else { try { return Long.valueOf(((Long) this.longArrayGetIndex.invoke(this.childNodeIdsField.get(accessibilityNodeInfo), Integer.valueOf(i))).longValue()); } catch (ArrayIndexOutOfBoundsException e3) { e = e3; Log.w(AccessibilityViewEmbedder.TAG, "The longArrayGetIndex method threw an exception when invoked.", e); return null; } catch (IllegalAccessException e4) { Log.w(AccessibilityViewEmbedder.TAG, "Failed to access longArrayGetIndex method or the childNodeId field.", e4); } catch (InvocationTargetException e5) { e = e5; Log.w(AccessibilityViewEmbedder.TAG, "The longArrayGetIndex method threw an exception when invoked.", e); return null; } } return null; } /* JADX INFO: Access modifiers changed from: private */ public Long getParentNodeId(AccessibilityNodeInfo accessibilityNodeInfo) { Method method = this.getParentNodeId; if (method != null) { try { return Long.valueOf(((Long) method.invoke(accessibilityNodeInfo, new Object[0])).longValue()); } catch (IllegalAccessException e) { Log.w(AccessibilityViewEmbedder.TAG, "Failed to access getParentNodeId method.", e); } catch (InvocationTargetException e2) { Log.w(AccessibilityViewEmbedder.TAG, "The getParentNodeId method threw an exception when invoked.", e2); } } return yoinkParentIdFromParcel(accessibilityNodeInfo); } private static Long yoinkParentIdFromParcel(AccessibilityNodeInfo accessibilityNodeInfo) { AccessibilityNodeInfo obtain = AccessibilityNodeInfo.obtain(accessibilityNodeInfo); Parcel obtain2 = Parcel.obtain(); obtain2.setDataPosition(0); obtain.writeToParcel(obtain2, 0); obtain2.setDataPosition(0); long readLong = obtain2.readLong(); if (isBitSet(readLong, 0)) { obtain2.readInt(); } if (isBitSet(readLong, 1)) { obtain2.readLong(); } if (isBitSet(readLong, 2)) { obtain2.readInt(); } Long valueOf = isBitSet(readLong, 3) ? Long.valueOf(obtain2.readLong()) : null; obtain2.recycle(); return valueOf; } /* JADX INFO: Access modifiers changed from: private */ public Long getRecordSourceNodeId(AccessibilityRecord accessibilityRecord) { Method method = this.getRecordSourceNodeId; if (method == null) { return null; } try { return (Long) method.invoke(accessibilityRecord, new Object[0]); } catch (IllegalAccessException e) { Log.w(AccessibilityViewEmbedder.TAG, "Failed to access the getRecordSourceNodeId method.", e); return null; } catch (InvocationTargetException e2) { Log.w(AccessibilityViewEmbedder.TAG, "The getRecordSourceNodeId method threw an exception when invoked.", e2); return null; } } } }