diff options
author | Arc Wang <arcwang@google.com> | 2020-04-28 01:09:26 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-04-28 01:09:26 +0000 |
commit | 32487070589855d410f68619edc3f04572c2777e (patch) | |
tree | 4acbd18c2f6a8db4adebabdf0f862fd2692ed1d0 /libs/WifiTrackerLib/src | |
parent | fb2e4f6bbecfb571797ec7c64d7c2ac36ee6f62e (diff) | |
parent | 06c4ec9a1638a0b57d68bc023d4ab000f7cdde63 (diff) | |
download | frameworks_opt_net_wifi-32487070589855d410f68619edc3f04572c2777e.tar.gz frameworks_opt_net_wifi-32487070589855d410f68619edc3f04572c2777e.tar.bz2 frameworks_opt_net_wifi-32487070589855d410f68619edc3f04572c2777e.zip |
Merge "Add Wi-Fi network selection verbose logging" into rvc-dev
Diffstat (limited to 'libs/WifiTrackerLib/src')
4 files changed, 55 insertions, 0 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java index d659151c2..9b923fa07 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java @@ -554,4 +554,9 @@ public class PasspointWifiEntry extends WifiEntry { // TODO(b/70983952): Fill this method in. return ""; } + + @Override + String getNetworkSelectionDescription() { + return Utils.getNetworkSelectionDescription(mWifiConfig); + } } diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java index b6afa984a..965a1c21d 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java @@ -852,4 +852,9 @@ public class StandardWifiEntry extends WifiEntry { description.append("}"); return description.toString(); } + + @Override + String getNetworkSelectionDescription() { + return Utils.getNetworkSelectionDescription(getWifiConfiguration()); + } } diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java index 5cdecd48e..00a8dcf30 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/Utils.java @@ -41,6 +41,7 @@ import android.net.NetworkInfo; import android.net.NetworkInfo.DetailedState; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.os.PersistableBundle; import android.os.RemoteException; import android.os.UserHandle; @@ -52,6 +53,7 @@ import android.text.Annotation; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.TextUtils; +import android.text.format.DateUtils; import android.text.style.ClickableSpan; import android.view.View; @@ -443,9 +445,47 @@ class Utils { sj.add(scanResultsDescription); } + final String networkSelectionDescription = wifiEntry.getNetworkSelectionDescription(); + if (!TextUtils.isEmpty(networkSelectionDescription)) { + sj.add(networkSelectionDescription); + } + return sj.toString(); } + static String getNetworkSelectionDescription(WifiConfiguration wifiConfig) { + if (wifiConfig == null) { + return ""; + } + + StringBuilder description = new StringBuilder(); + NetworkSelectionStatus networkSelectionStatus = wifiConfig.getNetworkSelectionStatus(); + + if (networkSelectionStatus.getNetworkSelectionStatus() != NETWORK_SELECTION_ENABLED) { + description.append(" (" + networkSelectionStatus.getNetworkStatusString()); + if (networkSelectionStatus.getDisableTime() > 0) { + long now = System.currentTimeMillis(); + long elapsedSeconds = (now - networkSelectionStatus.getDisableTime()) / 1000; + description.append(" " + DateUtils.formatElapsedTime(elapsedSeconds)); + } + description.append(")"); + } + + int maxNetworkSelectionDisableReason = + NetworkSelectionStatus.getMaxNetworkSelectionDisableReason(); + for (int reason = 0; reason <= maxNetworkSelectionDisableReason; reason++) { + int disableReasonCounter = networkSelectionStatus.getDisableReasonCounter(reason); + if (disableReasonCounter == 0) { + continue; + } + description.append(" ") + .append(NetworkSelectionStatus.getNetworkSelectionDisableReasonString(reason)) + .append("=") + .append(disableReasonCounter); + } + return description.toString(); + } + static String getCurrentNetworkCapabilitiesInformation(Context context, NetworkCapabilities networkCapabilities) { if (context == null || networkCapabilities == null) { diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java index 989c764aa..59062505f 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java @@ -428,6 +428,11 @@ public abstract class WifiEntry implements Comparable<WifiEntry> { /** Returns the ScanResult information of a WifiEntry */ abstract String getScanResultDescription(); + /** Returns the network selection information of a WifiEntry */ + String getNetworkSelectionDescription() { + return ""; + } + /** * Sets the callback listener for WifiEntryCallback methods. * Subsequent calls will overwrite the previous listener. |