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
This commit is contained in:
Soonil Nagarkar
2019-02-06 15:57:26 -08:00
parent d56355755b
commit 509580fbdf
7 changed files with 41 additions and 24 deletions

View File

@@ -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();

View File

@@ -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");
}

View File

@@ -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();
}
}

View File

@@ -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();

View File

@@ -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));

View File

@@ -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);

View File

@@ -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) {