• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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.telephony;
18 
19 import android.annotation.IntRange;
20 import android.os.PersistableBundle;
21 
22 /**
23  * Abstract base class for cell phone signal strength related information.
24  */
25 public abstract class CellSignalStrength {
26 
27     public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN =
28             TelephonyProtoEnums.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; // 0
29 
30     public static final int SIGNAL_STRENGTH_POOR =
31             TelephonyProtoEnums.SIGNAL_STRENGTH_POOR; // 1
32 
33     public static final int SIGNAL_STRENGTH_MODERATE =
34             TelephonyProtoEnums.SIGNAL_STRENGTH_MODERATE; // 2
35 
36     public static final int SIGNAL_STRENGTH_GOOD =
37             TelephonyProtoEnums.SIGNAL_STRENGTH_GOOD; // 3
38 
39     public static final int SIGNAL_STRENGTH_GREAT =
40             TelephonyProtoEnums.SIGNAL_STRENGTH_GREAT; // 4
41 
42     /** @hide */
43     public static final int NUM_SIGNAL_STRENGTH_BINS = 5;
44 
45     /** @hide */
46     protected static final int NUM_SIGNAL_STRENGTH_THRESHOLDS = NUM_SIGNAL_STRENGTH_BINS - 1;
47 
48     /** @hide */
49     public static final String[] SIGNAL_STRENGTH_NAMES = {
50         "none", "poor", "moderate", "good", "great"
51     };
52 
53     /** @hide */
CellSignalStrength()54     protected CellSignalStrength() {
55     }
56 
57     /** @hide */
setDefaultValues()58     public abstract void setDefaultValues();
59 
60     /**
61      * Retrieve an abstract level value for the overall signal quality.
62      *
63      * @return a single integer from 0 to 4 representing the general signal quality.
64      *     0 represents very poor or unknown signal quality while 4 represents excellent
65      *     signal quality.
66      */
67     @IntRange(from = SIGNAL_STRENGTH_NONE_OR_UNKNOWN, to = SIGNAL_STRENGTH_GREAT)
getLevel()68     public abstract int getLevel();
69 
70     /**
71      * Get the technology-specific signal strength in Arbitrary Strength Units, calculated from the
72      * strength of the pilot signal or equivalent.
73      */
getAsuLevel()74     public abstract int getAsuLevel();
75 
76     /**
77      * Get the technology-specific signal strength in dBm, which is the signal strength of the
78      * pilot signal or equivalent.
79      */
getDbm()80     public abstract int getDbm();
81 
82     /**
83      * Copies the CellSignalStrength.
84      *
85      * @return A deep copy of this class.
86      * @hide
87      */
copy()88     public abstract CellSignalStrength copy();
89 
90     /**
91      * Checks and returns whether there are any non-default values in this CellSignalStrength.
92      *
93      * Checks all the values in the subclass of CellSignalStrength and returns true if any of them
94      * have been set to a value other than their default.
95      *
96      * @hide
97      */
isValid()98     public abstract boolean isValid();
99 
100     @Override
hashCode()101     public abstract int hashCode();
102 
103     @Override
equals(Object o)104     public abstract boolean equals (Object o);
105 
106     /**
107      * Calculate and set the carrier-influenced values such as the signal "Level".
108      *
109      * @hide
110      */
updateLevel(PersistableBundle cc, ServiceState ss)111     public abstract void updateLevel(PersistableBundle cc, ServiceState ss);
112 
113     // Range for RSSI in ASU (0-31, 99) as defined in TS 27.007 8.69
114     /** @hide */
getRssiDbmFromAsu(int asu)115     protected static final int getRssiDbmFromAsu(int asu) {
116         if (asu > 31 || asu < 0) return CellInfo.UNAVAILABLE;
117         return -113 + (2 * asu);
118     }
119 
120     // Range for RSSI in ASU (0-31, 99) as defined in TS 27.007 8.69
121     /** @hide */
getAsuFromRssiDbm(int dbm)122     protected static final int getAsuFromRssiDbm(int dbm) {
123         if (dbm == CellInfo.UNAVAILABLE) return 99;
124         return (dbm + 113) / 2;
125     }
126 
127     // Range for RSCP in ASU (0-96, 255) as defined in TS 27.007 8.69
128     /** @hide */
getRscpDbmFromAsu(int asu)129     protected static final int getRscpDbmFromAsu(int asu) {
130         if (asu > 96 || asu < 0) return CellInfo.UNAVAILABLE;
131         return asu - 120;
132     }
133 
134     // Range for RSCP in ASU (0-96, 255) as defined in TS 27.007 8.69
135     /** @hide */
getAsuFromRscpDbm(int dbm)136     protected static final int getAsuFromRscpDbm(int dbm) {
137         if (dbm == CellInfo.UNAVAILABLE) return 255;
138         return dbm + 120;
139     }
140 
141     // Range for SNR in ASU (0-49, 255) as defined in TS 27.007 8.69
142     /** @hide */
getEcNoDbFromAsu(int asu)143     protected static final int getEcNoDbFromAsu(int asu) {
144         if (asu > 49 || asu < 0) return CellInfo.UNAVAILABLE;
145         return -24 + (asu / 2);
146     }
147 
148     /** @hide */
inRangeOrUnavailable(int value, int rangeMin, int rangeMax)149     protected static final int inRangeOrUnavailable(int value, int rangeMin, int rangeMax) {
150         if (value < rangeMin || value > rangeMax) return CellInfo.UNAVAILABLE;
151         return value;
152     }
153 
154     /** @hide */
inRangeOrUnavailable( int value, int rangeMin, int rangeMax, int special)155     protected static final int inRangeOrUnavailable(
156             int value, int rangeMin, int rangeMax, int special) {
157         if ((value < rangeMin || value > rangeMax) && value != special) return CellInfo.UNAVAILABLE;
158         return value;
159     }
160 }
161