diff options
author | Soonil Nagarkar <sooniln@google.com> | 2019-02-06 15:57:26 -0800 |
---|---|---|
committer | Soonil Nagarkar <sooniln@google.com> | 2019-02-13 13:34:45 -0800 |
commit | 509580fbdfdbd6b1a129bd348d40f56b43a5a0f1 (patch) | |
tree | 8faba9fd22f8b711c1932fecc9a5fdaf95533b41 | |
parent | d56355755b17db8a3c4ca58552747456671e32cc (diff) |
Refactor API naming and add unbundled support
Rename APIs while there are no clients. Also prevent throttling when
location settings are being ignored.
Bug: 118883513
Test: manual
Change-Id: I225c50b152e77ab181c959ecd9dc652333f59d5e
7 files changed, 41 insertions, 24 deletions
diff --git a/location/java/android/location/LocationRequest.java b/location/java/android/location/LocationRequest.java index 0caa0c5b377a..b3953fddb622 100644 --- a/location/java/android/location/LocationRequest.java +++ b/location/java/android/location/LocationRequest.java @@ -184,8 +184,7 @@ public final class LocationRequest implements Parcelable { * @return a new location request */ public static LocationRequest create() { - LocationRequest request = new LocationRequest(); - return request; + return new LocationRequest(); } /** @hide */ @@ -230,12 +229,10 @@ public final class LocationRequest implements Parcelable { quality = ACCURACY_FINE; break; default: { - switch (criteria.getPowerRequirement()) { - case Criteria.POWER_HIGH: - quality = POWER_HIGH; - break; - default: - quality = POWER_LOW; + if (criteria.getPowerRequirement() == Criteria.POWER_HIGH) { + quality = POWER_HIGH; + } else { + quality = POWER_LOW; } } } @@ -288,7 +285,7 @@ public final class LocationRequest implements Parcelable { * * @param quality an accuracy or power constant * @return the same object, so that setters can be chained - * @throws InvalidArgumentException if the quality constant is not valid + * @throws IllegalArgumentException if the quality constant is not valid */ public LocationRequest setQuality(int quality) { checkQuality(quality); @@ -331,7 +328,7 @@ public final class LocationRequest implements Parcelable { * * @param millis desired interval in millisecond, inexact * @return the same object, so that setters can be chained - * @throws InvalidArgumentException if the interval is less than zero + * @throws IllegalArgumentException if the interval is less than zero */ public LocationRequest setInterval(long millis) { checkInterval(millis); @@ -433,7 +430,7 @@ public final class LocationRequest implements Parcelable { * * @param millis fastest interval for updates in milliseconds, exact * @return the same object, so that setters can be chained - * @throws InvalidArgumentException if the interval is less than zero + * @throws IllegalArgumentException if the interval is less than zero */ public LocationRequest setFastestInterval(long millis) { checkInterval(millis); @@ -528,7 +525,7 @@ public final class LocationRequest implements Parcelable { * * @param numUpdates the number of location updates requested * @return the same object, so that setters can be chained - * @throws InvalidArgumentException if numUpdates is 0 or less + * @throws IllegalArgumentException if numUpdates is 0 or less */ public LocationRequest setNumUpdates(int numUpdates) { if (numUpdates <= 0) { @@ -668,7 +665,7 @@ public final class LocationRequest implements Parcelable { @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) private static void checkProvider(String name) { if (name == null) { - throw new IllegalArgumentException("invalid provider: " + name); + throw new IllegalArgumentException("invalid provider: null"); } } @@ -758,9 +755,11 @@ public final class LocationRequest implements Parcelable { if (mNumUpdates != Integer.MAX_VALUE) { s.append(" num=").append(mNumUpdates); } - s.append(" lowPowerMode=").append(mLowPowerMode); + if (mLowPowerMode) { + s.append(" lowPowerMode"); + } if (mLocationSettingsIgnored) { - s.append(" ignoreSettings"); + s.append(" locationSettingsIgnored"); } s.append(']'); return s.toString(); diff --git a/location/java/com/android/internal/location/ProviderRequest.java b/location/java/com/android/internal/location/ProviderRequest.java index a45c20d9d09d..af8123ac52f4 100644 --- a/location/java/com/android/internal/location/ProviderRequest.java +++ b/location/java/com/android/internal/location/ProviderRequest.java @@ -40,7 +40,7 @@ public final class ProviderRequest implements Parcelable { * 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. */ - public boolean forceLocation = false; + public boolean locationSettingsIgnored = false; /** * Whether provider shall make stronger than normal tradeoffs to substantially restrict power @@ -70,6 +70,7 @@ public final class ProviderRequest implements Parcelable { request.reportLocation = in.readInt() == 1; request.interval = in.readLong(); request.lowPowerMode = in.readBoolean(); + request.locationSettingsIgnored = in.readBoolean(); int count = in.readInt(); for (int i = 0; i < count; i++) { request.locationRequests.add(LocationRequest.CREATOR.createFromParcel(in)); @@ -93,6 +94,7 @@ public final class ProviderRequest implements Parcelable { parcel.writeInt(reportLocation ? 1 : 0); parcel.writeLong(interval); parcel.writeBoolean(lowPowerMode); + parcel.writeBoolean(locationSettingsIgnored); parcel.writeInt(locationRequests.size()); for (LocationRequest request : locationRequests) { request.writeToParcel(parcel, flags); @@ -107,7 +109,12 @@ public final class ProviderRequest implements Parcelable { s.append("ON"); s.append(" interval="); TimeUtils.formatDuration(interval, s); - s.append(" lowPowerMode=" + lowPowerMode); + if (lowPowerMode) { + s.append(" lowPowerMode"); + } + if (locationSettingsIgnored) { + s.append(" locationSettingsIgnored"); + } } else { s.append("OFF"); } diff --git a/location/lib/api/current.txt b/location/lib/api/current.txt index 67d64965ac96..dbb581fe54b2 100644 --- a/location/lib/api/current.txt +++ b/location/lib/api/current.txt @@ -31,6 +31,7 @@ package com.android.location.provider { method public long getInterval(); method public int getQuality(); method public float getSmallestDisplacement(); + method public boolean isLocationSettingsIgnored(); field public static final int ACCURACY_BLOCK = 102; // 0x66 field public static final int ACCURACY_CITY = 104; // 0x68 field public static final int ACCURACY_FINE = 100; // 0x64 @@ -44,10 +45,10 @@ package com.android.location.provider { } public final class ProviderRequestUnbundled { - method public boolean getForceLocation(); method public long getInterval(); method public java.util.List<com.android.location.provider.LocationRequestUnbundled> getLocationRequests(); method public boolean getReportLocation(); + method public boolean isLocationSettingsIgnored(); } } diff --git a/location/lib/java/com/android/location/provider/LocationRequestUnbundled.java b/location/lib/java/com/android/location/provider/LocationRequestUnbundled.java index 41fd769b5abd..2511c39caf5c 100644 --- a/location/lib/java/com/android/location/provider/LocationRequestUnbundled.java +++ b/location/lib/java/com/android/location/provider/LocationRequestUnbundled.java @@ -121,6 +121,15 @@ public final class LocationRequestUnbundled { return delegate.getSmallestDisplacement(); } + /** + * Returns true if location settings will be ignored in order to satisfy this request. + * + * @return true if location settings will be ignored in order to satisfy this request + */ + public boolean isLocationSettingsIgnored() { + return delegate.isLocationSettingsIgnored(); + } + @Override public String toString() { return delegate.toString(); diff --git a/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java b/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java index b825b58cd3e9..febbf1b23e0c 100644 --- a/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java +++ b/location/lib/java/com/android/location/provider/ProviderRequestUnbundled.java @@ -46,15 +46,15 @@ public final class ProviderRequestUnbundled { return mRequest.interval; } - public boolean getForceLocation() { - return mRequest.forceLocation; + public boolean isLocationSettingsIgnored() { + return mRequest.locationSettingsIgnored; } /** * Never null. */ public List<LocationRequestUnbundled> getLocationRequests() { - List<LocationRequestUnbundled> result = new ArrayList<LocationRequestUnbundled>( + List<LocationRequestUnbundled> result = new ArrayList<>( mRequest.locationRequests.size()); for (LocationRequest r : mRequest.locationRequests) { result.add(new LocationRequestUnbundled(r)); diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index 3479e18b97c5..0b0934bc5a5e 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -2069,7 +2069,7 @@ public class LocationManagerService extends ILocationManager.Stub { } if (!provider.isUseableLocked()) { if (isSettingsExemptLocked(record)) { - providerRequest.forceLocation = true; + providerRequest.locationSettingsIgnored = true; providerRequest.lowPowerMode = false; } else { continue; @@ -2079,8 +2079,9 @@ public class LocationManagerService extends ILocationManager.Stub { LocationRequest locationRequest = record.mRealRequest; long interval = locationRequest.getInterval(); + // if we're forcing location, don't apply any throttling - if (!providerRequest.forceLocation && !isThrottlingExemptLocked( + if (!providerRequest.locationSettingsIgnored && !isThrottlingExemptLocked( record.mReceiver.mCallerIdentity)) { if (!record.mIsForegroundUid) { interval = Math.max(interval, backgroundThrottleInterval); diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java index 3abacc2c9c10..e71b156c3e86 100644 --- a/services/core/java/com/android/server/location/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/GnssLocationProvider.java @@ -917,7 +917,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements synchronized (mLock) { boolean enabled = ((mProviderRequest != null && mProviderRequest.reportLocation - && mProviderRequest.forceLocation) || ( + && mProviderRequest.locationSettingsIgnored) || ( mContext.getSystemService(LocationManager.class).isLocationEnabled() && !mDisableGps)) && !mShutdown; if (enabled == mEnabled) { |