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 | |
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
14 files changed, 421 insertions, 296 deletions
diff --git a/location/java/android/location/LocationProvider.java b/location/java/android/location/LocationProvider.java index 52a03b61d21c..b9506041554b 100644 --- a/location/java/android/location/LocationProvider.java +++ b/location/java/android/location/LocationProvider.java @@ -92,23 +92,23 @@ public class LocationProvider { } if (criteria.getAccuracy() != Criteria.NO_REQUIREMENT && - criteria.getAccuracy() < properties.mAccuracy) { + criteria.getAccuracy() < properties.getAccuracy()) { return false; } if (criteria.getPowerRequirement() != Criteria.NO_REQUIREMENT && - criteria.getPowerRequirement() < properties.mPowerRequirement) { + criteria.getPowerRequirement() < properties.getPowerRequirement()) { return false; } - if (criteria.isAltitudeRequired() && !properties.mSupportsAltitude) { + if (criteria.isAltitudeRequired() && !properties.hasAltitudeSupport()) { return false; } - if (criteria.isSpeedRequired() && !properties.mSupportsSpeed) { + if (criteria.isSpeedRequired() && !properties.hasSpeedSupport()) { return false; } - if (criteria.isBearingRequired() && !properties.mSupportsBearing) { + if (criteria.isBearingRequired() && !properties.hasBearingSupport()) { return false; } - if (!criteria.isCostAllowed() && properties.mHasMonetaryCost) { + if (!criteria.isCostAllowed() && properties.hasMonetaryCost()) { return false; } return true; @@ -119,7 +119,7 @@ public class LocationProvider { * data network (e.g., the Internet), false otherwise. */ public boolean requiresNetwork() { - return mProperties.mRequiresNetwork; + return mProperties.hasNetworkRequirement(); } /** @@ -128,7 +128,7 @@ public class LocationProvider { * otherwise. */ public boolean requiresSatellite() { - return mProperties.mRequiresSatellite; + return mProperties.hasSatelliteRequirement(); } /** @@ -137,7 +137,7 @@ public class LocationProvider { * otherwise. */ public boolean requiresCell() { - return mProperties.mRequiresCell; + return mProperties.hasCellRequirement(); } /** @@ -146,7 +146,7 @@ public class LocationProvider { * each provider to give accurate information. */ public boolean hasMonetaryCost() { - return mProperties.mHasMonetaryCost; + return mProperties.hasMonetaryCost(); } /** @@ -156,7 +156,7 @@ public class LocationProvider { * should return true. */ public boolean supportsAltitude() { - return mProperties.mSupportsAltitude; + return mProperties.hasAltitudeSupport(); } /** @@ -166,7 +166,7 @@ public class LocationProvider { * should return true. */ public boolean supportsSpeed() { - return mProperties.mSupportsSpeed; + return mProperties.hasSpeedSupport(); } /** @@ -176,7 +176,7 @@ public class LocationProvider { * should return true. */ public boolean supportsBearing() { - return mProperties.mSupportsBearing; + return mProperties.hasBearingSupport(); } /** @@ -186,7 +186,7 @@ public class LocationProvider { * constants Criteria.POWER_REQUIREMENT_*. */ public int getPowerRequirement() { - return mProperties.mPowerRequirement; + return mProperties.getPowerRequirement(); } /** @@ -197,6 +197,6 @@ public class LocationProvider { * is returned. */ public int getAccuracy() { - return mProperties.mAccuracy; + return mProperties.getAccuracy(); } } diff --git a/location/java/com/android/internal/location/ILocationProvider.aidl b/location/java/com/android/internal/location/ILocationProvider.aidl index 4246c6cd1004..01570dc4415d 100644 --- a/location/java/com/android/internal/location/ILocationProvider.aidl +++ b/location/java/com/android/internal/location/ILocationProvider.aidl @@ -29,12 +29,12 @@ import com.android.internal.location.ProviderRequest; */ interface ILocationProvider { - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = 30, publicAlternatives = "{@code Do not use}") oneway void setLocationProviderManager(in ILocationProviderManager manager); - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = 30, publicAlternatives = "{@code Do not use}") oneway void setRequest(in ProviderRequest request, in WorkSource ws); - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = 30, publicAlternatives = "{@code Do not use}") oneway void sendExtraCommand(String command, in Bundle extras); } diff --git a/location/java/com/android/internal/location/ProviderProperties.java b/location/java/com/android/internal/location/ProviderProperties.java index c3439c5946b0..dbb61d2305f0 100644 --- a/location/java/com/android/internal/location/ProviderProperties.java +++ b/location/java/com/android/internal/location/ProviderProperties.java @@ -43,86 +43,96 @@ public final class ProviderProperties implements Parcelable { @IntDef({Criteria.ACCURACY_FINE, Criteria.ACCURACY_COARSE}) public @interface Accuracy {} + private final boolean mHasNetworkRequirement; + private final boolean mHasSatelliteRequirement; + private final boolean mHasCellRequirement; + private final boolean mHasMonetaryCost; + private final boolean mHasAltitudeSupport; + private final boolean mHasSpeedSupport; + private final boolean mHasBearingSupport; + private final @PowerRequirement int mPowerRequirement; + private final @Accuracy int mAccuracy; + + public ProviderProperties(boolean hasNetworkRequirement, boolean hasSatelliteRequirement, + boolean hasCellRequirement, boolean hasMonetaryCost, boolean hasAltitudeSupport, + boolean hasSpeedSupport, boolean hasBearingSupport, + @PowerRequirement int powerRequirement, @Accuracy int accuracy) { + mHasNetworkRequirement = hasNetworkRequirement; + mHasSatelliteRequirement = hasSatelliteRequirement; + mHasCellRequirement = hasCellRequirement; + mHasMonetaryCost = hasMonetaryCost; + mHasAltitudeSupport = hasAltitudeSupport; + mHasSpeedSupport = hasSpeedSupport; + mHasBearingSupport = hasBearingSupport; + mPowerRequirement = Preconditions.checkArgumentInRange(powerRequirement, Criteria.POWER_LOW, + Criteria.POWER_HIGH, "powerRequirement"); + mAccuracy = Preconditions.checkArgumentInRange(accuracy, Criteria.ACCURACY_FINE, + Criteria.ACCURACY_COARSE, "accuracy"); + } + /** - * True if provider requires access to a - * data network (e.g., the Internet), false otherwise. + * True if provider requires access to a data network (e.g., the Internet). */ - public final boolean mRequiresNetwork; + public boolean hasNetworkRequirement() { + return mHasNetworkRequirement; + } /** - * True if the provider requires access to a - * satellite-based positioning system (e.g., GPS), false - * otherwise. + * True if the provider requires access to a satellite-based positioning system (e.g., GPS). */ - public final boolean mRequiresSatellite; + public boolean hasSatelliteRequirement() { + return mHasSatelliteRequirement; + } /** - * True if the provider requires access to an appropriate - * cellular network (e.g., to make use of cell tower IDs), false - * otherwise. + * True if the provider requires access to a cellular network (e.g., for cell tower IDs). */ - public final boolean mRequiresCell; + public boolean hasCellRequirement() { + return mHasCellRequirement; + } /** - * True if the use of this provider may result in a - * monetary charge to the user, false if use is free. It is up to - * each provider to give accurate information. Cell (network) usage - * is not considered monetary cost. + * True if this provider may result in a monetary charge to the user. Network usage is not + * considered a monetary cost. */ - public final boolean mHasMonetaryCost; + public boolean hasMonetaryCost() { + return mHasMonetaryCost; + } /** - * True if the provider is able to provide altitude - * information, false otherwise. A provider that reports altitude - * under most circumstances but may occasionally not report it - * should return true. + * True if the provider is able to provide altitude under at least some conditions. */ - public final boolean mSupportsAltitude; + public boolean hasAltitudeSupport() { + return mHasAltitudeSupport; + } /** - * True if the provider is able to provide speed - * information, false otherwise. A provider that reports speed - * under most circumstances but may occasionally not report it - * should return true. + * True if the provider is able to provide speed under at least some conditions. */ - public final boolean mSupportsSpeed; + public boolean hasSpeedSupport() { + return mHasSpeedSupport; + } /** - * True if the provider is able to provide bearing - * information, false otherwise. A provider that reports bearing - * under most circumstances but may occasionally not report it - * should return true. + * True if the provider is able to provide bearing under at least some conditions. */ - public final boolean mSupportsBearing; + public boolean hasBearingSupport() { + return mHasBearingSupport; + } /** * Power requirement for this provider. */ - @PowerRequirement - public final int mPowerRequirement; + public @PowerRequirement int getPowerRequirement() { + return mPowerRequirement; + } /** * Constant describing the horizontal accuracy returned * by this provider. */ - @Accuracy - public final int mAccuracy; - - public ProviderProperties(boolean requiresNetwork, boolean requiresSatellite, - boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude, - boolean supportsSpeed, boolean supportsBearing, @PowerRequirement int powerRequirement, - @Accuracy int accuracy) { - mRequiresNetwork = requiresNetwork; - mRequiresSatellite = requiresSatellite; - mRequiresCell = requiresCell; - mHasMonetaryCost = hasMonetaryCost; - mSupportsAltitude = supportsAltitude; - mSupportsSpeed = supportsSpeed; - mSupportsBearing = supportsBearing; - mPowerRequirement = Preconditions.checkArgumentInRange(powerRequirement, Criteria.POWER_LOW, - Criteria.POWER_HIGH, "powerRequirement"); - mAccuracy = Preconditions.checkArgumentInRange(accuracy, Criteria.ACCURACY_FINE, - Criteria.ACCURACY_COARSE, "accuracy"); + public @Accuracy int getAccuracy() { + return mAccuracy; } public static final Parcelable.Creator<ProviderProperties> CREATOR = @@ -130,13 +140,13 @@ public final class ProviderProperties implements Parcelable { @Override public ProviderProperties createFromParcel(Parcel in) { return new ProviderProperties( - /* requiresNetwork= */ in.readBoolean(), - /* requiresSatellite= */ in.readBoolean(), - /* requiresCell= */ in.readBoolean(), + /* hasNetworkRequirement= */ in.readBoolean(), + /* hasSatelliteRequirement= */ in.readBoolean(), + /* hasCellRequirement= */ in.readBoolean(), /* hasMonetaryCost= */ in.readBoolean(), - /* supportsAltitude= */ in.readBoolean(), - /* supportsSpeed= */ in.readBoolean(), - /* supportsBearing= */ in.readBoolean(), + /* hasAltitudeSupport= */ in.readBoolean(), + /* hasSpeedSupport= */ in.readBoolean(), + /* hasBearingSupport= */ in.readBoolean(), /* powerRequirement= */ in.readInt(), /* accuracy= */ in.readInt()); } @@ -154,13 +164,13 @@ public final class ProviderProperties implements Parcelable { @Override public void writeToParcel(Parcel parcel, int flags) { - parcel.writeBoolean(mRequiresNetwork); - parcel.writeBoolean(mRequiresSatellite); - parcel.writeBoolean(mRequiresCell); + parcel.writeBoolean(mHasNetworkRequirement); + parcel.writeBoolean(mHasSatelliteRequirement); + parcel.writeBoolean(mHasCellRequirement); parcel.writeBoolean(mHasMonetaryCost); - parcel.writeBoolean(mSupportsAltitude); - parcel.writeBoolean(mSupportsSpeed); - parcel.writeBoolean(mSupportsBearing); + parcel.writeBoolean(mHasAltitudeSupport); + parcel.writeBoolean(mHasSpeedSupport); + parcel.writeBoolean(mHasBearingSupport); parcel.writeInt(mPowerRequirement); parcel.writeInt(mAccuracy); } @@ -174,21 +184,22 @@ public final class ProviderProperties implements Parcelable { return false; } ProviderProperties that = (ProviderProperties) o; - return mRequiresNetwork == that.mRequiresNetwork - && mRequiresSatellite == that.mRequiresSatellite - && mRequiresCell == that.mRequiresCell + return mHasNetworkRequirement == that.mHasNetworkRequirement + && mHasSatelliteRequirement == that.mHasSatelliteRequirement + && mHasCellRequirement == that.mHasCellRequirement && mHasMonetaryCost == that.mHasMonetaryCost - && mSupportsAltitude == that.mSupportsAltitude - && mSupportsSpeed == that.mSupportsSpeed - && mSupportsBearing == that.mSupportsBearing + && mHasAltitudeSupport == that.mHasAltitudeSupport + && mHasSpeedSupport == that.mHasSpeedSupport + && mHasBearingSupport == that.mHasBearingSupport && mPowerRequirement == that.mPowerRequirement && mAccuracy == that.mAccuracy; } @Override public int hashCode() { - return Objects.hash(mRequiresNetwork, mRequiresSatellite, mRequiresCell, mHasMonetaryCost, - mSupportsAltitude, mSupportsSpeed, mSupportsBearing, mPowerRequirement, mAccuracy); + return Objects.hash(mHasNetworkRequirement, mHasSatelliteRequirement, mHasCellRequirement, + mHasMonetaryCost, mHasAltitudeSupport, mHasSpeedSupport, mHasBearingSupport, + mPowerRequirement, mAccuracy); } @Override @@ -196,15 +207,15 @@ public final class ProviderProperties implements Parcelable { StringBuilder b = new StringBuilder("ProviderProperties["); b.append("power=").append(powerToString(mPowerRequirement)).append(", "); b.append("accuracy=").append(accuracyToString(mAccuracy)); - if (mRequiresNetwork || mRequiresSatellite || mRequiresCell) { + if (mHasNetworkRequirement || mHasSatelliteRequirement || mHasCellRequirement) { b.append(", requires="); - if (mRequiresNetwork) { + if (mHasNetworkRequirement) { b.append("network,"); } - if (mRequiresSatellite) { + if (mHasSatelliteRequirement) { b.append("satellite,"); } - if (mRequiresCell) { + if (mHasCellRequirement) { b.append("cell,"); } b.setLength(b.length() - 1); @@ -212,15 +223,15 @@ public final class ProviderProperties implements Parcelable { if (mHasMonetaryCost) { b.append(", hasMonetaryCost"); } - if (mSupportsBearing || mSupportsSpeed || mSupportsAltitude) { + if (mHasBearingSupport || mHasSpeedSupport || mHasAltitudeSupport) { b.append(", supports=["); - if (mSupportsBearing) { + if (mHasBearingSupport) { b.append("bearing, "); } - if (mSupportsSpeed) { + if (mHasSpeedSupport) { b.append("speed, "); } - if (mSupportsAltitude) { + if (mHasAltitudeSupport) { b.append("altitude, "); } b.setLength(b.length() - 2); diff --git a/location/java/com/android/internal/location/ProviderRequest.java b/location/java/com/android/internal/location/ProviderRequest.java index 5d072f838055..fee86ceb453a 100644 --- a/location/java/com/android/internal/location/ProviderRequest.java +++ b/location/java/com/android/internal/location/ProviderRequest.java @@ -16,66 +16,101 @@ package com.android.internal.location; +import android.annotation.IntRange; +import android.annotation.NonNull; import android.compat.annotation.UnsupportedAppUsage; import android.location.LocationRequest; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.os.WorkSource; import android.util.TimeUtils; +import com.android.internal.util.Preconditions; + import java.util.Collections; import java.util.List; import java.util.Objects; -/** @hide */ +/** + * Location provider request. + * @hide + */ public final class ProviderRequest implements Parcelable { - public static final ProviderRequest EMPTY_REQUEST = new ProviderRequest(false, Long.MAX_VALUE, - false, false, - Collections.emptyList(), new WorkSource()); + public static final long INTERVAL_DISABLED = Long.MAX_VALUE; - /** Location reporting is requested (true) */ - @UnsupportedAppUsage - public final boolean reportLocation; + public static final ProviderRequest EMPTY_REQUEST = new ProviderRequest( + INTERVAL_DISABLED, false, false, Collections.emptyList(), new WorkSource()); - /** The smallest requested interval */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@link " + + "ProviderRequest}") + public final boolean reportLocation; + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@link " + + "ProviderRequest}") public final long interval; + private final boolean mLowPower; + private final boolean mLocationSettingsIgnored; + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@link " + + "ProviderRequest}") + public final List<LocationRequest> locationRequests; + private final WorkSource mWorkSource; + + private ProviderRequest(long intervalMillis, boolean lowPower, + boolean locationSettingsIgnored, @NonNull List<LocationRequest> locationRequests, + @NonNull WorkSource workSource) { + reportLocation = intervalMillis != INTERVAL_DISABLED; + interval = intervalMillis; + mLowPower = lowPower; + mLocationSettingsIgnored = locationSettingsIgnored; + this.locationRequests = locationRequests; + mWorkSource = workSource; + } /** - * Whether provider shall make stronger than normal tradeoffs to substantially restrict power - * use. + * 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 final boolean lowPowerMode; + public boolean isActive() { + return interval != INTERVAL_DISABLED; + } /** - * When this flag is true, providers 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 flag should only be used in event of an emergency. + * The interval at which a provider should report location. Will return + * {@link #INTERVAL_DISABLED} for an inactive request. */ - public final boolean locationSettingsIgnored; + public @IntRange(from = 0) long getIntervalMillis() { + return interval; + } /** - * A more detailed set of requests. - * <p>Location Providers can optionally use this to - * fine tune location updates, for example when there - * is a high power slow interval request and a - * low power fast interval request. + * Whether any applicable hardware low power modes should be used to satisfy this request. */ - @UnsupportedAppUsage - public final List<LocationRequest> locationRequests; + public boolean isLowPower() { + return mLowPower; + } + + /** + * 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. + */ + public boolean isLocationSettingsIgnored() { + return mLocationSettingsIgnored; + } - public final WorkSource workSource; - - private ProviderRequest(boolean reportLocation, long interval, boolean lowPowerMode, - boolean locationSettingsIgnored, List<LocationRequest> locationRequests, - WorkSource workSource) { - this.reportLocation = reportLocation; - this.interval = interval; - this.lowPowerMode = lowPowerMode; - this.locationSettingsIgnored = locationSettingsIgnored; - this.locationRequests = Objects.requireNonNull(locationRequests); - this.workSource = Objects.requireNonNull(workSource); + /** + * The full list of location requests contributing to this provider request. + */ + public @NonNull List<LocationRequest> getLocationRequests() { + return locationRequests; + } + + /** + * The power blame for this provider request. + */ + public @NonNull WorkSource getWorkSource() { + return mWorkSource; } public static final Parcelable.Creator<ProviderRequest> CREATOR = @@ -83,9 +118,8 @@ public final class ProviderRequest implements Parcelable { @Override public ProviderRequest createFromParcel(Parcel in) { return new ProviderRequest( - /* reportLocation= */ in.readBoolean(), - /* interval= */ in.readLong(), - /* lowPowerMode= */ in.readBoolean(), + /* intervalMillis= */ in.readLong(), + /* lowPower= */ in.readBoolean(), /* locationSettingsIgnored= */ in.readBoolean(), /* locationRequests= */ in.createTypedArrayList(LocationRequest.CREATOR), @@ -105,29 +139,54 @@ public final class ProviderRequest implements Parcelable { @Override public void writeToParcel(Parcel parcel, int flags) { - parcel.writeBoolean(reportLocation); parcel.writeLong(interval); - parcel.writeBoolean(lowPowerMode); - parcel.writeBoolean(locationSettingsIgnored); + parcel.writeBoolean(mLowPower); + parcel.writeBoolean(mLocationSettingsIgnored); parcel.writeTypedList(locationRequests); - parcel.writeTypedObject(workSource, flags); + parcel.writeTypedObject(mWorkSource, flags); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + ProviderRequest that = (ProviderRequest) o; + if (interval == INTERVAL_DISABLED) { + return that.interval == INTERVAL_DISABLED; + } else { + return interval == that.interval + && mLowPower == that.mLowPower + && mLocationSettingsIgnored == that.mLocationSettingsIgnored + && locationRequests.equals(that.locationRequests) + && mWorkSource.equals(that.mWorkSource); + } + } + + @Override + public int hashCode() { + return Objects.hash(interval, mWorkSource); } @Override public String toString() { StringBuilder s = new StringBuilder(); s.append("ProviderRequest["); - if (reportLocation) { - s.append("interval="); + if (interval != INTERVAL_DISABLED) { + s.append("@"); TimeUtils.formatDuration(interval, s); - if (lowPowerMode) { - s.append(", lowPowerMode"); + if (mLowPower) { + s.append(", lowPower"); } - if (locationSettingsIgnored) { + if (mLocationSettingsIgnored) { s.append(", locationSettingsIgnored"); } - if (!workSource.isEmpty()) { - s.append(", ").append(workSource); + if (!mWorkSource.isEmpty()) { + s.append(", ").append(mWorkSource); } } else { s.append("OFF"); @@ -140,71 +199,64 @@ public final class ProviderRequest implements Parcelable { * A Builder for {@link ProviderRequest}s. */ public static class Builder { - private long mInterval = Long.MAX_VALUE; - private boolean mLowPowerMode; + private long mIntervalMillis = INTERVAL_DISABLED; + private boolean mLowPower; private boolean mLocationSettingsIgnored; private List<LocationRequest> mLocationRequests = Collections.emptyList(); private WorkSource mWorkSource = new WorkSource(); - public long getInterval() { - return mInterval; - } - - /** Sets the request interval. */ - public Builder setInterval(long interval) { - this.mInterval = interval; + /** + * Sets the request interval. Use {@link #INTERVAL_DISABLED} for an inactive request. + * Defaults to {@link #INTERVAL_DISABLED}. + */ + public @NonNull Builder setIntervalMillis(@IntRange(from = 0) long intervalMillis) { + mIntervalMillis = Preconditions.checkArgumentInRange(intervalMillis, 0, Long.MAX_VALUE, + "intervalMillis"); return this; } - public boolean isLowPowerMode() { - return mLowPowerMode; - } - - /** Sets whether low power mode is enabled. */ - public Builder setLowPowerMode(boolean lowPowerMode) { - this.mLowPowerMode = lowPowerMode; + /** + * Sets whether hardware low power mode should be used. False by default. + */ + public @NonNull Builder setLowPower(boolean lowPower) { + mLowPower = lowPower; return this; } - public boolean isLocationSettingsIgnored() { - return mLocationSettingsIgnored; - } - - /** Sets whether location settings should be ignored. */ - public Builder setLocationSettingsIgnored(boolean locationSettingsIgnored) { + /** + * Sets whether location settings should be ignored. False by default. + */ + public @NonNull Builder setLocationSettingsIgnored(boolean locationSettingsIgnored) { this.mLocationSettingsIgnored = locationSettingsIgnored; return this; } - public List<LocationRequest> getLocationRequests() { - return mLocationRequests; - } - - /** Sets the {@link LocationRequest}s associated with this request. */ - public Builder setLocationRequests(List<LocationRequest> locationRequests) { + /** + * Sets the {@link LocationRequest}s associated with this request. Empty by default. + */ + public @NonNull Builder setLocationRequests( + @NonNull List<LocationRequest> locationRequests) { this.mLocationRequests = Objects.requireNonNull(locationRequests); return this; } - public WorkSource getWorkSource() { - return mWorkSource; - } - - /** Sets the work source. */ - public Builder setWorkSource(WorkSource workSource) { + /** + * Sets the work source for power blame. Empty by default. + */ + public @NonNull Builder setWorkSource(@NonNull WorkSource workSource) { mWorkSource = Objects.requireNonNull(workSource); return this; } /** - * Builds a ProviderRequest object with the set information. + * Builds a ProviderRequest. */ - public ProviderRequest build() { - if (mInterval == Long.MAX_VALUE) { + public @NonNull ProviderRequest build() { + if (mIntervalMillis == INTERVAL_DISABLED) { return EMPTY_REQUEST; } else { - return new ProviderRequest(true, mInterval, mLowPowerMode, - mLocationSettingsIgnored, mLocationRequests, mWorkSource); + return new ProviderRequest(mIntervalMillis, mLowPower, mLocationSettingsIgnored, + mLocationRequests, mWorkSource); } } } 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(); diff --git a/packages/FusedLocation/test/src/com/android/location/fused/tests/FusedLocationServiceTest.java b/packages/FusedLocation/test/src/com/android/location/fused/tests/FusedLocationServiceTest.java index 687dd13f8732..e05bd3c22ae8 100644 --- a/packages/FusedLocation/test/src/com/android/location/fused/tests/FusedLocationServiceTest.java +++ b/packages/FusedLocation/test/src/com/android/location/fused/tests/FusedLocationServiceTest.java @@ -124,7 +124,7 @@ public class FusedLocationServiceTest { mProvider.setRequest( new ProviderRequest.Builder() - .setInterval(1000) + .setIntervalMillis(1000) .setLocationRequests(Collections.singletonList(request)) .build(), new WorkSource()); @@ -143,7 +143,7 @@ public class FusedLocationServiceTest { mProvider.setRequest( new ProviderRequest.Builder() - .setInterval(1000) + .setIntervalMillis(1000) .setLocationRequests(Collections.singletonList(request)) .build(), new WorkSource()); diff --git a/services/core/java/com/android/server/location/LocationProviderManager.java b/services/core/java/com/android/server/location/LocationProviderManager.java index 830548b044a6..e224a9d85115 100644 --- a/services/core/java/com/android/server/location/LocationProviderManager.java +++ b/services/core/java/com/android/server/location/LocationProviderManager.java @@ -35,6 +35,7 @@ import static com.android.server.location.LocationPermissions.PERMISSION_COARSE; import static com.android.server.location.LocationPermissions.PERMISSION_FINE; import static com.android.server.location.LocationPermissions.PERMISSION_NONE; +import static java.lang.Math.min; import static java.util.concurrent.TimeUnit.NANOSECONDS; import android.annotation.Nullable; @@ -363,7 +364,7 @@ class LocationProviderManager extends return isActive() && getRequest().getIntervalMillis() < MAX_HIGH_POWER_INTERVAL_MS - && getProperties().mPowerRequirement == Criteria.POWER_HIGH; + && getProperties().getPowerRequirement() == Criteria.POWER_HIGH; } @GuardedBy("mLock") @@ -1224,7 +1225,7 @@ class LocationProviderManager extends throw new IllegalArgumentException(mName + " provider is not a test provider"); } - return mProvider.getCurrentRequest().locationRequests; + return mProvider.getCurrentRequest().getLocationRequests(); } } @@ -1632,11 +1633,12 @@ class LocationProviderManager extends Preconditions.checkState(Thread.holdsLock(mLock)); } - ProviderRequest.Builder providerRequest = new ProviderRequest.Builder(); - // initialize the low power mode to true and set to false if any of the records requires - providerRequest.setLowPowerMode(true); - ArrayList<Registration> providerRegistrations = new ArrayList<>(registrations.size()); + + long intervalMs = Long.MAX_VALUE; + boolean locationSettingsIgnored = false; + boolean lowPower = true; + ArrayList<LocationRequest> locationRequests = new ArrayList<>(registrations.size()); for (Registration registration : registrations) { LocationRequest locationRequest = registration.getRequest(); @@ -1645,43 +1647,38 @@ class LocationProviderManager extends continue; } - if (locationRequest.isLocationSettingsIgnored()) { - providerRequest.setLocationSettingsIgnored(true); - } - if (!locationRequest.isLowPower()) { - providerRequest.setLowPowerMode(false); - } - - providerRequest.setInterval( - Math.min(locationRequest.getIntervalMillis(), providerRequest.getInterval())); providerRegistrations.add(registration); + intervalMs = min(locationRequest.getIntervalMillis(), intervalMs); + locationSettingsIgnored |= locationRequest.isLocationSettingsIgnored(); + lowPower &= locationRequest.isLowPower(); + locationRequests.add(locationRequest); } - // collect contributing location requests - ArrayList<LocationRequest> providerRequests = new ArrayList<>(providerRegistrations.size()); - final int registrationsSize = providerRegistrations.size(); - for (int i = 0; i < registrationsSize; i++) { - providerRequests.add(providerRegistrations.get(i).getRequest()); - } - - providerRequest.setLocationRequests(providerRequests); - // calculate who to blame for power in a somewhat arbitrary fashion. we pick a threshold // interval slightly higher that the minimum interval, and spread the blame across all - // contributing registrations under that threshold. - long thresholdIntervalMs = (providerRequest.getInterval() + 1000) * 3 / 2; + // contributing registrations under that threshold (since worksource does not allow us to + // represent differing power blame ratios). + WorkSource workSource = new WorkSource(); + long thresholdIntervalMs = (intervalMs + 1000) * 3 / 2; if (thresholdIntervalMs < 0) { - // handle overflow - thresholdIntervalMs = Long.MAX_VALUE; + // handle overflow by setting to one below the passive interval + thresholdIntervalMs = Long.MAX_VALUE - 1; } - for (int i = 0; i < registrationsSize; i++) { - LocationRequest request = providerRegistrations.get(i).getRequest(); - if (request.getIntervalMillis() <= thresholdIntervalMs) { - providerRequest.getWorkSource().add(providerRegistrations.get(i).getWorkSource()); + final int providerRegistrationsSize = providerRegistrations.size(); + for (int i = 0; i < providerRegistrationsSize; i++) { + Registration registration = providerRegistrations.get(i); + if (registration.getRequest().getIntervalMillis() <= thresholdIntervalMs) { + workSource.add(providerRegistrations.get(i).getWorkSource()); } } - return providerRequest.build(); + return new ProviderRequest.Builder() + .setIntervalMillis(intervalMs) + .setLocationSettingsIgnored(locationSettingsIgnored) + .setLowPower(lowPower) + .setLocationRequests(locationRequests) + .setWorkSource(workSource) + .build(); } private void onUserChanged(int userId, int change) { diff --git a/services/core/java/com/android/server/location/LocationProviderProxy.java b/services/core/java/com/android/server/location/LocationProviderProxy.java index d778d242f571..b111c155fac5 100644 --- a/services/core/java/com/android/server/location/LocationProviderProxy.java +++ b/services/core/java/com/android/server/location/LocationProviderProxy.java @@ -101,7 +101,7 @@ public class LocationProviderProxy extends AbstractLocationProvider { ProviderRequest request = mRequest; if (!request.equals(ProviderRequest.EMPTY_REQUEST)) { - provider.setRequest(request, request.workSource); + provider.setRequest(request, request.getWorkSource()); } } } @@ -119,7 +119,7 @@ public class LocationProviderProxy extends AbstractLocationProvider { mRequest = request; mServiceWatcher.runOnBinder(binder -> { ILocationProvider provider = ILocationProvider.Stub.asInterface(binder); - provider.setRequest(request, request.workSource); + provider.setRequest(request, request.getWorkSource()); }); } diff --git a/services/core/java/com/android/server/location/PassiveLocationProviderManager.java b/services/core/java/com/android/server/location/PassiveLocationProviderManager.java index 92ef5b7c73a8..5133683b0625 100644 --- a/services/core/java/com/android/server/location/PassiveLocationProviderManager.java +++ b/services/core/java/com/android/server/location/PassiveLocationProviderManager.java @@ -66,7 +66,7 @@ class PassiveLocationProviderManager extends LocationProviderManager { @Override protected ProviderRequest mergeRequests(Collection<Registration> registrations) { ProviderRequest.Builder providerRequest = new ProviderRequest.Builder() - .setInterval(0); + .setIntervalMillis(0); ArrayList<LocationRequest> requests = new ArrayList<>(registrations.size()); for (Registration registration : registrations) { diff --git a/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java b/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java index bd4fc135d2bb..ce7cf3ce85d1 100644 --- a/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java @@ -956,8 +956,9 @@ public class GnssLocationProvider extends AbstractLocationProvider implements enabled &= !mDisableGpsForPowerManager; // .. but enable anyway, if there's an active settings-ignored request (e.g. ELS) - enabled |= (mProviderRequest != null && mProviderRequest.reportLocation - && mProviderRequest.locationSettingsIgnored); + enabled |= (mProviderRequest != null + && mProviderRequest.isActive() + && mProviderRequest.isLocationSettingsIgnored()); // ... and, finally, disable anyway, if device is being shut down enabled &= !mShutdown; @@ -992,20 +993,20 @@ public class GnssLocationProvider extends AbstractLocationProvider implements // Called when the requirements for GPS may have changed private void updateRequirements() { - if (mProviderRequest == null || mProviderRequest.workSource == null) { + if (mProviderRequest == null || mProviderRequest.getWorkSource() == null) { return; } if (DEBUG) Log.d(TAG, "setRequest " + mProviderRequest); - if (mProviderRequest.reportLocation && isGpsEnabled()) { + if (mProviderRequest.isActive() && isGpsEnabled()) { // update client uids - updateClientUids(mProviderRequest.workSource); + updateClientUids(mProviderRequest.getWorkSource()); - mFixInterval = (int) mProviderRequest.interval; - mLowPowerMode = mProviderRequest.lowPowerMode; + mFixInterval = (int) mProviderRequest.getIntervalMillis(); + mLowPowerMode = mProviderRequest.isLowPower(); // check for overflow - if (mFixInterval != mProviderRequest.interval) { - Log.w(TAG, "interval overflow: " + mProviderRequest.interval); + if (mFixInterval != mProviderRequest.getIntervalMillis()) { + Log.w(TAG, "interval overflow: " + mProviderRequest.getIntervalMillis()); mFixInterval = Integer.MAX_VALUE; } @@ -1205,7 +1206,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements } int interval = (hasCapability(GPS_CAPABILITY_SCHEDULING) ? mFixInterval : 1000); - mLowPowerMode = mProviderRequest.lowPowerMode; + mLowPowerMode = mProviderRequest.isLowPower(); if (!setPositionMode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, interval, 0, 0, mLowPowerMode)) { setStarted(false); diff --git a/services/tests/mockingservicestests/src/com/android/server/location/LocationProviderManagerTest.java b/services/tests/mockingservicestests/src/com/android/server/location/LocationProviderManagerTest.java index c36cdeb582bd..149148649cf6 100644 --- a/services/tests/mockingservicestests/src/com/android/server/location/LocationProviderManagerTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/location/LocationProviderManagerTest.java @@ -739,44 +739,45 @@ public class LocationProviderManagerTest { @Test public void testProviderRequest() { - assertThat(mProvider.getRequest().reportLocation).isFalse(); - assertThat(mProvider.getRequest().locationRequests).isEmpty(); + assertThat(mProvider.getRequest().isActive()).isFalse(); + assertThat(mProvider.getRequest().getLocationRequests()).isEmpty(); ILocationListener listener1 = createMockLocationListener(); LocationRequest request1 = new LocationRequest.Builder(5).build(); mManager.registerLocationRequest(request1, IDENTITY, PERMISSION_FINE, listener1); - assertThat(mProvider.getRequest().reportLocation).isTrue(); - assertThat(mProvider.getRequest().locationRequests).containsExactly(request1); - assertThat(mProvider.getRequest().locationSettingsIgnored).isFalse(); - assertThat(mProvider.getRequest().interval).isEqualTo(5); - assertThat(mProvider.getRequest().lowPowerMode).isFalse(); - assertThat(mProvider.getRequest().workSource).isNotNull(); + assertThat(mProvider.getRequest().isActive()).isTrue(); + assertThat(mProvider.getRequest().getLocationRequests()).containsExactly(request1); + assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isFalse(); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(5); + assertThat(mProvider.getRequest().isLowPower()).isFalse(); + assertThat(mProvider.getRequest().getWorkSource()).isNotNull(); ILocationListener listener2 = createMockLocationListener(); LocationRequest request2 = new LocationRequest.Builder(1).setLowPower(true).build(); mManager.registerLocationRequest(request2, IDENTITY, PERMISSION_FINE, listener2); - assertThat(mProvider.getRequest().reportLocation).isTrue(); - assertThat(mProvider.getRequest().locationRequests).containsExactly(request1, request2); - assertThat(mProvider.getRequest().locationSettingsIgnored).isFalse(); - assertThat(mProvider.getRequest().interval).isEqualTo(1); - assertThat(mProvider.getRequest().lowPowerMode).isFalse(); - assertThat(mProvider.getRequest().workSource).isNotNull(); + assertThat(mProvider.getRequest().isActive()).isTrue(); + assertThat(mProvider.getRequest().getLocationRequests()).containsExactly(request1, + request2); + assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isFalse(); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(1); + assertThat(mProvider.getRequest().isLowPower()).isFalse(); + assertThat(mProvider.getRequest().getWorkSource()).isNotNull(); mManager.unregisterLocationRequest(listener1); - assertThat(mProvider.getRequest().reportLocation).isTrue(); - assertThat(mProvider.getRequest().locationRequests).containsExactly(request2); - assertThat(mProvider.getRequest().locationSettingsIgnored).isFalse(); - assertThat(mProvider.getRequest().interval).isEqualTo(1); - assertThat(mProvider.getRequest().lowPowerMode).isTrue(); - assertThat(mProvider.getRequest().workSource).isNotNull(); + assertThat(mProvider.getRequest().isActive()).isTrue(); + assertThat(mProvider.getRequest().getLocationRequests()).containsExactly(request2); + assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isFalse(); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(1); + assertThat(mProvider.getRequest().isLowPower()).isTrue(); + assertThat(mProvider.getRequest().getWorkSource()).isNotNull(); mManager.unregisterLocationRequest(listener2); - assertThat(mProvider.getRequest().reportLocation).isFalse(); - assertThat(mProvider.getRequest().locationRequests).isEmpty(); + assertThat(mProvider.getRequest().isActive()).isFalse(); + assertThat(mProvider.getRequest().getLocationRequests()).isEmpty(); } @Test @@ -785,10 +786,10 @@ public class LocationProviderManagerTest { LocationRequest request1 = new LocationRequest.Builder(5).build(); mManager.registerLocationRequest(request1, IDENTITY, PERMISSION_FINE, listener1); - assertThat(mProvider.getRequest().interval).isEqualTo(5); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(5); mInjector.getAppForegroundHelper().setAppForeground(IDENTITY.getUid(), false); - assertThat(mProvider.getRequest().interval).isEqualTo( + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo( mInjector.getSettingsHelper().getBackgroundThrottleIntervalMs()); } @@ -801,18 +802,18 @@ public class LocationProviderManagerTest { LocationRequest request1 = new LocationRequest.Builder(5).build(); mManager.registerLocationRequest(request1, IDENTITY, PERMISSION_FINE, listener1); - assertThat(mProvider.getRequest().reportLocation).isTrue(); - assertThat(mProvider.getRequest().interval).isEqualTo(5); - assertThat(mProvider.getRequest().locationSettingsIgnored).isFalse(); + assertThat(mProvider.getRequest().isActive()).isTrue(); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(5); + assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isFalse(); ILocationListener listener2 = createMockLocationListener(); LocationRequest request2 = new LocationRequest.Builder(1).setLocationSettingsIgnored( true).build(); mManager.registerLocationRequest(request2, IDENTITY, PERMISSION_FINE, listener2); - assertThat(mProvider.getRequest().reportLocation).isTrue(); - assertThat(mProvider.getRequest().interval).isEqualTo(1); - assertThat(mProvider.getRequest().locationSettingsIgnored).isTrue(); + assertThat(mProvider.getRequest().isActive()).isTrue(); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(1); + assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isTrue(); } @Test @@ -831,10 +832,10 @@ public class LocationProviderManagerTest { mInjector.getSettingsHelper().setLocationEnabled(false, IDENTITY.getUserId()); - assertThat(mProvider.getRequest().reportLocation).isTrue(); - assertThat(mProvider.getRequest().locationRequests).containsExactly(request2); - assertThat(mProvider.getRequest().interval).isEqualTo(5); - assertThat(mProvider.getRequest().locationSettingsIgnored).isTrue(); + assertThat(mProvider.getRequest().isActive()).isTrue(); + assertThat(mProvider.getRequest().getLocationRequests()).containsExactly(request2); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(5); + assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isTrue(); } @Test @@ -849,9 +850,9 @@ public class LocationProviderManagerTest { mInjector.getSettingsHelper().setIgnoreSettingsPackageWhitelist(Collections.emptySet()); - assertThat(mProvider.getRequest().reportLocation).isTrue(); - assertThat(mProvider.getRequest().interval).isEqualTo(1); - assertThat(mProvider.getRequest().locationSettingsIgnored).isFalse(); + assertThat(mProvider.getRequest().isActive()).isTrue(); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(1); + assertThat(mProvider.getRequest().isLocationSettingsIgnored()).isFalse(); } @Test @@ -864,10 +865,10 @@ public class LocationProviderManagerTest { true).build(); mManager.registerLocationRequest(request1, IDENTITY, PERMISSION_FINE, listener1); - assertThat(mProvider.getRequest().interval).isEqualTo(5); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(5); mInjector.getAppForegroundHelper().setAppForeground(IDENTITY.getUid(), false); - assertThat(mProvider.getRequest().interval).isEqualTo(5); + assertThat(mProvider.getRequest().getIntervalMillis()).isEqualTo(5); } @Test @@ -879,10 +880,10 @@ public class LocationProviderManagerTest { LocationRequest request = new LocationRequest.Builder(5).build(); mManager.registerLocationRequest(request, IDENTITY, PERMISSION_FINE, listener); - assertThat(mProvider.getRequest().reportLocation).isTrue(); + assertThat(mProvider.getRequest().isActive()).isTrue(); mInjector.getScreenInteractiveHelper().setScreenInteractive(false); - assertThat(mProvider.getRequest().reportLocation).isFalse(); + assertThat(mProvider.getRequest().isActive()).isFalse(); } private ILocationListener createMockLocationListener() { diff --git a/services/tests/mockingservicestests/src/com/android/server/location/MockableLocationProviderTest.java b/services/tests/mockingservicestests/src/com/android/server/location/MockableLocationProviderTest.java index 2026363044fd..374fc777546f 100644 --- a/services/tests/mockingservicestests/src/com/android/server/location/MockableLocationProviderTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/location/MockableLocationProviderTest.java @@ -95,7 +95,7 @@ public class MockableLocationProviderTest { assertThat(mProvider.getCurrentRequest()).isEqualTo(EMPTY_REQUEST); verify(mRealProvider, times(1)).onSetRequest(EMPTY_REQUEST); - ProviderRequest request = new ProviderRequest.Builder().setInterval(1).build(); + ProviderRequest request = new ProviderRequest.Builder().setIntervalMillis(1).build(); mProvider.setRequest(request); assertThat(mProvider.getCurrentRequest()).isEqualTo(request); |