diff options
author | Mohamed <mohamed@zenadi.com> | 2017-05-29 11:48:35 +0200 |
---|---|---|
committer | Mohamed <mohamed@zenadi.com> | 2017-05-29 11:48:49 +0200 |
commit | a45946988ee887d395a183849ed98c4fcc3701d3 (patch) | |
tree | 5b293b9b6e69968865ce67e0a2040057ea6ae446 /app/src/main/java/com | |
parent | 9b646222ce942d6044575623181e68ae9b9a9569 (diff) |
getRootInActiveWindow throws an exception if it is unable to get root
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java index 2d19860f..cb8459d5 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java @@ -110,27 +110,32 @@ public class AutofillService extends AccessibilityService { && (event.getPackageName().equals("com.android.chrome") || event.getPackageName().equals("com.android.browser")))) { // there is a chance for getRootInActiveWindow() to return null at any time. save it. - AccessibilityNodeInfo root = getRootInActiveWindow(); - webViewTitle = searchWebView(root); - webViewURL = null; - if (webViewTitle != null) { - List<AccessibilityNodeInfo> nodes = root.findAccessibilityNodeInfosByViewId("com.android.chrome:id/url_bar"); - if (nodes.isEmpty()) { - nodes = root.findAccessibilityNodeInfosByViewId("com.android.browser:id/url"); - } - for (AccessibilityNodeInfo node : nodes) - if (node.getText() != null) { - try { - webViewURL = new URL(node.getText().toString()).getHost(); - } catch (MalformedURLException e) { - if (e.toString().contains("Protocol not found")) { - try { - webViewURL = new URL("http://" + node.getText().toString()).getHost(); - } catch (MalformedURLException ignored) { + try { + AccessibilityNodeInfo root = getRootInActiveWindow(); + webViewTitle = searchWebView(root); + webViewURL = null; + if (webViewTitle != null) { + List<AccessibilityNodeInfo> nodes = root.findAccessibilityNodeInfosByViewId("com.android.chrome:id/url_bar"); + if (nodes.isEmpty()) { + nodes = root.findAccessibilityNodeInfosByViewId("com.android.browser:id/url"); + } + for (AccessibilityNodeInfo node : nodes) + if (node.getText() != null) { + try { + webViewURL = new URL(node.getText().toString()).getHost(); + } catch (MalformedURLException e) { + if (e.toString().contains("Protocol not found")) { + try { + webViewURL = new URL("http://" + node.getText().toString()).getHost(); + } catch (MalformedURLException ignored) { + } } } } - } + } + } catch (Exception e) { + // sadly we were unable to access the data we wanted + return; } } |