From 420fd08ed3d64cd764aff8152c8efe1371ee1372 Mon Sep 17 00:00:00 2001 From: Yu-Han Yang Date: Wed, 9 Aug 2023 22:57:12 +0000 Subject: Add WorkSource in GnssMeasurementRequest Bug: 295235160 Test: atest GnssMeasurementRequestTest Change-Id: I679a6bf7f110ec55db12e8381f8bf3efd43a727e --- core/api/system-current.txt | 2 + .../android/location/GnssMeasurementRequest.java | 62 +++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 77168e3a45b3..539f92f23cb2 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -6274,11 +6274,13 @@ package android.location { } public final class GnssMeasurementRequest implements android.os.Parcelable { + method @NonNull public android.os.WorkSource getWorkSource(); method public boolean isCorrelationVectorOutputsEnabled(); } public static final class GnssMeasurementRequest.Builder { method @NonNull public android.location.GnssMeasurementRequest.Builder setCorrelationVectorOutputsEnabled(boolean); + method @NonNull @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public android.location.GnssMeasurementRequest.Builder setWorkSource(@Nullable android.os.WorkSource); } public final class GnssReflectingPlane implements android.os.Parcelable { diff --git a/location/java/android/location/GnssMeasurementRequest.java b/location/java/android/location/GnssMeasurementRequest.java index 3f3ad759ed07..65af3928bd02 100644 --- a/location/java/android/location/GnssMeasurementRequest.java +++ b/location/java/android/location/GnssMeasurementRequest.java @@ -16,11 +16,15 @@ package android.location; +import android.Manifest; import android.annotation.IntRange; import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; +import android.os.WorkSource; import android.util.TimeUtils; import com.android.internal.util.Preconditions; @@ -46,15 +50,16 @@ public final class GnssMeasurementRequest implements Parcelable { private final boolean mCorrelationVectorOutputsEnabled; private final boolean mFullTracking; private final int mIntervalMillis; - + private WorkSource mWorkSource; /** * Creates a {@link GnssMeasurementRequest} with a full list of parameters. */ private GnssMeasurementRequest(boolean fullTracking, boolean correlationVectorOutputsEnabled, - int intervalMillis) { + int intervalMillis, WorkSource workSource) { mFullTracking = fullTracking; mCorrelationVectorOutputsEnabled = correlationVectorOutputsEnabled; mIntervalMillis = intervalMillis; + mWorkSource = Objects.requireNonNull(workSource); } /** @@ -107,14 +112,31 @@ public final class GnssMeasurementRequest implements Parcelable { return mIntervalMillis; } + /** + * Returns the work source used for power blame for this request. If empty (i.e., + * {@link WorkSource#isEmpty()} is {@code true}, the system is free to assign power blame as it + * deems most appropriate. + * + * @return the work source used for power blame for this request + * + * @hide + */ + @SystemApi + public @NonNull WorkSource getWorkSource() { + return mWorkSource; + } + @NonNull public static final Creator CREATOR = new Creator() { @Override @NonNull public GnssMeasurementRequest createFromParcel(@NonNull Parcel parcel) { - return new GnssMeasurementRequest(parcel.readBoolean(), parcel.readBoolean(), - parcel.readInt()); + return new GnssMeasurementRequest( + /* fullTracking= */ parcel.readBoolean(), + /* correlationVectorOutputsEnabled= */ parcel.readBoolean(), + /* intervalMillis= */ parcel.readInt(), + /* workSource= */ parcel.readTypedObject(WorkSource.CREATOR)); } @Override @@ -128,6 +150,7 @@ public final class GnssMeasurementRequest implements Parcelable { parcel.writeBoolean(mFullTracking); parcel.writeBoolean(mCorrelationVectorOutputsEnabled); parcel.writeInt(mIntervalMillis); + parcel.writeTypedObject(mWorkSource, 0); } @NonNull @@ -147,6 +170,9 @@ public final class GnssMeasurementRequest implements Parcelable { if (mCorrelationVectorOutputsEnabled) { s.append(", CorrelationVectorOutputs"); } + if (mWorkSource != null && !mWorkSource.isEmpty()) { + s.append(", ").append(mWorkSource); + } s.append(']'); return s.toString(); } @@ -165,12 +191,16 @@ public final class GnssMeasurementRequest implements Parcelable { if (mIntervalMillis != other.mIntervalMillis) { return false; } + if (!Objects.equals(mWorkSource, other.mWorkSource)) { + return false; + } return true; } @Override public int hashCode() { - return Objects.hash(mFullTracking, mCorrelationVectorOutputsEnabled, mIntervalMillis); + return Objects.hash(mFullTracking, mCorrelationVectorOutputsEnabled, mIntervalMillis, + mWorkSource); } @Override @@ -183,6 +213,7 @@ public final class GnssMeasurementRequest implements Parcelable { private boolean mCorrelationVectorOutputsEnabled; private boolean mFullTracking; private int mIntervalMillis; + private WorkSource mWorkSource; /** * Constructs a {@link Builder} instance. @@ -197,6 +228,7 @@ public final class GnssMeasurementRequest implements Parcelable { mCorrelationVectorOutputsEnabled = request.isCorrelationVectorOutputsEnabled(); mFullTracking = request.isFullTracking(); mIntervalMillis = request.getIntervalMillis(); + mWorkSource = request.getWorkSource(); } /** @@ -255,11 +287,29 @@ public final class GnssMeasurementRequest implements Parcelable { return this; } + /** + * Sets the work source to use for power blame for this request. Passing in null or leaving + * it unset will be an empty WorkSource, which implies the system is free to assign power + * blame as it determines best for this request (which usually means blaming the owner of + * the GnssMeasurement listener). + * + *

Permissions enforcement occurs when resulting request is actually used, not when this + * method is invoked. + * + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.UPDATE_DEVICE_STATS) + public @NonNull Builder setWorkSource(@Nullable WorkSource workSource) { + mWorkSource = workSource; + return this; + } + /** Builds a {@link GnssMeasurementRequest} instance as specified by this builder. */ @NonNull public GnssMeasurementRequest build() { return new GnssMeasurementRequest(mFullTracking, mCorrelationVectorOutputsEnabled, - mIntervalMillis); + mIntervalMillis, new WorkSource(mWorkSource)); } } } -- cgit v1.2.3-59-g8ed1b