Implements equals methods in Context Hub classes
Bug: 117612105
Test: Compile, sanity check
Change-Id: Icea345dc194c72eabc1c27b23fa6235544eeaca4
diff --git a/core/java/android/hardware/location/ContextHubInfo.java b/core/java/android/hardware/location/ContextHubInfo.java
index 36123e3..51daa92 100644
--- a/core/java/android/hardware/location/ContextHubInfo.java
+++ b/core/java/android/hardware/location/ContextHubInfo.java
@@ -15,6 +15,7 @@
*/
package android.hardware.location;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.hardware.contexthub.V1_0.ContextHub;
import android.os.Parcel;
@@ -267,6 +268,34 @@
return retVal;
}
+ @Override
+ public boolean equals(@Nullable Object object) {
+ if (object == this) {
+ return true;
+ }
+
+ boolean isEqual = false;
+ if (object instanceof ContextHubInfo) {
+ ContextHubInfo other = (ContextHubInfo) object;
+ isEqual = (other.getId() == mId)
+ && other.getName().equals(mName)
+ && other.getVendor().equals(mVendor)
+ && other.getToolchain().equals(mToolchain)
+ && (other.getToolchainVersion() == mToolchainVersion)
+ && (other.getStaticSwVersion() == getStaticSwVersion())
+ && (other.getChrePlatformId() == mChrePlatformId)
+ && (other.getPeakMips() == mPeakMips)
+ && (other.getStoppedPowerDrawMw() == mStoppedPowerDrawMw)
+ && (other.getSleepPowerDrawMw() == mSleepPowerDrawMw)
+ && (other.getPeakPowerDrawMw() == mPeakPowerDrawMw)
+ && (other.getMaxPacketLengthBytes() == mMaxPacketLengthBytes)
+ && Arrays.equals(other.getSupportedSensors(), mSupportedSensors)
+ && Arrays.equals(other.getMemoryRegions(), mMemoryRegions);
+ }
+
+ return isEqual;
+ }
+
private ContextHubInfo(Parcel in) {
mId = in.readInt();
mName = in.readString();
diff --git a/core/java/android/hardware/location/ContextHubIntentEvent.java b/core/java/android/hardware/location/ContextHubIntentEvent.java
index 96e7496..b2aa268 100644
--- a/core/java/android/hardware/location/ContextHubIntentEvent.java
+++ b/core/java/android/hardware/location/ContextHubIntentEvent.java
@@ -16,6 +16,7 @@
package android.hardware.location;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.app.PendingIntent;
import android.content.Intent;
@@ -206,6 +207,37 @@
return out + "]";
}
+ @Override
+ public boolean equals(@Nullable Object object) {
+ if (object == this) {
+ return true;
+ }
+
+ boolean isEqual = false;
+ if (object instanceof ContextHubIntentEvent) {
+ ContextHubIntentEvent other = (ContextHubIntentEvent) object;
+ if (other.getEventType() == mEventType
+ && other.getContextHubInfo().equals(mContextHubInfo)) {
+ isEqual = true;
+ try {
+ if (mEventType != ContextHubManager.EVENT_HUB_RESET) {
+ isEqual &= (other.getNanoAppId() == mNanoAppId);
+ }
+ if (mEventType == ContextHubManager.EVENT_NANOAPP_ABORTED) {
+ isEqual &= (other.getNanoAppAbortCode() == mNanoAppAbortCode);
+ }
+ if (mEventType == ContextHubManager.EVENT_NANOAPP_MESSAGE) {
+ isEqual &= other.getNanoAppMessage().equals(mNanoAppMessage);
+ }
+ } catch (UnsupportedOperationException e) {
+ isEqual = false;
+ }
+ }
+ }
+
+ return isEqual;
+ }
+
private static void hasExtraOrThrow(Intent intent, String extra) {
if (!intent.hasExtra(extra)) {
throw new IllegalArgumentException("Intent did not have extra: " + extra);
diff --git a/core/java/android/hardware/location/MemoryRegion.java b/core/java/android/hardware/location/MemoryRegion.java
index 857434e..3d9e859 100644
--- a/core/java/android/hardware/location/MemoryRegion.java
+++ b/core/java/android/hardware/location/MemoryRegion.java
@@ -16,6 +16,7 @@
package android.hardware.location;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -106,6 +107,25 @@
}
@Override
+ public boolean equals(@Nullable Object object) {
+ if (object == this) {
+ return true;
+ }
+
+ boolean isEqual = false;
+ if (object instanceof MemoryRegion) {
+ MemoryRegion other = (MemoryRegion) object;
+ isEqual = (other.getCapacityBytes() == mSizeBytes)
+ && (other.getFreeCapacityBytes() == mSizeBytesFree)
+ && (other.isReadable() == mIsReadable)
+ && (other.isWritable() == mIsWritable)
+ && (other.isExecutable() == mIsExecutable);
+ }
+
+ return isEqual;
+ }
+
+ @Override
public int describeContents() {
return 0;
}
diff --git a/core/java/android/hardware/location/NanoAppMessage.java b/core/java/android/hardware/location/NanoAppMessage.java
index 6635258..9f90d59 100644
--- a/core/java/android/hardware/location/NanoAppMessage.java
+++ b/core/java/android/hardware/location/NanoAppMessage.java
@@ -15,10 +15,13 @@
*/
package android.hardware.location;
+import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
+import java.util.Arrays;
+
/**
* A class describing messages send to or from nanoapps through the Context Hub Service.
*
@@ -168,4 +171,22 @@
return ret;
}
+
+ @Override
+ public boolean equals(@Nullable Object object) {
+ if (object == this) {
+ return true;
+ }
+
+ boolean isEqual = false;
+ if (object instanceof NanoAppMessage) {
+ NanoAppMessage other = (NanoAppMessage) object;
+ isEqual = (other.getNanoAppId() == mNanoAppId)
+ && (other.getMessageType() == mMessageType)
+ && (other.isBroadcastMessage() == mIsBroadcasted)
+ && Arrays.equals(other.getMessageBody(), mMessageBody);
+ }
+
+ return isEqual;
+ }
}