Last active
November 19, 2021 21:20
-
-
Save sergeykomlach/d3a7e21023d27f0651265941b56e66a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private AccessibilityNodeInfoCompat getActiveWindows(String pkg) { | |
List<AccessibilityWindowInfo> windows = serviceA11y.getWindows(); | |
if (windows != null) { | |
for (AccessibilityWindowInfo windowInfo : windows) { | |
if (windowInfo != null) { | |
try { | |
if (windowInfo.getType() == AccessibilityWindowInfo.TYPE_APPLICATION) { | |
AccessibilityNodeInfo nodeInfo = windowInfo.getRoot(); | |
if (nodeInfo != null) { | |
if (TextUtils.equals(pkg, nodeInfo.getPackageName())) | |
return AccessibilityNodeInfoCompat.wrap(nodeInfo); | |
else | |
nodeInfo.recycle(); | |
} | |
} | |
} catch (Throwable e) { | |
if (!(e instanceof ClassCastException))//sometimes happens that Object casted to AccessibilityWindowInfo | |
{ logException(e); } | |
} finally { | |
windowInfo.recycle(); | |
} | |
} | |
} | |
} | |
AccessibilityNodeInfo nodeInfo = serviceA11y.getRootInActiveWindow();//hangs very often | |
if (nodeInfo != null) { | |
AccessibilityWindowInfo windowInfo = nodeInfo.getWindow(); | |
try { | |
if (windowInfo != null && windowInfo.getType() == AccessibilityWindowInfo.TYPE_APPLICATION) { | |
if (TextUtils.equals(pkg, nodeInfo.getPackageName())) | |
return AccessibilityNodeInfoCompat.wrap(nodeInfo); | |
} else { | |
nodeInfo.recycle(); | |
} | |
} finally { | |
if (windowInfo != null) { | |
windowInfo.recycle(); | |
} | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment