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