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.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.util.Objects; 25 26 /** 27 * This class contains extra parameters to pass in a GNSS measurement request. 28 */ 29 public final class GnssMeasurementRequest implements Parcelable { 30 private final boolean mCorrelationVectorOutputsEnabled; 31 private final boolean mFullTracking; 32 33 /** 34 * Creates a {@link GnssMeasurementRequest} with a full list of parameters. 35 */ GnssMeasurementRequest(boolean fullTracking, boolean correlationVectorOutputsEnabled)36 private GnssMeasurementRequest(boolean fullTracking, boolean correlationVectorOutputsEnabled) { 37 mFullTracking = fullTracking; 38 mCorrelationVectorOutputsEnabled = correlationVectorOutputsEnabled; 39 } 40 41 /** 42 * Represents whether to enable correlation vector outputs. 43 * 44 * <p>If true, enable correlation vectors as part of the raw GNSS measurements outputs. 45 * If false, disable correlation vectors. 46 * 47 * @hide 48 */ 49 @SystemApi isCorrelationVectorOutputsEnabled()50 public boolean isCorrelationVectorOutputsEnabled() { 51 return mCorrelationVectorOutputsEnabled; 52 } 53 54 /** 55 * Represents whether to enable full GNSS tracking. 56 * 57 * <p>If true, GNSS chipset switches off duty cycling. In such a mode, no clock 58 * discontinuities are expected, and when supported, carrier phase should be continuous in 59 * good signal conditions. All non-blocklisted, healthy constellations, satellites and 60 * frequency bands that the chipset supports must be reported in this mode. The GNSS chipset 61 * will consume more power in full tracking mode than in duty cycling mode. If false, GNSS 62 * chipset optimizes power via duty cycling, constellations and frequency limits, etc. 63 * 64 * <p>Full GNSS tracking mode affects GnssMeasurement and other GNSS functionalities 65 * including GNSS location. 66 */ isFullTracking()67 public boolean isFullTracking() { 68 return mFullTracking; 69 } 70 71 @NonNull 72 public static final Creator<GnssMeasurementRequest> CREATOR = 73 new Creator<GnssMeasurementRequest>() { 74 @Override 75 @NonNull 76 public GnssMeasurementRequest createFromParcel(@NonNull Parcel parcel) { 77 return new GnssMeasurementRequest(parcel.readBoolean(), parcel.readBoolean()); 78 } 79 80 @Override 81 public GnssMeasurementRequest[] newArray(int i) { 82 return new GnssMeasurementRequest[i]; 83 } 84 }; 85 86 @Override writeToParcel(@onNull Parcel parcel, int flags)87 public void writeToParcel(@NonNull Parcel parcel, int flags) { 88 parcel.writeBoolean(mFullTracking); 89 parcel.writeBoolean(mCorrelationVectorOutputsEnabled); 90 } 91 92 @NonNull 93 @Override toString()94 public String toString() { 95 StringBuilder s = new StringBuilder(); 96 s.append("GnssMeasurementRequest["); 97 if (mFullTracking) { 98 s.append("FullTracking"); 99 } 100 if (mCorrelationVectorOutputsEnabled) { 101 s.append(", CorrelationVectorOutPuts"); 102 } 103 s.append(']'); 104 return s.toString(); 105 } 106 107 @Override equals(Object obj)108 public boolean equals(Object obj) { 109 if (this == obj) return true; 110 if (obj == null) return false; 111 if (!(obj instanceof GnssMeasurementRequest)) return false; 112 113 GnssMeasurementRequest other = (GnssMeasurementRequest) obj; 114 if (mFullTracking != other.mFullTracking) return false; 115 if (mCorrelationVectorOutputsEnabled != other.mCorrelationVectorOutputsEnabled) { 116 return false; 117 } 118 return true; 119 } 120 121 @Override hashCode()122 public int hashCode() { 123 return Objects.hash(mFullTracking, mCorrelationVectorOutputsEnabled); 124 } 125 126 @Override describeContents()127 public int describeContents() { 128 return 0; 129 } 130 131 /** Builder for {@link GnssMeasurementRequest} */ 132 public static final class Builder { 133 private boolean mCorrelationVectorOutputsEnabled; 134 private boolean mFullTracking; 135 136 /** 137 * Constructs a {@link Builder} instance. 138 */ Builder()139 public Builder() { 140 } 141 142 /** 143 * Constructs a {@link Builder} instance by copying a {@link GnssMeasurementRequest}. 144 */ Builder(@onNull GnssMeasurementRequest request)145 public Builder(@NonNull GnssMeasurementRequest request) { 146 mCorrelationVectorOutputsEnabled = request.isCorrelationVectorOutputsEnabled(); 147 mFullTracking = request.isFullTracking(); 148 } 149 150 /** 151 * Set the value of whether to enable correlation vector outputs, which is false by default. 152 * 153 * <p>If true, enable correlation vectors as part of the raw GNSS measurements outputs. 154 * If false, disable correlation vectors. 155 * 156 * @hide 157 */ 158 @SystemApi setCorrelationVectorOutputsEnabled(boolean value)159 @NonNull public Builder setCorrelationVectorOutputsEnabled(boolean value) { 160 mCorrelationVectorOutputsEnabled = value; 161 return this; 162 } 163 164 /** 165 * Set the value of whether to enable full GNSS tracking, which is false by default. 166 * 167 * <p>If true, GNSS chipset switches off duty cycling. In such a mode, no clock 168 * discontinuities are expected, and when supported, carrier phase should be continuous in 169 * good signal conditions. All non-blocklisted, healthy constellations, satellites and 170 * frequency bands that the chipset supports must be reported in this mode. The GNSS chipset 171 * will consume more power in full tracking mode than in duty cycling mode. If false, 172 * GNSS chipset optimizes power via duty cycling, constellations and frequency limits, etc. 173 * 174 * <p>Full GNSS tracking mode affects GnssMeasurement and other GNSS functionalities 175 * including GNSS location. 176 * 177 * <p>Full tracking requests always override non-full tracking requests. If any full 178 * tracking request occurs, all listeners on the device will receive full tracking GNSS 179 * measurements. 180 */ setFullTracking(boolean value)181 @NonNull public Builder setFullTracking(boolean value) { 182 mFullTracking = value; 183 return this; 184 } 185 186 /** Builds a {@link GnssMeasurementRequest} instance as specified by this builder. */ 187 @NonNull build()188 public GnssMeasurementRequest build() { 189 return new GnssMeasurementRequest(mFullTracking, mCorrelationVectorOutputsEnabled); 190 } 191 } 192 } 193