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 com.android.server.wifi; 18 19 import static com.android.server.wifi.util.InformationElementUtil.BssLoad.CHANNEL_UTILIZATION_SCALE; 20 21 import android.content.Context; 22 import android.os.Handler; 23 import android.provider.DeviceConfig; 24 import android.provider.Settings; 25 import android.util.ArraySet; 26 27 import com.android.internal.annotations.VisibleForTesting; 28 29 import java.util.Collections; 30 import java.util.Optional; 31 import java.util.Set; 32 import java.util.concurrent.TimeUnit; 33 import java.util.function.Consumer; 34 35 /** 36 * This class allows getting all configurable flags from DeviceConfig. 37 */ 38 public class DeviceConfigFacade { 39 private final Context mContext; 40 private final WifiMetrics mWifiMetrics; 41 42 private static final String NAMESPACE = "wifi"; 43 44 // Default values of fields 45 @VisibleForTesting 46 protected static final int DEFAULT_ABNORMAL_CONNECTION_DURATION_MS = 47 (int) TimeUnit.SECONDS.toMillis(30); 48 // Default duration for evaluating Wifi condition to trigger a data stall 49 // measured in milliseconds 50 public static final int DEFAULT_DATA_STALL_DURATION_MS = 1500; 51 // Default threshold of Tx throughput below which to trigger a data stall measured in Kbps 52 public static final int DEFAULT_DATA_STALL_TX_TPUT_THR_KBPS = 2000; 53 // Default threshold of Rx throughput below which to trigger a data stall measured in Kbps 54 public static final int DEFAULT_DATA_STALL_RX_TPUT_THR_KBPS = 2000; 55 // Default threshold of Tx packet error rate above which to trigger a data stall in percentage 56 public static final int DEFAULT_DATA_STALL_TX_PER_THR = 90; 57 // Default threshold of CCA level above which to trigger a data stall 58 public static final int DEFAULT_DATA_STALL_CCA_LEVEL_THR = CHANNEL_UTILIZATION_SCALE; 59 // Default low threshold of L2 sufficient Tx throughput in Kbps 60 public static final int DEFAULT_TX_TPUT_SUFFICIENT_THR_LOW_KBPS = 2000; 61 // Default high threshold of L2 sufficient Tx throughput in Kbps 62 public static final int DEFAULT_TX_TPUT_SUFFICIENT_THR_HIGH_KBPS = 8000; 63 // Default low threshold of L2 sufficient Rx throughput in Kbps 64 public static final int DEFAULT_RX_TPUT_SUFFICIENT_THR_LOW_KBPS = 2000; 65 // Default high threshold of L2 sufficient Rx throughput in Kbps 66 public static final int DEFAULT_RX_TPUT_SUFFICIENT_THR_HIGH_KBPS = 8000; 67 // Numerator part of default threshold of L2 throughput over L3 throughput ratio 68 public static final int DEFAULT_TPUT_SUFFICIENT_RATIO_THR_NUM = 2; 69 // Denominator part of default threshold of L2 throughput over L3 throughput ratio 70 public static final int DEFAULT_TPUT_SUFFICIENT_RATIO_THR_DEN = 1; 71 // Default threshold of Tx packet per second 72 public static final int DEFAULT_TX_PACKET_PER_SECOND_THR = 2; 73 // Default threshold of Rx packet per second 74 public static final int DEFAULT_RX_PACKET_PER_SECOND_THR = 2; 75 // Default high threshold values for various connection/disconnection cases 76 // All of them are in percent with respect to connection attempts 77 static final int DEFAULT_CONNECTION_FAILURE_HIGH_THR_PERCENT = 40; 78 static final int DEFAULT_CONNECTION_FAILURE_DISCONNECTION_HIGH_THR_PERCENT = 30; 79 static final int DEFAULT_ASSOC_REJECTION_HIGH_THR_PERCENT = 30; 80 static final int DEFAULT_ASSOC_TIMEOUT_HIGH_THR_PERCENT = 30; 81 static final int DEFAULT_AUTH_FAILURE_HIGH_THR_PERCENT = 30; 82 static final int DEFAULT_SHORT_CONNECTION_NONLOCAL_HIGH_THR_PERCENT = 20; 83 static final int DEFAULT_DISCONNECTION_NONLOCAL_HIGH_THR_PERCENT = 25; 84 // Default health monitor abnormal count minimum for various cases 85 static final int DEFAULT_CONNECTION_FAILURE_COUNT_MIN = 6; 86 static final int DEFAULT_CONNECTION_FAILURE_DISCONNECTION_COUNT_MIN = 5; 87 static final int DEFAULT_ASSOC_REJECTION_COUNT_MIN = 3; 88 static final int DEFAULT_ASSOC_TIMEOUT_COUNT_MIN = 3; 89 static final int DEFAULT_AUTH_FAILURE_COUNT_MIN = 3; 90 static final int DEFAULT_SHORT_CONNECTION_NONLOCAL_COUNT_MIN = 3; 91 static final int DEFAULT_DISCONNECTION_NONLOCAL_COUNT_MIN = 3; 92 // Numerator part of default ratio threshold values for all cases 93 static final int DEFAULT_HEALTH_MONITOR_RATIO_THR_NUMERATOR = 4; 94 // Denominator part of ratio threshold for all cases 95 static final int HEALTH_MONITOR_RATIO_THR_DENOMINATOR = 2; 96 // Minimum RSSI in dBm for connection stats collection 97 // Connection or disconnection events with RSSI below this threshold are not 98 // included in connection stats collection. 99 static final int DEFAULT_HEALTH_MONITOR_MIN_RSSI_THR_DBM = -68; 100 // Default minimum number of connection attempts to qualify daily detection 101 static final int DEFAULT_HEALTH_MONITOR_MIN_NUM_CONNECTION_ATTEMPT = 10; 102 // Default minimum wait time between two bug report captures 103 static final int DEFAULT_BUG_REPORT_MIN_WINDOW_MS = 3_600_000; 104 // Default report-high threshold to take-bug-report threshold ratio. 105 // It should be larger than 1 since the bar to take bugreport should be higher. 106 static final int DEFAULT_BUG_REPORT_THRESHOLD_EXTRA_RATIO = 2; 107 // Default overlapping connection duration threshold in ms to trigger bug report 108 static final int DEFAULT_OVERLAPPING_CONNECTION_DURATION_THRESHOLD_MS = 75_000; 109 // At low traffic, Tx link speed values below the following threshold 110 // are ignored because it could be due to low rate management frames 111 static final int DEFAULT_TX_LINK_SPEED_LOW_THRESHOLD_MBPS = 9; 112 // At low traffic, Rx link speed values below the following threshold 113 // are ignored because it could be due to low rate management frames 114 static final int DEFAULT_RX_LINK_SPEED_LOW_THRESHOLD_MBPS = 9; 115 // Default health monitor short connection duration threshold in ms 116 static final int DEFAULT_HEALTH_MONITOR_SHORT_CONNECTION_DURATION_THR_MS = 20_000; 117 118 // Default mask for abnormal disconnection reason codes. 119 // Each bit of mask corresponds to a reason code defined in 802.11 standard section 9.4.1.7 120 // For example, b0 for reason code 0, b1 for reason code 1, etc. 121 // Bits below are abnormal disconnection reasons and thus are set to 1 122 // b0: reserved (e.g., STA heartbeat failure) 123 // b2: invalid auth 124 // b4: disassociated due to inactivity 125 // b6 and b7: invalid class 2 and 3 frames 126 // b34: disassociated due to missing ACKs 127 static final long DEFAULT_ABNORMAL_DISCONNECTION_REASON_CODE_MASK = 0x4_0000_00d5L; 128 // Default maximum interval between last RSSI poll and disconnection 129 static final int DEFAULT_HEALTH_MONITOR_RSSI_POLL_VALID_TIME_MS = 2_100; 130 // Default maximum interval between scan and connection attempt in non-stationary state 131 static final int DEFAULT_NONSTATIONARY_SCAN_RSSI_VALID_TIME_MS = 5_000; 132 // Default maximum interval between scan and connection attempt in stationary state 133 static final int DEFAULT_STATIONARY_SCAN_RSSI_VALID_TIME_MS = 8_000; 134 // Default health monitor firmware alert valid time. 135 // -1 disables firmware alert time check 136 static final int DEFAULT_HEALTH_MONITOR_FW_ALERT_VALID_TIME_MS = -1; 137 // Default minimum confirmation duration for sending network score to connectivity service 138 // when score breaches low. The actual confirmation duration is longer in general and it 139 // depends on the score evaluation period normally controlled by 140 // 'com.android.wifi.resources.R' config_wifiPollRssiIntervalMilliseconds. 141 static final int DEFAULT_MIN_CONFIRMATION_DURATION_SEND_LOW_SCORE_MS = 5000; 142 // Default minimum confirmation duration for sending network score to connectivity service 143 // when score breaches high. The actual confirmation duration is longer in general and it 144 // depends on the score evaluation period normally controlled by 145 // 'com.android.wifi.resources.R' config_wifiPollRssiIntervalMilliseconds. 146 static final int DEFAULT_MIN_CONFIRMATION_DURATION_SEND_HIGH_SCORE_MS = 0; 147 // Default RSSI threshold in dBm above which low score is not sent to connectivity service 148 // when external scorer takes action. 149 static final int DEFAULT_RSSI_THRESHOLD_NOT_SEND_LOW_SCORE_TO_CS_DBM = -67; 150 // Maximum traffic stats threshold for link bandwidth estimator 151 static final int DEFAULT_TRAFFIC_STATS_THRESHOLD_MAX_KB = 8000; 152 static final int DEFAULT_BANDWIDTH_ESTIMATOR_TIME_CONSTANT_LARGE_SEC = 6; 153 // Cached values of fields updated via updateDeviceConfigFlags() 154 private boolean mIsAbnormalConnectionBugreportEnabled; 155 private int mAbnormalConnectionDurationMs; 156 private int mDataStallDurationMs; 157 private int mDataStallTxTputThrKbps; 158 private int mDataStallRxTputThrKbps; 159 private int mDataStallTxPerThr; 160 private int mDataStallCcaLevelThr; 161 private int mTxTputSufficientLowThrKbps; 162 private int mTxTputSufficientHighThrKbps; 163 private int mRxTputSufficientLowThrKbps; 164 private int mRxTputSufficientHighThrKbps; 165 private int mTputSufficientRatioThrNum; 166 private int mTputSufficientRatioThrDen; 167 private int mTxPktPerSecondThr; 168 private int mRxPktPerSecondThr; 169 private int mConnectionFailureHighThrPercent; 170 private int mConnectionFailureCountMin; 171 private int mConnectionFailureDisconnectionHighThrPercent; 172 private int mConnectionFailureDisconnectionCountMin; 173 private int mAssocRejectionHighThrPercent; 174 private int mAssocRejectionCountMin; 175 private int mAssocTimeoutHighThrPercent; 176 private int mAssocTimeoutCountMin; 177 private int mAuthFailureHighThrPercent; 178 private int mAuthFailureCountMin; 179 private int mShortConnectionNonlocalHighThrPercent; 180 private int mShortConnectionNonlocalCountMin; 181 private int mDisconnectionNonlocalHighThrPercent; 182 private int mDisconnectionNonlocalCountMin; 183 private int mHealthMonitorRatioThrNumerator; 184 private int mHealthMonitorMinRssiThrDbm; 185 private Set<String> mRandomizationFlakySsidHotlist; 186 private Set<String> mNonPersistentMacRandomizationSsidAllowlist; 187 private Set<String> mNonPersistentMacRandomizationSsidBlocklist; 188 private boolean mIsAbnormalConnectionFailureBugreportEnabled; 189 private boolean mIsAbnormalDisconnectionBugreportEnabled; 190 private int mHealthMonitorMinNumConnectionAttempt; 191 private int mBugReportMinWindowMs; 192 private int mBugReportThresholdExtraRatio; 193 private boolean mWifiBatterySaverEnabled; 194 private boolean mIsOverlappingConnectionBugreportEnabled; 195 private int mOverlappingConnectionDurationThresholdMs; 196 private int mTxLinkSpeedLowThresholdMbps; 197 private int mRxLinkSpeedLowThresholdMbps; 198 private int mHealthMonitorShortConnectionDurationThrMs; 199 private long mAbnormalDisconnectionReasonCodeMask; 200 private int mHealthMonitorRssiPollValidTimeMs; 201 private int mNonstationaryScanRssiValidTimeMs; 202 private int mStationaryScanRssiValidTimeMs; 203 private int mHealthMonitorFwAlertValidTimeMs; 204 private int mMinConfirmationDurationSendLowScoreMs; 205 private int mMinConfirmationDurationSendHighScoreMs; 206 private int mRssiThresholdNotSendLowScoreToCsDbm; 207 private int mTrafficStatsThresholdMaxKbyte; 208 private int mBandwidthEstimatorLargeTimeConstantSec; 209 private boolean mInterfaceFailureBugreportEnabled; 210 private boolean mP2pFailureBugreportEnabled; 211 private boolean mApmEnhancementEnabled; 212 private boolean mAwareSuspensionEnabled; 213 private boolean mHighPerfLockDeprecated; 214 private Optional<Boolean> mOobPseudonymEnabled = Optional.empty(); 215 private Consumer<Boolean> mOobPseudonymFeatureFlagChangedListener = null; 216 private boolean mApplicationQosPolicyApiEnabled; 217 private boolean mAdjustPollRssiIntervalEnabled; 218 private boolean mSoftwarePnoEnabled; 219 private boolean mIncludePasspointSsidsInPnoScans; 220 private boolean mHandleRssiOrganicKernelFailuresEnabled; 221 222 private final Handler mWifiHandler; 223 DeviceConfigFacade(Context context, Handler handler, WifiMetrics wifiMetrics)224 public DeviceConfigFacade(Context context, Handler handler, WifiMetrics wifiMetrics) { 225 mContext = context; 226 mWifiMetrics = wifiMetrics; 227 mWifiHandler = handler; 228 updateDeviceConfigFlags(); 229 DeviceConfig.addOnPropertiesChangedListener( 230 NAMESPACE, 231 command -> handler.post(command), 232 properties -> { 233 updateDeviceConfigFlags(); 234 }); 235 } 236 updateDeviceConfigFlags()237 private void updateDeviceConfigFlags() { 238 mIsAbnormalConnectionBugreportEnabled = DeviceConfig.getBoolean(NAMESPACE, 239 "abnormal_connection_bugreport_enabled", false); 240 mAbnormalConnectionDurationMs = DeviceConfig.getInt(NAMESPACE, 241 "abnormal_connection_duration_ms", 242 DEFAULT_ABNORMAL_CONNECTION_DURATION_MS); 243 244 mDataStallDurationMs = DeviceConfig.getInt(NAMESPACE, 245 "data_stall_duration_ms", DEFAULT_DATA_STALL_DURATION_MS); 246 mDataStallTxTputThrKbps = DeviceConfig.getInt(NAMESPACE, 247 "data_stall_tx_tput_thr_kbps", DEFAULT_DATA_STALL_TX_TPUT_THR_KBPS); 248 mDataStallRxTputThrKbps = DeviceConfig.getInt(NAMESPACE, 249 "data_stall_rx_tput_thr_kbps", DEFAULT_DATA_STALL_RX_TPUT_THR_KBPS); 250 mDataStallTxPerThr = DeviceConfig.getInt(NAMESPACE, 251 "data_stall_tx_per_thr", DEFAULT_DATA_STALL_TX_PER_THR); 252 mDataStallCcaLevelThr = DeviceConfig.getInt(NAMESPACE, 253 "data_stall_cca_level_thr", DEFAULT_DATA_STALL_CCA_LEVEL_THR); 254 mWifiMetrics.setDataStallDurationMs(mDataStallDurationMs); 255 mWifiMetrics.setDataStallTxTputThrKbps(mDataStallTxTputThrKbps); 256 mWifiMetrics.setDataStallRxTputThrKbps(mDataStallRxTputThrKbps); 257 mWifiMetrics.setDataStallTxPerThr(mDataStallTxPerThr); 258 mWifiMetrics.setDataStallCcaLevelThr(mDataStallCcaLevelThr); 259 260 mTxTputSufficientLowThrKbps = DeviceConfig.getInt(NAMESPACE, 261 "tput_sufficient_low_thr_kbps", DEFAULT_TX_TPUT_SUFFICIENT_THR_LOW_KBPS); 262 mTxTputSufficientHighThrKbps = DeviceConfig.getInt(NAMESPACE, 263 "tput_sufficient_high_thr_kbps", DEFAULT_TX_TPUT_SUFFICIENT_THR_HIGH_KBPS); 264 mRxTputSufficientLowThrKbps = DeviceConfig.getInt(NAMESPACE, 265 "rx_tput_sufficient_low_thr_kbps", DEFAULT_RX_TPUT_SUFFICIENT_THR_LOW_KBPS); 266 mRxTputSufficientHighThrKbps = DeviceConfig.getInt(NAMESPACE, 267 "rx_tput_sufficient_high_thr_kbps", DEFAULT_RX_TPUT_SUFFICIENT_THR_HIGH_KBPS); 268 mTputSufficientRatioThrNum = DeviceConfig.getInt(NAMESPACE, 269 "tput_sufficient_ratio_thr_num", DEFAULT_TPUT_SUFFICIENT_RATIO_THR_NUM); 270 mTputSufficientRatioThrDen = DeviceConfig.getInt(NAMESPACE, 271 "tput_sufficient_ratio_thr_den", DEFAULT_TPUT_SUFFICIENT_RATIO_THR_DEN); 272 mTxPktPerSecondThr = DeviceConfig.getInt(NAMESPACE, 273 "tx_pkt_per_second_thr", DEFAULT_TX_PACKET_PER_SECOND_THR); 274 mRxPktPerSecondThr = DeviceConfig.getInt(NAMESPACE, 275 "rx_pkt_per_second_thr", DEFAULT_RX_PACKET_PER_SECOND_THR); 276 277 mConnectionFailureHighThrPercent = DeviceConfig.getInt(NAMESPACE, 278 "connection_failure_high_thr_percent", 279 DEFAULT_CONNECTION_FAILURE_HIGH_THR_PERCENT); 280 mConnectionFailureCountMin = DeviceConfig.getInt(NAMESPACE, 281 "connection_failure_count_min", 282 DEFAULT_CONNECTION_FAILURE_COUNT_MIN); 283 mConnectionFailureDisconnectionHighThrPercent = DeviceConfig.getInt(NAMESPACE, 284 "connection_failure_disconnection_high_thr_percent", 285 DEFAULT_CONNECTION_FAILURE_DISCONNECTION_HIGH_THR_PERCENT); 286 mConnectionFailureDisconnectionCountMin = DeviceConfig.getInt(NAMESPACE, 287 "connection_failure_disconnection_count_min", 288 DEFAULT_CONNECTION_FAILURE_DISCONNECTION_COUNT_MIN); 289 mAssocRejectionHighThrPercent = DeviceConfig.getInt(NAMESPACE, 290 "assoc_rejection_high_thr_percent", 291 DEFAULT_ASSOC_REJECTION_HIGH_THR_PERCENT); 292 mAssocRejectionCountMin = DeviceConfig.getInt(NAMESPACE, 293 "assoc_rejection_count_min", 294 DEFAULT_ASSOC_REJECTION_COUNT_MIN); 295 mAssocTimeoutHighThrPercent = DeviceConfig.getInt(NAMESPACE, 296 "assoc_timeout_high_thr_percent", 297 DEFAULT_ASSOC_TIMEOUT_HIGH_THR_PERCENT); 298 mAssocTimeoutCountMin = DeviceConfig.getInt(NAMESPACE, 299 "assoc_timeout_count_min", 300 DEFAULT_ASSOC_TIMEOUT_COUNT_MIN); 301 mAuthFailureHighThrPercent = DeviceConfig.getInt(NAMESPACE, 302 "auth_failure_high_thr_percent", 303 DEFAULT_AUTH_FAILURE_HIGH_THR_PERCENT); 304 mAuthFailureCountMin = DeviceConfig.getInt(NAMESPACE, 305 "auth_failure_count_min", 306 DEFAULT_AUTH_FAILURE_COUNT_MIN); 307 mShortConnectionNonlocalHighThrPercent = DeviceConfig.getInt(NAMESPACE, 308 "short_connection_nonlocal_high_thr_percent", 309 DEFAULT_SHORT_CONNECTION_NONLOCAL_HIGH_THR_PERCENT); 310 mShortConnectionNonlocalCountMin = DeviceConfig.getInt(NAMESPACE, 311 "short_connection_nonlocal_count_min", 312 DEFAULT_SHORT_CONNECTION_NONLOCAL_COUNT_MIN); 313 mDisconnectionNonlocalHighThrPercent = DeviceConfig.getInt(NAMESPACE, 314 "disconnection_nonlocal_high_thr_percent", 315 DEFAULT_DISCONNECTION_NONLOCAL_HIGH_THR_PERCENT); 316 mDisconnectionNonlocalCountMin = DeviceConfig.getInt(NAMESPACE, 317 "disconnection_nonlocal_count_min", 318 DEFAULT_DISCONNECTION_NONLOCAL_COUNT_MIN); 319 mHealthMonitorRatioThrNumerator = DeviceConfig.getInt(NAMESPACE, 320 "health_monitor_ratio_thr_numerator", 321 DEFAULT_HEALTH_MONITOR_RATIO_THR_NUMERATOR); 322 mHealthMonitorMinRssiThrDbm = DeviceConfig.getInt(NAMESPACE, 323 "health_monitor_min_rssi_thr_dbm", 324 DEFAULT_HEALTH_MONITOR_MIN_RSSI_THR_DBM); 325 326 mRandomizationFlakySsidHotlist = 327 getUnmodifiableSetQuoted("randomization_flaky_ssid_hotlist"); 328 mNonPersistentMacRandomizationSsidAllowlist = 329 getUnmodifiableSetQuoted("aggressive_randomization_ssid_allowlist"); 330 mNonPersistentMacRandomizationSsidBlocklist = 331 getUnmodifiableSetQuoted("aggressive_randomization_ssid_blocklist"); 332 333 mIsAbnormalConnectionFailureBugreportEnabled = DeviceConfig.getBoolean(NAMESPACE, 334 "abnormal_connection_failure_bugreport_enabled", false); 335 mIsAbnormalDisconnectionBugreportEnabled = DeviceConfig.getBoolean(NAMESPACE, 336 "abnormal_disconnection_bugreport_enabled", false); 337 mHealthMonitorMinNumConnectionAttempt = DeviceConfig.getInt(NAMESPACE, 338 "health_monitor_min_num_connection_attempt", 339 DEFAULT_HEALTH_MONITOR_MIN_NUM_CONNECTION_ATTEMPT); 340 mBugReportMinWindowMs = DeviceConfig.getInt(NAMESPACE, 341 "bug_report_min_window_ms", 342 DEFAULT_BUG_REPORT_MIN_WINDOW_MS); 343 mBugReportThresholdExtraRatio = DeviceConfig.getInt(NAMESPACE, 344 "report_bug_report_threshold_extra_ratio", 345 DEFAULT_BUG_REPORT_THRESHOLD_EXTRA_RATIO); 346 mIsOverlappingConnectionBugreportEnabled = DeviceConfig.getBoolean(NAMESPACE, 347 "overlapping_connection_bugreport_enabled", false); 348 mOverlappingConnectionDurationThresholdMs = DeviceConfig.getInt(NAMESPACE, 349 "overlapping_connection_duration_threshold_ms", 350 DEFAULT_OVERLAPPING_CONNECTION_DURATION_THRESHOLD_MS); 351 mTxLinkSpeedLowThresholdMbps = DeviceConfig.getInt(NAMESPACE, 352 "tx_link_speed_low_threshold_mbps", 353 DEFAULT_TX_LINK_SPEED_LOW_THRESHOLD_MBPS); 354 mRxLinkSpeedLowThresholdMbps = DeviceConfig.getInt(NAMESPACE, 355 "rx_link_speed_low_threshold_mbps", 356 DEFAULT_RX_LINK_SPEED_LOW_THRESHOLD_MBPS); 357 mWifiBatterySaverEnabled = DeviceConfig.getBoolean(NAMESPACE, "battery_saver_enabled", 358 false); 359 mHealthMonitorShortConnectionDurationThrMs = DeviceConfig.getInt(NAMESPACE, 360 "health_monitor_short_connection_duration_thr_ms", 361 DEFAULT_HEALTH_MONITOR_SHORT_CONNECTION_DURATION_THR_MS); 362 mAbnormalDisconnectionReasonCodeMask = DeviceConfig.getLong(NAMESPACE, 363 "abnormal_disconnection_reason_code_mask", 364 DEFAULT_ABNORMAL_DISCONNECTION_REASON_CODE_MASK); 365 mHealthMonitorRssiPollValidTimeMs = DeviceConfig.getInt(NAMESPACE, 366 "health_monitor_rssi_poll_valid_time_ms", 367 DEFAULT_HEALTH_MONITOR_RSSI_POLL_VALID_TIME_MS); 368 mNonstationaryScanRssiValidTimeMs = DeviceConfig.getInt(NAMESPACE, 369 "nonstationary_scan_rssi_valid_time_ms", 370 DEFAULT_NONSTATIONARY_SCAN_RSSI_VALID_TIME_MS); 371 mStationaryScanRssiValidTimeMs = DeviceConfig.getInt(NAMESPACE, 372 "stationary_scan_rssi_valid_time_ms", 373 DEFAULT_STATIONARY_SCAN_RSSI_VALID_TIME_MS); 374 mHealthMonitorFwAlertValidTimeMs = DeviceConfig.getInt(NAMESPACE, 375 "health_monitor_fw_alert_valid_time_ms", 376 DEFAULT_HEALTH_MONITOR_FW_ALERT_VALID_TIME_MS); 377 mWifiMetrics.setHealthMonitorRssiPollValidTimeMs(mHealthMonitorRssiPollValidTimeMs); 378 mMinConfirmationDurationSendLowScoreMs = DeviceConfig.getInt(NAMESPACE, 379 "min_confirmation_duration_send_low_score_ms", 380 DEFAULT_MIN_CONFIRMATION_DURATION_SEND_LOW_SCORE_MS); 381 mMinConfirmationDurationSendHighScoreMs = DeviceConfig.getInt(NAMESPACE, 382 "min_confirmation_duration_send_high_score_ms", 383 DEFAULT_MIN_CONFIRMATION_DURATION_SEND_HIGH_SCORE_MS); 384 mRssiThresholdNotSendLowScoreToCsDbm = DeviceConfig.getInt(NAMESPACE, 385 "rssi_threshold_not_send_low_score_to_cs_dbm", 386 DEFAULT_RSSI_THRESHOLD_NOT_SEND_LOW_SCORE_TO_CS_DBM); 387 mTrafficStatsThresholdMaxKbyte = DeviceConfig.getInt(NAMESPACE, 388 "traffic_stats_threshold_max_kbyte", DEFAULT_TRAFFIC_STATS_THRESHOLD_MAX_KB); 389 mBandwidthEstimatorLargeTimeConstantSec = DeviceConfig.getInt(NAMESPACE, 390 "bandwidth_estimator_time_constant_large_sec", 391 DEFAULT_BANDWIDTH_ESTIMATOR_TIME_CONSTANT_LARGE_SEC); 392 mInterfaceFailureBugreportEnabled = DeviceConfig.getBoolean(NAMESPACE, 393 "interface_failure_bugreport_enabled", false); 394 mP2pFailureBugreportEnabled = DeviceConfig.getBoolean(NAMESPACE, 395 "p2p_failure_bugreport_enabled", false); 396 mApmEnhancementEnabled = DeviceConfig.getBoolean(NAMESPACE, 397 "apm_enhancement_enabled", false); 398 mAwareSuspensionEnabled = DeviceConfig.getBoolean(NAMESPACE, 399 "aware_suspension_enabled", true); 400 mHighPerfLockDeprecated = DeviceConfig.getBoolean(NAMESPACE, 401 "high_perf_lock_deprecated", true); 402 boolean oobPseudonymEnabled = DeviceConfig.getBoolean(NAMESPACE, 403 "oob_pseudonym_enabled", true); 404 if (mOobPseudonymEnabled.isPresent() 405 && mOobPseudonymEnabled.get() != oobPseudonymEnabled 406 && mOobPseudonymFeatureFlagChangedListener != null) { 407 mWifiHandler.post( 408 () -> mOobPseudonymFeatureFlagChangedListener.accept(oobPseudonymEnabled)); 409 } 410 mOobPseudonymEnabled = Optional.of(oobPseudonymEnabled); 411 mApplicationQosPolicyApiEnabled = DeviceConfig.getBoolean(NAMESPACE, 412 "application_qos_policy_api_enabled", false); 413 mAdjustPollRssiIntervalEnabled = DeviceConfig.getBoolean(NAMESPACE, 414 "adjust_poll_rssi_interval_enabled", true); 415 mSoftwarePnoEnabled = DeviceConfig.getBoolean(NAMESPACE, 416 "software_pno_enabled", false); 417 mIncludePasspointSsidsInPnoScans = DeviceConfig.getBoolean(NAMESPACE, 418 "include_passpoint_ssids_in_pno_scans", false); 419 mHandleRssiOrganicKernelFailuresEnabled = DeviceConfig.getBoolean(NAMESPACE, 420 "handle_rssi_organic_kernel_failures_enabled", true); 421 } 422 getUnmodifiableSetQuoted(String key)423 private Set<String> getUnmodifiableSetQuoted(String key) { 424 String rawList = DeviceConfig.getString(NAMESPACE, key, ""); 425 Set<String> result = new ArraySet<>(); 426 String[] list = rawList.split(","); 427 for (String cur : list) { 428 if (cur.length() == 0) { 429 continue; 430 } 431 result.add("\"" + cur + "\""); 432 } 433 return Collections.unmodifiableSet(result); 434 } 435 436 /** 437 * Gets the feature flag for reporting abnormally long connections. 438 */ isAbnormalConnectionBugreportEnabled()439 public boolean isAbnormalConnectionBugreportEnabled() { 440 return mIsAbnormalConnectionBugreportEnabled; 441 } 442 443 /** 444 * Gets the threshold for classifying abnormally long connections. 445 */ getAbnormalConnectionDurationMs()446 public int getAbnormalConnectionDurationMs() { 447 return mAbnormalConnectionDurationMs; 448 } 449 450 /** 451 * Gets the duration of evaluating Wifi condition to trigger a data stall. 452 */ getDataStallDurationMs()453 public int getDataStallDurationMs() { 454 return mDataStallDurationMs; 455 } 456 457 /** 458 * Gets the threshold of Tx throughput below which to trigger a data stall. 459 */ getDataStallTxTputThrKbps()460 public int getDataStallTxTputThrKbps() { 461 return mDataStallTxTputThrKbps; 462 } 463 464 /** 465 * Gets the threshold of Rx throughput below which to trigger a data stall. 466 */ getDataStallRxTputThrKbps()467 public int getDataStallRxTputThrKbps() { 468 return mDataStallRxTputThrKbps; 469 } 470 471 /** 472 * Gets the threshold of Tx packet error rate above which to trigger a data stall. 473 */ getDataStallTxPerThr()474 public int getDataStallTxPerThr() { 475 return mDataStallTxPerThr; 476 } 477 478 /** 479 * Gets the threshold of CCA level above which to trigger a data stall. 480 */ getDataStallCcaLevelThr()481 public int getDataStallCcaLevelThr() { 482 return mDataStallCcaLevelThr; 483 } 484 485 /** 486 * Gets the low threshold of L2 throughput below which L2 throughput is always insufficient 487 */ getTxTputSufficientLowThrKbps()488 public int getTxTputSufficientLowThrKbps() { 489 return mTxTputSufficientLowThrKbps; 490 } 491 492 /** 493 * Gets the high threshold of L2 throughput above which L2 throughput is always sufficient 494 */ getTxTputSufficientHighThrKbps()495 public int getTxTputSufficientHighThrKbps() { 496 return mTxTputSufficientHighThrKbps; 497 } 498 499 /** 500 * Gets the low threshold of L2 throughput below which L2 Rx throughput is always insufficient 501 */ getRxTputSufficientLowThrKbps()502 public int getRxTputSufficientLowThrKbps() { 503 return mRxTputSufficientLowThrKbps; 504 } 505 506 /** 507 * Gets the high threshold of L2 throughput above which L2 Rx throughput is always sufficient 508 */ getRxTputSufficientHighThrKbps()509 public int getRxTputSufficientHighThrKbps() { 510 return mRxTputSufficientHighThrKbps; 511 } 512 513 /** 514 * Gets the numerator part of L2 throughput over L3 throughput ratio sufficiency threshold 515 * above which L2 throughput is sufficient 516 */ getTputSufficientRatioThrNum()517 public int getTputSufficientRatioThrNum() { 518 return mTputSufficientRatioThrNum; 519 } 520 521 /** 522 * Gets the denominator part of L2 throughput over L3 throughput ratio sufficiency threshold 523 * above which L2 throughput is sufficient 524 */ getTputSufficientRatioThrDen()525 public int getTputSufficientRatioThrDen() { 526 return mTputSufficientRatioThrDen; 527 } 528 529 /** 530 * Gets the threshold of Tx packet per second 531 * below which Tx throughput sufficiency check will always pass 532 */ getTxPktPerSecondThr()533 public int getTxPktPerSecondThr() { 534 return mTxPktPerSecondThr; 535 } 536 537 /** 538 * Gets the threshold of Rx packet per second 539 * below which Rx throughput sufficiency check will always pass 540 */ getRxPktPerSecondThr()541 public int getRxPktPerSecondThr() { 542 return mRxPktPerSecondThr; 543 } 544 545 /** 546 * Gets the high threshold of connection failure rate in percent 547 */ getConnectionFailureHighThrPercent()548 public int getConnectionFailureHighThrPercent() { 549 return mConnectionFailureHighThrPercent; 550 } 551 552 /** 553 * Gets connection-failure-due-to-disconnection min count 554 */ getConnectionFailureDisconnectionCountMin()555 public int getConnectionFailureDisconnectionCountMin() { 556 return mConnectionFailureDisconnectionCountMin; 557 } 558 559 /** 560 * Gets the high threshold of connection-failure-due-to-disconnection rate in percent 561 */ getConnectionFailureDisconnectionHighThrPercent()562 public int getConnectionFailureDisconnectionHighThrPercent() { 563 return mConnectionFailureDisconnectionHighThrPercent; 564 } 565 566 /** 567 * Gets connection failure min count 568 */ getConnectionFailureCountMin()569 public int getConnectionFailureCountMin() { 570 return mConnectionFailureCountMin; 571 } 572 573 /** 574 * Gets the high threshold of association rejection rate in percent 575 */ getAssocRejectionHighThrPercent()576 public int getAssocRejectionHighThrPercent() { 577 return mAssocRejectionHighThrPercent; 578 } 579 580 /** 581 * Gets association rejection min count 582 */ getAssocRejectionCountMin()583 public int getAssocRejectionCountMin() { 584 return mAssocRejectionCountMin; 585 } 586 587 /** 588 * Gets the high threshold of association timeout rate in percent 589 */ getAssocTimeoutHighThrPercent()590 public int getAssocTimeoutHighThrPercent() { 591 return mAssocTimeoutHighThrPercent; 592 } 593 594 /** 595 * Gets association timeout min count 596 */ getAssocTimeoutCountMin()597 public int getAssocTimeoutCountMin() { 598 return mAssocTimeoutCountMin; 599 } 600 601 602 /** 603 * Gets the high threshold of authentication failure rate in percent 604 */ getAuthFailureHighThrPercent()605 public int getAuthFailureHighThrPercent() { 606 return mAuthFailureHighThrPercent; 607 } 608 609 /** 610 * Gets authentication failure min count 611 */ getAuthFailureCountMin()612 public int getAuthFailureCountMin() { 613 return mAuthFailureCountMin; 614 } 615 616 /** 617 * Gets the high threshold of nonlocal short connection rate in percent 618 */ getShortConnectionNonlocalHighThrPercent()619 public int getShortConnectionNonlocalHighThrPercent() { 620 return mShortConnectionNonlocalHighThrPercent; 621 } 622 623 /** 624 * Gets nonlocal short connection min count 625 */ getShortConnectionNonlocalCountMin()626 public int getShortConnectionNonlocalCountMin() { 627 return mShortConnectionNonlocalCountMin; 628 } 629 630 /** 631 * Gets the high threshold of nonlocal disconnection rate in percent 632 */ getDisconnectionNonlocalHighThrPercent()633 public int getDisconnectionNonlocalHighThrPercent() { 634 return mDisconnectionNonlocalHighThrPercent; 635 } 636 637 /** 638 * Gets nonlocal disconnection min count 639 */ getDisconnectionNonlocalCountMin()640 public int getDisconnectionNonlocalCountMin() { 641 return mDisconnectionNonlocalCountMin; 642 } 643 644 /** 645 * Gets health monitor ratio threshold, numerator part 646 */ getHealthMonitorRatioThrNumerator()647 public int getHealthMonitorRatioThrNumerator() { 648 return mHealthMonitorRatioThrNumerator; 649 } 650 651 /** 652 * Gets health monitor min RSSI threshold in dBm 653 */ getHealthMonitorMinRssiThrDbm()654 public int getHealthMonitorMinRssiThrDbm() { 655 return mHealthMonitorMinRssiThrDbm; 656 } 657 658 /** 659 * Gets the Set of SSIDs in the flaky SSID hotlist. 660 */ getRandomizationFlakySsidHotlist()661 public Set<String> getRandomizationFlakySsidHotlist() { 662 return mRandomizationFlakySsidHotlist; 663 } 664 665 /** 666 * Gets the list of SSIDs for non-persistent MAC randomization. 667 */ getNonPersistentMacRandomizationSsidAllowlist()668 public Set<String> getNonPersistentMacRandomizationSsidAllowlist() { 669 return mNonPersistentMacRandomizationSsidAllowlist; 670 } 671 672 /** 673 * Gets the list of SSIDs that non-persistent MAC randomization should not be used for. 674 */ getNonPersistentMacRandomizationSsidBlocklist()675 public Set<String> getNonPersistentMacRandomizationSsidBlocklist() { 676 return mNonPersistentMacRandomizationSsidBlocklist; 677 } 678 /** 679 * Gets the feature flag for reporting abnormal connection failure. 680 */ isAbnormalConnectionFailureBugreportEnabled()681 public boolean isAbnormalConnectionFailureBugreportEnabled() { 682 return mIsAbnormalConnectionFailureBugreportEnabled; 683 } 684 685 /** 686 * Gets the feature flag for reporting abnormal disconnection. 687 */ isAbnormalDisconnectionBugreportEnabled()688 public boolean isAbnormalDisconnectionBugreportEnabled() { 689 return mIsAbnormalDisconnectionBugreportEnabled; 690 } 691 692 /** 693 * Gets health monitor min number of connection attempt threshold 694 */ getHealthMonitorMinNumConnectionAttempt()695 public int getHealthMonitorMinNumConnectionAttempt() { 696 return mHealthMonitorMinNumConnectionAttempt; 697 } 698 699 /** 700 * Gets minimum wait time between two bug report captures 701 */ getBugReportMinWindowMs()702 public int getBugReportMinWindowMs() { 703 return mBugReportMinWindowMs; 704 } 705 706 /** 707 * Gets the extra ratio of threshold to trigger bug report. 708 */ getBugReportThresholdExtraRatio()709 public int getBugReportThresholdExtraRatio() { 710 return mBugReportThresholdExtraRatio; 711 } 712 713 /** 714 * Gets the feature flag for reporting overlapping connection. 715 */ isOverlappingConnectionBugreportEnabled()716 public boolean isOverlappingConnectionBugreportEnabled() { 717 return mIsOverlappingConnectionBugreportEnabled; 718 } 719 720 /** 721 * Gets overlapping connection duration threshold in ms 722 */ getOverlappingConnectionDurationThresholdMs()723 public int getOverlappingConnectionDurationThresholdMs() { 724 return mOverlappingConnectionDurationThresholdMs; 725 } 726 727 /** 728 * Gets the threshold of link speed below which Tx link speed is ignored at low traffic 729 */ getTxLinkSpeedLowThresholdMbps()730 public int getTxLinkSpeedLowThresholdMbps() { 731 return mTxLinkSpeedLowThresholdMbps; 732 } 733 734 /** 735 * Gets the threshold of link speed below which Rx link speed is ignored at low traffic 736 */ getRxLinkSpeedLowThresholdMbps()737 public int getRxLinkSpeedLowThresholdMbps() { 738 return mRxLinkSpeedLowThresholdMbps; 739 } 740 741 /** 742 * Gets the feature flag for Wifi battery saver. 743 */ isWifiBatterySaverEnabled()744 public boolean isWifiBatterySaverEnabled() { 745 return mWifiBatterySaverEnabled; 746 } 747 748 /** 749 * Gets health monitor short connection duration threshold in ms 750 */ getHealthMonitorShortConnectionDurationThrMs()751 public int getHealthMonitorShortConnectionDurationThrMs() { 752 return mHealthMonitorShortConnectionDurationThrMs; 753 } 754 755 /** 756 * Gets abnormal disconnection reason code mask 757 */ getAbnormalDisconnectionReasonCodeMask()758 public long getAbnormalDisconnectionReasonCodeMask() { 759 return mAbnormalDisconnectionReasonCodeMask; 760 } 761 762 /** 763 * Gets health monitor RSSI poll valid time in ms 764 */ getHealthMonitorRssiPollValidTimeMs()765 public int getHealthMonitorRssiPollValidTimeMs() { 766 return mHealthMonitorRssiPollValidTimeMs; 767 } 768 769 /** 770 * Gets scan rssi valid time in ms when device is in non-stationary state 771 */ getNonstationaryScanRssiValidTimeMs()772 public int getNonstationaryScanRssiValidTimeMs() { 773 return mNonstationaryScanRssiValidTimeMs; 774 } 775 776 /** 777 * Gets scan rssi valid time in ms when device is in stationary state 778 */ getStationaryScanRssiValidTimeMs()779 public int getStationaryScanRssiValidTimeMs() { 780 return mStationaryScanRssiValidTimeMs; 781 } 782 783 /** 784 * Gets health monitor firmware alert valid time in ms, 785 * -1 disables firmware alert time check 786 */ getHealthMonitorFwAlertValidTimeMs()787 public int getHealthMonitorFwAlertValidTimeMs() { 788 return mHealthMonitorFwAlertValidTimeMs; 789 } 790 791 /** 792 * Gets the minimum confirmation duration for sending network score to connectivity service 793 * when score breaches low. 794 */ getMinConfirmationDurationSendLowScoreMs()795 public int getMinConfirmationDurationSendLowScoreMs() { 796 return mMinConfirmationDurationSendLowScoreMs; 797 } 798 799 /** 800 * Gets the minimum confirmation duration for sending network score to connectivity service 801 * when score breaches high. 802 */ getMinConfirmationDurationSendHighScoreMs()803 public int getMinConfirmationDurationSendHighScoreMs() { 804 return mMinConfirmationDurationSendHighScoreMs; 805 } 806 807 /** 808 * Gets the RSSI threshold above which low score is not sent to connectivity service when 809 * external scorer takes action. 810 */ getRssiThresholdNotSendLowScoreToCsDbm()811 public int getRssiThresholdNotSendLowScoreToCsDbm() { 812 return mRssiThresholdNotSendLowScoreToCsDbm; 813 } 814 815 /** 816 * Gets traffic stats maximum threshold in KByte 817 */ getTrafficStatsThresholdMaxKbyte()818 public int getTrafficStatsThresholdMaxKbyte() { 819 return mTrafficStatsThresholdMaxKbyte; 820 } 821 822 /** 823 * Gets bandwidth estimator large time constant in second 824 */ getBandwidthEstimatorLargeTimeConstantSec()825 public int getBandwidthEstimatorLargeTimeConstantSec() { 826 return mBandwidthEstimatorLargeTimeConstantSec; 827 } 828 829 /** 830 * Gets the feature flag for reporting interface setup failure 831 */ isInterfaceFailureBugreportEnabled()832 public boolean isInterfaceFailureBugreportEnabled() { 833 return mInterfaceFailureBugreportEnabled; 834 } 835 836 /** 837 * Gets the feature flag for reporting p2p setup failure 838 */ isP2pFailureBugreportEnabled()839 public boolean isP2pFailureBugreportEnabled() { 840 return mP2pFailureBugreportEnabled; 841 } 842 843 /** 844 * Gets the feature flag for APM enhancement 845 */ isApmEnhancementEnabled()846 public boolean isApmEnhancementEnabled() { 847 // reads the value set by Bluetooth device config for APM enhancement feature flag 848 return Settings.Global.getInt( 849 mContext.getContentResolver(), "apm_enhancement_enabled", 0) == 1; 850 } 851 852 /** 853 * Gets the feature flag for Aware suspension 854 */ isAwareSuspensionEnabled()855 public boolean isAwareSuspensionEnabled() { 856 return mAwareSuspensionEnabled; 857 } 858 859 /** 860 * Gets the feature flag for High Perf lock deprecation 861 */ isHighPerfLockDeprecated()862 public boolean isHighPerfLockDeprecated() { 863 return mHighPerfLockDeprecated; 864 } 865 866 /** 867 * Gets the feature flag for the OOB pseudonym of EAP-SIM/AKA/AKA' 868 */ isOobPseudonymEnabled()869 public boolean isOobPseudonymEnabled() { 870 return mOobPseudonymEnabled.isPresent() && mOobPseudonymEnabled.get(); 871 } 872 873 /** 874 * Gets the feature flag indicating whether the application QoS policy API is enabled. 875 */ isApplicationQosPolicyApiEnabled()876 public boolean isApplicationQosPolicyApiEnabled() { 877 return mApplicationQosPolicyApiEnabled; 878 } 879 880 /** 881 * Gets the feature flag for adjusting link layer stats and RSSI polling interval 882 */ isAdjustPollRssiIntervalEnabled()883 public boolean isAdjustPollRssiIntervalEnabled() { 884 return mAdjustPollRssiIntervalEnabled; 885 } 886 887 /** 888 * Gets the feature flag for Software PNO 889 */ isSoftwarePnoEnabled()890 public boolean isSoftwarePnoEnabled() { 891 return mSoftwarePnoEnabled; 892 } 893 894 /** 895 * Gets the feature flag indicating whether Passpoint SSIDs should be included in PNO scans. 896 */ includePasspointSsidsInPnoScans()897 public boolean includePasspointSsidsInPnoScans() { 898 return mIncludePasspointSsidsInPnoScans; 899 } 900 901 /** 902 * Gets the feature flag indicating whether handling IP reachability failures triggered from 903 * Wi-Fi RSSI polling or organic kernel probes the same as failure post roaming. 904 */ isHandleRssiOrganicKernelFailuresEnabled()905 public boolean isHandleRssiOrganicKernelFailuresEnabled() { 906 return mHandleRssiOrganicKernelFailuresEnabled; 907 } 908 909 /* 910 * Sets the listener to be notified when the OOB Pseudonym feature is enabled; 911 * Only 1 listener is accepted. 912 */ setOobPseudonymFeatureFlagChangedListener( Consumer<Boolean> listener)913 public void setOobPseudonymFeatureFlagChangedListener( 914 Consumer<Boolean> listener) { 915 mOobPseudonymFeatureFlagChangedListener = listener; 916 } 917 } 918