diff options
author | Rebecca Silberstein <silberst@google.com> | 2016-02-23 14:00:35 -0800 |
---|---|---|
committer | Rebecca Silberstein <silberst@google.com> | 2016-02-24 15:41:32 -0800 |
commit | 25fccb255c269bf0c59fa776623a0002cc24a211 (patch) | |
tree | 56f4eec140745f2f7806221a455ae87a35f09a0d /service | |
parent | af8f9541d248f7e1ca8232774de1310838ef4b0a (diff) |
Move calculateWifiScore out of WSM and create new WifiScoreReport class
Pulled the calculation for a Wifi Score out of WSM and created a class to
hold score related objects. This new class holds the score report
string along with the badLinkspeedcount int. The calculateWifiScore
function is now a static method in the new WifiScoreReport class. Added
the ScoreReport to a couple of places where related counters are also
cleaned up.
This CL also cleans up some style issues and converts hardcoded values
to static variables for the class. No functionality changes were
introduced into the score calculation.
BUG=27312068
Change-Id: I167ecbef6e365923a687928235beecf3ac1b66f1
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiScoreReport.java | 375 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 271 |
2 files changed, 390 insertions, 256 deletions
diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java new file mode 100644 index 000000000..8f09a54cd --- /dev/null +++ b/service/java/com/android/server/wifi/WifiScoreReport.java @@ -0,0 +1,375 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi; + +import android.net.NetworkAgent; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; +import android.util.Log; + + +/** +* Calculate scores for connected wifi networks. +*/ +public class WifiScoreReport { + // TODO: switch to WifiScoreReport if it doesn't break any tools + private static final String TAG = "WifiStateMachine"; + + // TODO: This score was hardcorded to 56. Need to understand why after finishing code refactor + private static final int STARTING_SCORE = 56; + + // TODO: Understand why these values are used + private static final int MAX_BAD_LINKSPEED_COUNT = 6; + private static final int SCAN_CACHE_VISIBILITY_MS = 12000; + private static final int HOME_VISIBLE_NETWORK_MAX_COUNT = 6; + private static final int SCAN_CACHE_COUNT_PENALTY = 2; + private static final int AGGRESSIVE_HANDOVER_PENALTY = 6; + private static final int MIN_SUCCESS_COUNT = 5; + private static final int MAX_SUCCESS_COUNT_OF_STUCK_LINK = 3; + private static final int MAX_STUCK_LINK_COUNT = 5; + private static final int MIN_NUM_TICKS_AT_STATE = 1000; + private static final int USER_DISCONNECT_PENALTY = 5; + private static final int MAX_BAD_RSSI_COUNT = 7; + private static final int BAD_RSSI_COUNT_PENALTY = 2; + private static final int MAX_LOW_RSSI_COUNT = 1; + private static final double MIN_TX_RATE_FOR_WORKING_LINK = 0.3; + private static final int MIN_SUSTAINED_LINK_STUCK_COUNT = 1; + private static final int LINK_STUCK_PENALTY = 2; + private static final int BAD_LINKSPEED_PENALTY = 4; + private static final int GOOD_LINKSPEED_BONUS = 4; + + + private String mReport; + private int mBadLinkspeedcount; + + WifiScoreReport(String report, int badLinkspeedcount) { + mReport = report; + mBadLinkspeedcount = badLinkspeedcount; + } + + /** + * Method returning the String representation of the score report. + * + * @return String score report + */ + public String getReport() { + return mReport; + } + + /** + * Method returning the bad link speed count at the time of the current score report. + * + * @return int bad linkspeed count + */ + public int getBadLinkspeedcount() { + return mBadLinkspeedcount; + } + + /** + * Calculate wifi network score based on updated link layer stats and return a new + * WifiScoreReport object. + * + * If the score has changed from the previous value, update the WifiNetworkAgent. + * @param wifiInfo WifiInfo information about current network connection + * @param currentConfiguration WifiConfiguration current wifi config + * @param wifiConfigManager WifiConfigManager Object holding current config state + * @param networkAgent NetworkAgent to be notified of new score + * @param lastReport String most recent score report + * @param aggressiveHandover int current aggressiveHandover setting + * @return WifiScoreReport Wifi Score report + */ + public static WifiScoreReport calculateScore(WifiInfo wifiInfo, + WifiConfiguration currentConfiguration, + WifiConfigManager wifiConfigManager, + NetworkAgent networkAgent, + WifiScoreReport lastReport, + int aggressiveHandover) { + boolean debugLogging = false; + if (wifiConfigManager.enableVerboseLogging.get() > 0) { + debugLogging = true; + } + + StringBuilder sb = new StringBuilder(); + + int score = STARTING_SCORE; + boolean isBadLinkspeed = (wifiInfo.is24GHz() + && wifiInfo.getLinkSpeed() < wifiConfigManager.badLinkSpeed24) + || (wifiInfo.is5GHz() && wifiInfo.getLinkSpeed() + < wifiConfigManager.badLinkSpeed5); + boolean isGoodLinkspeed = (wifiInfo.is24GHz() + && wifiInfo.getLinkSpeed() >= wifiConfigManager.goodLinkSpeed24) + || (wifiInfo.is5GHz() && wifiInfo.getLinkSpeed() + >= wifiConfigManager.goodLinkSpeed5); + + int badLinkspeedcount = 0; + if (lastReport != null) { + badLinkspeedcount = lastReport.getBadLinkspeedcount(); + } + + if (isBadLinkspeed) { + if (badLinkspeedcount < MAX_BAD_LINKSPEED_COUNT) { + badLinkspeedcount++; + } + } else { + if (badLinkspeedcount > 0) { + badLinkspeedcount--; + } + } + + if (isBadLinkspeed) sb.append(" bl(").append(badLinkspeedcount).append(")"); + if (isGoodLinkspeed) sb.append(" gl"); + + /** + * We want to make sure that we use the 24GHz RSSI thresholds if + * there are 2.4GHz scan results + * otherwise we end up lowering the score based on 5GHz values + * which may cause a switch to LTE before roaming has a chance to try 2.4GHz + * We also might unblacklist the configuation based on 2.4GHz + * thresholds but joining 5GHz anyhow, and failing over to 2.4GHz because 5GHz is not good + */ + boolean use24Thresholds = false; + boolean homeNetworkBoost = false; + ScanDetailCache scanDetailCache = + wifiConfigManager.getScanDetailCache(currentConfiguration); + if (currentConfiguration != null && scanDetailCache != null) { + currentConfiguration.setVisibility( + scanDetailCache.getVisibility(SCAN_CACHE_VISIBILITY_MS)); + if (currentConfiguration.visibility != null) { + if (currentConfiguration.visibility.rssi24 != WifiConfiguration.INVALID_RSSI + && currentConfiguration.visibility.rssi24 + >= (currentConfiguration.visibility.rssi5 - SCAN_CACHE_COUNT_PENALTY)) { + use24Thresholds = true; + } + } + if (scanDetailCache.size() <= HOME_VISIBLE_NETWORK_MAX_COUNT + && currentConfiguration.allowedKeyManagement.cardinality() == 1 + && currentConfiguration.allowedKeyManagement + .get(WifiConfiguration.KeyMgmt.WPA_PSK)) { + // A PSK network with less than 6 known BSSIDs + // This is most likely a home network and thus we want to stick to wifi more + homeNetworkBoost = true; + } + } + if (homeNetworkBoost) sb.append(" hn"); + if (use24Thresholds) sb.append(" u24"); + + int rssi = wifiInfo.getRssi() - AGGRESSIVE_HANDOVER_PENALTY * aggressiveHandover + + (homeNetworkBoost ? WifiConfiguration.HOME_NETWORK_RSSI_BOOST : 0); + sb.append(String.format(" rssi=%d ag=%d", rssi, aggressiveHandover)); + + boolean is24GHz = use24Thresholds || wifiInfo.is24GHz(); + + boolean isBadRSSI = (is24GHz && rssi < wifiConfigManager.thresholdMinimumRssi24.get()) + || (!is24GHz && rssi < wifiConfigManager.thresholdMinimumRssi5.get()); + boolean isLowRSSI = (is24GHz && rssi < wifiConfigManager.thresholdQualifiedRssi24.get()) + || (!is24GHz + && wifiInfo.getRssi() < wifiConfigManager.thresholdMinimumRssi5.get()); + boolean isHighRSSI = (is24GHz && rssi >= wifiConfigManager.thresholdSaturatedRssi24.get()) + || (!is24GHz + && wifiInfo.getRssi() >= wifiConfigManager.thresholdSaturatedRssi5.get()); + + if (isBadRSSI) sb.append(" br"); + if (isLowRSSI) sb.append(" lr"); + if (isHighRSSI) sb.append(" hr"); + + int penalizedDueToUserTriggeredDisconnect = 0; // Not a user triggered disconnect + if (currentConfiguration != null + && (wifiInfo.txSuccessRate > MIN_SUCCESS_COUNT + || wifiInfo.rxSuccessRate > MIN_SUCCESS_COUNT)) { + if (isBadRSSI) { + currentConfiguration.numTicksAtBadRSSI++; + if (currentConfiguration.numTicksAtBadRSSI > MIN_NUM_TICKS_AT_STATE) { + // We remained associated for a compound amount of time while passing + // traffic, hence loose the corresponding user triggered disabled stats + if (currentConfiguration.numUserTriggeredWifiDisableBadRSSI > 0) { + currentConfiguration.numUserTriggeredWifiDisableBadRSSI--; + } + if (currentConfiguration.numUserTriggeredWifiDisableLowRSSI > 0) { + currentConfiguration.numUserTriggeredWifiDisableLowRSSI--; + } + if (currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0) { + currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI--; + } + currentConfiguration.numTicksAtBadRSSI = 0; + } + if (wifiConfigManager.enableWifiCellularHandoverUserTriggeredAdjustment + && (currentConfiguration.numUserTriggeredWifiDisableBadRSSI > 0 + || currentConfiguration.numUserTriggeredWifiDisableLowRSSI > 0 + || currentConfiguration + .numUserTriggeredWifiDisableNotHighRSSI > 0)) { + score = score - USER_DISCONNECT_PENALTY; + penalizedDueToUserTriggeredDisconnect = 1; + sb.append(" p1"); + } + } else if (isLowRSSI) { + currentConfiguration.numTicksAtLowRSSI++; + if (currentConfiguration.numTicksAtLowRSSI > MIN_NUM_TICKS_AT_STATE) { + // We remained associated for a compound amount of time while passing + // traffic, hence loose the corresponding user triggered disabled stats + if (currentConfiguration.numUserTriggeredWifiDisableLowRSSI > 0) { + currentConfiguration.numUserTriggeredWifiDisableLowRSSI--; + } + if (currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0) { + currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI--; + } + currentConfiguration.numTicksAtLowRSSI = 0; + } + if (wifiConfigManager.enableWifiCellularHandoverUserTriggeredAdjustment + && (currentConfiguration.numUserTriggeredWifiDisableLowRSSI > 0 + || currentConfiguration + .numUserTriggeredWifiDisableNotHighRSSI > 0)) { + score = score - USER_DISCONNECT_PENALTY; + penalizedDueToUserTriggeredDisconnect = 2; + sb.append(" p2"); + } + } else if (!isHighRSSI) { + currentConfiguration.numTicksAtNotHighRSSI++; + if (currentConfiguration.numTicksAtNotHighRSSI > MIN_NUM_TICKS_AT_STATE) { + // We remained associated for a compound amount of time while passing + // traffic, hence loose the corresponding user triggered disabled stats + if (currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0) { + currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI--; + } + currentConfiguration.numTicksAtNotHighRSSI = 0; + } + if (wifiConfigManager.enableWifiCellularHandoverUserTriggeredAdjustment + && currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0) { + score = score - USER_DISCONNECT_PENALTY; + penalizedDueToUserTriggeredDisconnect = 3; + sb.append(" p3"); + } + } + sb.append(String.format(" ticks %d,%d,%d", currentConfiguration.numTicksAtBadRSSI, + currentConfiguration.numTicksAtLowRSSI, + currentConfiguration.numTicksAtNotHighRSSI)); + } + + if (debugLogging) { + String rssiStatus = ""; + if (isBadRSSI) { + rssiStatus += " badRSSI "; + } else if (isHighRSSI) { + rssiStatus += " highRSSI "; + } else if (isLowRSSI) { + rssiStatus += " lowRSSI "; + } + if (isBadLinkspeed) rssiStatus += " lowSpeed "; + Log.d(TAG, "calculateWifiScore freq=" + Integer.toString(wifiInfo.getFrequency()) + + " speed=" + Integer.toString(wifiInfo.getLinkSpeed()) + + " score=" + Integer.toString(wifiInfo.score) + + rssiStatus + + " -> txbadrate=" + String.format("%.2f", wifiInfo.txBadRate) + + " txgoodrate=" + String.format("%.2f", wifiInfo.txSuccessRate) + + " txretriesrate=" + String.format("%.2f", wifiInfo.txRetriesRate) + + " rxrate=" + String.format("%.2f", wifiInfo.rxSuccessRate) + + " userTriggerdPenalty" + penalizedDueToUserTriggeredDisconnect); + } + + if ((wifiInfo.txBadRate >= 1) && (wifiInfo.txSuccessRate < MAX_SUCCESS_COUNT_OF_STUCK_LINK) + && (isBadRSSI || isLowRSSI)) { + // Link is stuck + if (wifiInfo.linkStuckCount < MAX_STUCK_LINK_COUNT) { + wifiInfo.linkStuckCount += 1; + } + sb.append(String.format(" ls+=%d", wifiInfo.linkStuckCount)); + if (debugLogging) { + Log.d(TAG, " bad link -> stuck count =" + + Integer.toString(wifiInfo.linkStuckCount)); + } + } else if (wifiInfo.txBadRate < MIN_TX_RATE_FOR_WORKING_LINK) { + if (wifiInfo.linkStuckCount > 0) { + wifiInfo.linkStuckCount -= 1; + } + sb.append(String.format(" ls-=%d", wifiInfo.linkStuckCount)); + if (debugLogging) { + Log.d(TAG, " good link -> stuck count =" + + Integer.toString(wifiInfo.linkStuckCount)); + } + } + + sb.append(String.format(" [%d", score)); + + if (wifiInfo.linkStuckCount > MIN_SUSTAINED_LINK_STUCK_COUNT) { + // Once link gets stuck for more than 3 seconds, start reducing the score + score = score - LINK_STUCK_PENALTY * (wifiInfo.linkStuckCount - 1); + } + sb.append(String.format(",%d", score)); + + if (isBadLinkspeed) { + score -= BAD_LINKSPEED_PENALTY; + if (debugLogging) { + Log.d(TAG, " isBadLinkspeed ---> count=" + badLinkspeedcount + + " score=" + Integer.toString(score)); + } + } else if ((isGoodLinkspeed) && (wifiInfo.txSuccessRate > 5)) { + score += GOOD_LINKSPEED_BONUS; // So as bad rssi alone dont kill us + } + sb.append(String.format(",%d", score)); + + if (isBadRSSI) { + if (wifiInfo.badRssiCount < MAX_BAD_RSSI_COUNT) { + wifiInfo.badRssiCount += 1; + } + } else if (isLowRSSI) { + wifiInfo.lowRssiCount = MAX_LOW_RSSI_COUNT; // Dont increment the lowRssi count above 1 + if (wifiInfo.badRssiCount > 0) { + // Decrement bad Rssi count + wifiInfo.badRssiCount -= 1; + } + } else { + wifiInfo.badRssiCount = 0; + wifiInfo.lowRssiCount = 0; + } + + score -= wifiInfo.badRssiCount * BAD_RSSI_COUNT_PENALTY + wifiInfo.lowRssiCount; + sb.append(String.format(",%d", score)); + + if (debugLogging) { + Log.d(TAG, " badRSSI count" + Integer.toString(wifiInfo.badRssiCount) + + " lowRSSI count" + Integer.toString(wifiInfo.lowRssiCount) + + " --> score " + Integer.toString(score)); + } + + if (isHighRSSI) { + score += 5; + if (debugLogging) Log.d(TAG, " isHighRSSI ---> score=" + Integer.toString(score)); + } + sb.append(String.format(",%d]", score)); + + sb.append(String.format(" brc=%d lrc=%d", wifiInfo.badRssiCount, wifiInfo.lowRssiCount)); + + //sanitize boundaries + if (score > NetworkAgent.WIFI_BASE_SCORE) { + score = NetworkAgent.WIFI_BASE_SCORE; + } + if (score < 0) { + score = 0; + } + + //report score + if (score != wifiInfo.score) { + if (debugLogging) { + Log.d(TAG, "calculateWifiScore() report new score " + Integer.toString(score)); + } + wifiInfo.score = score; + if (networkAgent != null) { + networkAgent.sendNetworkScore(score); + } + } + return new WifiScoreReport(sb.toString(), badLinkspeedcount); + } +} diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 025f8c6ec..e07634999 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -3160,8 +3160,8 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno if (report != null) { sb.append(" ").append(report); } - if (wifiScoringReport != null) { - sb.append(wifiScoringReport); + if (mWifiScoreReport != null) { + sb.append(mWifiScoreReport.getReport()); } if (mConnectedModeGScanOffloadStarted) { sb.append(" offload-started periodMilli " + mGScanPeriodMilli); @@ -4127,259 +4127,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno mWifiInfo.txSuccessRate = 0; mWifiInfo.txRetriesRate = 0; mWifiInfo.rxSuccessRate = 0; + mWifiScoreReport = null; } - int mBadLinkspeedcount = 0; - - // For debug, provide information about the last scoring operation - String wifiScoringReport = null; - - private void calculateWifiScore(WifiLinkLayerStats stats) { - StringBuilder sb = new StringBuilder(); - - int score = 56; // Starting score, temporarily hardcoded in between 50 and 60 - boolean isBadLinkspeed = (mWifiInfo.is24GHz() - && mWifiInfo.getLinkSpeed() < mWifiConfigManager.badLinkSpeed24) - || (mWifiInfo.is5GHz() && mWifiInfo.getLinkSpeed() - < mWifiConfigManager.badLinkSpeed5); - boolean isGoodLinkspeed = (mWifiInfo.is24GHz() - && mWifiInfo.getLinkSpeed() >= mWifiConfigManager.goodLinkSpeed24) - || (mWifiInfo.is5GHz() && mWifiInfo.getLinkSpeed() - >= mWifiConfigManager.goodLinkSpeed5); - - if (isBadLinkspeed) { - if (mBadLinkspeedcount < 6) - mBadLinkspeedcount++; - } else { - if (mBadLinkspeedcount > 0) - mBadLinkspeedcount--; - } - - if (isBadLinkspeed) sb.append(" bl(").append(mBadLinkspeedcount).append(")"); - if (isGoodLinkspeed) sb.append(" gl"); - - /** - * We want to make sure that we use the 24GHz RSSI thresholds if - * there are 2.4GHz scan results - * otherwise we end up lowering the score based on 5GHz values - * which may cause a switch to LTE before roaming has a chance to try 2.4GHz - * We also might unblacklist the configuation based on 2.4GHz - * thresholds but joining 5GHz anyhow, and failing over to 2.4GHz because 5GHz is not good - */ - boolean use24Thresholds = false; - boolean homeNetworkBoost = false; - WifiConfiguration currentConfiguration = getCurrentWifiConfiguration(); - ScanDetailCache scanDetailCache = - mWifiConfigManager.getScanDetailCache(currentConfiguration); - if (currentConfiguration != null && scanDetailCache != null) { - currentConfiguration.setVisibility(scanDetailCache.getVisibility(12000)); - if (currentConfiguration.visibility != null) { - if (currentConfiguration.visibility.rssi24 != WifiConfiguration.INVALID_RSSI - && currentConfiguration.visibility.rssi24 - >= (currentConfiguration.visibility.rssi5 - 2)) { - use24Thresholds = true; - } - } - if (scanDetailCache.size() <= 6 - && currentConfiguration.allowedKeyManagement.cardinality() == 1 - && currentConfiguration.allowedKeyManagement. - get(WifiConfiguration.KeyMgmt.WPA_PSK) == true) { - // A PSK network with less than 6 known BSSIDs - // This is most likely a home network and thus we want to stick to wifi more - homeNetworkBoost = true; - } - } - if (homeNetworkBoost) sb.append(" hn"); - if (use24Thresholds) sb.append(" u24"); - - int rssi = mWifiInfo.getRssi() - 6 * mAggressiveHandover - + (homeNetworkBoost ? WifiConfiguration.HOME_NETWORK_RSSI_BOOST : 0); - sb.append(String.format(" rssi=%d ag=%d", rssi, mAggressiveHandover)); - - boolean is24GHz = use24Thresholds || mWifiInfo.is24GHz(); - - boolean isBadRSSI = (is24GHz && rssi < mWifiConfigManager.thresholdMinimumRssi24.get()) - || (!is24GHz && rssi < mWifiConfigManager.thresholdMinimumRssi5.get()); - boolean isLowRSSI = (is24GHz && rssi < mWifiConfigManager.thresholdQualifiedRssi24.get()) - || (!is24GHz && - mWifiInfo.getRssi() < mWifiConfigManager.thresholdMinimumRssi5.get()); - boolean isHighRSSI = (is24GHz && rssi >= mWifiConfigManager.thresholdSaturatedRssi24.get()) - || (!is24GHz && mWifiInfo.getRssi() - >= mWifiConfigManager.thresholdSaturatedRssi5.get()); - - if (isBadRSSI) sb.append(" br"); - if (isLowRSSI) sb.append(" lr"); - if (isHighRSSI) sb.append(" hr"); - - int penalizedDueToUserTriggeredDisconnect = 0; // For debug information - if (currentConfiguration != null && - (mWifiInfo.txSuccessRate > 5 || mWifiInfo.rxSuccessRate > 5)) { - if (isBadRSSI) { - currentConfiguration.numTicksAtBadRSSI++; - if (currentConfiguration.numTicksAtBadRSSI > 1000) { - // We remained associated for a compound amount of time while passing - // traffic, hence loose the corresponding user triggered disabled stats - if (currentConfiguration.numUserTriggeredWifiDisableBadRSSI > 0) { - currentConfiguration.numUserTriggeredWifiDisableBadRSSI--; - } - if (currentConfiguration.numUserTriggeredWifiDisableLowRSSI > 0) { - currentConfiguration.numUserTriggeredWifiDisableLowRSSI--; - } - if (currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0) { - currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI--; - } - currentConfiguration.numTicksAtBadRSSI = 0; - } - if (mWifiConfigManager.enableWifiCellularHandoverUserTriggeredAdjustment && - (currentConfiguration.numUserTriggeredWifiDisableBadRSSI > 0 - || currentConfiguration.numUserTriggeredWifiDisableLowRSSI > 0 - || currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0)) { - score = score - 5; - penalizedDueToUserTriggeredDisconnect = 1; - sb.append(" p1"); - } - } else if (isLowRSSI) { - currentConfiguration.numTicksAtLowRSSI++; - if (currentConfiguration.numTicksAtLowRSSI > 1000) { - // We remained associated for a compound amount of time while passing - // traffic, hence loose the corresponding user triggered disabled stats - if (currentConfiguration.numUserTriggeredWifiDisableLowRSSI > 0) { - currentConfiguration.numUserTriggeredWifiDisableLowRSSI--; - } - if (currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0) { - currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI--; - } - currentConfiguration.numTicksAtLowRSSI = 0; - } - if (mWifiConfigManager.enableWifiCellularHandoverUserTriggeredAdjustment && - (currentConfiguration.numUserTriggeredWifiDisableLowRSSI > 0 - || currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0)) { - score = score - 5; - penalizedDueToUserTriggeredDisconnect = 2; - sb.append(" p2"); - } - } else if (!isHighRSSI) { - currentConfiguration.numTicksAtNotHighRSSI++; - if (currentConfiguration.numTicksAtNotHighRSSI > 1000) { - // We remained associated for a compound amount of time while passing - // traffic, hence loose the corresponding user triggered disabled stats - if (currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0) { - currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI--; - } - currentConfiguration.numTicksAtNotHighRSSI = 0; - } - if (mWifiConfigManager.enableWifiCellularHandoverUserTriggeredAdjustment && - currentConfiguration.numUserTriggeredWifiDisableNotHighRSSI > 0) { - score = score - 5; - penalizedDueToUserTriggeredDisconnect = 3; - sb.append(" p3"); - } - } - sb.append(String.format(" ticks %d,%d,%d", currentConfiguration.numTicksAtBadRSSI, - currentConfiguration.numTicksAtLowRSSI, - currentConfiguration.numTicksAtNotHighRSSI)); - } - - if (PDBG) { - String rssiStatus = ""; - if (isBadRSSI) rssiStatus += " badRSSI "; - else if (isHighRSSI) rssiStatus += " highRSSI "; - else if (isLowRSSI) rssiStatus += " lowRSSI "; - if (isBadLinkspeed) rssiStatus += " lowSpeed "; - logd("calculateWifiScore freq=" + Integer.toString(mWifiInfo.getFrequency()) - + " speed=" + Integer.toString(mWifiInfo.getLinkSpeed()) - + " score=" + Integer.toString(mWifiInfo.score) - + rssiStatus - + " -> txbadrate=" + String.format("%.2f", mWifiInfo.txBadRate) - + " txgoodrate=" + String.format("%.2f", mWifiInfo.txSuccessRate) - + " txretriesrate=" + String.format("%.2f", mWifiInfo.txRetriesRate) - + " rxrate=" + String.format("%.2f", mWifiInfo.rxSuccessRate) - + " userTriggerdPenalty" + penalizedDueToUserTriggeredDisconnect); - } - - if ((mWifiInfo.txBadRate >= 1) && (mWifiInfo.txSuccessRate < 3) - && (isBadRSSI || isLowRSSI)) { - // Link is stuck - if (mWifiInfo.linkStuckCount < 5) - mWifiInfo.linkStuckCount += 1; - sb.append(String.format(" ls+=%d", mWifiInfo.linkStuckCount)); - if (PDBG) logd(" bad link -> stuck count =" - + Integer.toString(mWifiInfo.linkStuckCount)); - } else if (mWifiInfo.txBadRate < 0.3) { - if (mWifiInfo.linkStuckCount > 0) - mWifiInfo.linkStuckCount -= 1; - sb.append(String.format(" ls-=%d", mWifiInfo.linkStuckCount)); - if (PDBG) logd(" good link -> stuck count =" - + Integer.toString(mWifiInfo.linkStuckCount)); - } - - sb.append(String.format(" [%d", score)); - - if (mWifiInfo.linkStuckCount > 1) { - // Once link gets stuck for more than 3 seconds, start reducing the score - score = score - 2 * (mWifiInfo.linkStuckCount - 1); - } - sb.append(String.format(",%d", score)); - - if (isBadLinkspeed) { - score -= 4; - if (PDBG) { - logd(" isBadLinkspeed ---> count=" + mBadLinkspeedcount - + " score=" + Integer.toString(score)); - } - } else if ((isGoodLinkspeed) && (mWifiInfo.txSuccessRate > 5)) { - score += 4; // So as bad rssi alone dont kill us - } - sb.append(String.format(",%d", score)); - - if (isBadRSSI) { - if (mWifiInfo.badRssiCount < 7) - mWifiInfo.badRssiCount += 1; - } else if (isLowRSSI) { - mWifiInfo.lowRssiCount = 1; // Dont increment the lowRssi count above 1 - if (mWifiInfo.badRssiCount > 0) { - // Decrement bad Rssi count - mWifiInfo.badRssiCount -= 1; - } - } else { - mWifiInfo.badRssiCount = 0; - mWifiInfo.lowRssiCount = 0; - } - - score -= mWifiInfo.badRssiCount * 2 + mWifiInfo.lowRssiCount; - sb.append(String.format(",%d", score)); - - if (PDBG) logd(" badRSSI count" + Integer.toString(mWifiInfo.badRssiCount) - + " lowRSSI count" + Integer.toString(mWifiInfo.lowRssiCount) - + " --> score " + Integer.toString(score)); - - - if (isHighRSSI) { - score += 5; - if (PDBG) logd(" isHighRSSI ---> score=" + Integer.toString(score)); - } - sb.append(String.format(",%d]", score)); - - sb.append(String.format(" brc=%d lrc=%d", mWifiInfo.badRssiCount, mWifiInfo.lowRssiCount)); - - //sanitize boundaries - if (score > NetworkAgent.WIFI_BASE_SCORE) - score = NetworkAgent.WIFI_BASE_SCORE; - if (score < 0) - score = 0; - - //report score - if (score != mWifiInfo.score) { - if (DBG) { - logd("calculateWifiScore() report new score " + Integer.toString(score)); - } - mWifiInfo.score = score; - if (mNetworkAgent != null) { - mNetworkAgent.sendNetworkScore(score); - } - } - wifiScoringReport = sb.toString(); - } + // Object holding most recent wifi score report and bad Linkspeed count + WifiScoreReport mWifiScoreReport = null; public double getTxPacketRate() { if (mWifiInfo != null) { @@ -4722,7 +4474,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno stopIpManager(); /* Reset data structures */ - mBadLinkspeedcount = 0; + mWifiScoreReport = null; mWifiInfo.reset(); linkDebouncing = false; /* Reset roaming parameters */ @@ -6437,7 +6189,8 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno config.getNetworkSelectionStatus().clearDisableReasonCounter(); config.numAssociation++; } - mBadLinkspeedcount = 0; + // On connect, reset wifiScoreReport + mWifiScoreReport = null; } } @@ -7952,7 +7705,13 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno } // Get Info and continue polling fetchRssiLinkSpeedAndFrequencyNative(); - calculateWifiScore(stats); + mWifiScoreReport = + WifiScoreReport.calculateScore(mWifiInfo, + getCurrentWifiConfiguration(), + mWifiConfigManager, + mNetworkAgent, + mWifiScoreReport, + mAggressiveHandover); } sendMessageDelayed(obtainMessage(CMD_RSSI_POLL, mRssiPollToken, 0), POLL_RSSI_INTERVAL_MSECS); |