Merge "Fix up LocationRequest and ProviderRequest" into rvc-dev am: 240eaaaaab
Change-Id: Ie8a5c1fd84140ac876e1a1efb77596ea07a2fd46
This commit is contained in:
@@ -335,7 +335,17 @@ public class TimeUtils {
|
|||||||
|
|
||||||
/** @hide Just for debugging; not internationalized. */
|
/** @hide Just for debugging; not internationalized. */
|
||||||
public static String formatUptime(long time) {
|
public static String formatUptime(long time) {
|
||||||
final long diff = time - SystemClock.uptimeMillis();
|
return formatTime(time, SystemClock.uptimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @hide Just for debugging; not internationalized. */
|
||||||
|
public static String formatRealtime(long time) {
|
||||||
|
return formatTime(time, SystemClock.elapsedRealtime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @hide Just for debugging; not internationalized. */
|
||||||
|
public static String formatTime(long time, long referenceTime) {
|
||||||
|
long diff = time - referenceTime;
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
return time + " (in " + diff + " ms)";
|
return time + " (in " + diff + " ms)";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ import com.android.internal.util.Preconditions;
|
|||||||
* heavy-weight work after receiving an update - such as using the network.
|
* heavy-weight work after receiving an update - such as using the network.
|
||||||
*
|
*
|
||||||
* <p>Activities should strongly consider removing all location
|
* <p>Activities should strongly consider removing all location
|
||||||
* request when entering the background
|
* request when entering the background, or
|
||||||
* (for example at {@link android.app.Activity#onPause}), or
|
|
||||||
* at least swap the request to a larger interval and lower quality.
|
* at least swap the request to a larger interval and lower quality.
|
||||||
* Future version of the location manager may automatically perform background
|
* Future version of the location manager may automatically perform background
|
||||||
* throttling on behalf of applications.
|
* throttling on behalf of applications.
|
||||||
@@ -146,38 +145,32 @@ public final class LocationRequest implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public static final int POWER_HIGH = 203;
|
public static final int POWER_HIGH = 203;
|
||||||
|
|
||||||
/**
|
private static final long DEFAULT_INTERVAL_MS = 60 * 60 * 1000; // 1 hour
|
||||||
* By default, mFastestInterval = FASTEST_INTERVAL_MULTIPLE * mInterval
|
|
||||||
*/
|
|
||||||
private static final double FASTEST_INTERVAL_FACTOR = 6.0; // 6x
|
private static final double FASTEST_INTERVAL_FACTOR = 6.0; // 6x
|
||||||
|
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
|
||||||
private int mQuality = POWER_LOW;
|
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
private long mInterval = 60 * 60 * 1000; // 60 minutes
|
private String mProvider;
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||||
private long mFastestInterval = (long) (mInterval / FASTEST_INTERVAL_FACTOR); // 10 minutes
|
private int mQuality;
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
|
||||||
private boolean mExplicitFastestInterval = false;
|
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
|
||||||
private long mExpireAt = Long.MAX_VALUE; // no expiry
|
|
||||||
private long mExpireIn = Long.MAX_VALUE; // no expiry
|
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
|
||||||
private int mNumUpdates = Integer.MAX_VALUE; // no expiry
|
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
|
||||||
private float mSmallestDisplacement = 0.0f; // meters
|
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
private WorkSource mWorkSource = null;
|
private long mInterval;
|
||||||
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||||
|
private long mFastestInterval;
|
||||||
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||||
|
private boolean mExplicitFastestInterval;
|
||||||
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||||
|
private long mExpireAt;
|
||||||
|
private long mExpireIn;
|
||||||
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||||
|
private int mNumUpdates;
|
||||||
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||||
|
private float mSmallestDisplacement;
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
private boolean mHideFromAppOps = false; // True if this request shouldn't be counted by AppOps
|
private boolean mHideFromAppOps;
|
||||||
private boolean mLocationSettingsIgnored = false;
|
private boolean mLocationSettingsIgnored;
|
||||||
|
private boolean mLowPowerMode;
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
private String mProvider = LocationManager.FUSED_PROVIDER;
|
private @Nullable WorkSource mWorkSource;
|
||||||
// for deprecated APIs that explicitly request a provider
|
|
||||||
|
|
||||||
/** If true, GNSS chipset will make strong tradeoffs to substantially restrict power use */
|
|
||||||
private boolean mLowPowerMode = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a location request with default parameters.
|
* Create a location request with default parameters.
|
||||||
@@ -260,23 +253,71 @@ public final class LocationRequest implements Parcelable {
|
|||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public LocationRequest() {
|
public LocationRequest() {
|
||||||
|
this(
|
||||||
|
/* provider= */ LocationManager.FUSED_PROVIDER,
|
||||||
|
/* quality= */ POWER_LOW,
|
||||||
|
/* interval= */ DEFAULT_INTERVAL_MS,
|
||||||
|
/* fastestInterval= */ (long) (DEFAULT_INTERVAL_MS / FASTEST_INTERVAL_FACTOR),
|
||||||
|
/* explicitFastestInterval= */ false,
|
||||||
|
/* expireAt= */ Long.MAX_VALUE,
|
||||||
|
/* expireIn= */ Long.MAX_VALUE,
|
||||||
|
/* numUpdates= */ Integer.MAX_VALUE,
|
||||||
|
/* smallestDisplacement= */ 0,
|
||||||
|
/* hideFromAppOps= */ false,
|
||||||
|
/* lowPowerMode= */ false,
|
||||||
|
/* locationSettingsIgnored= */ false,
|
||||||
|
/* workSource= */ null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public LocationRequest(LocationRequest src) {
|
public LocationRequest(LocationRequest src) {
|
||||||
mQuality = src.mQuality;
|
this(
|
||||||
mInterval = src.mInterval;
|
src.mProvider,
|
||||||
mFastestInterval = src.mFastestInterval;
|
src.mQuality,
|
||||||
mExplicitFastestInterval = src.mExplicitFastestInterval;
|
src.mInterval,
|
||||||
mExpireAt = src.mExpireAt;
|
src.mFastestInterval,
|
||||||
mExpireIn = src.mExpireIn;
|
src.mExplicitFastestInterval,
|
||||||
mNumUpdates = src.mNumUpdates;
|
src.mExpireAt,
|
||||||
mSmallestDisplacement = src.mSmallestDisplacement;
|
src.mExpireIn,
|
||||||
mProvider = src.mProvider;
|
src.mNumUpdates,
|
||||||
mWorkSource = src.mWorkSource;
|
src.mSmallestDisplacement,
|
||||||
mHideFromAppOps = src.mHideFromAppOps;
|
src.mHideFromAppOps,
|
||||||
mLowPowerMode = src.mLowPowerMode;
|
src.mLowPowerMode,
|
||||||
mLocationSettingsIgnored = src.mLocationSettingsIgnored;
|
src.mLocationSettingsIgnored,
|
||||||
|
src.mWorkSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocationRequest(
|
||||||
|
@NonNull String provider,
|
||||||
|
int quality,
|
||||||
|
long intervalMs,
|
||||||
|
long fastestIntervalMs,
|
||||||
|
boolean explicitFastestInterval,
|
||||||
|
long expireAt,
|
||||||
|
long expireInMs,
|
||||||
|
int numUpdates,
|
||||||
|
float smallestDisplacementM,
|
||||||
|
boolean hideFromAppOps,
|
||||||
|
boolean locationSettingsIgnored,
|
||||||
|
boolean lowPowerMode,
|
||||||
|
WorkSource workSource) {
|
||||||
|
Preconditions.checkArgument(provider != null, "invalid provider: null");
|
||||||
|
checkQuality(quality);
|
||||||
|
|
||||||
|
mProvider = provider;
|
||||||
|
mQuality = quality;
|
||||||
|
mInterval = intervalMs;
|
||||||
|
mFastestInterval = fastestIntervalMs;
|
||||||
|
mExplicitFastestInterval = explicitFastestInterval;
|
||||||
|
mExpireAt = expireAt;
|
||||||
|
mExpireIn = expireInMs;
|
||||||
|
mNumUpdates = numUpdates;
|
||||||
|
mSmallestDisplacement = Preconditions.checkArgumentInRange(smallestDisplacementM, 0,
|
||||||
|
Float.MAX_VALUE, "smallestDisplacementM");
|
||||||
|
mHideFromAppOps = hideFromAppOps;
|
||||||
|
mLowPowerMode = lowPowerMode;
|
||||||
|
mLocationSettingsIgnored = locationSettingsIgnored;
|
||||||
|
mWorkSource = workSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -567,7 +608,7 @@ public final class LocationRequest implements Parcelable {
|
|||||||
|
|
||||||
/** Sets the provider to use for this location request. */
|
/** Sets the provider to use for this location request. */
|
||||||
public @NonNull LocationRequest setProvider(@NonNull String provider) {
|
public @NonNull LocationRequest setProvider(@NonNull String provider) {
|
||||||
checkProvider(provider);
|
Preconditions.checkArgument(provider != null, "invalid provider: null");
|
||||||
mProvider = provider;
|
mProvider = provider;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -580,9 +621,9 @@ public final class LocationRequest implements Parcelable {
|
|||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@SystemApi
|
@SystemApi
|
||||||
public @NonNull LocationRequest setSmallestDisplacement(float meters) {
|
public @NonNull LocationRequest setSmallestDisplacement(float smallestDisplacementM) {
|
||||||
checkDisplacement(meters);
|
mSmallestDisplacement = Preconditions.checkArgumentInRange(smallestDisplacementM, 0,
|
||||||
mSmallestDisplacement = meters;
|
Float.MAX_VALUE, "smallestDisplacementM");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,40 +694,24 @@ public final class LocationRequest implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
public static final @NonNull Parcelable.Creator<LocationRequest> CREATOR =
|
||||||
private static void checkDisplacement(float meters) {
|
|
||||||
if (meters < 0.0f) {
|
|
||||||
throw new IllegalArgumentException("invalid displacement: " + meters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
|
||||||
private static void checkProvider(String name) {
|
|
||||||
if (name == null) {
|
|
||||||
throw new IllegalArgumentException("invalid provider: null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final @android.annotation.NonNull Parcelable.Creator<LocationRequest> CREATOR =
|
|
||||||
new Parcelable.Creator<LocationRequest>() {
|
new Parcelable.Creator<LocationRequest>() {
|
||||||
@Override
|
@Override
|
||||||
public LocationRequest createFromParcel(Parcel in) {
|
public LocationRequest createFromParcel(Parcel in) {
|
||||||
LocationRequest request = new LocationRequest();
|
return new LocationRequest(
|
||||||
request.setQuality(in.readInt());
|
/* provider= */ in.readString(),
|
||||||
request.setFastestInterval(in.readLong());
|
/* quality= */ in.readInt(),
|
||||||
request.setInterval(in.readLong());
|
/* interval= */ in.readLong(),
|
||||||
request.setExpireAt(in.readLong());
|
/* fastestInterval= */ in.readLong(),
|
||||||
request.setExpireIn(in.readLong());
|
/* explicitFastestInterval= */ in.readBoolean(),
|
||||||
request.setNumUpdates(in.readInt());
|
/* expireAt= */ in.readLong(),
|
||||||
request.setSmallestDisplacement(in.readFloat());
|
/* expireIn= */ in.readLong(),
|
||||||
request.setHideFromAppOps(in.readInt() != 0);
|
/* numUpdates= */ in.readInt(),
|
||||||
request.setLowPowerMode(in.readInt() != 0);
|
/* smallestDisplacement= */ in.readFloat(),
|
||||||
request.setLocationSettingsIgnored(in.readInt() != 0);
|
/* hideFromAppOps= */ in.readBoolean(),
|
||||||
String provider = in.readString();
|
/* locationSettingsIgnored= */ in.readBoolean(),
|
||||||
if (provider != null) request.setProvider(provider);
|
/* lowPowerMode= */ in.readBoolean(),
|
||||||
WorkSource workSource = in.readParcelable(null);
|
/* workSource= */ in.readTypedObject(WorkSource.CREATOR));
|
||||||
if (workSource != null) request.setWorkSource(workSource);
|
|
||||||
return request;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -702,18 +727,19 @@ public final class LocationRequest implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel parcel, int flags) {
|
public void writeToParcel(Parcel parcel, int flags) {
|
||||||
|
parcel.writeString(mProvider);
|
||||||
parcel.writeInt(mQuality);
|
parcel.writeInt(mQuality);
|
||||||
parcel.writeLong(mFastestInterval);
|
|
||||||
parcel.writeLong(mInterval);
|
parcel.writeLong(mInterval);
|
||||||
|
parcel.writeLong(mFastestInterval);
|
||||||
|
parcel.writeBoolean(mExplicitFastestInterval);
|
||||||
parcel.writeLong(mExpireAt);
|
parcel.writeLong(mExpireAt);
|
||||||
parcel.writeLong(mExpireIn);
|
parcel.writeLong(mExpireIn);
|
||||||
parcel.writeInt(mNumUpdates);
|
parcel.writeInt(mNumUpdates);
|
||||||
parcel.writeFloat(mSmallestDisplacement);
|
parcel.writeFloat(mSmallestDisplacement);
|
||||||
parcel.writeInt(mHideFromAppOps ? 1 : 0);
|
parcel.writeBoolean(mHideFromAppOps);
|
||||||
parcel.writeInt(mLowPowerMode ? 1 : 0);
|
parcel.writeBoolean(mLocationSettingsIgnored);
|
||||||
parcel.writeInt(mLocationSettingsIgnored ? 1 : 0);
|
parcel.writeBoolean(mLowPowerMode);
|
||||||
parcel.writeString(mProvider);
|
parcel.writeTypedObject(mWorkSource, 0);
|
||||||
parcel.writeParcelable(mWorkSource, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -740,16 +766,19 @@ public final class LocationRequest implements Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder s = new StringBuilder();
|
StringBuilder s = new StringBuilder();
|
||||||
s.append("Request[").append(qualityToString(mQuality));
|
s.append("Request[");
|
||||||
if (mProvider != null) s.append(' ').append(mProvider);
|
s.append(qualityToString(mQuality));
|
||||||
|
s.append(" ").append(mProvider);
|
||||||
if (mQuality != POWER_NONE) {
|
if (mQuality != POWER_NONE) {
|
||||||
s.append(" requested=");
|
s.append(" interval=");
|
||||||
TimeUtils.formatDuration(mInterval, s);
|
TimeUtils.formatDuration(mInterval, s);
|
||||||
|
if (mExplicitFastestInterval) {
|
||||||
|
s.append(" fastestInterval=");
|
||||||
|
TimeUtils.formatDuration(mFastestInterval, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
s.append(" fastest=");
|
|
||||||
TimeUtils.formatDuration(mFastestInterval, s);
|
|
||||||
if (mExpireAt != Long.MAX_VALUE) {
|
if (mExpireAt != Long.MAX_VALUE) {
|
||||||
s.append(" expireAt=").append(TimeUtils.formatUptime(mExpireAt));
|
s.append(" expireAt=").append(TimeUtils.formatRealtime(mExpireAt));
|
||||||
}
|
}
|
||||||
if (mExpireIn != Long.MAX_VALUE) {
|
if (mExpireIn != Long.MAX_VALUE) {
|
||||||
s.append(" expireIn=");
|
s.append(" expireIn=");
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import android.os.Parcelable;
|
|||||||
import android.os.WorkSource;
|
import android.os.WorkSource;
|
||||||
import android.util.TimeUtils;
|
import android.util.TimeUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -83,18 +82,14 @@ public final class ProviderRequest implements Parcelable {
|
|||||||
new Parcelable.Creator<ProviderRequest>() {
|
new Parcelable.Creator<ProviderRequest>() {
|
||||||
@Override
|
@Override
|
||||||
public ProviderRequest createFromParcel(Parcel in) {
|
public ProviderRequest createFromParcel(Parcel in) {
|
||||||
boolean reportLocation = in.readInt() == 1;
|
return new ProviderRequest(
|
||||||
long interval = in.readLong();
|
/* reportLocation= */ in.readBoolean(),
|
||||||
boolean lowPowerMode = in.readBoolean();
|
/* interval= */ in.readLong(),
|
||||||
boolean locationSettingsIgnored = in.readBoolean();
|
/* lowPowerMode= */ in.readBoolean(),
|
||||||
int count = in.readInt();
|
/* locationSettingsIgnored= */ in.readBoolean(),
|
||||||
ArrayList<LocationRequest> locationRequests = new ArrayList<>(count);
|
/* locationRequests= */
|
||||||
for (int i = 0; i < count; i++) {
|
in.createTypedArrayList(LocationRequest.CREATOR),
|
||||||
locationRequests.add(LocationRequest.CREATOR.createFromParcel(in));
|
/* workSource= */ in.readTypedObject(WorkSource.CREATOR));
|
||||||
}
|
|
||||||
WorkSource workSource = in.readParcelable(null);
|
|
||||||
return new ProviderRequest(reportLocation, interval, lowPowerMode,
|
|
||||||
locationSettingsIgnored, locationRequests, workSource);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -110,15 +105,12 @@ public final class ProviderRequest implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel parcel, int flags) {
|
public void writeToParcel(Parcel parcel, int flags) {
|
||||||
parcel.writeInt(reportLocation ? 1 : 0);
|
parcel.writeBoolean(reportLocation);
|
||||||
parcel.writeLong(interval);
|
parcel.writeLong(interval);
|
||||||
parcel.writeBoolean(lowPowerMode);
|
parcel.writeBoolean(lowPowerMode);
|
||||||
parcel.writeBoolean(locationSettingsIgnored);
|
parcel.writeBoolean(locationSettingsIgnored);
|
||||||
parcel.writeInt(locationRequests.size());
|
parcel.writeTypedList(locationRequests);
|
||||||
for (LocationRequest request : locationRequests) {
|
parcel.writeTypedObject(workSource, flags);
|
||||||
request.writeToParcel(parcel, flags);
|
|
||||||
}
|
|
||||||
parcel.writeParcelable(workSource, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user