From adb89214532a2eda2b5396886ae1ada16d890b24 Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Thu, 28 May 2015 15:35:52 -0700 Subject: Clean up calls to Rect.intersect() This CL checks for the return value for Rect.intersect() for whether there is actually an intersection before taking the return intersected rect. In the case of no intersection (Rect.intersect() returns false), an empty rect will be used as the intersection. bug: 7368679 Change-Id: Ibda3bfd662f8ca83cb5662748d9be250243b72b2 --- .../com/android/uiautomator/core/AccessibilityNodeInfoHelper.java | 7 +++++-- .../library/core-src/com/android/uiautomator/core/UiObject.java | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'cmds') diff --git a/cmds/uiautomator/library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java b/cmds/uiautomator/library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java index 54835e3..de2fec0 100644 --- a/cmds/uiautomator/library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java +++ b/cmds/uiautomator/library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java @@ -46,7 +46,10 @@ class AccessibilityNodeInfoHelper { displayRect.right = width; displayRect.bottom = height; - nodeRect.intersect(displayRect); - return nodeRect; + if (nodeRect.intersect(displayRect)) { + return nodeRect; + } else { + return new Rect(); + } } } diff --git a/cmds/uiautomator/library/core-src/com/android/uiautomator/core/UiObject.java b/cmds/uiautomator/library/core-src/com/android/uiautomator/core/UiObject.java index 4bb99cd..2118da8 100644 --- a/cmds/uiautomator/library/core-src/com/android/uiautomator/core/UiObject.java +++ b/cmds/uiautomator/library/core-src/com/android/uiautomator/core/UiObject.java @@ -353,8 +353,12 @@ public class UiObject { Rect parentRect = AccessibilityNodeInfoHelper .getVisibleBoundsInScreen(scrollableParentNode, w, h); // adjust for partial clipping of targeted by parent node if required - nodeRect.intersect(parentRect); - return nodeRect; + if (nodeRect.intersect(parentRect)) { + return nodeRect; + } else { + // Node rect has no intersection with parent Rect + return new Rect(); + } } /** -- cgit v1.1