1 /* 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 17 package android.location; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 import java.util.Objects; 28 import java.util.concurrent.Executor; 29 30 /** 31 * GNSS chipset capabilities. 32 */ 33 public final class GnssCapabilities implements Parcelable { 34 35 // IMPORTANT - must match the Capabilities enum in IGnssCallback.hal 36 /** @hide */ 37 public static final int TOP_HAL_CAPABILITY_SCHEDULING = 1; 38 /** @hide */ 39 public static final int TOP_HAL_CAPABILITY_MSB = 2; 40 /** @hide */ 41 public static final int TOP_HAL_CAPABILITY_MSA = 4; 42 /** @hide */ 43 public static final int TOP_HAL_CAPABILITY_SINGLE_SHOT = 8; 44 /** @hide */ 45 public static final int TOP_HAL_CAPABILITY_ON_DEMAND_TIME = 16; 46 /** @hide */ 47 public static final int TOP_HAL_CAPABILITY_GEOFENCING = 32; 48 /** @hide */ 49 public static final int TOP_HAL_CAPABILITY_MEASUREMENTS = 64; 50 /** @hide */ 51 public static final int TOP_HAL_CAPABILITY_NAV_MESSAGES = 128; 52 /** @hide */ 53 public static final int TOP_HAL_CAPABILITY_LOW_POWER_MODE = 256; 54 /** @hide */ 55 public static final int TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST = 512; 56 /** @hide */ 57 public static final int TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS = 1024; 58 /** @hide */ 59 public static final int TOP_HAL_CAPABILITY_ANTENNA_INFO = 2048; 60 /** @hide */ 61 public static final int TOP_HAL_CAPABILITY_CORRELATION_VECTOR = 4096; 62 /** @hide */ 63 public static final int TOP_HAL_CAPABILITY_SATELLITE_PVT = 8192; 64 /** @hide */ 65 public static final int TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING = 16384; 66 67 /** @hide */ 68 @IntDef(flag = true, prefix = {"TOP_HAL_CAPABILITY_"}, value = {TOP_HAL_CAPABILITY_SCHEDULING, 69 TOP_HAL_CAPABILITY_MSB, TOP_HAL_CAPABILITY_MSA, TOP_HAL_CAPABILITY_SINGLE_SHOT, 70 TOP_HAL_CAPABILITY_ON_DEMAND_TIME, TOP_HAL_CAPABILITY_GEOFENCING, 71 TOP_HAL_CAPABILITY_MEASUREMENTS, TOP_HAL_CAPABILITY_NAV_MESSAGES, 72 TOP_HAL_CAPABILITY_LOW_POWER_MODE, TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST, 73 TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS, TOP_HAL_CAPABILITY_ANTENNA_INFO, 74 TOP_HAL_CAPABILITY_CORRELATION_VECTOR, TOP_HAL_CAPABILITY_SATELLITE_PVT, 75 TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING}) 76 77 @Retention(RetentionPolicy.SOURCE) 78 public @interface TopHalCapabilityFlags {} 79 80 // IMPORTANT - must match the Capabilities enum in IMeasurementCorrectionsCallback.hal 81 /** @hide */ 82 public static final int SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_LOS_SATS = 1; 83 /** @hide */ 84 public static final int SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_EXCESS_PATH_LENGTH = 2; 85 /** @hide */ 86 public static final int SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_REFLECTING_PLANE = 4; 87 88 /** @hide */ 89 @IntDef(flag = true, prefix = {"SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_"}, value = { 90 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_LOS_SATS, 91 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_EXCESS_PATH_LENGTH, 92 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_REFLECTING_PLANE}) 93 @Retention(RetentionPolicy.SOURCE) 94 public @interface SubHalMeasurementCorrectionsCapabilityFlags {} 95 96 // IMPORATANT - must match values in IGnssPowerIndicationCallback.aidl 97 /** @hide */ 98 public static final int SUB_HAL_POWER_CAPABILITY_TOTAL = 1; 99 /** @hide */ 100 public static final int SUB_HAL_POWER_CAPABILITY_SINGLEBAND_TRACKING = 2; 101 /** @hide */ 102 public static final int SUB_HAL_POWER_CAPABILITY_MULTIBAND_TRACKING = 4; 103 /** @hide */ 104 public static final int SUB_HAL_POWER_CAPABILITY_SINGLEBAND_ACQUISITION = 8; 105 /** @hide */ 106 public static final int SUB_HAL_POWER_CAPABILITY_MULTIBAND_ACQUISITION = 16; 107 /** @hide */ 108 public static final int SUB_HAL_POWER_CAPABILITY_OTHER_MODES = 32; 109 110 /** @hide */ 111 @IntDef(flag = true, prefix = {"SUB_HAL_POWER_CAPABILITY_"}, value = { 112 SUB_HAL_POWER_CAPABILITY_TOTAL, SUB_HAL_POWER_CAPABILITY_SINGLEBAND_TRACKING, 113 SUB_HAL_POWER_CAPABILITY_MULTIBAND_TRACKING, 114 SUB_HAL_POWER_CAPABILITY_SINGLEBAND_ACQUISITION, 115 SUB_HAL_POWER_CAPABILITY_MULTIBAND_ACQUISITION, 116 SUB_HAL_POWER_CAPABILITY_OTHER_MODES}) 117 @Retention(RetentionPolicy.SOURCE) 118 public @interface SubHalPowerCapabilityFlags {} 119 120 /** 121 * Returns an empty GnssCapabilities object. 122 * 123 * @hide 124 */ empty()125 public static GnssCapabilities empty() { 126 return new GnssCapabilities(0, 0, 0); 127 } 128 129 private final @TopHalCapabilityFlags int mTopFlags; 130 private final @SubHalMeasurementCorrectionsCapabilityFlags int mMeasurementCorrectionsFlags; 131 private final @SubHalPowerCapabilityFlags int mPowerFlags; 132 GnssCapabilities( @opHalCapabilityFlags int topFlags, @SubHalMeasurementCorrectionsCapabilityFlags int measurementCorrectionsFlags, @SubHalPowerCapabilityFlags int powerFlags)133 private GnssCapabilities( 134 @TopHalCapabilityFlags int topFlags, 135 @SubHalMeasurementCorrectionsCapabilityFlags int measurementCorrectionsFlags, 136 @SubHalPowerCapabilityFlags int powerFlags) { 137 mTopFlags = topFlags; 138 mMeasurementCorrectionsFlags = measurementCorrectionsFlags; 139 mPowerFlags = powerFlags; 140 } 141 142 /** 143 * Returns a new GnssCapabilities object with top hal values set from the given flags. 144 * 145 * @hide 146 */ withTopHalFlags(@opHalCapabilityFlags int flags)147 public GnssCapabilities withTopHalFlags(@TopHalCapabilityFlags int flags) { 148 if (mTopFlags == flags) { 149 return this; 150 } else { 151 return new GnssCapabilities(flags, mMeasurementCorrectionsFlags, mPowerFlags); 152 } 153 } 154 155 /** 156 * Returns a new GnssCapabilities object with gnss measurement corrections sub hal values set 157 * from the given flags. 158 * 159 * @hide 160 */ withSubHalMeasurementCorrectionsFlags( @ubHalMeasurementCorrectionsCapabilityFlags int flags)161 public GnssCapabilities withSubHalMeasurementCorrectionsFlags( 162 @SubHalMeasurementCorrectionsCapabilityFlags int flags) { 163 if (mMeasurementCorrectionsFlags == flags) { 164 return this; 165 } else { 166 return new GnssCapabilities(mTopFlags, flags, mPowerFlags); 167 } 168 } 169 170 /** 171 * Returns a new GnssCapabilities object with gnss measurement corrections sub hal values set 172 * from the given flags. 173 * 174 * @hide 175 */ withSubHalPowerFlags(@ubHalPowerCapabilityFlags int flags)176 public GnssCapabilities withSubHalPowerFlags(@SubHalPowerCapabilityFlags int flags) { 177 if (mPowerFlags == flags) { 178 return this; 179 } else { 180 return new GnssCapabilities(mTopFlags, mMeasurementCorrectionsFlags, flags); 181 } 182 } 183 184 /** 185 * Returns {@code true} if GNSS chipset supports scheduling, {@code false} otherwise. 186 * 187 * @hide 188 */ hasScheduling()189 public boolean hasScheduling() { 190 return (mTopFlags & TOP_HAL_CAPABILITY_SCHEDULING) != 0; 191 } 192 193 /** 194 * Returns {@code true} if GNSS chipset supports Mobile Station Based assistance, {@code false} 195 * otherwise. 196 * 197 * @hide 198 */ hasMsb()199 public boolean hasMsb() { 200 return (mTopFlags & TOP_HAL_CAPABILITY_MSB) != 0; 201 } 202 203 /** 204 * Returns {@code true} if GNSS chipset supports Mobile Station Assisted assitance, 205 * {@code false} otherwise. 206 * 207 * @hide 208 */ hasMsa()209 public boolean hasMsa() { 210 return (mTopFlags & TOP_HAL_CAPABILITY_MSA) != 0; 211 } 212 213 /** 214 * Returns {@code true} if GNSS chipset supports single shot locating, {@code false} otherwise. 215 * 216 * @hide 217 */ hasSingleShot()218 public boolean hasSingleShot() { 219 return (mTopFlags & TOP_HAL_CAPABILITY_SINGLE_SHOT) != 0; 220 } 221 222 /** 223 * Returns {@code true} if GNSS chipset supports on demand time, {@code false} otherwise. 224 * 225 * @hide 226 */ hasOnDemandTime()227 public boolean hasOnDemandTime() { 228 return (mTopFlags & TOP_HAL_CAPABILITY_ON_DEMAND_TIME) != 0; 229 } 230 231 /** 232 * Returns {@code true} if GNSS chipset supports geofencing, {@code false} otherwise. 233 * 234 * @hide 235 */ 236 @SystemApi hasGeofencing()237 public boolean hasGeofencing() { 238 return (mTopFlags & TOP_HAL_CAPABILITY_GEOFENCING) != 0; 239 } 240 241 /** 242 * Returns {@code true} if GNSS chipset supports measurements, {@code false} otherwise. 243 * 244 * @see LocationManager#registerGnssMeasurementsCallback(Executor, GnssMeasurementsEvent.Callback) 245 */ hasMeasurements()246 public boolean hasMeasurements() { 247 return (mTopFlags & TOP_HAL_CAPABILITY_MEASUREMENTS) != 0; 248 } 249 250 /** 251 * Returns {@code true} if GNSS chipset supports navigation messages, {@code false} otherwise. 252 * 253 * @deprecated Use {@link #hasNavigationMessages()} instead. 254 * 255 * @hide 256 */ 257 @Deprecated 258 @SystemApi hasNavMessages()259 public boolean hasNavMessages() { 260 return hasNavigationMessages(); 261 } 262 263 /** 264 * Returns {@code true} if GNSS chipset supports navigation messages, {@code false} otherwise. 265 * 266 * @see LocationManager#registerGnssNavigationMessageCallback(Executor, GnssNavigationMessage.Callback) 267 */ hasNavigationMessages()268 public boolean hasNavigationMessages() { 269 return (mTopFlags & TOP_HAL_CAPABILITY_NAV_MESSAGES) != 0; 270 } 271 272 /** 273 * Returns {@code true} if GNSS chipset supports low power mode, {@code false} otherwise. 274 * 275 * @hide 276 */ 277 @SystemApi hasLowPowerMode()278 public boolean hasLowPowerMode() { 279 return (mTopFlags & TOP_HAL_CAPABILITY_LOW_POWER_MODE) != 0; 280 } 281 282 /** 283 * Returns {@code true} if GNSS chipset supports satellite blocklists, {@code false} otherwise. 284 * 285 * @deprecated Use {@link #hasSatelliteBlocklist} instead. 286 * 287 * @hide 288 */ 289 @SystemApi 290 @Deprecated hasSatelliteBlacklist()291 public boolean hasSatelliteBlacklist() { 292 return (mTopFlags & TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST) != 0; 293 } 294 295 /** 296 * Returns {@code true} if GNSS chipset supports satellite blocklists, {@code false} otherwise. 297 * 298 * @hide 299 */ 300 @SystemApi hasSatelliteBlocklist()301 public boolean hasSatelliteBlocklist() { 302 return (mTopFlags & TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST) != 0; 303 } 304 305 /** 306 * Returns {@code true} if GNSS chipset supports satellite PVT, {@code false} otherwise. 307 * 308 * @hide 309 */ 310 @SystemApi hasSatellitePvt()311 public boolean hasSatellitePvt() { 312 return (mTopFlags & TOP_HAL_CAPABILITY_SATELLITE_PVT) != 0; 313 } 314 315 /** 316 * Returns {@code true} if GNSS chipset supports measurement corrections, {@code false} 317 * otherwise. 318 * 319 * @hide 320 */ 321 @SystemApi hasMeasurementCorrections()322 public boolean hasMeasurementCorrections() { 323 return (mTopFlags & TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS) != 0; 324 } 325 326 /** 327 * Returns {@code true} if GNSS chipset supports antenna info, {@code false} otherwise. 328 * 329 * @deprecated Use {@link #hasAntennaInfo()} instead. 330 */ 331 @Deprecated hasGnssAntennaInfo()332 public boolean hasGnssAntennaInfo() { 333 return hasAntennaInfo(); 334 } 335 336 /** 337 * Returns {@code true} if GNSS chipset supports antenna info, {@code false} otherwise. 338 * 339 * @see LocationManager#registerAntennaInfoListener(Executor, GnssAntennaInfo.Listener) 340 */ hasAntennaInfo()341 public boolean hasAntennaInfo() { 342 return (mTopFlags & TOP_HAL_CAPABILITY_ANTENNA_INFO) != 0; 343 } 344 345 /** 346 * Returns {@code true} if GNSS chipset supports correlation vectors as part of measurements 347 * outputs, {@code false} otherwise. 348 * 349 * @hide 350 */ 351 @SystemApi hasMeasurementCorrelationVectors()352 public boolean hasMeasurementCorrelationVectors() { 353 return (mTopFlags & TOP_HAL_CAPABILITY_CORRELATION_VECTOR) != 0; 354 } 355 356 /** 357 * Returns {@code true} if GNSS chipset will benefit from measurement corrections for driving 358 * use case if provided, {@code false} otherwise. 359 * 360 * @hide 361 */ 362 @SystemApi hasMeasurementCorrectionsForDriving()363 public boolean hasMeasurementCorrectionsForDriving() { 364 return (mTopFlags & TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING) != 0; 365 } 366 367 /** 368 * Returns {@code true} if GNSS chipset supports line-of-sight satellite identification 369 * measurement corrections, {@code false} otherwise. 370 * 371 * @hide 372 */ 373 @SystemApi hasMeasurementCorrectionsLosSats()374 public boolean hasMeasurementCorrectionsLosSats() { 375 return (mMeasurementCorrectionsFlags & SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_LOS_SATS) 376 != 0; 377 } 378 379 /** 380 * Returns {@code true} if GNSS chipset supports per satellite excess-path-length measurement 381 * corrections, {@code false} otherwise. 382 * 383 * @hide 384 */ 385 @SystemApi hasMeasurementCorrectionsExcessPathLength()386 public boolean hasMeasurementCorrectionsExcessPathLength() { 387 return (mMeasurementCorrectionsFlags 388 & SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_EXCESS_PATH_LENGTH) != 0; 389 } 390 391 /** 392 * Returns {@code true} if GNSS chipset supports reflecting plane measurement corrections, 393 * {@code false} otherwise. 394 * 395 * @deprecated Use {@link #hasMeasurementCorrectionsReflectingPlane()} instead. 396 * 397 * @hide 398 */ 399 @SystemApi hasMeasurementCorrectionsReflectingPane()400 public boolean hasMeasurementCorrectionsReflectingPane() { 401 return hasMeasurementCorrectionsReflectingPlane(); 402 } 403 404 /** 405 * Returns {@code true} if GNSS chipset supports reflecting plane measurement corrections, 406 * {@code false} otherwise. 407 * 408 * @hide 409 */ 410 @SystemApi hasMeasurementCorrectionsReflectingPlane()411 public boolean hasMeasurementCorrectionsReflectingPlane() { 412 return (mMeasurementCorrectionsFlags 413 & SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_REFLECTING_PLANE) != 0; 414 } 415 416 /** 417 * Returns {@code true} if GNSS chipset supports measuring power totals, {@code false} 418 * otherwise. 419 * 420 * @hide 421 */ hasPowerTotal()422 public boolean hasPowerTotal() { 423 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_TOTAL) != 0; 424 } 425 426 /** 427 * Returns {@code true} if GNSS chipset supports measuring single-band tracking power, 428 * {@code false} otherwise. 429 * 430 * @hide 431 */ hasPowerSinglebandTracking()432 public boolean hasPowerSinglebandTracking() { 433 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_SINGLEBAND_TRACKING) != 0; 434 } 435 436 /** 437 * Returns {@code true} if GNSS chipset supports measuring multi-band tracking power, 438 * {@code false} otherwise. 439 * 440 * @hide 441 */ hasPowerMultibandTracking()442 public boolean hasPowerMultibandTracking() { 443 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_MULTIBAND_TRACKING) != 0; 444 } 445 446 /** 447 * Returns {@code true} if GNSS chipset supports measuring single-band acquisition power, 448 * {@code false} otherwise. 449 * 450 * @hide 451 */ hasPowerSinglebandAcquisition()452 public boolean hasPowerSinglebandAcquisition() { 453 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_SINGLEBAND_ACQUISITION) != 0; 454 } 455 456 /** 457 * Returns {@code true} if GNSS chipset supports measuring multi-band acquisition power, 458 * {@code false} otherwise. 459 * 460 * @hide 461 */ hasPowerMultibandAcquisition()462 public boolean hasPowerMultibandAcquisition() { 463 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_MULTIBAND_ACQUISITION) != 0; 464 } 465 466 /** 467 * Returns {@code true} if GNSS chipset supports measuring OEM defined mode power, {@code false} 468 * otherwise. 469 * 470 * @hide 471 */ hasPowerOtherModes()472 public boolean hasPowerOtherModes() { 473 return (mPowerFlags & SUB_HAL_POWER_CAPABILITY_OTHER_MODES) != 0; 474 } 475 476 @Override equals(Object o)477 public boolean equals(Object o) { 478 if (this == o) { 479 return true; 480 } 481 if (!(o instanceof GnssCapabilities)) { 482 return false; 483 } 484 485 GnssCapabilities that = (GnssCapabilities) o; 486 return mTopFlags == that.mTopFlags 487 && mMeasurementCorrectionsFlags == that.mMeasurementCorrectionsFlags 488 && mPowerFlags == that.mPowerFlags; 489 } 490 491 @Override hashCode()492 public int hashCode() { 493 return Objects.hash(mTopFlags, mMeasurementCorrectionsFlags, mPowerFlags); 494 } 495 496 public static final @NonNull Creator<GnssCapabilities> CREATOR = 497 new Creator<GnssCapabilities>() { 498 @Override 499 public GnssCapabilities createFromParcel(Parcel in) { 500 return new GnssCapabilities(in.readInt(), in.readInt(), in.readInt()); 501 } 502 503 @Override 504 public GnssCapabilities[] newArray(int size) { 505 return new GnssCapabilities[size]; 506 } 507 }; 508 509 @Override describeContents()510 public int describeContents() { 511 return 0; 512 } 513 514 @Override writeToParcel(@onNull Parcel parcel, int flags)515 public void writeToParcel(@NonNull Parcel parcel, int flags) { 516 parcel.writeInt(mTopFlags); 517 parcel.writeInt(mMeasurementCorrectionsFlags); 518 parcel.writeInt(mPowerFlags); 519 } 520 521 @Override toString()522 public String toString() { 523 StringBuilder builder = new StringBuilder(); 524 builder.append("["); 525 if (hasScheduling()) { 526 builder.append("SCHEDULING "); 527 } 528 if (hasMsb()) { 529 builder.append("MSB "); 530 } 531 if (hasMsa()) { 532 builder.append("MSA "); 533 } 534 if (hasSingleShot()) { 535 builder.append("SINGLE_SHOT "); 536 } 537 if (hasOnDemandTime()) { 538 builder.append("ON_DEMAND_TIME "); 539 } 540 if (hasGeofencing()) { 541 builder.append("GEOFENCING "); 542 } 543 if (hasMeasurementCorrections()) { 544 builder.append("MEASUREMENTS "); 545 } 546 if (hasNavigationMessages()) { 547 builder.append("NAVIGATION_MESSAGES "); 548 } 549 if (hasLowPowerMode()) { 550 builder.append("LOW_POWER_MODE "); 551 } 552 if (hasSatelliteBlocklist()) { 553 builder.append("SATELLITE_BLOCKLIST "); 554 } 555 if (hasSatellitePvt()) { 556 builder.append("SATELLITE_PVT "); 557 } 558 if (hasMeasurementCorrections()) { 559 builder.append("MEASUREMENT_CORRECTIONS "); 560 } 561 if (hasAntennaInfo()) { 562 builder.append("ANTENNA_INFO "); 563 } 564 if (hasMeasurementCorrelationVectors()) { 565 builder.append("MEASUREMENT_CORRELATION_VECTORS "); 566 } 567 if (hasMeasurementCorrectionsForDriving()) { 568 builder.append("MEASUREMENT_CORRECTIONS_FOR_DRIVING "); 569 } 570 if (hasMeasurementCorrectionsLosSats()) { 571 builder.append("LOS_SATS "); 572 } 573 if (hasMeasurementCorrectionsExcessPathLength()) { 574 builder.append("EXCESS_PATH_LENGTH "); 575 } 576 if (hasMeasurementCorrectionsReflectingPlane()) { 577 builder.append("REFLECTING_PLANE "); 578 } 579 if (hasPowerTotal()) { 580 builder.append("TOTAL_POWER "); 581 } 582 if (hasPowerSinglebandTracking()) { 583 builder.append("SINGLEBAND_TRACKING_POWER "); 584 } 585 if (hasPowerMultibandTracking()) { 586 builder.append("MULTIBAND_TRACKING_POWER "); 587 } 588 if (hasPowerSinglebandAcquisition()) { 589 builder.append("SINGLEBAND_ACQUISITION_POWER "); 590 } 591 if (hasPowerMultibandAcquisition()) { 592 builder.append("MULTIBAND_ACQUISITION_POWER "); 593 } 594 if (hasPowerOtherModes()) { 595 builder.append("OTHER_MODES_POWER "); 596 } 597 if (builder.length() > 1) { 598 builder.setLength(builder.length() - 1); 599 } else { 600 builder.append("NONE"); 601 } 602 builder.append("]"); 603 return builder.toString(); 604 } 605 606 /** 607 * Builder for GnssCapabilities. 608 */ 609 public static final class Builder { 610 611 private @TopHalCapabilityFlags int mTopFlags; 612 private @SubHalMeasurementCorrectionsCapabilityFlags int mMeasurementCorrectionsFlags; 613 private @SubHalPowerCapabilityFlags int mPowerFlags; 614 Builder()615 public Builder() { 616 mTopFlags = 0; 617 mMeasurementCorrectionsFlags = 0; 618 mPowerFlags = 0; 619 } 620 Builder(@onNull GnssCapabilities capabilities)621 public Builder(@NonNull GnssCapabilities capabilities) { 622 mTopFlags = capabilities.mTopFlags; 623 mMeasurementCorrectionsFlags = capabilities.mMeasurementCorrectionsFlags; 624 mPowerFlags = capabilities.mPowerFlags; 625 } 626 627 /** 628 * Sets scheduling capability. 629 * 630 * @hide 631 */ setHasScheduling(boolean capable)632 public @NonNull Builder setHasScheduling(boolean capable) { 633 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_SCHEDULING, capable); 634 return this; 635 } 636 637 /** 638 * Sets Mobile Station Based capability. 639 * 640 * @hide 641 */ setHasMsb(boolean capable)642 public @NonNull Builder setHasMsb(boolean capable) { 643 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MSB, capable); 644 return this; 645 } 646 647 /** 648 * Sets Mobile Station Assisted capability. 649 * 650 * @hide 651 */ setHasMsa(boolean capable)652 public @NonNull Builder setHasMsa(boolean capable) { 653 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MSA, capable); 654 return this; 655 } 656 657 /** 658 * Sets single shot locating capability. 659 * 660 * @hide 661 */ setHasSingleShot(boolean capable)662 public @NonNull Builder setHasSingleShot(boolean capable) { 663 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_SINGLE_SHOT, capable); 664 return this; 665 } 666 667 /** 668 * Sets on demand time capability. 669 * 670 * @hide 671 */ setHasOnDemandTime(boolean capable)672 public @NonNull Builder setHasOnDemandTime(boolean capable) { 673 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_ON_DEMAND_TIME, capable); 674 return this; 675 } 676 677 /** 678 * Sets geofencing capability. 679 * 680 * @hide 681 */ 682 @SystemApi setHasGeofencing(boolean capable)683 public @NonNull Builder setHasGeofencing(boolean capable) { 684 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_GEOFENCING, capable); 685 return this; 686 } 687 688 /** 689 * Sets measurements capability. 690 */ setHasMeasurements(boolean capable)691 public @NonNull Builder setHasMeasurements(boolean capable) { 692 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MEASUREMENTS, capable); 693 return this; 694 } 695 696 /** 697 * Sets navigation messages capability. 698 */ setHasNavigationMessages(boolean capable)699 public @NonNull Builder setHasNavigationMessages(boolean capable) { 700 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_NAV_MESSAGES, capable); 701 return this; 702 } 703 704 /** 705 * Sets low power mode capability. 706 * 707 * @hide 708 */ 709 @SystemApi setHasLowPowerMode(boolean capable)710 public @NonNull Builder setHasLowPowerMode(boolean capable) { 711 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_LOW_POWER_MODE, capable); 712 return this; 713 } 714 715 /** 716 * Sets satellite blocklist capability. 717 * 718 * @hide 719 */ 720 @SystemApi setHasSatelliteBlocklist(boolean capable)721 public @NonNull Builder setHasSatelliteBlocklist(boolean capable) { 722 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_SATELLITE_BLOCKLIST, capable); 723 return this; 724 } 725 726 /** 727 * Sets satellite PVT capability. 728 * 729 * @hide 730 */ 731 @SystemApi setHasSatellitePvt(boolean capable)732 public @NonNull Builder setHasSatellitePvt(boolean capable) { 733 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_SATELLITE_PVT, capable); 734 return this; 735 } 736 737 /** 738 * Sets measurement corrections capability. 739 * 740 * @hide 741 */ 742 @SystemApi setHasMeasurementCorrections(boolean capable)743 public @NonNull Builder setHasMeasurementCorrections(boolean capable) { 744 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS, capable); 745 return this; 746 } 747 748 /** 749 * Sets antenna info capability. 750 */ setHasAntennaInfo(boolean capable)751 public @NonNull Builder setHasAntennaInfo(boolean capable) { 752 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_ANTENNA_INFO, capable); 753 return this; 754 } 755 756 /** 757 * Sets correlation vector capability. 758 * 759 * @hide 760 */ 761 @SystemApi setHasMeasurementCorrelationVectors(boolean capable)762 public @NonNull Builder setHasMeasurementCorrelationVectors(boolean capable) { 763 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_CORRELATION_VECTOR, capable); 764 return this; 765 } 766 767 /** 768 * Sets measurement corrections for driving capability. 769 * 770 * @hide 771 */ 772 @SystemApi setHasMeasurementCorrectionsForDriving(boolean capable)773 public @NonNull Builder setHasMeasurementCorrectionsForDriving(boolean capable) { 774 mTopFlags = setFlag(mTopFlags, TOP_HAL_CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING, 775 capable); 776 return this; 777 } 778 779 /** 780 * Sets measurement corrections line-of-sight satellites capabilitity. 781 * 782 * @hide 783 */ 784 @SystemApi setHasMeasurementCorrectionsLosSats(boolean capable)785 public @NonNull Builder setHasMeasurementCorrectionsLosSats(boolean capable) { 786 mMeasurementCorrectionsFlags = setFlag(mMeasurementCorrectionsFlags, 787 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_LOS_SATS, capable); 788 return this; 789 } 790 791 /** 792 * Sets measurement corrections excess path length capabilitity. 793 * 794 * @hide 795 */ 796 @SystemApi setHasMeasurementCorrectionsExcessPathLength(boolean capable)797 public @NonNull Builder setHasMeasurementCorrectionsExcessPathLength(boolean capable) { 798 mMeasurementCorrectionsFlags = setFlag(mMeasurementCorrectionsFlags, 799 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_EXCESS_PATH_LENGTH, capable); 800 return this; 801 } 802 803 /** 804 * Sets measurement corrections reflecting plane capabilitity. 805 * 806 * @hide 807 */ 808 @SystemApi setHasMeasurementCorrectionsReflectingPlane(boolean capable)809 public @NonNull Builder setHasMeasurementCorrectionsReflectingPlane(boolean capable) { 810 mMeasurementCorrectionsFlags = setFlag(mMeasurementCorrectionsFlags, 811 SUB_HAL_MEASUREMENT_CORRECTIONS_CAPABILITY_REFLECTING_PLANE, capable); 812 return this; 813 } 814 815 /** 816 * Sets power totals capabilitity. 817 * 818 * @hide 819 */ setHasPowerTotal(boolean capable)820 public @NonNull Builder setHasPowerTotal(boolean capable) { 821 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_TOTAL, capable); 822 return this; 823 } 824 825 /** 826 * Sets power single-band tracking capabilitity. 827 * 828 * @hide 829 */ setHasPowerSinglebandTracking(boolean capable)830 public @NonNull Builder setHasPowerSinglebandTracking(boolean capable) { 831 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_SINGLEBAND_TRACKING, 832 capable); 833 return this; 834 } 835 836 /** 837 * Sets power multi-band tracking capabilitity. 838 * 839 * @hide 840 */ setHasPowerMultibandTracking(boolean capable)841 public @NonNull Builder setHasPowerMultibandTracking(boolean capable) { 842 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_MULTIBAND_TRACKING, 843 capable); 844 return this; 845 } 846 847 /** 848 * Sets power single-band acquisition capabilitity. 849 * 850 * @hide 851 */ setHasPowerSinglebandAcquisition(boolean capable)852 public @NonNull Builder setHasPowerSinglebandAcquisition(boolean capable) { 853 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_SINGLEBAND_ACQUISITION, 854 capable); 855 return this; 856 } 857 858 /** 859 * Sets power multi-band acquisition capabilitity. 860 * 861 * @hide 862 */ setHasPowerMultibandAcquisition(boolean capable)863 public @NonNull Builder setHasPowerMultibandAcquisition(boolean capable) { 864 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_MULTIBAND_ACQUISITION, 865 capable); 866 return this; 867 } 868 869 /** 870 * Sets power other modes capabilitity. 871 * 872 * @hide 873 */ setHasPowerOtherModes(boolean capable)874 public @NonNull Builder setHasPowerOtherModes(boolean capable) { 875 mPowerFlags = setFlag(mPowerFlags, SUB_HAL_POWER_CAPABILITY_OTHER_MODES, capable); 876 return this; 877 } 878 879 /** 880 * Builds a new GnssCapabilities. 881 */ build()882 public @NonNull GnssCapabilities build() { 883 return new GnssCapabilities(mTopFlags, mMeasurementCorrectionsFlags, mPowerFlags); 884 } 885 setFlag(int value, int flag, boolean set)886 private static int setFlag(int value, int flag, boolean set) { 887 if (set) { 888 return value | flag; 889 } else { 890 return value & ~flag; 891 } 892 } 893 } 894 } 895