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 */
CellSignalStrength()49     protected CellSignalStrength() {
50     }
51 
52     /** @hide */
setDefaultValues()53     public abstract void setDefaultValues();
54 
55     /**
56      * Retrieve an abstract level value for the overall signal quality.
57      *
58      * @return a single integer from 0 to 4 representing the general signal quality.
59      *     0 represents very poor or unknown signal quality while 4 represents excellent
60      *     signal quality.
61      */
62     @IntRange(from = SIGNAL_STRENGTH_NONE_OR_UNKNOWN, to = SIGNAL_STRENGTH_GREAT)
getLevel()63     public abstract int getLevel();
64 
65     /**
66      * Get the technology-specific signal strength in Arbitrary Strength Units, calculated from the
67      * strength of the pilot signal or equivalent.
68      */
getAsuLevel()69     public abstract int getAsuLevel();
70 
71     /**
72      * Get the technology-specific signal strength in dBm, which is the signal strength of the
73      * pilot signal or equivalent.
74      */
getDbm()75     public abstract int getDbm();
76 
77     /**
78      * Copies the CellSignalStrength.
79      *
80      * @return A deep copy of this class.
81      * @hide
82      */
copy()83     public abstract CellSignalStrength copy();
84 
85     /**
86      * Checks and returns whether there are any non-default values in this CellSignalStrength.
87      *
88      * Checks all the values in the subclass of CellSignalStrength and returns true if any of them
89      * have been set to a value other than their default.
90      *
91      * @hide
92      */
isValid()93     public abstract boolean isValid();
94 
95     @Override
hashCode()96     public abstract int hashCode();
97 
98     @Override
equals(Object o)99     public abstract boolean equals (Object o);
100 
101     /**
102      * Calculate and set the carrier-influenced values such as the signal "Level".
103      *
104      * @hide
105      */
updateLevel(PersistableBundle cc, ServiceState ss)106     public abstract void updateLevel(PersistableBundle cc, ServiceState ss);
107 
108     // Range for RSSI in ASU (0-31, 99) as defined in TS 27.007 8.69
109     /** @hide */
getRssiDbmFromAsu(int asu)110     protected static final int getRssiDbmFromAsu(int asu) {
111         if (asu > 31 || asu < 0) return CellInfo.UNAVAILABLE;
112         return -113 + (2 * asu);
113     }
114 
115     // Range for RSSI in ASU (0-31, 99) as defined in TS 27.007 8.69
116     /** @hide */
getAsuFromRssiDbm(int dbm)117     protected static final int getAsuFromRssiDbm(int dbm) {
118         if (dbm == CellInfo.UNAVAILABLE) return 99;
119         return (dbm + 113) / 2;
120     }
121 
122     // Range for RSCP in ASU (0-96, 255) as defined in TS 27.007 8.69
123     /** @hide */
getRscpDbmFromAsu(int asu)124     protected static final int getRscpDbmFromAsu(int asu) {
125         if (asu > 96 || asu < 0) return CellInfo.UNAVAILABLE;
126         return asu - 120;
127     }
128 
129     // Range for RSCP in ASU (0-96, 255) as defined in TS 27.007 8.69
130     /** @hide */
getAsuFromRscpDbm(int dbm)131     protected static final int getAsuFromRscpDbm(int dbm) {
132         if (dbm == CellInfo.UNAVAILABLE) return 255;
133         return dbm + 120;
134     }
135 
136     // Range for SNR in ASU (0-49, 255) as defined in TS 27.007 8.69
137     /** @hide */
getEcNoDbFromAsu(int asu)138     protected static final int getEcNoDbFromAsu(int asu) {
139         if (asu > 49 || asu < 0) return CellInfo.UNAVAILABLE;
140         return -24 + (asu / 2);
141     }
142 
143     /** @hide */
inRangeOrUnavailable(int value, int rangeMin, int rangeMax)144     protected static final int inRangeOrUnavailable(int value, int rangeMin, int rangeMax) {
145         if (value < rangeMin || value > rangeMax) return CellInfo.UNAVAILABLE;
146         return value;
147     }
148 
149     /** @hide */
inRangeOrUnavailable( int value, int rangeMin, int rangeMax, int special)150     protected static final int inRangeOrUnavailable(
151             int value, int rangeMin, int rangeMax, int special) {
152         if ((value < rangeMin || value > rangeMax) && value != special) return CellInfo.UNAVAILABLE;
153         return value;
154     }
155 
156     /**
157      * Returns the number of signal strength levels.
158      * @return Number of signal strength levels, enforced to be 5
159      *
160      * @hide
161      */
getNumSignalStrengthLevels()162     public static final int getNumSignalStrengthLevels() {
163         return NUM_SIGNAL_STRENGTH_BINS;
164     }
165 }
166