Index: build/android/pylib/device/device_utils.py |
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py |
index 46aec6fc9df0eb7b94b89628457567a692299b81..33fde341b7e6cde128317485ab36c7bf09c31363 100644 |
--- a/build/android/pylib/device/device_utils.py |
+++ b/build/android/pylib/device/device_utils.py |
@@ -175,6 +175,37 @@ class DeviceUtils(object): |
assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR) |
assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR) |
+ def __eq__(self, other): |
+ """Checks whether |other| refers to the same device as |self|. |
+ |
+ Args: |
+ other: The object to compare to. This can be a basestring, an instance |
+ of adb_wrapper.AdbWrapper, or an instance of DeviceUtils. |
+ Returns: |
+ Whether |other| refers to the same device as |self|. |
+ """ |
+ if isinstance(other, basestring): |
perezju
2015/04/28 14:36:19
why not just do like we do in AdbWrapper, i.e.:
jbudorick
2015/04/28 15:52:53
Wow, that's much better. Done.
|
+ other_serial = other |
+ elif isinstance(other, adb_wrapper.AdbWrapper): |
+ other_serial = other.GetDeviceSerial() |
+ elif isinstance(other, DeviceUtils): |
+ other_serial = other.adb.GetDeviceSerial() |
+ else: |
+ return False |
+ return self.adb.GetDeviceSerial() == other_serial |
+ |
+ def __lt__(self, other): |
+ """Compares two instances of DeviceUtils. |
+ |
+ This merely compares their serial numbers. |
+ |
+ Args: |
+ other: The instance of DeviceUtils to compare to. |
+ Returns: |
+ Whether |self| is less than |other|. |
+ """ |
+ return self.adb.GetDeviceSerial() < other.adb.GetDeviceSerial() |
+ |
def __str__(self): |
"""Returns the device serial.""" |
return self.adb.GetDeviceSerial() |