2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 package android.location;
19 import android.annotation.TestApi;
20 import android.annotation.IntDef;
21 import android.annotation.NonNull;
22 import android.os.Parcel;
23 import android.os.Parcelable;
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 import java.security.InvalidParameterException;
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.Collections;
33 * A class implementing a container for data associated with a measurement event.
34 * Events are delivered to registered instances of {@link Callback}.
36 public final class GnssMeasurementsEvent implements Parcelable {
38 public static final int STATUS_NOT_SUPPORTED = 0;
40 public static final int STATUS_READY = 1;
42 public static final int STATUS_GNSS_LOCATION_DISABLED = 2;
44 private final GnssClock mClock;
45 private final Collection<GnssMeasurement> mReadOnlyMeasurements;
48 * Used for receiving GNSS satellite measurements from the GNSS engine.
49 * Each measurement contains raw and computed data identifying a satellite.
50 * You can implement this interface and call
51 * {@link LocationManager#registerGnssMeasurementsCallback}.
53 public static abstract class Callback {
55 * The status of the GNSS measurements event.
58 @Retention(RetentionPolicy.SOURCE)
59 @IntDef({STATUS_NOT_SUPPORTED, STATUS_READY, STATUS_LOCATION_DISABLED})
60 public @interface GnssMeasurementsStatus {}
63 * The system does not support tracking of GNSS Measurements.
65 * <p>This status will not change in the future.
67 public static final int STATUS_NOT_SUPPORTED = 0;
70 * GNSS Measurements are successfully being tracked, it will receive updates once they are
73 public static final int STATUS_READY = 1;
76 * GPS provider or Location is disabled, updates will not be received until they are
79 public static final int STATUS_LOCATION_DISABLED = 2;
82 * Reports the latest collected GNSS Measurements.
84 public void onGnssMeasurementsReceived(GnssMeasurementsEvent eventArgs) {}
87 * Reports the latest status of the GNSS Measurements sub-system.
89 public void onStatusChanged(@GnssMeasurementsStatus int status) {}
96 public GnssMeasurementsEvent(GnssClock clock, GnssMeasurement[] measurements) {
98 throw new InvalidParameterException("Parameter 'clock' must not be null.");
100 if (measurements == null || measurements.length == 0) {
101 throw new InvalidParameterException(
102 "Parameter 'measurements' must not be null or empty.");
106 Collection<GnssMeasurement> measurementCollection = Arrays.asList(measurements);
107 mReadOnlyMeasurements = Collections.unmodifiableCollection(measurementCollection);
111 * Gets the GNSS receiver clock information associated with the measurements for the current
115 public GnssClock getClock() {
120 * Gets a read-only collection of measurements associated with the current event.
123 public Collection<GnssMeasurement> getMeasurements() {
124 return mReadOnlyMeasurements;
127 public static final Creator<GnssMeasurementsEvent> CREATOR =
128 new Creator<GnssMeasurementsEvent>() {
130 public GnssMeasurementsEvent createFromParcel(Parcel in) {
131 ClassLoader classLoader = getClass().getClassLoader();
133 GnssClock clock = in.readParcelable(classLoader);
135 int measurementsLength = in.readInt();
136 GnssMeasurement[] measurementsArray = new GnssMeasurement[measurementsLength];
137 in.readTypedArray(measurementsArray, GnssMeasurement.CREATOR);
139 return new GnssMeasurementsEvent(clock, measurementsArray);
143 public GnssMeasurementsEvent[] newArray(int size) {
144 return new GnssMeasurementsEvent[size];
149 public int describeContents() {
154 public void writeToParcel(Parcel parcel, int flags) {
155 parcel.writeParcelable(mClock, flags);
157 int measurementsCount = mReadOnlyMeasurements.size();
158 GnssMeasurement[] measurementsArray =
159 mReadOnlyMeasurements.toArray(new GnssMeasurement[measurementsCount]);
160 parcel.writeInt(measurementsArray.length);
161 parcel.writeTypedArray(measurementsArray, flags);
165 public String toString() {
166 StringBuilder builder = new StringBuilder("[ GnssMeasurementsEvent:\n\n");
168 builder.append(mClock.toString());
169 builder.append("\n");
171 for (GnssMeasurement measurement : mReadOnlyMeasurements) {
172 builder.append(measurement.toString());
173 builder.append("\n");
178 return builder.toString();