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
diff --git a/location/java/com/android/internal/location/ProviderProperties.java b/location/java/com/android/internal/location/ProviderProperties.java
index 68f9ec3..c3439c5 100644
--- a/location/java/com/android/internal/location/ProviderProperties.java
+++ b/location/java/com/android/internal/location/ProviderProperties.java
@@ -25,11 +25,10 @@
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
+import java.util.Objects;
 
 /**
- * A Parcelable containing (legacy) location provider properties.
- * This object is just used inside the framework and system services.
- *
+ * Location provider properties.
  * @hide
  */
 public final class ProviderProperties implements Parcelable {
@@ -37,14 +36,12 @@
     /** @hide */
     @Retention(RetentionPolicy.SOURCE)
     @IntDef({Criteria.POWER_LOW, Criteria.POWER_MEDIUM, Criteria.POWER_HIGH})
-    public @interface PowerRequirement {
-    }
+    public @interface PowerRequirement {}
 
     /** @hide */
     @Retention(RetentionPolicy.SOURCE)
     @IntDef({Criteria.ACCURACY_FINE, Criteria.ACCURACY_COARSE})
-    public @interface Accuracy {
-    }
+    public @interface Accuracy {}
 
     /**
      * True if provider requires access to a
@@ -132,19 +129,16 @@
             new Parcelable.Creator<ProviderProperties>() {
                 @Override
                 public ProviderProperties createFromParcel(Parcel in) {
-                    boolean requiresNetwork = in.readInt() == 1;
-                    boolean requiresSatellite = in.readInt() == 1;
-                    boolean requiresCell = in.readInt() == 1;
-                    boolean hasMonetaryCost = in.readInt() == 1;
-                    boolean supportsAltitude = in.readInt() == 1;
-                    boolean supportsSpeed = in.readInt() == 1;
-                    boolean supportsBearing = in.readInt() == 1;
-                    int powerRequirement = in.readInt();
-                    int accuracy = in.readInt();
-                    return new ProviderProperties(requiresNetwork, requiresSatellite,
-                            requiresCell, hasMonetaryCost, supportsAltitude, supportsSpeed,
-                            supportsBearing,
-                            powerRequirement, accuracy);
+                    return new ProviderProperties(
+                            /* requiresNetwork= */ in.readBoolean(),
+                            /* requiresSatellite= */ in.readBoolean(),
+                            /* requiresCell= */ in.readBoolean(),
+                            /* hasMonetaryCost= */ in.readBoolean(),
+                            /* supportsAltitude= */ in.readBoolean(),
+                            /* supportsSpeed= */ in.readBoolean(),
+                            /* supportsBearing= */ in.readBoolean(),
+                            /* powerRequirement= */ in.readInt(),
+                            /* accuracy= */ in.readInt());
                 }
 
                 @Override
@@ -160,18 +154,44 @@
 
     @Override
     public void writeToParcel(Parcel parcel, int flags) {
-        parcel.writeInt(mRequiresNetwork ? 1 : 0);
-        parcel.writeInt(mRequiresSatellite ? 1 : 0);
-        parcel.writeInt(mRequiresCell ? 1 : 0);
-        parcel.writeInt(mHasMonetaryCost ? 1 : 0);
-        parcel.writeInt(mSupportsAltitude ? 1 : 0);
-        parcel.writeInt(mSupportsSpeed ? 1 : 0);
-        parcel.writeInt(mSupportsBearing ? 1 : 0);
+        parcel.writeBoolean(mRequiresNetwork);
+        parcel.writeBoolean(mRequiresSatellite);
+        parcel.writeBoolean(mRequiresCell);
+        parcel.writeBoolean(mHasMonetaryCost);
+        parcel.writeBoolean(mSupportsAltitude);
+        parcel.writeBoolean(mSupportsSpeed);
+        parcel.writeBoolean(mSupportsBearing);
         parcel.writeInt(mPowerRequirement);
         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
     public String toString() {
         StringBuilder b = new StringBuilder("ProviderProperties[");
         b.append("power=").append(powerToString(mPowerRequirement)).append(", ");
diff --git a/services/core/java/com/android/server/ServiceWatcher.java b/services/core/java/com/android/server/ServiceWatcher.java
index 953fb8c..c14b18a 100644
--- a/services/core/java/com/android/server/ServiceWatcher.java
+++ b/services/core/java/com/android/server/ServiceWatcher.java
@@ -75,15 +75,6 @@
     }
 
     /**
-     * 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.
      */
     public static final class ServiceInfo implements Comparable<ServiceInfo> {