1 /* 2 * Copyright (C) 2019 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.IntDef; 20 import android.annotation.NonNull; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 import java.util.Arrays; 27 import java.util.Objects; 28 29 /** 30 * Defines the threshold value of the signal strength. 31 * @hide 32 */ 33 public class SignalThresholdInfo implements Parcelable { 34 /** 35 * Received Signal Strength Indication. 36 * Range: -113 dBm and -51 dBm 37 * Used RAN: GERAN, CDMA2000 38 * Reference: 3GPP TS 27.007 section 8.5. 39 */ 40 public static final int SIGNAL_RSSI = 1; 41 42 /** 43 * Received Signal Code Power. 44 * Range: -120 dBm to -25 dBm; 45 * Used RAN: UTRAN 46 * Reference: 3GPP TS 25.123, section 9.1.1.1 47 */ 48 public static final int SIGNAL_RSCP = 2; 49 50 /** 51 * Reference Signal Received Power. 52 * Range: -140 dBm to -44 dBm; 53 * Used RAN: EUTRAN 54 * Reference: 3GPP TS 36.133 9.1.4 55 */ 56 public static final int SIGNAL_RSRP = 3; 57 58 /** 59 * Reference Signal Received Quality 60 * Range: -20 dB to -3 dB; 61 * Used RAN: EUTRAN 62 * Reference: 3GPP TS 36.133 9.1.7 63 */ 64 public static final int SIGNAL_RSRQ = 4; 65 66 /** 67 * Reference Signal Signal to Noise Ratio 68 * Range: -20 dB to 30 dB; 69 * Used RAN: EUTRAN 70 */ 71 public static final int SIGNAL_RSSNR = 5; 72 73 /** 74 * 5G SS reference signal received power. 75 * Range: -140 dBm to -44 dBm. 76 * Used RAN: NGRAN 77 * Reference: 3GPP TS 38.215. 78 */ 79 public static final int SIGNAL_SSRSRP = 6; 80 81 /** 82 * 5G SS reference signal received quality. 83 * Range: -20 dB to -3 dB. 84 * Used RAN: NGRAN 85 * Reference: 3GPP TS 38.215. 86 */ 87 public static final int SIGNAL_SSRSRQ = 7; 88 89 /** 90 * 5G SS signal-to-noise and interference ratio. 91 * Range: -23 dB to 40 dB 92 * Used RAN: NGRAN 93 * Reference: 3GPP TS 38.215 section 5.1.*, 3GPP TS 38.133 section 10.1.16.1. 94 */ 95 public static final int SIGNAL_SSSINR = 8; 96 97 /** @hide */ 98 @IntDef(prefix = { "SIGNAL_" }, value = { 99 SIGNAL_RSSI, 100 SIGNAL_RSCP, 101 SIGNAL_RSRP, 102 SIGNAL_RSRQ, 103 SIGNAL_RSSNR, 104 SIGNAL_SSRSRP, 105 SIGNAL_SSRSRQ, 106 SIGNAL_SSSINR 107 }) 108 @Retention(RetentionPolicy.SOURCE) 109 public @interface SignalMeasurementType {} 110 111 @SignalMeasurementType 112 private int mSignalMeasurement; 113 114 /** 115 * A hysteresis time in milliseconds to prevent flapping. 116 * A value of 0 disables hysteresis 117 */ 118 private int mHysteresisMs; 119 120 /** 121 * An interval in dB defining the required magnitude change between reports. 122 * hysteresisDb must be smaller than the smallest threshold delta. 123 * An interval value of 0 disables hysteresis. 124 */ 125 private int mHysteresisDb; 126 127 /** 128 * List of threshold values. 129 * Range and unit must reference specific SignalMeasurementType 130 * The threshold values for which to apply criteria. 131 * A vector size of 0 disables the use of thresholds for reporting. 132 */ 133 private int[] mThresholds = null; 134 135 /** 136 * {@code true} means modem must trigger the report based on the criteria; 137 * {@code false} means modem must not trigger the report based on the criteria. 138 */ 139 private boolean mIsEnabled = true; 140 141 /** 142 * Indicates the hysteresisMs is disabled. 143 */ 144 public static final int HYSTERESIS_MS_DISABLED = 0; 145 146 /** 147 * Indicates the hysteresisDb is disabled. 148 */ 149 public static final int HYSTERESIS_DB_DISABLED = 0; 150 151 /** 152 * Constructor 153 * 154 * @param signalMeasurement Signal Measurement Type 155 * @param hysteresisMs hysteresisMs 156 * @param hysteresisDb hysteresisDb 157 * @param thresholds threshold value 158 * @param isEnabled isEnabled 159 */ SignalThresholdInfo(@ignalMeasurementType int signalMeasurement, int hysteresisMs, int hysteresisDb, @NonNull int [] thresholds, boolean isEnabled)160 public SignalThresholdInfo(@SignalMeasurementType int signalMeasurement, 161 int hysteresisMs, int hysteresisDb, @NonNull int [] thresholds, boolean isEnabled) { 162 mSignalMeasurement = signalMeasurement; 163 mHysteresisMs = hysteresisMs < 0 ? HYSTERESIS_MS_DISABLED : hysteresisMs; 164 mHysteresisDb = hysteresisDb < 0 ? HYSTERESIS_DB_DISABLED : hysteresisDb; 165 mThresholds = thresholds == null ? null : thresholds.clone(); 166 mIsEnabled = isEnabled; 167 } 168 169 public @SignalMeasurementType int getSignalMeasurement() { 170 return mSignalMeasurement; 171 } 172 173 public int getHysteresisMs() { 174 return mHysteresisMs; 175 } 176 177 public int getHysteresisDb() { 178 return mHysteresisDb; 179 } 180 181 public boolean isEnabled() { 182 return mIsEnabled; 183 } 184 185 public int[] getThresholds() { 186 return mThresholds == null ? null : mThresholds.clone(); 187 } 188 189 @Override 190 public int describeContents() { 191 return 0; 192 } 193 194 @Override 195 public void writeToParcel(Parcel out, int flags) { 196 out.writeInt(mSignalMeasurement); 197 out.writeInt(mHysteresisMs); 198 out.writeInt(mHysteresisDb); 199 out.writeIntArray(mThresholds); 200 out.writeBoolean(mIsEnabled); 201 } 202 203 private SignalThresholdInfo(Parcel in) { 204 mSignalMeasurement = in.readInt(); 205 mHysteresisMs = in.readInt(); 206 mHysteresisDb = in.readInt(); 207 mThresholds = in.createIntArray(); 208 mIsEnabled = in.readBoolean(); 209 } 210 211 @Override 212 public boolean equals(Object o) { 213 if (this == o) return true; 214 215 if (!(o instanceof SignalThresholdInfo)) { 216 return false; 217 } 218 219 SignalThresholdInfo other = (SignalThresholdInfo) o; 220 return mSignalMeasurement == other.mSignalMeasurement 221 && mHysteresisMs == other.mHysteresisMs 222 && mHysteresisDb == other.mHysteresisDb 223 && Arrays.equals(mThresholds, other.mThresholds) 224 && mIsEnabled == other.mIsEnabled; 225 } 226 227 @Override 228 public int hashCode() { 229 return Objects.hash( 230 mSignalMeasurement, mHysteresisMs, mHysteresisDb, mThresholds, mIsEnabled); 231 } 232 233 public static final @NonNull Parcelable.Creator<SignalThresholdInfo> CREATOR = 234 new Parcelable.Creator<SignalThresholdInfo>() { 235 @Override 236 public SignalThresholdInfo createFromParcel(Parcel in) { 237 return new SignalThresholdInfo(in); 238 } 239 240 @Override 241 public SignalThresholdInfo[] newArray(int size) { 242 return new SignalThresholdInfo[size]; 243 } 244 }; 245 246 @Override 247 public String toString() { 248 return new StringBuilder("SignalThresholdInfo{") 249 .append("mSignalMeasurement=").append(mSignalMeasurement) 250 .append("mHysteresisMs=").append(mSignalMeasurement) 251 .append("mHysteresisDb=").append(mHysteresisDb) 252 .append("mThresholds=").append(Arrays.toString(mThresholds)) 253 .append("mIsEnabled=").append(mIsEnabled) 254 .append("}").toString(); 255 } 256 } 257