diff options
| author | 2018-11-08 15:17:11 -0800 | |
|---|---|---|
| committer | 2018-11-16 10:31:11 -0800 | |
| commit | 1eef69f9cc26b4e2ea2d7912f4eb88a887cf9d85 (patch) | |
| tree | 647bef3186d6e4627c45e54d160aabd1ee46b2e3 | |
| parent | 45ac8e40024ed729ef85c51356b8047d27750433 (diff) | |
Implements equals methods in Context Hub classes
Bug: 117612105
Test: Compile, sanity check
Change-Id: Icea345dc194c72eabc1c27b23fa6235544eeaca4
4 files changed, 102 insertions, 0 deletions
diff --git a/core/java/android/hardware/location/ContextHubInfo.java b/core/java/android/hardware/location/ContextHubInfo.java index 36123e3d4229..51daa92d138e 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 @@ public class ContextHubInfo implements Parcelable { 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 96e74969a2e8..b2aa26853f7e 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 @@ public class ContextHubIntentEvent { 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 857434ea75b9..3d9e85955850 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 @@ public class MemoryRegion implements Parcelable{ } @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 66352581dac3..9f90d5966e4d 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 @@ public final class NanoAppMessage implements Parcelable { 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; + } } |