diff options
author | Soonil Nagarkar <sooniln@google.com> | 2020-09-15 10:32:40 -0700 |
---|---|---|
committer | Soonil Nagarkar <sooniln@google.com> | 2020-09-15 17:13:46 -0700 |
commit | f2bc6ba3a0ee6f6a45807e17582d018e961a8421 (patch) | |
tree | c5cd9635a7094ecb7a3445bf94c091b8e3cd800c /location/lib | |
parent | 56b327db8854096221c60d181e953159ebda850e (diff) |
Fix up provider internal/external APIs
-Encapsulate various fields
-Bring naming in line with API guidelines
-Minor refactoring
Bug: 168621146
Test: manual
Change-Id: I55681a3d84d7833c98569a13a57e6c4f0b728a67
Diffstat (limited to 'location/lib')
3 files changed, 85 insertions, 22 deletions
diff --git a/location/lib/api/current.txt b/location/lib/api/current.txt index 4d0acea15263..c00ff57889d1 100644 --- a/location/lib/api/current.txt +++ b/location/lib/api/current.txt @@ -44,14 +44,17 @@ package com.android.location.provider { } public final class ProviderPropertiesUnbundled { - method public static com.android.location.provider.ProviderPropertiesUnbundled create(boolean, boolean, boolean, boolean, boolean, boolean, boolean, int, int); + method @NonNull public static com.android.location.provider.ProviderPropertiesUnbundled create(boolean, boolean, boolean, boolean, boolean, boolean, boolean, int, int); } public final class ProviderRequestUnbundled { method public long getInterval(); - method public java.util.List<com.android.location.provider.LocationRequestUnbundled> getLocationRequests(); + method @NonNull public java.util.List<com.android.location.provider.LocationRequestUnbundled> getLocationRequests(); method public boolean getReportLocation(); + method @NonNull @RequiresApi(android.os.Build.VERSION_CODES.S) public android.os.WorkSource getWorkSource(); method @RequiresApi(android.os.Build.VERSION_CODES.Q) public boolean isLocationSettingsIgnored(); + method @RequiresApi(android.os.Build.VERSION_CODES.S) public boolean isLowPower(); + field public static final long INTERVAL_DISABLED = 9223372036854775807L; // 0x7fffffffffffffffL } } diff --git a/location/lib/java/com/android/location/provider/ProviderPropertiesUnbundled.java b/location/lib/java/com/android/location/provider/ProviderPropertiesUnbundled.java index b1a1bda45f39..21ee5f465c48 100644 --- a/location/lib/java/com/android/location/provider/ProviderPropertiesUnbundled.java +++ b/location/lib/java/com/android/location/provider/ProviderPropertiesUnbundled.java @@ -16,19 +16,24 @@ package com.android.location.provider; +import android.annotation.NonNull; + import com.android.internal.location.ProviderProperties; +import java.util.Objects; + /** - * This class is an interface to Provider Properties for unbundled applications. + * Represents provider properties for unbundled applications. * - * <p>IMPORTANT: This class is effectively a public API for unbundled - * applications, and must remain API stable. See README.txt in the root - * of this package for more information. + * <p>IMPORTANT: This class is effectively a public API for unbundled applications, and must remain + * API stable. */ public final class ProviderPropertiesUnbundled { - private final ProviderProperties mProperties; - public static ProviderPropertiesUnbundled create(boolean requiresNetwork, + /** + * Create new instance of {@link ProviderPropertiesUnbundled} with the given arguments. + */ + public static @NonNull ProviderPropertiesUnbundled create(boolean requiresNetwork, boolean requiresSatellite, boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude, boolean supportsSpeed, boolean supportsBearing, int powerRequirement, int accuracy) { @@ -37,12 +42,14 @@ public final class ProviderPropertiesUnbundled { supportsBearing, powerRequirement, accuracy)); } + private final ProviderProperties mProperties; + private ProviderPropertiesUnbundled(ProviderProperties properties) { - mProperties = properties; + mProperties = Objects.requireNonNull(properties); } /** @hide */ - public ProviderProperties getProviderProperties() { + public @NonNull ProviderProperties getProviderProperties() { return mProperties; } @@ -50,4 +57,22 @@ public final class ProviderPropertiesUnbundled { public String toString() { return mProperties.toString(); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + ProviderPropertiesUnbundled that = (ProviderPropertiesUnbundled) o; + return mProperties.equals(that.mProperties); + } + + @Override + public int hashCode() { + return Objects.hash(mProperties); + } } diff --git a/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java b/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java index b650efc91907..6f5fcc7bfc8e 100644 --- a/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java +++ b/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java @@ -16,8 +16,10 @@ package com.android.location.provider; +import android.annotation.NonNull; import android.location.LocationRequest; import android.os.Build; +import android.os.WorkSource; import androidx.annotation.RequiresApi; @@ -27,14 +29,18 @@ import java.util.ArrayList; import java.util.List; /** - * This class is an interface to Provider Requests for unbundled applications. + * Represents a provider request for unbundled applications. * - * <p>IMPORTANT: This class is effectively a public API for unbundled - * applications, and must remain API stable. See README.txt in the root - * of this package for more information. + * <p>IMPORTANT: This class is effectively a public API for unbundled applications, and must remain + * API stable. */ public final class ProviderRequestUnbundled { + /** + * Represents a disabled request. + */ + public static final long INTERVAL_DISABLED = ProviderRequest.INTERVAL_DISABLED; + private final ProviderRequest mRequest; /** @hide */ @@ -42,31 +48,60 @@ public final class ProviderRequestUnbundled { mRequest = request; } + /** + * True if this is an active request with a valid location reporting interval, false if this + * request is inactive and does not require any locations to be reported. + */ public boolean getReportLocation() { - return mRequest.reportLocation; + return mRequest.isActive(); } + /** + * The interval at which a provider should report location. Will return + * {@link #INTERVAL_DISABLED} for an inactive request. + */ public long getInterval() { - return mRequest.interval; + return mRequest.getIntervalMillis(); } + /** + * Whether any applicable hardware low power modes should be used to satisfy this request. + */ + @RequiresApi(Build.VERSION_CODES.S) + public boolean isLowPower() { + return mRequest.isLowPower(); + } + + /** + * Whether the provider should ignore all location settings, user consents, power restrictions + * or any other restricting factors and always satisfy this request to the best of their + * ability. This should only be used in case of a user initiated emergency. + */ @RequiresApi(Build.VERSION_CODES.Q) public boolean isLocationSettingsIgnored() { - return mRequest.locationSettingsIgnored; + return mRequest.isLocationSettingsIgnored(); } /** - * Never null. + * The full list of location requests contributing to this provider request. */ - public List<LocationRequestUnbundled> getLocationRequests() { + public @NonNull List<LocationRequestUnbundled> getLocationRequests() { List<LocationRequestUnbundled> result = new ArrayList<>( - mRequest.locationRequests.size()); - for (LocationRequest r : mRequest.locationRequests) { - result.add(new LocationRequestUnbundled(r)); + mRequest.getLocationRequests().size()); + for (LocationRequest r : mRequest.getLocationRequests()) { + result.add(new LocationRequestUnbundled(r)); } return result; } + /** + * The power blame for this provider request. + */ + @RequiresApi(Build.VERSION_CODES.S) + public @NonNull WorkSource getWorkSource() { + return mRequest.getWorkSource(); + } + @Override public String toString() { return mRequest.toString(); |