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.net.wifi; 18 19 import android.annotation.IntDef; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import android.telephony.Annotation.NetworkType; 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 28 /** 29 * This class makes a subset of 30 * com.android.server.wifi.nano.WifiMetricsProto.WifiUsabilityStatsEntry parcelable. 31 * 32 * @hide 33 */ 34 @SystemApi 35 public final class WifiUsabilityStatsEntry implements Parcelable { 36 /** {@hide} */ 37 @Retention(RetentionPolicy.SOURCE) 38 @IntDef(prefix = {"PROBE_STATUS_"}, value = { 39 PROBE_STATUS_UNKNOWN, 40 PROBE_STATUS_NO_PROBE, 41 PROBE_STATUS_SUCCESS, 42 PROBE_STATUS_FAILURE}) 43 public @interface ProbeStatus {} 44 45 /** Link probe status is unknown */ 46 public static final int PROBE_STATUS_UNKNOWN = 0; 47 /** Link probe is not triggered */ 48 public static final int PROBE_STATUS_NO_PROBE = 1; 49 /** Link probe is triggered and the result is success */ 50 public static final int PROBE_STATUS_SUCCESS = 2; 51 /** Link probe is triggered and the result is failure */ 52 public static final int PROBE_STATUS_FAILURE = 3; 53 54 /** Absolute milliseconds from device boot when these stats were sampled */ 55 private final long mTimeStampMillis; 56 /** The RSSI (in dBm) at the sample time */ 57 private final int mRssi; 58 /** Link speed at the sample time in Mbps */ 59 private final int mLinkSpeedMbps; 60 /** The total number of tx success counted from the last radio chip reset */ 61 private final long mTotalTxSuccess; 62 /** The total number of MPDU data packet retries counted from the last radio chip reset */ 63 private final long mTotalTxRetries; 64 /** The total number of tx bad counted from the last radio chip reset */ 65 private final long mTotalTxBad; 66 /** The total number of rx success counted from the last radio chip reset */ 67 private final long mTotalRxSuccess; 68 /** The total time the wifi radio is on in ms counted from the last radio chip reset */ 69 private final long mTotalRadioOnTimeMillis; 70 /** The total time the wifi radio is doing tx in ms counted from the last radio chip reset */ 71 private final long mTotalRadioTxTimeMillis; 72 /** The total time the wifi radio is doing rx in ms counted from the last radio chip reset */ 73 private final long mTotalRadioRxTimeMillis; 74 /** The total time spent on all types of scans in ms counted from the last radio chip reset */ 75 private final long mTotalScanTimeMillis; 76 /** The total time spent on nan scans in ms counted from the last radio chip reset */ 77 private final long mTotalNanScanTimeMillis; 78 /** The total time spent on background scans in ms counted from the last radio chip reset */ 79 private final long mTotalBackgroundScanTimeMillis; 80 /** The total time spent on roam scans in ms counted from the last radio chip reset */ 81 private final long mTotalRoamScanTimeMillis; 82 /** The total time spent on pno scans in ms counted from the last radio chip reset */ 83 private final long mTotalPnoScanTimeMillis; 84 /** The total time spent on hotspot2.0 scans and GAS exchange in ms counted from the last radio 85 * chip reset */ 86 private final long mTotalHotspot2ScanTimeMillis; 87 /** The total time CCA is on busy status on the current frequency in ms counted from the last 88 * radio chip reset */ 89 private final long mTotalCcaBusyFreqTimeMillis; 90 /** The total radio on time on the current frequency from the last radio chip reset */ 91 private final long mTotalRadioOnFreqTimeMillis; 92 /** The total number of beacons received from the last radio chip reset */ 93 private final long mTotalBeaconRx; 94 /** The status of link probe since last stats update */ 95 @ProbeStatus private final int mProbeStatusSinceLastUpdate; 96 /** The elapsed time of the most recent link probe since last stats update */ 97 private final int mProbeElapsedTimeSinceLastUpdateMillis; 98 /** The MCS rate of the most recent link probe since last stats update */ 99 private final int mProbeMcsRateSinceLastUpdate; 100 /** Rx link speed at the sample time in Mbps */ 101 private final int mRxLinkSpeedMbps; 102 private final @NetworkType int mCellularDataNetworkType; 103 private final int mCellularSignalStrengthDbm; 104 private final int mCellularSignalStrengthDb; 105 private final boolean mIsSameRegisteredCell; 106 107 /** Constructor function {@hide} */ WifiUsabilityStatsEntry(long timeStampMillis, int rssi, int linkSpeedMbps, long totalTxSuccess, long totalTxRetries, long totalTxBad, long totalRxSuccess, long totalRadioOnTimeMillis, long totalRadioTxTimeMillis, long totalRadioRxTimeMillis, long totalScanTimeMillis, long totalNanScanTimeMillis, long totalBackgroundScanTimeMillis, long totalRoamScanTimeMillis, long totalPnoScanTimeMillis, long totalHotspot2ScanTimeMillis, long totalCcaBusyFreqTimeMillis, long totalRadioOnFreqTimeMillis, long totalBeaconRx, @ProbeStatus int probeStatusSinceLastUpdate, int probeElapsedTimeSinceLastUpdateMillis, int probeMcsRateSinceLastUpdate, int rxLinkSpeedMbps, @NetworkType int cellularDataNetworkType, int cellularSignalStrengthDbm, int cellularSignalStrengthDb, boolean isSameRegisteredCell)108 public WifiUsabilityStatsEntry(long timeStampMillis, int rssi, int linkSpeedMbps, 109 long totalTxSuccess, long totalTxRetries, long totalTxBad, long totalRxSuccess, 110 long totalRadioOnTimeMillis, long totalRadioTxTimeMillis, long totalRadioRxTimeMillis, 111 long totalScanTimeMillis, long totalNanScanTimeMillis, 112 long totalBackgroundScanTimeMillis, 113 long totalRoamScanTimeMillis, long totalPnoScanTimeMillis, 114 long totalHotspot2ScanTimeMillis, 115 long totalCcaBusyFreqTimeMillis, long totalRadioOnFreqTimeMillis, long totalBeaconRx, 116 @ProbeStatus int probeStatusSinceLastUpdate, int probeElapsedTimeSinceLastUpdateMillis, 117 int probeMcsRateSinceLastUpdate, int rxLinkSpeedMbps, 118 @NetworkType int cellularDataNetworkType, 119 int cellularSignalStrengthDbm, int cellularSignalStrengthDb, 120 boolean isSameRegisteredCell) { 121 mTimeStampMillis = timeStampMillis; 122 mRssi = rssi; 123 mLinkSpeedMbps = linkSpeedMbps; 124 mTotalTxSuccess = totalTxSuccess; 125 mTotalTxRetries = totalTxRetries; 126 mTotalTxBad = totalTxBad; 127 mTotalRxSuccess = totalRxSuccess; 128 mTotalRadioOnTimeMillis = totalRadioOnTimeMillis; 129 mTotalRadioTxTimeMillis = totalRadioTxTimeMillis; 130 mTotalRadioRxTimeMillis = totalRadioRxTimeMillis; 131 mTotalScanTimeMillis = totalScanTimeMillis; 132 mTotalNanScanTimeMillis = totalNanScanTimeMillis; 133 mTotalBackgroundScanTimeMillis = totalBackgroundScanTimeMillis; 134 mTotalRoamScanTimeMillis = totalRoamScanTimeMillis; 135 mTotalPnoScanTimeMillis = totalPnoScanTimeMillis; 136 mTotalHotspot2ScanTimeMillis = totalHotspot2ScanTimeMillis; 137 mTotalCcaBusyFreqTimeMillis = totalCcaBusyFreqTimeMillis; 138 mTotalRadioOnFreqTimeMillis = totalRadioOnFreqTimeMillis; 139 mTotalBeaconRx = totalBeaconRx; 140 mProbeStatusSinceLastUpdate = probeStatusSinceLastUpdate; 141 mProbeElapsedTimeSinceLastUpdateMillis = probeElapsedTimeSinceLastUpdateMillis; 142 mProbeMcsRateSinceLastUpdate = probeMcsRateSinceLastUpdate; 143 mRxLinkSpeedMbps = rxLinkSpeedMbps; 144 mCellularDataNetworkType = cellularDataNetworkType; 145 mCellularSignalStrengthDbm = cellularSignalStrengthDbm; 146 mCellularSignalStrengthDb = cellularSignalStrengthDb; 147 mIsSameRegisteredCell = isSameRegisteredCell; 148 } 149 150 /** Implement the Parcelable interface */ describeContents()151 public int describeContents() { 152 return 0; 153 } 154 155 /** Implement the Parcelable interface */ writeToParcel(Parcel dest, int flags)156 public void writeToParcel(Parcel dest, int flags) { 157 dest.writeLong(mTimeStampMillis); 158 dest.writeInt(mRssi); 159 dest.writeInt(mLinkSpeedMbps); 160 dest.writeLong(mTotalTxSuccess); 161 dest.writeLong(mTotalTxRetries); 162 dest.writeLong(mTotalTxBad); 163 dest.writeLong(mTotalRxSuccess); 164 dest.writeLong(mTotalRadioOnTimeMillis); 165 dest.writeLong(mTotalRadioTxTimeMillis); 166 dest.writeLong(mTotalRadioRxTimeMillis); 167 dest.writeLong(mTotalScanTimeMillis); 168 dest.writeLong(mTotalNanScanTimeMillis); 169 dest.writeLong(mTotalBackgroundScanTimeMillis); 170 dest.writeLong(mTotalRoamScanTimeMillis); 171 dest.writeLong(mTotalPnoScanTimeMillis); 172 dest.writeLong(mTotalHotspot2ScanTimeMillis); 173 dest.writeLong(mTotalCcaBusyFreqTimeMillis); 174 dest.writeLong(mTotalRadioOnFreqTimeMillis); 175 dest.writeLong(mTotalBeaconRx); 176 dest.writeInt(mProbeStatusSinceLastUpdate); 177 dest.writeInt(mProbeElapsedTimeSinceLastUpdateMillis); 178 dest.writeInt(mProbeMcsRateSinceLastUpdate); 179 dest.writeInt(mRxLinkSpeedMbps); 180 dest.writeInt(mCellularDataNetworkType); 181 dest.writeInt(mCellularSignalStrengthDbm); 182 dest.writeInt(mCellularSignalStrengthDb); 183 dest.writeBoolean(mIsSameRegisteredCell); 184 } 185 186 /** Implement the Parcelable interface */ 187 public static final @android.annotation.NonNull Creator<WifiUsabilityStatsEntry> CREATOR = 188 new Creator<WifiUsabilityStatsEntry>() { 189 public WifiUsabilityStatsEntry createFromParcel(Parcel in) { 190 return new WifiUsabilityStatsEntry( 191 in.readLong(), in.readInt(), 192 in.readInt(), in.readLong(), in.readLong(), 193 in.readLong(), in.readLong(), in.readLong(), 194 in.readLong(), in.readLong(), in.readLong(), 195 in.readLong(), in.readLong(), in.readLong(), 196 in.readLong(), in.readLong(), in.readLong(), 197 in.readLong(), in.readLong(), in.readInt(), 198 in.readInt(), in.readInt(), in.readInt(), 199 in.readInt(), in.readInt(), in.readInt(), 200 in.readBoolean() 201 ); 202 } 203 204 public WifiUsabilityStatsEntry[] newArray(int size) { 205 return new WifiUsabilityStatsEntry[size]; 206 } 207 }; 208 209 /** Absolute milliseconds from device boot when these stats were sampled */ getTimeStampMillis()210 public long getTimeStampMillis() { 211 return mTimeStampMillis; 212 } 213 214 /** The RSSI (in dBm) at the sample time */ getRssi()215 public int getRssi() { 216 return mRssi; 217 } 218 219 /** Link speed at the sample time in Mbps */ getLinkSpeedMbps()220 public int getLinkSpeedMbps() { 221 return mLinkSpeedMbps; 222 } 223 224 /** The total number of tx success counted from the last radio chip reset */ getTotalTxSuccess()225 public long getTotalTxSuccess() { 226 return mTotalTxSuccess; 227 } 228 229 /** The total number of MPDU data packet retries counted from the last radio chip reset */ getTotalTxRetries()230 public long getTotalTxRetries() { 231 return mTotalTxRetries; 232 } 233 234 /** The total number of tx bad counted from the last radio chip reset */ getTotalTxBad()235 public long getTotalTxBad() { 236 return mTotalTxBad; 237 } 238 239 /** The total number of rx success counted from the last radio chip reset */ getTotalRxSuccess()240 public long getTotalRxSuccess() { 241 return mTotalRxSuccess; 242 } 243 244 /** The total time the wifi radio is on in ms counted from the last radio chip reset */ getTotalRadioOnTimeMillis()245 public long getTotalRadioOnTimeMillis() { 246 return mTotalRadioOnTimeMillis; 247 } 248 249 /** The total time the wifi radio is doing tx in ms counted from the last radio chip reset */ getTotalRadioTxTimeMillis()250 public long getTotalRadioTxTimeMillis() { 251 return mTotalRadioTxTimeMillis; 252 } 253 254 /** The total time the wifi radio is doing rx in ms counted from the last radio chip reset */ getTotalRadioRxTimeMillis()255 public long getTotalRadioRxTimeMillis() { 256 return mTotalRadioRxTimeMillis; 257 } 258 259 /** The total time spent on all types of scans in ms counted from the last radio chip reset */ getTotalScanTimeMillis()260 public long getTotalScanTimeMillis() { 261 return mTotalScanTimeMillis; 262 } 263 264 /** The total time spent on nan scans in ms counted from the last radio chip reset */ getTotalNanScanTimeMillis()265 public long getTotalNanScanTimeMillis() { 266 return mTotalNanScanTimeMillis; 267 } 268 269 /** The total time spent on background scans in ms counted from the last radio chip reset */ getTotalBackgroundScanTimeMillis()270 public long getTotalBackgroundScanTimeMillis() { 271 return mTotalBackgroundScanTimeMillis; 272 } 273 274 /** The total time spent on roam scans in ms counted from the last radio chip reset */ getTotalRoamScanTimeMillis()275 public long getTotalRoamScanTimeMillis() { 276 return mTotalRoamScanTimeMillis; 277 } 278 279 /** The total time spent on pno scans in ms counted from the last radio chip reset */ getTotalPnoScanTimeMillis()280 public long getTotalPnoScanTimeMillis() { 281 return mTotalPnoScanTimeMillis; 282 } 283 284 /** The total time spent on hotspot2.0 scans and GAS exchange in ms counted from the last radio 285 * chip reset */ getTotalHotspot2ScanTimeMillis()286 public long getTotalHotspot2ScanTimeMillis() { 287 return mTotalHotspot2ScanTimeMillis; 288 } 289 290 /** The total time CCA is on busy status on the current frequency in ms counted from the last 291 * radio chip reset */ getTotalCcaBusyFreqTimeMillis()292 public long getTotalCcaBusyFreqTimeMillis() { 293 return mTotalCcaBusyFreqTimeMillis; 294 } 295 296 /** The total radio on time on the current frequency from the last radio chip reset */ getTotalRadioOnFreqTimeMillis()297 public long getTotalRadioOnFreqTimeMillis() { 298 return mTotalRadioOnFreqTimeMillis; 299 } 300 301 /** The total number of beacons received from the last radio chip reset */ getTotalBeaconRx()302 public long getTotalBeaconRx() { 303 return mTotalBeaconRx; 304 } 305 306 /** The status of link probe since last stats update */ getProbeStatusSinceLastUpdate()307 @ProbeStatus public int getProbeStatusSinceLastUpdate() { 308 return mProbeStatusSinceLastUpdate; 309 } 310 311 /** The elapsed time of the most recent link probe since last stats update */ getProbeElapsedTimeSinceLastUpdateMillis()312 public int getProbeElapsedTimeSinceLastUpdateMillis() { 313 return mProbeElapsedTimeSinceLastUpdateMillis; 314 } 315 316 /** The MCS rate of the most recent link probe since last stats update */ getProbeMcsRateSinceLastUpdate()317 public int getProbeMcsRateSinceLastUpdate() { 318 return mProbeMcsRateSinceLastUpdate; 319 } 320 321 /** Rx link speed at the sample time in Mbps */ getRxLinkSpeedMbps()322 public int getRxLinkSpeedMbps() { 323 return mRxLinkSpeedMbps; 324 } 325 326 /** Cellular data network type currently in use on the device for data transmission */ getCellularDataNetworkType()327 @NetworkType public int getCellularDataNetworkType() { 328 return mCellularDataNetworkType; 329 } 330 331 /** 332 * Cellular signal strength in dBm, NR: CsiRsrp, LTE: Rsrp, WCDMA/TDSCDMA: Rscp, 333 * CDMA: Rssi, EVDO: Rssi, GSM: Rssi 334 */ getCellularSignalStrengthDbm()335 public int getCellularSignalStrengthDbm() { 336 return mCellularSignalStrengthDbm; 337 } 338 339 /** 340 * Cellular signal strength in dB, NR: CsiSinr, LTE: Rsrq, WCDMA: EcNo, TDSCDMA: invalid, 341 * CDMA: Ecio, EVDO: SNR, GSM: invalid 342 */ getCellularSignalStrengthDb()343 public int getCellularSignalStrengthDb() { 344 return mCellularSignalStrengthDb; 345 } 346 347 /** Whether the primary registered cell of current entry is same as that of previous entry */ isSameRegisteredCell()348 public boolean isSameRegisteredCell() { 349 return mIsSameRegisteredCell; 350 } 351 } 352