fix getrootinactivewindow() nullpointerexceptions

This commit is contained in:
Matthew Wong 2016-01-03 20:39:37 -05:00
parent 6ef9e3bbca
commit aaa9af93de

View file

@ -108,17 +108,14 @@ public class AutofillService extends AccessibilityService {
&& event.getSource() != null && event.getSource() != null
&& (event.getSource().getPackageName().equals("com.android.chrome") && (event.getSource().getPackageName().equals("com.android.chrome")
|| event.getSource().getPackageName().equals("com.android.browser")))) { || event.getSource().getPackageName().equals("com.android.browser")))) {
webViewTitle = searchWebView(getRootInActiveWindow()); // there is a chance for getRootInActiveWindow() to return null at any time. save it.
AccessibilityNodeInfo root = getRootInActiveWindow();
// non-null webViewTitle means there is a webView. But still somehow webViewTitle = searchWebView(root);
// getRootInActiveWindow() can be null, when switching windows
webViewURL = null; webViewURL = null;
if (webViewTitle != null && getRootInActiveWindow() != null) { if (webViewTitle != null) {
List<AccessibilityNodeInfo> nodes = getRootInActiveWindow() List<AccessibilityNodeInfo> nodes = root.findAccessibilityNodeInfosByViewId("com.android.chrome:id/url_bar");
.findAccessibilityNodeInfosByViewId("com.android.chrome:id/url_bar");
if (nodes.isEmpty()) { if (nodes.isEmpty()) {
nodes = getRootInActiveWindow() nodes = root.findAccessibilityNodeInfosByViewId("com.android.browser:id/url");
.findAccessibilityNodeInfosByViewId("com.android.browser:id/url");
} }
for (AccessibilityNodeInfo node : nodes) for (AccessibilityNodeInfo node : nodes)
if (node.getText() != null) { if (node.getText() != null) {