Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1eef69f9 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Implements equals methods in Context Hub classes

Bug: 117612105
Test: Compile, sanity check
Change-Id: Icea345dc194c72eabc1c27b23fa6235544eeaca4
parent 45ac8e40
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -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();
+32 −0
Original line number Diff line number Diff line
@@ -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);
+20 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.hardware.location;

import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -105,6 +106,25 @@ public class MemoryRegion implements Parcelable{
        return retVal;
    }

    @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;
+21 −0
Original line number Diff line number Diff line
@@ -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;
    }
}