summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2017-11-02 04:12:09 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-11-02 04:12:09 +0000
commit7dbaf8998dc90f671ec3fdf3f70fe8bb65cc99cd (patch)
treec89bbf71140a005f8f2017dc5ab1b1a37e6e8f58 /core/java
parentc76ca48825cf82eabe65ec2acb538b028993480e (diff)
parentddfee6b1542eed7cde4420a264706781cdb1535f (diff)
Merge "Allow equality checking and hash for HIDL interface proxies." am: 762f27c6a2 am: 0134fd1577
am: ddfee6b154 Change-Id: I70c7fb09397cf9b483ed648f1516158c6c431475
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/os/HidlSupport.java23
-rw-r--r--core/java/android/os/HwRemoteBinder.java5
2 files changed, 28 insertions, 0 deletions
diff --git a/core/java/android/os/HidlSupport.java b/core/java/android/os/HidlSupport.java
index 7dec4d724f15..3544ea1e03e3 100644
--- a/core/java/android/os/HidlSupport.java
+++ b/core/java/android/os/HidlSupport.java
@@ -156,4 +156,27 @@ public class HidlSupport {
// Should not reach here.
throw new UnsupportedOperationException();
}
+
+ /**
+ * Test that two interfaces are equal. This is the Java equivalent to C++
+ * interfacesEqual function.
+ * This essentially calls .equals on the internal binder objects (via Binder()).
+ * - If both interfaces are proxies, asBinder() returns a {@link HwRemoteBinder}
+ * object, and they are compared in {@link HwRemoteBinder#equals}.
+ * - If both interfaces are stubs, asBinder() returns the object itself. By default,
+ * auto-generated IFoo.Stub does not override equals(), but an implementation can
+ * optionally override it, and {@code interfacesEqual} will use it here.
+ */
+ public static boolean interfacesEqual(IHwInterface lft, Object rgt) {
+ if (lft == rgt) {
+ return true;
+ }
+ if (lft == null || rgt == null) {
+ return false;
+ }
+ if (!(rgt instanceof IHwInterface)) {
+ return false;
+ }
+ return Objects.equals(lft.asBinder(), ((IHwInterface) rgt).asBinder());
+ }
}
diff --git a/core/java/android/os/HwRemoteBinder.java b/core/java/android/os/HwRemoteBinder.java
index 2f89ce6270be..a07e42c720c5 100644
--- a/core/java/android/os/HwRemoteBinder.java
+++ b/core/java/android/os/HwRemoteBinder.java
@@ -63,4 +63,9 @@ public class HwRemoteBinder implements IHwBinder {
}
private long mNativeContext;
+
+ @Override
+ public final native boolean equals(Object other);
+ @Override
+ public final native int hashCode();
}