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

Commit cfb945c4 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Add equals() to ProviderProperties

This lets us ignore updates to properties which are the same, and spend
less cycles giving everyone state updates when nothing has changed. Also
updates the Parcelable format for ProviderProperties, and removes dead
code from ServiceWatcher.

Test: presubmits
Change-Id: Ia6517438ff8988064247cc8d3288d576f73a1aa9
parent 6d60e86b
Loading
Loading
Loading
Loading
+47 −27
Original line number Original line Diff line number Diff line
@@ -25,11 +25,10 @@ import com.android.internal.util.Preconditions;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;


/**
/**
 * A Parcelable containing (legacy) location provider properties.
 * Location provider properties.
 * This object is just used inside the framework and system services.
 *
 * @hide
 * @hide
 */
 */
public final class ProviderProperties implements Parcelable {
public final class ProviderProperties implements Parcelable {
@@ -37,14 +36,12 @@ public final class ProviderProperties implements Parcelable {
    /** @hide */
    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({Criteria.POWER_LOW, Criteria.POWER_MEDIUM, Criteria.POWER_HIGH})
    @IntDef({Criteria.POWER_LOW, Criteria.POWER_MEDIUM, Criteria.POWER_HIGH})
    public @interface PowerRequirement {
    public @interface PowerRequirement {}
    }


    /** @hide */
    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({Criteria.ACCURACY_FINE, Criteria.ACCURACY_COARSE})
    @IntDef({Criteria.ACCURACY_FINE, Criteria.ACCURACY_COARSE})
    public @interface Accuracy {
    public @interface Accuracy {}
    }


    /**
    /**
     * True if provider requires access to a
     * True if provider requires access to a
@@ -132,19 +129,16 @@ public final class ProviderProperties implements Parcelable {
            new Parcelable.Creator<ProviderProperties>() {
            new Parcelable.Creator<ProviderProperties>() {
                @Override
                @Override
                public ProviderProperties createFromParcel(Parcel in) {
                public ProviderProperties createFromParcel(Parcel in) {
                    boolean requiresNetwork = in.readInt() == 1;
                    return new ProviderProperties(
                    boolean requiresSatellite = in.readInt() == 1;
                            /* requiresNetwork= */ in.readBoolean(),
                    boolean requiresCell = in.readInt() == 1;
                            /* requiresSatellite= */ in.readBoolean(),
                    boolean hasMonetaryCost = in.readInt() == 1;
                            /* requiresCell= */ in.readBoolean(),
                    boolean supportsAltitude = in.readInt() == 1;
                            /* hasMonetaryCost= */ in.readBoolean(),
                    boolean supportsSpeed = in.readInt() == 1;
                            /* supportsAltitude= */ in.readBoolean(),
                    boolean supportsBearing = in.readInt() == 1;
                            /* supportsSpeed= */ in.readBoolean(),
                    int powerRequirement = in.readInt();
                            /* supportsBearing= */ in.readBoolean(),
                    int accuracy = in.readInt();
                            /* powerRequirement= */ in.readInt(),
                    return new ProviderProperties(requiresNetwork, requiresSatellite,
                            /* accuracy= */ in.readInt());
                            requiresCell, hasMonetaryCost, supportsAltitude, supportsSpeed,
                            supportsBearing,
                            powerRequirement, accuracy);
                }
                }


                @Override
                @Override
@@ -160,17 +154,43 @@ public final class ProviderProperties implements Parcelable {


    @Override
    @Override
    public void writeToParcel(Parcel parcel, int flags) {
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeInt(mRequiresNetwork ? 1 : 0);
        parcel.writeBoolean(mRequiresNetwork);
        parcel.writeInt(mRequiresSatellite ? 1 : 0);
        parcel.writeBoolean(mRequiresSatellite);
        parcel.writeInt(mRequiresCell ? 1 : 0);
        parcel.writeBoolean(mRequiresCell);
        parcel.writeInt(mHasMonetaryCost ? 1 : 0);
        parcel.writeBoolean(mHasMonetaryCost);
        parcel.writeInt(mSupportsAltitude ? 1 : 0);
        parcel.writeBoolean(mSupportsAltitude);
        parcel.writeInt(mSupportsSpeed ? 1 : 0);
        parcel.writeBoolean(mSupportsSpeed);
        parcel.writeInt(mSupportsBearing ? 1 : 0);
        parcel.writeBoolean(mSupportsBearing);
        parcel.writeInt(mPowerRequirement);
        parcel.writeInt(mPowerRequirement);
        parcel.writeInt(mAccuracy);
        parcel.writeInt(mAccuracy);
    }
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof ProviderProperties)) {
            return false;
        }
        ProviderProperties that = (ProviderProperties) o;
        return mRequiresNetwork == that.mRequiresNetwork
                && mRequiresSatellite == that.mRequiresSatellite
                && mRequiresCell == that.mRequiresCell
                && mHasMonetaryCost == that.mHasMonetaryCost
                && mSupportsAltitude == that.mSupportsAltitude
                && mSupportsSpeed == that.mSupportsSpeed
                && mSupportsBearing == that.mSupportsBearing
                && mPowerRequirement == that.mPowerRequirement
                && mAccuracy == that.mAccuracy;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mRequiresNetwork, mRequiresSatellite, mRequiresCell, mHasMonetaryCost,
                mSupportsAltitude, mSupportsSpeed, mSupportsBearing, mPowerRequirement, mAccuracy);
    }

    @Override
    @Override
    public String toString() {
    public String toString() {
        StringBuilder b = new StringBuilder("ProviderProperties[");
        StringBuilder b = new StringBuilder("ProviderProperties[");
+0 −9
Original line number Original line Diff line number Diff line
@@ -74,15 +74,6 @@ public class ServiceWatcher implements ServiceConnection {
        default void onError() {}
        default void onError() {}
    }
    }


    /**
     * Function to run on binder interface.
     * @param <T> Type to return.
     */
    public interface BlockingBinderRunner<T> {
        /** Called to run client code with the binder. */
        T run(IBinder binder) throws RemoteException;
    }

    /**
    /**
     * Information on the service ServiceWatcher has selected as the best option for binding.
     * Information on the service ServiceWatcher has selected as the best option for binding.
     */
     */