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.SystemApi; 20 21 /** 22 * A container of supported GNSS chipset capabilities. 23 * 24 * @hide 25 */ 26 @SystemApi 27 public final class GnssCapabilities { 28 /** 29 * Bit mask indicating GNSS chipset supports low power mode. 30 * @hide 31 */ 32 public static final long LOW_POWER_MODE = 1L << 0; 33 34 /** 35 * Bit mask indicating GNSS chipset supports blacklisting satellites. 36 * @hide 37 */ 38 public static final long SATELLITE_BLACKLIST = 1L << 1; 39 40 /** 41 * Bit mask indicating GNSS chipset supports geofencing. 42 * @hide 43 */ 44 public static final long GEOFENCING = 1L << 2; 45 46 /** 47 * Bit mask indicating GNSS chipset supports measurements. 48 * @hide 49 */ 50 public static final long MEASUREMENTS = 1L << 3; 51 52 /** 53 * Bit mask indicating GNSS chipset supports navigation messages. 54 * @hide 55 */ 56 public static final long NAV_MESSAGES = 1L << 4; 57 58 /** 59 * Bit mask indicating GNSS chipset supports measurement corrections. 60 * @hide 61 */ 62 public static final long MEASUREMENT_CORRECTIONS = 1L << 5; 63 64 /** 65 * Bit mask indicating GNSS chipset supports line-of-sight satellite identification 66 * measurement corrections. 67 * @hide 68 */ 69 public static final long MEASUREMENT_CORRECTIONS_LOS_SATS = 1L << 6; 70 71 /** 72 * Bit mask indicating GNSS chipset supports per satellite excess-path-length 73 * measurement corrections. 74 * @hide 75 */ 76 public static final long MEASUREMENT_CORRECTIONS_EXCESS_PATH_LENGTH = 1L << 7; 77 78 /** 79 * Bit mask indicating GNSS chipset supports reflecting planes measurement corrections. 80 * @hide 81 */ 82 public static final long MEASUREMENT_CORRECTIONS_REFLECTING_PLANE = 1L << 8; 83 84 /** @hide */ 85 public static final long INVALID_CAPABILITIES = -1; 86 87 /** A bitmask of supported GNSS capabilities. */ 88 private final long mGnssCapabilities; 89 90 /** @hide */ of(long gnssCapabilities)91 public static GnssCapabilities of(long gnssCapabilities) { 92 return new GnssCapabilities(gnssCapabilities); 93 } 94 GnssCapabilities(long gnssCapabilities)95 private GnssCapabilities(long gnssCapabilities) { 96 mGnssCapabilities = gnssCapabilities; 97 } 98 99 /** 100 * Returns {@code true} if GNSS chipset supports low power mode, {@code false} otherwise. 101 */ hasLowPowerMode()102 public boolean hasLowPowerMode() { 103 return hasCapability(LOW_POWER_MODE); 104 } 105 106 /** 107 * Returns {@code true} if GNSS chipset supports blacklisting satellites, {@code false} 108 * otherwise. 109 */ hasSatelliteBlacklist()110 public boolean hasSatelliteBlacklist() { 111 return hasCapability(SATELLITE_BLACKLIST); 112 } 113 114 /** 115 * Returns {@code true} if GNSS chipset supports geofencing, {@code false} otherwise. 116 */ hasGeofencing()117 public boolean hasGeofencing() { 118 return hasCapability(GEOFENCING); 119 } 120 121 /** 122 * Returns {@code true} if GNSS chipset supports measurements, {@code false} otherwise. 123 */ hasMeasurements()124 public boolean hasMeasurements() { 125 return hasCapability(MEASUREMENTS); 126 } 127 128 /** 129 * Returns {@code true} if GNSS chipset supports navigation messages, {@code false} otherwise. 130 */ hasNavMessages()131 public boolean hasNavMessages() { 132 return hasCapability(NAV_MESSAGES); 133 } 134 135 /** 136 * Returns {@code true} if GNSS chipset supports measurement corrections, {@code false} 137 * otherwise. 138 */ hasMeasurementCorrections()139 public boolean hasMeasurementCorrections() { 140 return hasCapability(MEASUREMENT_CORRECTIONS); 141 } 142 143 /** 144 * Returns {@code true} if GNSS chipset supports line-of-sight satellite identification 145 * measurement corrections, {@code false} otherwise. 146 */ hasMeasurementCorrectionsLosSats()147 public boolean hasMeasurementCorrectionsLosSats() { 148 return hasCapability(MEASUREMENT_CORRECTIONS_LOS_SATS); 149 } 150 151 /** 152 * Returns {@code true} if GNSS chipset supports per satellite excess-path-length measurement 153 * corrections, {@code false} otherwise. 154 */ hasMeasurementCorrectionsExcessPathLength()155 public boolean hasMeasurementCorrectionsExcessPathLength() { 156 return hasCapability(MEASUREMENT_CORRECTIONS_EXCESS_PATH_LENGTH); 157 } 158 159 /** 160 * Returns {@code true} if GNSS chipset supports reflecting planes measurement corrections, 161 * {@code false} otherwise. 162 */ hasMeasurementCorrectionsReflectingPane()163 public boolean hasMeasurementCorrectionsReflectingPane() { 164 return hasCapability(MEASUREMENT_CORRECTIONS_REFLECTING_PLANE); 165 } 166 167 @Override toString()168 public String toString() { 169 StringBuilder sb = new StringBuilder("GnssCapabilities: ( "); 170 if (hasLowPowerMode()) sb.append("LOW_POWER_MODE "); 171 if (hasSatelliteBlacklist()) sb.append("SATELLITE_BLACKLIST "); 172 if (hasGeofencing()) sb.append("GEOFENCING "); 173 if (hasMeasurements()) sb.append("MEASUREMENTS "); 174 if (hasNavMessages()) sb.append("NAV_MESSAGES "); 175 if (hasMeasurementCorrections()) sb.append("MEASUREMENT_CORRECTIONS "); 176 if (hasMeasurementCorrectionsLosSats()) sb.append("MEASUREMENT_CORRECTIONS_LOS_SATS "); 177 if (hasMeasurementCorrectionsExcessPathLength()) { 178 sb.append("MEASUREMENT_CORRECTIONS_EXCESS_PATH_LENGTH "); 179 } 180 if (hasMeasurementCorrectionsReflectingPane()) { 181 sb.append("MEASUREMENT_CORRECTIONS_REFLECTING_PLANE "); 182 } 183 sb.append(")"); 184 return sb.toString(); 185 } 186 hasCapability(long capability)187 private boolean hasCapability(long capability) { 188 return (mGnssCapabilities & capability) == capability; 189 } 190 } 191