• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.location;
18 
19 import android.annotation.IntRange;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.util.TimeUtils;
25 
26 import com.android.internal.util.Preconditions;
27 
28 import java.util.Objects;
29 
30 /**
31  * This class contains extra parameters to pass in a GNSS measurement request.
32  */
33 public final class GnssMeasurementRequest implements Parcelable {
34     private final boolean mCorrelationVectorOutputsEnabled;
35     private final boolean mFullTracking;
36     private final int mIntervalMillis;
37 
38     /**
39      * Creates a {@link GnssMeasurementRequest} with a full list of parameters.
40      */
GnssMeasurementRequest(boolean fullTracking, boolean correlationVectorOutputsEnabled, int intervalMillis)41     private GnssMeasurementRequest(boolean fullTracking, boolean correlationVectorOutputsEnabled,
42             int intervalMillis) {
43         mFullTracking = fullTracking;
44         mCorrelationVectorOutputsEnabled = correlationVectorOutputsEnabled;
45         mIntervalMillis = intervalMillis;
46     }
47 
48     /**
49      * Represents whether to enable correlation vector outputs.
50      *
51      * <p>If true, enable correlation vectors as part of the raw GNSS measurements outputs.
52      * If false, disable correlation vectors.
53      *
54      * @hide
55      */
56     @SystemApi
isCorrelationVectorOutputsEnabled()57     public boolean isCorrelationVectorOutputsEnabled() {
58         return mCorrelationVectorOutputsEnabled;
59     }
60 
61     /**
62      * Represents whether to enable full GNSS tracking.
63      *
64      * <p>If true, GNSS chipset switches off duty cycling. In such a mode, no clock
65      * discontinuities are expected, and when supported, carrier phase should be continuous in
66      * good signal conditions. All non-blocklisted, healthy constellations, satellites and
67      * frequency bands that the chipset supports must be reported in this mode. The GNSS chipset
68      * will consume more power in full tracking mode than in duty cycling mode. If false, GNSS
69      * chipset optimizes power via duty cycling, constellations and frequency limits, etc.
70      *
71      * <p>Full GNSS tracking mode affects GnssMeasurement and other GNSS functionalities
72      * including GNSS location.
73      */
isFullTracking()74     public boolean isFullTracking() {
75         return mFullTracking;
76     }
77 
78     /**
79      * Represents the requested time interval between the reported measurements in milliseconds.
80      *
81      * <p>If the time interval is not set, the default value is 0, which means the fastest rate the
82      * GNSS chipset can report.
83      *
84      * <p>The GNSS chipset may report measurements with a rate faster than requested.
85      */
getIntervalMillis()86     public @IntRange(from = 0) int getIntervalMillis() {
87         return mIntervalMillis;
88     }
89 
90     @NonNull
91     public static final Creator<GnssMeasurementRequest> CREATOR =
92             new Creator<GnssMeasurementRequest>() {
93                 @Override
94                 @NonNull
95                 public GnssMeasurementRequest createFromParcel(@NonNull Parcel parcel) {
96                     return new GnssMeasurementRequest(parcel.readBoolean(), parcel.readBoolean(),
97                             parcel.readInt());
98                 }
99 
100                 @Override
101                 public GnssMeasurementRequest[] newArray(int i) {
102                     return new GnssMeasurementRequest[i];
103                 }
104             };
105 
106     @Override
writeToParcel(@onNull Parcel parcel, int flags)107     public void writeToParcel(@NonNull Parcel parcel, int flags) {
108         parcel.writeBoolean(mFullTracking);
109         parcel.writeBoolean(mCorrelationVectorOutputsEnabled);
110         parcel.writeInt(mIntervalMillis);
111     }
112 
113     @NonNull
114     @Override
toString()115     public String toString() {
116         StringBuilder s = new StringBuilder();
117         s.append("GnssMeasurementRequest[");
118         s.append("@");
119         TimeUtils.formatDuration(mIntervalMillis, s);
120         if (mFullTracking) {
121             s.append(", FullTracking");
122         }
123         if (mCorrelationVectorOutputsEnabled) {
124             s.append(", CorrelationVectorOutputs");
125         }
126         s.append(']');
127         return s.toString();
128     }
129 
130     @Override
equals(Object obj)131     public boolean equals(Object obj) {
132         if (this == obj) return true;
133         if (obj == null) return false;
134         if (!(obj instanceof GnssMeasurementRequest)) return false;
135 
136         GnssMeasurementRequest other = (GnssMeasurementRequest) obj;
137         if (mFullTracking != other.mFullTracking) return false;
138         if (mCorrelationVectorOutputsEnabled != other.mCorrelationVectorOutputsEnabled) {
139             return false;
140         }
141         if (mIntervalMillis != other.mIntervalMillis) {
142             return false;
143         }
144         return true;
145     }
146 
147     @Override
hashCode()148     public int hashCode() {
149         return Objects.hash(mFullTracking, mCorrelationVectorOutputsEnabled, mIntervalMillis);
150     }
151 
152     @Override
describeContents()153     public int describeContents() {
154         return 0;
155     }
156 
157     /** Builder for {@link GnssMeasurementRequest} */
158     public static final class Builder {
159         private boolean mCorrelationVectorOutputsEnabled;
160         private boolean mFullTracking;
161         private int mIntervalMillis;
162 
163         /**
164          * Constructs a {@link Builder} instance.
165          */
Builder()166         public Builder() {
167         }
168 
169         /**
170          * Constructs a {@link Builder} instance by copying a {@link GnssMeasurementRequest}.
171          */
Builder(@onNull GnssMeasurementRequest request)172         public Builder(@NonNull GnssMeasurementRequest request) {
173             mCorrelationVectorOutputsEnabled = request.isCorrelationVectorOutputsEnabled();
174             mFullTracking = request.isFullTracking();
175             mIntervalMillis = request.getIntervalMillis();
176         }
177 
178         /**
179          * Set the value of whether to enable correlation vector outputs, which is false by default.
180          *
181          * <p>If true, enable correlation vectors as part of the raw GNSS measurements outputs.
182          * If false, disable correlation vectors.
183          *
184          * @hide
185          */
186         @SystemApi
setCorrelationVectorOutputsEnabled(boolean value)187         @NonNull public Builder setCorrelationVectorOutputsEnabled(boolean value) {
188             mCorrelationVectorOutputsEnabled = value;
189             return this;
190         }
191 
192         /**
193          * Set the value of whether to enable full GNSS tracking, which is false by default.
194          *
195          * <p>If true, GNSS chipset switches off duty cycling. In such a mode, no clock
196          * discontinuities are expected, and when supported, carrier phase should be continuous in
197          * good signal conditions. All non-blocklisted, healthy constellations, satellites and
198          * frequency bands that the chipset supports must be reported in this mode. The GNSS chipset
199          * will consume more power in full tracking mode than in duty cycling mode. If false,
200          * GNSS chipset optimizes power via duty cycling, constellations and frequency limits, etc.
201          *
202          * <p>Full GNSS tracking mode affects GnssMeasurement and other GNSS functionalities
203          * including GNSS location.
204          *
205          * <p>Full tracking requests always override non-full tracking requests. If any full
206          * tracking request occurs, all listeners on the device will receive full tracking GNSS
207          * measurements.
208          */
setFullTracking(boolean value)209         @NonNull public Builder setFullTracking(boolean value) {
210             mFullTracking = value;
211             return this;
212         }
213 
214         /**
215          * Set the time interval between the reported measurements in milliseconds, which is 0 by
216          * default.
217          *
218          * <p>An interval of 0 milliseconds means the fastest rate the chipset can report.
219          *
220          * <p>The GNSS chipset may report measurements with a rate faster than requested.
221          */
setIntervalMillis(@ntRangefrom = 0) int value)222         @NonNull public Builder setIntervalMillis(@IntRange(from = 0) int value) {
223             mIntervalMillis = Preconditions.checkArgumentInRange(value, 0, Integer.MAX_VALUE,
224                     "intervalMillis");
225             return this;
226         }
227 
228         /** Builds a {@link GnssMeasurementRequest} instance as specified by this builder. */
229         @NonNull
build()230         public GnssMeasurementRequest build() {
231             return new GnssMeasurementRequest(mFullTracking, mCorrelationVectorOutputsEnabled,
232                     mIntervalMillis);
233         }
234     }
235 }
236