GnssStatus.java revision 120480f17ae18bbe8c6fa7ec4854281fdf349b59
1/*
2 * Copyright (C) 2016 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
19/**
20 * This class represents the current state of the GNSS engine.
21 * This class is used in conjunction with the {@link GnssStatusCallback}.
22 */
23public final class GnssStatus {
24    /** Unknown constellation type. */
25    public static final int CONSTELLATION_UNKNOWN = 0;
26    /** Constellation type constant for GPS. */
27    public static final int CONSTELLATION_GPS = 1;
28    /** Constellation type constant for SBAS. */
29    public static final int CONSTELLATION_SBAS = 2;
30    /** Constellation type constant for Glonass. */
31    public static final int CONSTELLATION_GLONASS = 3;
32    /** Constellation type constant for QZSS. */
33    public static final int CONSTELLATION_QZSS = 4;
34    /** Constellation type constant for Beidou. */
35    public static final int CONSTELLATION_BEIDOU = 5;
36    /** Constellation type constant for Galileo. */
37    public static final int CONSTELLATION_GALILEO = 6;
38
39    // these must match the definitions in gps.h
40    /** @hide */
41    public static final int GNSS_SV_FLAGS_NONE = 0;
42    /** @hide */
43    public static final int GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA = (1 << 0);
44    /** @hide */
45    public static final int GNSS_SV_FLAGS_HAS_ALMANAC_DATA = (1 << 1);
46    /** @hide */
47    public static final int GNSS_SV_FLAGS_USED_IN_FIX = (1 << 2);
48
49    /** @hide */
50    public static final int SVID_SHIFT_WIDTH = 7;
51    /** @hide */
52    public static final int CONSTELLATION_TYPE_SHIFT_WIDTH = 3;
53    /** @hide */
54    public static final int CONSTELLATION_TYPE_MASK = 0xf;
55
56    /* These package private values are modified by the LocationManager class */
57    /* package */ int[] mSvidWithFlags;
58    /* package */ float[] mSnrs;
59    /* package */ float[] mElevations;
60    /* package */ float[] mAzimuths;
61    /* package */ int mSvCount;
62
63    GnssStatus(int svCount, int[] svidWithFlags, float[] snrs, float[] elevations,
64            float[] azimuths) {
65        mSvCount = svCount;
66        mSvidWithFlags = svidWithFlags;
67        mSnrs = snrs;
68        mElevations = elevations;
69        mAzimuths = azimuths;
70    }
71
72    /**
73     * Gets the total number of satellites in satellite list.
74     */
75    public int getNumSatellites() {
76        return mSvCount;
77    }
78
79    /**
80     * Retrieves the constellation type of the satellite at the specified position.
81     * @param satIndex the index of the satellite in the list.
82     */
83    public int getConstellationType(int satIndex) {
84        return (mSvidWithFlags[satIndex] >> CONSTELLATION_TYPE_SHIFT_WIDTH)
85                & CONSTELLATION_TYPE_MASK;
86    }
87
88    /**
89     * Retrieves the pseudo-random number of the satellite at the specified position.
90     * @param satIndex the index of the satellite in the list.
91     */
92    public int getSvid(int satIndex) {
93        return mSvidWithFlags[satIndex] >> SVID_SHIFT_WIDTH;
94    }
95
96    /**
97     * Retrieves the signal-noise ration of the satellite at the specified position.
98     * @param satIndex the index of the satellite in the list.
99     */
100    public float getSnr(int satIndex) {
101        return mSnrs[satIndex];
102    }
103
104    /**
105     * Retrieves the elevation of the satellite at the specified position.
106     * @param satIndex the index of the satellite in the list.
107     */
108    public float getElevation(int satIndex) {
109        return 0f;
110    }
111
112    /**
113     * Retrieves the azimuth the satellite at the specified position.
114     * @param satIndex the index of the satellite in the list.
115     */
116    public float getAzimuth(int satIndex) {
117        return mAzimuths[satIndex];
118    }
119
120    /**
121     * Detects whether the satellite at the specified position has ephemeris data.
122     * @param satIndex the index of the satellite in the list.
123     */
124    public boolean hasEphemeris(int satIndex) {
125        return (mSvidWithFlags[satIndex] & GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA) != 0;
126    }
127
128    /**
129     * Detects whether the satellite at the specified position has almanac data.
130     * @param satIndex the index of the satellite in the list.
131     */
132    public boolean hasAlmanac(int satIndex) {
133        return (mSvidWithFlags[satIndex] & GNSS_SV_FLAGS_HAS_ALMANAC_DATA) != 0;
134    }
135
136    /**
137     * Detects whether the satellite at the specified position is used in fix.
138     * @param satIndex the index of the satellite in the list.
139     */
140    public boolean usedInFix(int satIndex) {
141        return (mSvidWithFlags[satIndex] & GNSS_SV_FLAGS_USED_IN_FIX) != 0;
142    }
143}
144