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