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 /** 25 * This class contains extra parameters to pass to a GNSS provider implementation. 26 * @hide 27 */ 28 @SystemApi 29 public final class GnssRequest implements Parcelable { 30 private final boolean mFullTracking; 31 32 /** 33 * Creates a {@link GnssRequest} with a full list of parameters. 34 */ GnssRequest(boolean fullTracking)35 private GnssRequest(boolean fullTracking) { 36 mFullTracking = fullTracking; 37 } 38 39 /** 40 * Represents whether to enable full GNSS tracking. 41 * 42 * <p>If true, GNSS chipset switches off duty cycling. In such a mode, no clock 43 * discontinuities are expected, and when supported, carrier phase should be continuous in 44 * good signal conditions. All non-blacklisted, healthy constellations, satellites and 45 * frequency bands that the chipset supports must be reported in this mode. The GNSS chipset 46 * is allowed to consume more power in this mode. If false, GNSS chipset optimizes power via 47 * duty cycling, constellations and frequency limits, etc. 48 */ isFullTracking()49 public boolean isFullTracking() { 50 return mFullTracking; 51 } 52 53 @NonNull 54 public static final Creator<GnssRequest> CREATOR = 55 new Creator<GnssRequest>() { 56 @Override 57 @NonNull 58 public GnssRequest createFromParcel(@NonNull Parcel parcel) { 59 return new GnssRequest(parcel.readBoolean()); 60 } 61 62 @Override 63 public GnssRequest[] newArray(int i) { 64 return new GnssRequest[i]; 65 } 66 }; 67 68 @NonNull 69 @Override toString()70 public String toString() { 71 StringBuilder s = new StringBuilder(); 72 s.append("GnssRequest["); 73 s.append("FullTracking=").append(mFullTracking); 74 s.append(']'); 75 return s.toString(); 76 } 77 78 @Override equals(Object obj)79 public boolean equals(Object obj) { 80 if (this == obj) return true; 81 if (obj == null) return false; 82 if (!(obj instanceof GnssRequest)) return false; 83 84 GnssRequest other = (GnssRequest) obj; 85 if (mFullTracking != other.mFullTracking) return false; 86 87 return true; 88 } 89 90 @Override hashCode()91 public int hashCode() { 92 return mFullTracking ? 1 : 0; 93 } 94 95 @Override describeContents()96 public int describeContents() { 97 return 0; 98 } 99 100 @Override writeToParcel(@onNull Parcel parcel, int flags)101 public void writeToParcel(@NonNull Parcel parcel, int flags) { 102 parcel.writeBoolean(mFullTracking); 103 } 104 105 /** Builder for {@link GnssRequest} */ 106 public static final class Builder { 107 private boolean mFullTracking; 108 109 /** 110 * Constructs a {@link Builder} instance. 111 */ Builder()112 public Builder() { 113 } 114 115 /** 116 * Constructs a {@link Builder} instance by copying a {@link GnssRequest}. 117 */ Builder(@onNull GnssRequest request)118 public Builder(@NonNull GnssRequest request) { 119 mFullTracking = request.isFullTracking(); 120 } 121 122 /** 123 * Set the value of whether to enable full GNSS tracking, which is false by default. 124 * 125 * <p>If true, GNSS chipset switches off duty cycling. In such a mode, no clock 126 * discontinuities are expected, and when supported, carrier phase should be continuous in 127 * good signal conditions. All non-blacklisted, healthy constellations, satellites and 128 * frequency bands that the chipset supports must be reported in this mode. The GNSS chipset 129 * is allowed to consume more power in this mode. If false, GNSS chipset optimizes power via 130 * duty cycling, constellations and frequency limits, etc. 131 * 132 * <p>Full tracking requests always override non-full tracking requests. If any full 133 * tracking request occurs, all listeners on the device will receive full tracking GNSS 134 * measurements. 135 */ setFullTracking(boolean value)136 @NonNull public Builder setFullTracking(boolean value) { 137 mFullTracking = value; 138 return this; 139 } 140 141 /** Builds a {@link GnssRequest} instance as specified by this builder. */ 142 @NonNull build()143 public GnssRequest build() { 144 return new GnssRequest(mFullTracking); 145 } 146 } 147 } 148