Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 653cfeeb authored by vandwalle's avatar vandwalle
Browse files

when vervbose logging, keep track of a list of ScanResults per AP

Change-Id: Ib8f797de360f11eb9914a6aa44d418e1d0571973
parent 27ed053b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -3153,10 +3153,12 @@

    <!-- Setting Checkbox title whether to show options for wireless display certification -->
    <string name="wifi_display_certification">Wireless display certification</string>
    <!-- Setting Checkbox title whether to show options for WiFi Verbose Logging -->
    <!-- Setting Checkbox title whether to enable WiFi Verbose Logging. [CHAR LIMIT=40] -->
    <string name="wifi_verbose_logging">Enable WiFi Verbose Logging</string>
    <!-- setting Checkbox summary whether to show options for wireless display certification  -->
    <string name="wifi_display_certification_summary">Show options for wireless display certification</string>
    <!-- Setting Checkbox title whether to enable Wifi verbose Logging [CHAR LIMIT=80] -->
    <string name="wifi_verbose_logging_summary">Increase Wifi logging level, show per SSID RSSI in WiFi Picker</string>
    <!-- Setting Checkbox title whether to allow mock locations -->
    <string name="allow_mock_location">Allow mock locations</string>
    <!-- setting Checkbox summary whether to allow mock locations  -->
+1 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@
        <CheckBoxPreference
            android:key="wifi_verbose_logging"
            android:title="@string/wifi_verbose_logging" />
            android:summary="@string/wifi_verbose_logging_summary"/>

    </PreferenceCategory>

+96 −8
Original line number Diff line number Diff line
@@ -28,9 +28,13 @@ import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.preference.Preference;
import android.util.Log;
import android.util.LruCache;
import android.view.View;
import android.widget.ImageView;

import java.util.Map;


class AccessPoint extends Preference {
    static final String TAG = "Settings.AccessPoint";

@@ -74,6 +78,21 @@ class AccessPoint extends Preference {
    private WifiInfo mInfo;
    private DetailedState mState;

    private static final int VISIBILITY_MAX_AGE_IN_MILLI = 1000000;
    private static final int VISIBILITY_OUTDATED_AGE_IN_MILLI = 20000;
    private static final int LOWER_FREQ_24GHZ = 2400;
    private static final int HIGHER_FREQ_24GHZ = 2500;
    private static final int LOWER_FREQ_5GHZ = 4900;
    private static final int HIGHER_FREQ_5GHZ = 5900;
    private static final int SECOND_TO_MILLI = 1000;

    /** Experiemental: we should be able to show the user the list of BSSIDs and bands
     *  for that SSID.
     *  For now this data is used only with Verbose Logging so as to show the band and number
     *  of BSSIDs on which that network is seen.
     */
    public LruCache<String, ScanResult> scanResultCache;

    static int getSecurity(WifiConfiguration config) {
        if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
            return SECURITY_PSK;
@@ -201,6 +220,9 @@ class AccessPoint extends Preference {
            pskType = getPskType(result);
        mRssi = result.level;
        mScanResult = result;
        if (result.seen > mSeen) {
            mSeen = result.seen;
        }
    }

    @Override
@@ -267,6 +289,13 @@ class AccessPoint extends Preference {
        if (result.seen > mSeen) {
            mSeen = result.seen;
        }
        if (WifiSettings.mVerboseLogging > 0) {
            if (scanResultCache == null) {
                scanResultCache = new LruCache<String, ScanResult>(32);
            }
            scanResultCache.put(result.BSSID, result);
        }

        if (ssid.equals(result.SSID) && security == getSecurity(result)) {
            if (WifiManager.compareSignalLevel(result.level, mRssi) > 0) {
                int oldLevel = getLevel();
@@ -340,25 +369,84 @@ class AccessPoint extends Preference {

    /** visibility status of the WifiConfiguration
     * @return RSSI and update indicator
     * TODO: indicate both 2.4 and 5GHz RSSI as well as number of results
     * TODO: use a string formatter
     * ["rssi 5Ghz", "num results on 5GHz" / "rssi 5Ghz", "num results on 5GHz"]
     * For instance [-40,5/-30,2]
     */
    private String getVisibilityStatus() {
        String visibility ;
        StringBuilder visibility = new StringBuilder();

        long now = System.currentTimeMillis();
        long age = (now - mSeen);
        if (age < 1000000) {
        if (age < VISIBILITY_MAX_AGE_IN_MILLI) {
            //show age in seconds, in the form xx
            visibility = Long.toString((age / 1000) % 1000);
            visibility.append(Long.toString((age / SECOND_TO_MILLI) % SECOND_TO_MILLI));
        } else {
            //not seen for more than 1000 seconds
            visibility = "!";
        }
            visibility.append("!");
        }

        if (scanResultCache != null) {
            int rssi5 = WifiConfiguration.INVALID_RSSI;
            int rssi24 = WifiConfiguration.INVALID_RSSI;
            int num5 = 0;
            int num24 = 0;
            Map<String, ScanResult> list = scanResultCache.snapshot();
            for (ScanResult result : list.values()) {
                if (result.seen == 0)
                    continue;

                if (result.frequency > LOWER_FREQ_5GHZ
                        && result.frequency < HIGHER_FREQ_5GHZ) {
                    //strictly speaking: [4915, 5825]
                    //number of known BSSID on 5GHz band
                    num5 = num5 + 1;
                } else if (result.frequency > LOWER_FREQ_24GHZ
                        && result.frequency < HIGHER_FREQ_24GHZ) {
                    //strictly speaking: [2412, 2482]
                    //number of known BSSID on 2.4Ghz band
                    num24 = num24 + 1;
                }

                //ignore results seen, older than 20 seconds
                if (now - result.seen > VISIBILITY_OUTDATED_AGE_IN_MILLI) continue;

                if (result.frequency > LOWER_FREQ_5GHZ
                        &&result.frequency < HIGHER_FREQ_5GHZ) {
                    if (result.level > rssi5) {
                        rssi5 = result.level;
                    }
                } else if (result.frequency > LOWER_FREQ_24GHZ
                        && result.frequency < HIGHER_FREQ_24GHZ) {
                    if (result.level > rssi24) {
                        rssi24 = result.level;
                    }
                }
            }
            visibility.append(" [");
            if (num24 > 0 || rssi24 > WifiConfiguration.INVALID_RSSI) {
                visibility.append(Integer.toString(rssi24));
                visibility.append(",");
                visibility.append(Integer.toString(num24));
            }
            visibility.append(";");
            if (num5 > 0 || rssi5 > WifiConfiguration.INVALID_RSSI) {
                visibility.append(Integer.toString(rssi5));
                visibility.append(",");
                visibility.append(Integer.toString(num5));
            }
            visibility.append("]");
        } else {
            if (mRssi != Integer.MAX_VALUE) {
            visibility = visibility + ", " + Integer.toString(mRssi);
                visibility.append(", ");
                visibility.append(Integer.toString(mRssi));
                if (mScanResult != null) {
                    visibility.append(", ");
                    visibility.append(Integer.toString(mScanResult.frequency));
                }
            }
        }
        return visibility;
        return visibility.toString();
    }

    /** Updates the title and summary; may indirectly call notifyChanged()  */
+5 −3
Original line number Diff line number Diff line
@@ -178,6 +178,10 @@ public class WifiSettings extends RestrictedSettingsFragment

    private SwitchBar mSwitchBar;

    /** verbose logging flag. this flag is set thru developer debugging options
     * and used so as to assist with in-the-field WiFi connectivity debugging  */
    public static int mVerboseLogging = 0;

    /* End of "used in Wifi Setup context" */

    public WifiSettings() {
@@ -712,8 +716,6 @@ public class WifiSettings extends RestrictedSettingsFragment
        return super.onCreateDialog(dialogId);
    }

    /** verbose logging flag is set only thru developer debugging options */
    public static int mVerboseLogging = 0;
    /**
     * Shows the latest access points available with supplimental information like
     * the strength of network and the security for it.
@@ -728,7 +730,7 @@ public class WifiSettings extends RestrictedSettingsFragment
        }
        final int wifiState = mWifiManager.getWifiState();

        //check if verbose logging has been turned on or off
        //when we update the screen, check if verbose logging has been turned on or off
        mVerboseLogging = mWifiManager.getVerboseLoggingLevel();

        switch (wifiState) {