blob: 88f00dc38cb3c6aade15579f15261742f2fb36b5 [file] [log] [blame]
Anil Admal99349782019-03-19 18:58:42 -07001/*
2 * Copyright (C) 2019 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
17package android.location;
18
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080019import android.annotation.IntDef;
20import android.annotation.NonNull;
Anil Admal99349782019-03-19 18:58:42 -070021import android.annotation.SystemApi;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080022import android.os.Parcel;
23import android.os.Parcelable;
24
25import java.lang.annotation.Retention;
26import java.lang.annotation.RetentionPolicy;
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +000027import java.util.ArrayList;
Yu-Han Yang0d08d6d2022-11-08 17:38:17 +000028import java.util.Collections;
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +000029import java.util.List;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080030import java.util.Objects;
31import java.util.concurrent.Executor;
Anil Admal99349782019-03-19 18:58:42 -070032
Anil Admal99349782019-03-19 18:58:42 -070033/**
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080034 * GNSS chipset capabilities.
Anil Admal99349782019-03-19 18:58:42 -070035 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080036public final class GnssCapabilities implements Parcelable {
Anil Admal3ba0fa92019-04-19 17:43:00 -070037
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080038 // IMPORTANT - must match the Capabilities enum in IGnssCallback.hal
39 /** @hide */
40 public static final int TOP_HAL_CAPABILITY_SCHEDULING = 1;
41 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000042 public static final int TOP_HAL_CAPABILITY_MSB = 1 << 1;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080043 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000044 public static final int TOP_HAL_CAPABILITY_MSA = 1 << 2;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080045 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000046 public static final int TOP_HAL_CAPABILITY_SINGLE_SHOT = 1 << 3;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080047 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000048 public static final int TOP_HAL_CAPABILITY_ON_DEMAND_TIME = 1 << 4;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080049 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000050 public static final int TOP_HAL_CAPABILITY_GEOFENCING = 1 << 5;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080051 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000052 public static final int TOP_HAL_CAPABILITY_MEASUREMENTS = 1 << 6;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080053 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000054 public static final int TOP_HAL_CAPABILITY_NAV_MESSAGES = 1 << 7;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080055 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000056 public static final int TOP_HAL_CAPABILITY_LOW_POWER_MODE = 1 << 8;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080057 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000058 public static final int TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST = 1 << 9;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080059 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000060 public static final int TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS = 1 << 10;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080061 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000062 public static final int TOP_HAL_CAPABILITY_ANTENNA_INFO = 1 << 11;
Joe Huange2562192020-12-19 21:04:23 +080063 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000064 public static final int TOP_HAL_CAPABILITY_CORRELATION_VECTOR = 1 << 12;
Shinru Handaffd222020-12-21 21:11:33 +080065 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000066 public static final int TOP_HAL_CAPABILITY_SATELLITE_PVT = 1 << 13;
Shinru Han2bd63042021-03-16 17:37:16 +080067 /** @hide */
Yu-Han Yang40076ac2022-11-22 22:09:06 +000068 public static final int TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING = 1 << 14;
69 /** @hide */
70 public static final int TOP_HAL_CAPABILITY_ACCUMULATED_DELTA_RANGE = 1 << 15;
Sasha Kuznetsova68a7a32020-02-11 06:00:10 +000071
Anil Admal312fddb2019-03-25 12:15:43 -070072 /** @hide */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080073 @IntDef(flag = true, prefix = {"TOP_HAL_CAPABILITY_"}, value = {TOP_HAL_CAPABILITY_SCHEDULING,
74 TOP_HAL_CAPABILITY_MSB, TOP_HAL_CAPABILITY_MSA, TOP_HAL_CAPABILITY_SINGLE_SHOT,
75 TOP_HAL_CAPABILITY_ON_DEMAND_TIME, TOP_HAL_CAPABILITY_GEOFENCING,
76 TOP_HAL_CAPABILITY_MEASUREMENTS, TOP_HAL_CAPABILITY_NAV_MESSAGES,
77 TOP_HAL_CAPABILITY_LOW_POWER_MODE, TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST,
Joe Huange2562192020-12-19 21:04:23 +080078 TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS, TOP_HAL_CAPABILITY_ANTENNA_INFO,
Shinru Han2bd63042021-03-16 17:37:16 +080079 TOP_HAL_CAPABILITY_CORRELATION_VECTOR, TOP_HAL_CAPABILITY_SATELLITE_PVT,
Yu-Han Yang40076ac2022-11-22 22:09:06 +000080 TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING,
81 TOP_HAL_CAPABILITY_ACCUMULATED_DELTA_RANGE})
Shinru Handaffd222020-12-21 21:11:33 +080082
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080083 @Retention(RetentionPolicy.SOURCE)
84 public @interface TopHalCapabilityFlags {}
Anil Admal99349782019-03-19 18:58:42 -070085
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080086 // IMPORTANT - must match the Capabilities enum in IMeasurementCorrectionsCallback.hal
87 /** @hide */
88 public static final int SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_LOS_SATS = 1;
89 /** @hide */
90 public static final int SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_EXCESS_PATH_LENGTH = 2;
91 /** @hide */
92 public static final int SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_REFLECTING_PLANE = 4;
Anil Admal99349782019-03-19 18:58:42 -070093
Anil Admal312fddb2019-03-25 12:15:43 -070094 /** @hide */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -080095 @IntDef(flag = true, prefix = {"SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_"}, value = {
96 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_LOS_SATS,
97 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_EXCESS_PATH_LENGTH,
98 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_REFLECTING_PLANE})
99 @Retention(RetentionPolicy.SOURCE)
100 public @interface SubHalMeasurementCorrectionsCapabilityFlags {}
Anil Admal99349782019-03-19 18:58:42 -0700101
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800102 // IMPORATANT - must match values in IGnssPowerIndicationCallback.aidl
103 /** @hide */
104 public static final int SUB_HAL_POWER_CAPABILITY_TOTAL = 1;
105 /** @hide */
106 public static final int SUB_HAL_POWER_CAPABILITY_SINGLEBAND_TRACKING = 2;
107 /** @hide */
108 public static final int SUB_HAL_POWER_CAPABILITY_MULTIBAND_TRACKING = 4;
109 /** @hide */
110 public static final int SUB_HAL_POWER_CAPABILITY_SINGLEBAND_ACQUISITION = 8;
111 /** @hide */
112 public static final int SUB_HAL_POWER_CAPABILITY_MULTIBAND_ACQUISITION = 16;
113 /** @hide */
114 public static final int SUB_HAL_POWER_CAPABILITY_OTHER_MODES = 32;
115
116 /** @hide */
117 @IntDef(flag = true, prefix = {"SUB_HAL_POWER_CAPABILITY_"}, value = {
118 SUB_HAL_POWER_CAPABILITY_TOTAL, SUB_HAL_POWER_CAPABILITY_SINGLEBAND_TRACKING,
119 SUB_HAL_POWER_CAPABILITY_MULTIBAND_TRACKING,
120 SUB_HAL_POWER_CAPABILITY_SINGLEBAND_ACQUISITION,
121 SUB_HAL_POWER_CAPABILITY_MULTIBAND_ACQUISITION,
122 SUB_HAL_POWER_CAPABILITY_OTHER_MODES})
123 @Retention(RetentionPolicy.SOURCE)
124 public @interface SubHalPowerCapabilityFlags {}
Anil Admal99349782019-03-19 18:58:42 -0700125
Yu-Han Yange5aef392023-03-01 22:38:35 +0000126 /** The capability is unknown to be supported or not. */
127 public static final int CAPABILITY_UNKNOWN = 0;
128 /** The capability is supported. */
129 public static final int CAPABILITY_SUPPORTED = 1;
130 /** The capability is not supported. */
131 public static final int CAPABILITY_UNSUPPORTED = 2;
132
133 /** @hide */
134 @IntDef(flag = true, prefix = {"CAPABILITY_"}, value = {CAPABILITY_UNKNOWN,
135 CAPABILITY_SUPPORTED,
136 CAPABILITY_UNSUPPORTED})
137 @Retention(RetentionPolicy.SOURCE)
138 public @interface CapabilitySupportType {}
139
140
Anil Admal99349782019-03-19 18:58:42 -0700141 /**
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800142 * Returns an empty GnssCapabilities object.
Sasha Kuznetsov213bb702020-02-14 16:14:39 -0800143 *
144 * @hide
Anil Admal99349782019-03-19 18:58:42 -0700145 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800146 public static GnssCapabilities empty() {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000147 return new GnssCapabilities(/*topFlags=*/ 0, /*isAdrCapabilityKnown=*/ false,
148 /*measurementCorrectionsFlags=*/ 0, /*powerFlags=*/ 0, /*gnssSignalTypes=*/
149 Collections.emptyList());
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800150 }
151
152 private final @TopHalCapabilityFlags int mTopFlags;
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000153 private final boolean mIsAdrCapabilityKnown;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800154 private final @SubHalMeasurementCorrectionsCapabilityFlags int mMeasurementCorrectionsFlags;
155 private final @SubHalPowerCapabilityFlags int mPowerFlags;
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +0000156 private final @NonNull List<GnssSignalType> mGnssSignalTypes;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800157
158 private GnssCapabilities(
159 @TopHalCapabilityFlags int topFlags,
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000160 boolean isAdrCapabilityKnown,
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800161 @SubHalMeasurementCorrectionsCapabilityFlags int measurementCorrectionsFlags,
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +0000162 @SubHalPowerCapabilityFlags int powerFlags,
163 @NonNull List<GnssSignalType> gnssSignalTypes) {
Yu-Han Yange75758a2022-10-28 21:13:25 +0000164 Objects.requireNonNull(gnssSignalTypes);
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800165 mTopFlags = topFlags;
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000166 mIsAdrCapabilityKnown = isAdrCapabilityKnown;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800167 mMeasurementCorrectionsFlags = measurementCorrectionsFlags;
168 mPowerFlags = powerFlags;
Yu-Han Yang0d08d6d2022-11-08 17:38:17 +0000169 mGnssSignalTypes = Collections.unmodifiableList(gnssSignalTypes);
Anil Admal3ba0fa92019-04-19 17:43:00 -0700170 }
171
172 /**
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800173 * Returns a new GnssCapabilities object with top hal values set from the given flags.
Yu-Han Yang8318aba2020-10-19 12:08:09 -0700174 *
175 * @hide
Yu-Han Yang8318aba2020-10-19 12:08:09 -0700176 */
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000177 public GnssCapabilities withTopHalFlags(@TopHalCapabilityFlags int flags,
178 boolean isAdrCapabilityKnown) {
179 if (mTopFlags == flags && mIsAdrCapabilityKnown == isAdrCapabilityKnown) {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800180 return this;
181 } else {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000182 return new GnssCapabilities(flags, isAdrCapabilityKnown,
183 mMeasurementCorrectionsFlags, mPowerFlags, mGnssSignalTypes);
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800184 }
Yu-Han Yang8318aba2020-10-19 12:08:09 -0700185 }
186
187 /**
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800188 * Returns a new GnssCapabilities object with gnss measurement corrections sub hal values set
189 * from the given flags.
190 *
191 * @hide
192 */
193 public GnssCapabilities withSubHalMeasurementCorrectionsFlags(
194 @SubHalMeasurementCorrectionsCapabilityFlags int flags) {
195 if (mMeasurementCorrectionsFlags == flags) {
196 return this;
197 } else {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000198 return new GnssCapabilities(mTopFlags, mIsAdrCapabilityKnown, flags, mPowerFlags,
Yu-Han Yang0d08d6d2022-11-08 17:38:17 +0000199 mGnssSignalTypes);
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800200 }
201 }
202
203 /**
204 * Returns a new GnssCapabilities object with gnss measurement corrections sub hal values set
205 * from the given flags.
206 *
207 * @hide
208 */
209 public GnssCapabilities withSubHalPowerFlags(@SubHalPowerCapabilityFlags int flags) {
210 if (mPowerFlags == flags) {
211 return this;
212 } else {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000213 return new GnssCapabilities(mTopFlags, mIsAdrCapabilityKnown,
214 mMeasurementCorrectionsFlags, flags, mGnssSignalTypes);
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800215 }
216 }
217
218 /**
Yu-Han Yange75758a2022-10-28 21:13:25 +0000219 * Returns a new GnssCapabilities object with a list of GnssSignalType.
220 *
221 * @hide
222 */
223 public GnssCapabilities withSignalTypes(@NonNull List<GnssSignalType> gnssSignalTypes) {
224 Objects.requireNonNull(gnssSignalTypes);
225 if (mGnssSignalTypes.equals(gnssSignalTypes)) {
226 return this;
227 } else {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000228 return new GnssCapabilities(mTopFlags, mIsAdrCapabilityKnown,
229 mMeasurementCorrectionsFlags, mPowerFlags, new ArrayList<>(gnssSignalTypes));
Yu-Han Yange75758a2022-10-28 21:13:25 +0000230 }
231 }
232
233 /**
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800234 * Returns {@code true} if GNSS chipset supports scheduling, {@code false} otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800235 */
236 public boolean hasScheduling() {
237 return (mTopFlags & TOP_HAL_CAPABILITY_SCHEDULING) != 0;
238 }
239
240 /**
241 * Returns {@code true} if GNSS chipset supports Mobile Station Based assistance, {@code false}
Anil Admal3ba0fa92019-04-19 17:43:00 -0700242 * otherwise.
243 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800244 public boolean hasMsb() {
245 return (mTopFlags & TOP_HAL_CAPABILITY_MSB) != 0;
246 }
247
248 /**
249 * Returns {@code true} if GNSS chipset supports Mobile Station Assisted assitance,
250 * {@code false} otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800251 */
252 public boolean hasMsa() {
253 return (mTopFlags & TOP_HAL_CAPABILITY_MSA) != 0;
254 }
255
256 /**
257 * Returns {@code true} if GNSS chipset supports single shot locating, {@code false} otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800258 */
Yu-Han Yangac913962022-10-25 16:49:17 +0000259 public boolean hasSingleShotFix() {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800260 return (mTopFlags & TOP_HAL_CAPABILITY_SINGLE_SHOT) != 0;
261 }
262
263 /**
Neil Fuller8ad07e22022-12-13 14:49:06 +0000264 * Returns {@code true} if GNSS chipset requests periodic time signal injection from the
265 * platform in addition to on-demand and occasional time updates, {@code false} otherwise.
266 *
267 * <p><em>Note: The naming of this capability and the behavior it controls differ substantially.
268 * This is the result of a historic implementation bug, b/73893222.</em>
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800269 */
270 public boolean hasOnDemandTime() {
271 return (mTopFlags & TOP_HAL_CAPABILITY_ON_DEMAND_TIME) != 0;
Anil Admal3ba0fa92019-04-19 17:43:00 -0700272 }
273
274 /**
275 * Returns {@code true} if GNSS chipset supports geofencing, {@code false} otherwise.
276 */
277 public boolean hasGeofencing() {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800278 return (mTopFlags & TOP_HAL_CAPABILITY_GEOFENCING) != 0;
Anil Admal3ba0fa92019-04-19 17:43:00 -0700279 }
280
281 /**
282 * Returns {@code true} if GNSS chipset supports measurements, {@code false} otherwise.
Sasha Kuznetsov213bb702020-02-14 16:14:39 -0800283 *
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800284 * @see LocationManager#registerGnssMeasurementsCallback(Executor, GnssMeasurementsEvent.Callback)
Anil Admal3ba0fa92019-04-19 17:43:00 -0700285 */
286 public boolean hasMeasurements() {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800287 return (mTopFlags & TOP_HAL_CAPABILITY_MEASUREMENTS) != 0;
Anil Admal3ba0fa92019-04-19 17:43:00 -0700288 }
289
290 /**
291 * Returns {@code true} if GNSS chipset supports navigation messages, {@code false} otherwise.
Sasha Kuznetsov213bb702020-02-14 16:14:39 -0800292 *
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800293 * @deprecated Use {@link #hasNavigationMessages()} instead.
294 *
295 * @hide
296 */
297 @Deprecated
298 @SystemApi
299 public boolean hasNavMessages() {
300 return hasNavigationMessages();
301 }
302
303 /**
304 * Returns {@code true} if GNSS chipset supports navigation messages, {@code false} otherwise.
305 *
306 * @see LocationManager#registerGnssNavigationMessageCallback(Executor, GnssNavigationMessage.Callback)
307 */
308 public boolean hasNavigationMessages() {
309 return (mTopFlags & TOP_HAL_CAPABILITY_NAV_MESSAGES) != 0;
310 }
311
312 /**
313 * Returns {@code true} if GNSS chipset supports low power mode, {@code false} otherwise.
314 *
Yu-Han Yang77560592022-10-11 03:49:32 +0000315 * <p>The low power mode is defined in GNSS HAL. When the low power mode is active, the GNSS
316 * hardware must make strong tradeoffs to substantially restrict power use.
Anil Admal3ba0fa92019-04-19 17:43:00 -0700317 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800318 public boolean hasLowPowerMode() {
319 return (mTopFlags & TOP_HAL_CAPABILITY_LOW_POWER_MODE) != 0;
320 }
321
322 /**
323 * Returns {@code true} if GNSS chipset supports satellite blocklists, {@code false} otherwise.
324 *
325 * @deprecated Use {@link #hasSatelliteBlocklist} instead.
326 *
327 * @hide
328 */
329 @SystemApi
330 @Deprecated
331 public boolean hasSatelliteBlacklist() {
332 return (mTopFlags & TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST) != 0;
333 }
334
335 /**
336 * Returns {@code true} if GNSS chipset supports satellite blocklists, {@code false} otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800337 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800338 public boolean hasSatelliteBlocklist() {
339 return (mTopFlags & TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST) != 0;
Anil Admal3ba0fa92019-04-19 17:43:00 -0700340 }
341
342 /**
Joe Huange2562192020-12-19 21:04:23 +0800343 * Returns {@code true} if GNSS chipset supports satellite PVT, {@code false} otherwise.
Joe Huange2562192020-12-19 21:04:23 +0800344 */
Joe Huange2562192020-12-19 21:04:23 +0800345 public boolean hasSatellitePvt() {
346 return (mTopFlags & TOP_HAL_CAPABILITY_SATELLITE_PVT) != 0;
347 }
348
349 /**
Anil Admal3ba0fa92019-04-19 17:43:00 -0700350 * Returns {@code true} if GNSS chipset supports measurement corrections, {@code false}
351 * otherwise.
352 */
353 public boolean hasMeasurementCorrections() {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800354 return (mTopFlags & TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS) != 0;
355 }
356
357 /**
358 * Returns {@code true} if GNSS chipset supports antenna info, {@code false} otherwise.
359 *
360 * @deprecated Use {@link #hasAntennaInfo()} instead.
361 */
362 @Deprecated
363 public boolean hasGnssAntennaInfo() {
364 return hasAntennaInfo();
365 }
366
367 /**
368 * Returns {@code true} if GNSS chipset supports antenna info, {@code false} otherwise.
369 *
370 * @see LocationManager#registerAntennaInfoListener(Executor, GnssAntennaInfo.Listener)
371 */
372 public boolean hasAntennaInfo() {
373 return (mTopFlags & TOP_HAL_CAPABILITY_ANTENNA_INFO) != 0;
Anil Admal3ba0fa92019-04-19 17:43:00 -0700374 }
375
376 /**
Shinru Handaffd222020-12-21 21:11:33 +0800377 * Returns {@code true} if GNSS chipset supports correlation vectors as part of measurements
378 * outputs, {@code false} otherwise.
Shinru Handaffd222020-12-21 21:11:33 +0800379 */
Shinru Handaffd222020-12-21 21:11:33 +0800380 public boolean hasMeasurementCorrelationVectors() {
381 return (mTopFlags & TOP_HAL_CAPABILITY_CORRELATION_VECTOR) != 0;
382 }
383
384 /**
Shinru Han2bd63042021-03-16 17:37:16 +0800385 * Returns {@code true} if GNSS chipset will benefit from measurement corrections for driving
386 * use case if provided, {@code false} otherwise.
Shinru Han2bd63042021-03-16 17:37:16 +0800387 */
Shinru Han2bd63042021-03-16 17:37:16 +0800388 public boolean hasMeasurementCorrectionsForDriving() {
389 return (mTopFlags & TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING) != 0;
390 }
391
392 /**
Yu-Han Yange5aef392023-03-01 22:38:35 +0000393 * Returns {@link #CAPABILITY_SUPPORTED} if GNSS chipset supports accumulated delta
394 * range, {@link #CAPABILITY_UNSUPPORTED} if GNSS chipset does not support accumulated
395 * delta range, and {@link #CAPABILITY_UNKNOWN} if it is unknown, which means GNSS
396 * chipset may or may not support accumulated delta range.
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000397 *
Yu-Han Yang40076ac2022-11-22 22:09:06 +0000398 * <p>The accumulated delta range information can be queried in
399 * {@link android.location.GnssMeasurement#getAccumulatedDeltaRangeState()},
400 * {@link android.location.GnssMeasurement#getAccumulatedDeltaRangeMeters()}, and
401 * {@link android.location.GnssMeasurement#getAccumulatedDeltaRangeUncertaintyMeters()}.
402 */
Yu-Han Yange5aef392023-03-01 22:38:35 +0000403 public @CapabilitySupportType int hasAccumulatedDeltaRange() {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000404 if (!mIsAdrCapabilityKnown) {
Yu-Han Yange5aef392023-03-01 22:38:35 +0000405 return CAPABILITY_UNKNOWN;
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000406 }
Yu-Han Yange5aef392023-03-01 22:38:35 +0000407 if ((mTopFlags & TOP_HAL_CAPABILITY_ACCUMULATED_DELTA_RANGE) != 0) {
408 return CAPABILITY_SUPPORTED;
409 } else {
410 return CAPABILITY_UNSUPPORTED;
411 }
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000412 }
413
414 /**
Anil Admal3ba0fa92019-04-19 17:43:00 -0700415 * Returns {@code true} if GNSS chipset supports line-of-sight satellite identification
416 * measurement corrections, {@code false} otherwise.
417 */
418 public boolean hasMeasurementCorrectionsLosSats() {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800419 return (mMeasurementCorrectionsFlags & SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_LOS_SATS)
420 != 0;
Anil Admal3ba0fa92019-04-19 17:43:00 -0700421 }
422
423 /**
424 * Returns {@code true} if GNSS chipset supports per satellite excess-path-length measurement
425 * corrections, {@code false} otherwise.
426 */
427 public boolean hasMeasurementCorrectionsExcessPathLength() {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800428 return (mMeasurementCorrectionsFlags
429 & SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_EXCESS_PATH_LENGTH) != 0;
Anil Admal3ba0fa92019-04-19 17:43:00 -0700430 }
431
432 /**
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800433 * Returns {@code true} if GNSS chipset supports reflecting plane measurement corrections,
Anil Admal3ba0fa92019-04-19 17:43:00 -0700434 * {@code false} otherwise.
Sasha Kuznetsov213bb702020-02-14 16:14:39 -0800435 *
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800436 * @deprecated Use {@link #hasMeasurementCorrectionsReflectingPlane()} instead.
437 *
Sasha Kuznetsov213bb702020-02-14 16:14:39 -0800438 * @hide
Anil Admal3ba0fa92019-04-19 17:43:00 -0700439 */
Sasha Kuznetsov213bb702020-02-14 16:14:39 -0800440 @SystemApi
Anil Admal3ba0fa92019-04-19 17:43:00 -0700441 public boolean hasMeasurementCorrectionsReflectingPane() {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800442 return hasMeasurementCorrectionsReflectingPlane();
Anil Admal99349782019-03-19 18:58:42 -0700443 }
444
Sasha Kuznetsova68a7a32020-02-11 06:00:10 +0000445 /**
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800446 * Returns {@code true} if GNSS chipset supports reflecting plane measurement corrections,
447 * {@code false} otherwise.
Sasha Kuznetsova68a7a32020-02-11 06:00:10 +0000448 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800449 public boolean hasMeasurementCorrectionsReflectingPlane() {
450 return (mMeasurementCorrectionsFlags
451 & SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_REFLECTING_PLANE) != 0;
Sasha Kuznetsova68a7a32020-02-11 06:00:10 +0000452 }
453
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800454 /**
455 * Returns {@code true} if GNSS chipset supports measuring power totals, {@code false}
456 * otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800457 */
458 public boolean hasPowerTotal() {
459 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_TOTAL) != 0;
460 }
461
462 /**
463 * Returns {@code true} if GNSS chipset supports measuring single-band tracking power,
464 * {@code false} otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800465 */
466 public boolean hasPowerSinglebandTracking() {
467 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_SINGLEBAND_TRACKING) != 0;
468 }
469
470 /**
471 * Returns {@code true} if GNSS chipset supports measuring multi-band tracking power,
472 * {@code false} otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800473 */
474 public boolean hasPowerMultibandTracking() {
475 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_MULTIBAND_TRACKING) != 0;
476 }
477
478 /**
479 * Returns {@code true} if GNSS chipset supports measuring single-band acquisition power,
480 * {@code false} otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800481 */
482 public boolean hasPowerSinglebandAcquisition() {
483 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_SINGLEBAND_ACQUISITION) != 0;
484 }
485
486 /**
487 * Returns {@code true} if GNSS chipset supports measuring multi-band acquisition power,
488 * {@code false} otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800489 */
490 public boolean hasPowerMultibandAcquisition() {
491 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_MULTIBAND_ACQUISITION) != 0;
492 }
493
494 /**
495 * Returns {@code true} if GNSS chipset supports measuring OEM defined mode power, {@code false}
496 * otherwise.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800497 */
498 public boolean hasPowerOtherModes() {
499 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_OTHER_MODES) != 0;
500 }
501
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +0000502 /**
503 * Returns the list of {@link GnssSignalType}s that the GNSS chipset supports.
504 */
505 @NonNull
506 public List<GnssSignalType> getGnssSignalTypes() {
507 return mGnssSignalTypes;
508 }
509
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800510 @Override
511 public boolean equals(Object o) {
512 if (this == o) {
513 return true;
514 }
515 if (!(o instanceof GnssCapabilities)) {
516 return false;
517 }
518
519 GnssCapabilities that = (GnssCapabilities) o;
520 return mTopFlags == that.mTopFlags
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000521 && mIsAdrCapabilityKnown == that.mIsAdrCapabilityKnown
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800522 && mMeasurementCorrectionsFlags == that.mMeasurementCorrectionsFlags
Yu-Han Yange75758a2022-10-28 21:13:25 +0000523 && mPowerFlags == that.mPowerFlags
524 && mGnssSignalTypes.equals(that.mGnssSignalTypes);
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800525 }
526
527 @Override
528 public int hashCode() {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000529 return Objects.hash(mTopFlags, mIsAdrCapabilityKnown, mMeasurementCorrectionsFlags,
530 mPowerFlags, mGnssSignalTypes);
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800531 }
532
533 public static final @NonNull Creator<GnssCapabilities> CREATOR =
534 new Creator<GnssCapabilities>() {
535 @Override
536 public GnssCapabilities createFromParcel(Parcel in) {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000537 return new GnssCapabilities(in.readInt(), in.readBoolean(), in.readInt(),
538 in.readInt(), in.createTypedArrayList(GnssSignalType.CREATOR));
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800539 }
540
541 @Override
542 public GnssCapabilities[] newArray(int size) {
543 return new GnssCapabilities[size];
544 }
545 };
546
547 @Override
548 public int describeContents() {
549 return 0;
550 }
551
552 @Override
553 public void writeToParcel(@NonNull Parcel parcel, int flags) {
554 parcel.writeInt(mTopFlags);
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000555 parcel.writeBoolean(mIsAdrCapabilityKnown);
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800556 parcel.writeInt(mMeasurementCorrectionsFlags);
557 parcel.writeInt(mPowerFlags);
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +0000558 parcel.writeTypedList(mGnssSignalTypes);
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800559 }
560
561 @Override
562 public String toString() {
563 StringBuilder builder = new StringBuilder();
564 builder.append("[");
565 if (hasScheduling()) {
566 builder.append("SCHEDULING ");
567 }
568 if (hasMsb()) {
569 builder.append("MSB ");
570 }
571 if (hasMsa()) {
572 builder.append("MSA ");
573 }
Yu-Han Yangac913962022-10-25 16:49:17 +0000574 if (hasSingleShotFix()) {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800575 builder.append("SINGLE_SHOT ");
576 }
577 if (hasOnDemandTime()) {
578 builder.append("ON_DEMAND_TIME ");
579 }
580 if (hasGeofencing()) {
581 builder.append("GEOFENCING ");
582 }
583 if (hasMeasurementCorrections()) {
584 builder.append("MEASUREMENTS ");
585 }
586 if (hasNavigationMessages()) {
587 builder.append("NAVIGATION_MESSAGES ");
588 }
589 if (hasLowPowerMode()) {
590 builder.append("LOW_POWER_MODE ");
591 }
592 if (hasSatelliteBlocklist()) {
593 builder.append("SATELLITE_BLOCKLIST ");
594 }
Joe Huange2562192020-12-19 21:04:23 +0800595 if (hasSatellitePvt()) {
596 builder.append("SATELLITE_PVT ");
597 }
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800598 if (hasMeasurementCorrections()) {
599 builder.append("MEASUREMENT_CORRECTIONS ");
600 }
601 if (hasAntennaInfo()) {
602 builder.append("ANTENNA_INFO ");
603 }
Shinru Handaffd222020-12-21 21:11:33 +0800604 if (hasMeasurementCorrelationVectors()) {
605 builder.append("MEASUREMENT_CORRELATION_VECTORS ");
606 }
Shinru Han2bd63042021-03-16 17:37:16 +0800607 if (hasMeasurementCorrectionsForDriving()) {
608 builder.append("MEASUREMENT_CORRECTIONS_FOR_DRIVING ");
609 }
Yu-Han Yange5aef392023-03-01 22:38:35 +0000610 if (hasAccumulatedDeltaRange() == CAPABILITY_SUPPORTED) {
Yu-Han Yang40076ac2022-11-22 22:09:06 +0000611 builder.append("ACCUMULATED_DELTA_RANGE ");
Yu-Han Yange5aef392023-03-01 22:38:35 +0000612 } else if (hasAccumulatedDeltaRange() == CAPABILITY_UNKNOWN) {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000613 builder.append("ACCUMULATED_DELTA_RANGE(unknown) ");
Yu-Han Yang40076ac2022-11-22 22:09:06 +0000614 }
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800615 if (hasMeasurementCorrectionsLosSats()) {
616 builder.append("LOS_SATS ");
617 }
618 if (hasMeasurementCorrectionsExcessPathLength()) {
619 builder.append("EXCESS_PATH_LENGTH ");
620 }
621 if (hasMeasurementCorrectionsReflectingPlane()) {
622 builder.append("REFLECTING_PLANE ");
623 }
624 if (hasPowerTotal()) {
625 builder.append("TOTAL_POWER ");
626 }
627 if (hasPowerSinglebandTracking()) {
628 builder.append("SINGLEBAND_TRACKING_POWER ");
629 }
630 if (hasPowerMultibandTracking()) {
631 builder.append("MULTIBAND_TRACKING_POWER ");
632 }
633 if (hasPowerSinglebandAcquisition()) {
634 builder.append("SINGLEBAND_ACQUISITION_POWER ");
635 }
636 if (hasPowerMultibandAcquisition()) {
637 builder.append("MULTIBAND_ACQUISITION_POWER ");
638 }
639 if (hasPowerOtherModes()) {
640 builder.append("OTHER_MODES_POWER ");
641 }
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +0000642 if (!mGnssSignalTypes.isEmpty()) {
643 builder.append("signalTypes=").append(mGnssSignalTypes).append(" ");
644 }
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800645 if (builder.length() > 1) {
646 builder.setLength(builder.length() - 1);
647 } else {
648 builder.append("NONE");
649 }
650 builder.append("]");
651 return builder.toString();
652 }
653
654 /**
655 * Builder for GnssCapabilities.
656 */
657 public static final class Builder {
658
659 private @TopHalCapabilityFlags int mTopFlags;
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000660 private boolean mIsAdrCapabilityKnown;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800661 private @SubHalMeasurementCorrectionsCapabilityFlags int mMeasurementCorrectionsFlags;
662 private @SubHalPowerCapabilityFlags int mPowerFlags;
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +0000663 private @NonNull List<GnssSignalType> mGnssSignalTypes;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800664
665 public Builder() {
666 mTopFlags = 0;
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000667 mIsAdrCapabilityKnown = false;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800668 mMeasurementCorrectionsFlags = 0;
669 mPowerFlags = 0;
Yu-Han Yang0d08d6d2022-11-08 17:38:17 +0000670 mGnssSignalTypes = Collections.emptyList();
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800671 }
672
673 public Builder(@NonNull GnssCapabilities capabilities) {
674 mTopFlags = capabilities.mTopFlags;
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000675 mIsAdrCapabilityKnown = capabilities.mIsAdrCapabilityKnown;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800676 mMeasurementCorrectionsFlags = capabilities.mMeasurementCorrectionsFlags;
677 mPowerFlags = capabilities.mPowerFlags;
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +0000678 mGnssSignalTypes = capabilities.mGnssSignalTypes;
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800679 }
680
681 /**
682 * Sets scheduling capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800683 */
684 public @NonNull Builder setHasScheduling(boolean capable) {
685 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_SCHEDULING, capable);
686 return this;
687 }
688
689 /**
690 * Sets Mobile Station Based capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800691 */
692 public @NonNull Builder setHasMsb(boolean capable) {
693 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MSB, capable);
694 return this;
695 }
696
697 /**
698 * Sets Mobile Station Assisted capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800699 */
700 public @NonNull Builder setHasMsa(boolean capable) {
701 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MSA, capable);
702 return this;
703 }
704
705 /**
706 * Sets single shot locating capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800707 */
Yu-Han Yangac913962022-10-25 16:49:17 +0000708 public @NonNull Builder setHasSingleShotFix(boolean capable) {
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800709 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_SINGLE_SHOT, capable);
710 return this;
711 }
712
713 /**
714 * Sets on demand time capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800715 */
716 public @NonNull Builder setHasOnDemandTime(boolean capable) {
717 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_ON_DEMAND_TIME, capable);
718 return this;
719 }
720
721 /**
722 * Sets geofencing capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800723 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800724 public @NonNull Builder setHasGeofencing(boolean capable) {
725 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_GEOFENCING, capable);
726 return this;
727 }
728
729 /**
730 * Sets measurements capability.
731 */
732 public @NonNull Builder setHasMeasurements(boolean capable) {
733 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MEASUREMENTS, capable);
734 return this;
735 }
736
737 /**
738 * Sets navigation messages capability.
739 */
740 public @NonNull Builder setHasNavigationMessages(boolean capable) {
741 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_NAV_MESSAGES, capable);
742 return this;
743 }
744
745 /**
746 * Sets low power mode capability.
747 *
Yu-Han Yang77560592022-10-11 03:49:32 +0000748 * <p>The low power mode is defined in GNSS HAL. When the low power mode is active, the GNSS
749 * hardware must make strong tradeoffs to substantially restrict power use.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800750 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800751 public @NonNull Builder setHasLowPowerMode(boolean capable) {
752 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_LOW_POWER_MODE, capable);
753 return this;
754 }
755
756 /**
757 * Sets satellite blocklist capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800758 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800759 public @NonNull Builder setHasSatelliteBlocklist(boolean capable) {
760 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST, capable);
761 return this;
762 }
763
764 /**
Joe Huange2562192020-12-19 21:04:23 +0800765 * Sets satellite PVT capability.
Joe Huange2562192020-12-19 21:04:23 +0800766 */
Joe Huange2562192020-12-19 21:04:23 +0800767 public @NonNull Builder setHasSatellitePvt(boolean capable) {
768 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_SATELLITE_PVT, capable);
769 return this;
770 }
771
772 /**
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800773 * Sets measurement corrections capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800774 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800775 public @NonNull Builder setHasMeasurementCorrections(boolean capable) {
776 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS, capable);
777 return this;
778 }
779
780 /**
781 * Sets antenna info capability.
782 */
783 public @NonNull Builder setHasAntennaInfo(boolean capable) {
784 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_ANTENNA_INFO, capable);
785 return this;
786 }
787
788 /**
Shinru Handaffd222020-12-21 21:11:33 +0800789 * Sets correlation vector capability.
Shinru Handaffd222020-12-21 21:11:33 +0800790 */
Shinru Handaffd222020-12-21 21:11:33 +0800791 public @NonNull Builder setHasMeasurementCorrelationVectors(boolean capable) {
792 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_CORRELATION_VECTOR, capable);
793 return this;
794 }
795
796 /**
Shinru Han2bd63042021-03-16 17:37:16 +0800797 * Sets measurement corrections for driving capability.
Shinru Han2bd63042021-03-16 17:37:16 +0800798 */
Shinru Han2bd63042021-03-16 17:37:16 +0800799 public @NonNull Builder setHasMeasurementCorrectionsForDriving(boolean capable) {
800 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING,
801 capable);
802 return this;
803 }
804
805 /**
Yu-Han Yang40076ac2022-11-22 22:09:06 +0000806 * Sets accumulated delta range capability.
807 */
Yu-Han Yange5aef392023-03-01 22:38:35 +0000808 public @NonNull Builder setHasAccumulatedDeltaRange(@CapabilitySupportType int capable) {
809 if (capable == CAPABILITY_UNKNOWN) {
810 mIsAdrCapabilityKnown = false;
811 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_ACCUMULATED_DELTA_RANGE, false);
812 } else if (capable == CAPABILITY_SUPPORTED) {
813 mIsAdrCapabilityKnown = true;
814 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_ACCUMULATED_DELTA_RANGE, true);
815 } else if (capable == CAPABILITY_UNSUPPORTED) {
816 mIsAdrCapabilityKnown = true;
817 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_ACCUMULATED_DELTA_RANGE, false);
818 }
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000819 return this;
820 }
821
822 /**
Yu-Han Yang77560592022-10-11 03:49:32 +0000823 * Sets measurement corrections line-of-sight satellites capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800824 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800825 public @NonNull Builder setHasMeasurementCorrectionsLosSats(boolean capable) {
826 mMeasurementCorrectionsFlags = setFlag(mMeasurementCorrectionsFlags,
827 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_LOS_SATS, capable);
828 return this;
829 }
830
831 /**
Yu-Han Yang77560592022-10-11 03:49:32 +0000832 * Sets measurement corrections excess path length capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800833 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800834 public @NonNull Builder setHasMeasurementCorrectionsExcessPathLength(boolean capable) {
835 mMeasurementCorrectionsFlags = setFlag(mMeasurementCorrectionsFlags,
836 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_EXCESS_PATH_LENGTH, capable);
837 return this;
838 }
839
840 /**
Yu-Han Yang77560592022-10-11 03:49:32 +0000841 * Sets measurement corrections reflecting plane capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800842 */
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800843 public @NonNull Builder setHasMeasurementCorrectionsReflectingPlane(boolean capable) {
844 mMeasurementCorrectionsFlags = setFlag(mMeasurementCorrectionsFlags,
845 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_REFLECTING_PLANE, capable);
846 return this;
847 }
848
849 /**
Yu-Han Yang77560592022-10-11 03:49:32 +0000850 * Sets power totals capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800851 */
852 public @NonNull Builder setHasPowerTotal(boolean capable) {
853 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_TOTAL, capable);
854 return this;
855 }
856
857 /**
Yu-Han Yang77560592022-10-11 03:49:32 +0000858 * Sets power single-band tracking capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800859 */
860 public @NonNull Builder setHasPowerSinglebandTracking(boolean capable) {
861 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_SINGLEBAND_TRACKING,
862 capable);
863 return this;
864 }
865
866 /**
Yu-Han Yang77560592022-10-11 03:49:32 +0000867 * Sets power multi-band tracking capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800868 */
869 public @NonNull Builder setHasPowerMultibandTracking(boolean capable) {
870 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_MULTIBAND_TRACKING,
871 capable);
872 return this;
873 }
874
875 /**
Yu-Han Yang77560592022-10-11 03:49:32 +0000876 * Sets power single-band acquisition capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800877 */
878 public @NonNull Builder setHasPowerSinglebandAcquisition(boolean capable) {
879 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_SINGLEBAND_ACQUISITION,
880 capable);
881 return this;
882 }
883
884 /**
Yu-Han Yang77560592022-10-11 03:49:32 +0000885 * Sets power multi-band acquisition capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800886 */
887 public @NonNull Builder setHasPowerMultibandAcquisition(boolean capable) {
888 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_MULTIBAND_ACQUISITION,
889 capable);
890 return this;
891 }
892
893 /**
Yu-Han Yang77560592022-10-11 03:49:32 +0000894 * Sets OEM-defined power modes capability.
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800895 */
896 public @NonNull Builder setHasPowerOtherModes(boolean capable) {
897 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_OTHER_MODES, capable);
898 return this;
899 }
900
901 /**
Yu-Han Yangd4dea7d2022-10-28 21:13:25 +0000902 * Sets a list of {@link GnssSignalType}.
903 */
904 public @NonNull Builder setGnssSignalTypes(@NonNull List<GnssSignalType> gnssSignalTypes) {
905 mGnssSignalTypes = gnssSignalTypes;
906 return this;
907 }
908
909 /**
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800910 * Builds a new GnssCapabilities.
911 */
912 public @NonNull GnssCapabilities build() {
Yu-Han Yang17d08b82022-12-22 22:26:25 +0000913 return new GnssCapabilities(mTopFlags, mIsAdrCapabilityKnown,
914 mMeasurementCorrectionsFlags, mPowerFlags, new ArrayList<>(mGnssSignalTypes));
Soonil Nagarkara8e676b2020-12-08 18:47:08 -0800915 }
916
917 private static int setFlag(int value, int flag, boolean set) {
918 if (set) {
919 return value | flag;
920 } else {
921 return value & ~flag;
922 }
923 }
Anil Admal99349782019-03-19 18:58:42 -0700924 }
925}