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