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

Commit 2ab9089d authored by vandwalle's avatar vandwalle
Browse files

remember and report network score

Change-Id: Iccb2ec603bc9c0d3cf1976d0cc3f343cb1096494
parent bb1b8578
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -80,6 +80,11 @@ public abstract class NetworkAgent extends Handler {
     */
    public static final int EVENT_NETWORK_PROPERTIES_CHANGED = BASE + 3;

    /* centralize place where base network score, and network score scaling, will be
     * stored, so as we can consistently compare apple and oranges, or wifi, ethernet and LTE
     */
    public static final int WIFI_BASE_SCORE = 60;

    /**
     * Sent by the NetworkAgent to ConnectivityService to pass the current
     * network score.
+5 −1
Original line number Diff line number Diff line
@@ -34,14 +34,17 @@ public class RssiPacketCountInfo implements Parcelable {

    public int txbad;

    public int rxgood;

    public RssiPacketCountInfo() {
        rssi = txgood = txbad = 0;
        rssi = txgood = txbad = rxgood = 0;
    }

    private RssiPacketCountInfo(Parcel in) {
        rssi = in.readInt();
        txgood = in.readInt();
        txbad = in.readInt();
        rxgood = in.readInt();
    }

    @Override
@@ -49,6 +52,7 @@ public class RssiPacketCountInfo implements Parcelable {
        out.writeInt(rssi);
        out.writeInt(txgood);
        out.writeInt(txbad);
        out.writeInt(rxgood);
    }

    @Override
+95 −32
Original line number Diff line number Diff line
@@ -347,9 +347,64 @@ public class WifiConfiguration implements Parcelable {
     */
    public HashMap<String, ScanResult> scanResultCache;

    /** The Below RSSI thresholds are used to configure AutoJoin
     *  - GOOD/LOW/BAD thresholds are used so as to calculate link score
     *  - UNWANTED_SOFT are used by the blacklisting logic so as to handle the unwanted network message coming from CS
     *  - UNBLACKLIST thresholds are used so as to tweak the speed at which the network is unblacklisted (i.e. if
     *          it is seen with good RSSI, it is blacklisted faster)
     *  - INITIAL_AUTOJOIN_ATTEMPT, used to determine how close from the network we need to be before autojoin kicks in
     */
    /** @hide **/
    public static int INVALID_RSSI = -127;

    /** @hide **/
    public static int UNWANTED_BLACKLIST_SOFT_RSSI_24 = -80;

    /** @hide **/
    public static int UNWANTED_BLACKLIST_SOFT_RSSI_5 = -70;

    /** @hide **/
    public static int GOOD_RSSI_24 = -65;

    /** @hide **/
    public static int LOW_RSSI_24 = -75;

    /** @hide **/
    public static int BAD_RSSI_24 = -85;

    /** @hide **/
    public static int GOOD_RSSI_5 = -55;

    /** @hide **/
    public static int LOW_RSSI_5 = -65;

    /** @hide **/
    public static int BAD_RSSI_5 = -75;

    /** @hide **/
    public static int UNWANTED_BLACKLIST_SOFT_BUMP = 4;

    /** @hide **/
    public static int UNWANTED_BLACKLIST_HARD_BUMP = 8;

    /** @hide **/
    public static int UNBLACKLIST_THRESHOLD_24_SOFT = -75;

    /** @hide **/
    public static int UNBLACKLIST_THRESHOLD_24_HARD = -68;

    /** @hide **/
    public static int UNBLACKLIST_THRESHOLD_5_SOFT = -63;

    /** @hide **/
    public static int UNBLACKLIST_THRESHOLD_5_HARD = -56;

    /** @hide **/
    public static int INITIAL_AUTO_JOIN_ATTEMPT_MIN_24 = -80;

    /** @hide **/
    public static int INITIAL_AUTO_JOIN_ATTEMPT_MIN_5 = -70;

    /**
     * @hide
     * A summary of the RSSI and Band status for that configuration
@@ -456,7 +511,7 @@ public class WifiConfiguration implements Parcelable {

    /** @hide */
    public static final int AUTO_JOIN_ENABLED                   = 0;
    /** @hide
    /**
     * if this is set, the WifiConfiguration cannot use linkages so as to bump
     * it's relative priority.
     * - status between and 128 indicate various level of blacklisting depending
@@ -465,7 +520,17 @@ public class WifiConfiguration implements Parcelable {
     * although it may have been self added we will not re-self-add it, ignore it,
     * not return it to applications, and not connect to it
     * */

    /** @hide
     * network was temporary disabled due to bad connection, most likely due
     * to weak RSSI */
    public static final int AUTO_JOIN_TEMPORARY_DISABLED  = 1;
    /** @hide
     * network was temporary disabled due to bad connection, which cant be attributed
     * to weak RSSI */
    public static final int AUTO_JOIN_TEMPORARY_DISABLED_LINK_ERRORS  = 32;
    /** @hide */
    public static final int AUTO_JOIN_TEMPORARY_DISABLED_AT_SUPPLICANT  = 64;
    /** @hide */
    public static final int AUTO_JOIN_DISABLED_ON_AUTH_FAILURE  = 128;
    /** @hide */
@@ -476,6 +541,13 @@ public class WifiConfiguration implements Parcelable {
     */
    public int autoJoinStatus;


    /**
     * @hide
     */
    public long blackListTimestamp;


    /**
     * Set if the configuration was self added by the framework
     * This boolean is cleared if we get a connect/save/ update or
@@ -614,6 +686,16 @@ public class WifiConfiguration implements Parcelable {
        return mostRecent;
    }

    /** @hide **/
    public void setAutoJoinStatus(int status) {
        if (status == 0) {
            blackListTimestamp = 0;
        }  else if (status > autoJoinStatus) {
            blackListTimestamp = System.currentTimeMillis();
        }
        autoJoinStatus = status;
    }

    @Override
    public String toString() {
        StringBuilder sbuf = new StringBuilder();
@@ -697,6 +779,15 @@ public class WifiConfiguration implements Parcelable {
        if (selfAdded)  sbuf.append("selfAdded");
        if (creatorUid != 0)  sbuf.append("uid=" + Integer.toString(creatorUid));

        if (blackListTimestamp != 0) {
            long now_ms = System.currentTimeMillis();
            long diff = now_ms - blackListTimestamp;
            if (diff <= 0) {
                sbuf.append("blackListed since <incorrect>");
            } else {
                sbuf.append("blackListed since ").append(Long.toString(diff/1000)).append( "sec");
            }
        }

        return sbuf.toString();
    }
@@ -987,6 +1078,7 @@ public class WifiConfiguration implements Parcelable {
            lastUpdateUid = source.lastUpdateUid;
            creatorUid = source.creatorUid;
            peerWifiConfiguration = source.peerWifiConfiguration;
            blackListTimestamp = source.blackListTimestamp;
        }
    }

@@ -1030,17 +1122,7 @@ public class WifiConfiguration implements Parcelable {
        dest.writeInt(creatorUid);
        dest.writeInt(lastConnectUid);
        dest.writeInt(lastUpdateUid);
        /*
        TODO: should we write the cache results to the parcel?
        if (scanResultCache != null) {
            dest.writeInt(WifiConfiguration.SCAN_CACHE_TAG);
            dest.writeInt(scanResultCache.size());
            for (ScanResult result : scanResultCache.values()) {
                result.writeToParcel(dest, flags);
            }
        } else {
            dest.writeInt(WifiConfiguration.NOTHING_TAG);
        }*/
        dest.writeLong(blackListTimestamp);
    }

    /** Implement the Parcelable interface {@hide} */
@@ -1079,26 +1161,7 @@ public class WifiConfiguration implements Parcelable {
                config.creatorUid = in.readInt();
                config.lastConnectUid = in.readInt();
                config.lastUpdateUid = in.readInt();
                /*
                TODO: should we write the cache results to the parcel?
                boolean done = false;
                do {
                    int tag = in.readInt();
                    switch (tag) {
                        case WifiConfiguration.SCAN_CACHE_TAG:
                            int size = in.readInt();
                            config.scanResultCache = new HashMap<String, ScanResult>();
                            while (size > 0) {
                                ScanResult result = ScanResult.CREATOR.createFromParcel(in);
                                config.scanResultCache.put(result.BSSID, result);
                                size--;
                            }
                            break;
                        case WifiConfiguration.NOTHING_TAG:
                            done = true;
                            break;
                    }
                } while (!done);*/
                config.blackListTimestamp = in.readLong();
                return config;
            }

+134 −6
Original line number Diff line number Diff line
@@ -62,20 +62,107 @@ public class WifiInfo implements Parcelable {
    private String mBSSID;
    private WifiSsid mWifiSsid;
    private int mNetworkId;
    /** Received Signal Strength Indicator */
    /**
     * Received Signal Strength Indicator
     */
    private int mRssi;

    /** Link speed in Mbps */
    /**
     * Link speed in Mbps
     */
    public static final String LINK_SPEED_UNITS = "Mbps";
    private int mLinkSpeed;

    /** Frequency in MHz */
    /**
     * Frequency in MHz
     */
    public static final String FREQUENCY_UNITS = "MHz";
    private int mFrequency;

    private InetAddress mIpAddress;
    private String mMacAddress;

    /**
     * @hide
     */
    public long txBad;
    /**
     * @hide
     */
    public long txRetries;
    /**
     * @hide
     */
    public long txSuccess;
    /**
     * @hide
     */
    public long rxSuccess;
    /**
     * @hide
     */
    public double txBadRate;
    /**
     * @hide
     */
    public double txRetriesRate;
    /**
     * @hide
     */
    public double txSuccessRate;
    /**
     * @hide
     */
    public double rxSuccessRate;

    /**
     * @hide
     */
    public int badRssiCount;

    /**
     * @hide
     */
    public int lowRssiCount;

    /**
     * @hide *
     */
    public int score;

    /**
     * @hide *
     */
    public void updatePacketRates(WifiLinkLayerStats stats) {
        if (stats != null) {
            long txgood = stats.txmpdu_be + stats.txmpdu_bk + stats.txmpdu_vi + stats.txmpdu_vo;
            long txretries = stats.retries_be + stats.retries_bk
                    + stats.retries_vi + stats.retries_vo;
            long rxgood = stats.rxmpdu_be + stats.rxmpdu_bk + stats.rxmpdu_vi + stats.rxmpdu_vo;
            long txbad = stats.lostmpdu_be + stats.lostmpdu_bk
                    + stats.lostmpdu_vi + stats.lostmpdu_vo;

            txBadRate = (txBadRate * 0.5)
                + ((double) (txbad - txBad) * 0.5);
            txSuccessRate = (txSuccessRate * 0.5)
                + ((double) (txgood - txSuccess) * 0.5);
            rxSuccessRate = (rxSuccessRate * 0.5)
                + ((double) (rxgood - rxSuccess) * 0.5);
            txRetriesRate = (txRetriesRate * 0.5)
                + ((double) (txretries - txRetries) * 0.5);

            txBad = txbad;
            txSuccess = txgood;
            rxSuccess = rxgood;
            txRetries = txretries;
        } else {
            txBadRate = 0;
            txSuccess = 0;
            rxSuccess = 0;
            txRetries = 0;
        }
    }

    /**
     * Flag indicating that AP has hinted that upstream connection is metered,
     * and sensitive to heavy data transfers.
@@ -109,6 +196,17 @@ public class WifiInfo implements Parcelable {
            mIpAddress = source.mIpAddress;
            mMacAddress = source.mMacAddress;
            mMeteredHint = source.mMeteredHint;
            txBad = source.txBad;
            txRetries = source.txRetries;
            txSuccess = source.txSuccess;
            rxSuccess = source.rxSuccess;
            txBadRate = source.txBadRate;
            txRetriesRate = source.txRetriesRate;
            txSuccessRate = source.txSuccessRate;
            rxSuccessRate = source.rxSuccessRate;
            score = source.score;
            badRssiCount = source.badRssiCount;
            lowRssiCount = source.lowRssiCount;
        }
    }

@@ -197,6 +295,22 @@ public class WifiInfo implements Parcelable {
        this.mFrequency = frequency;
    }

    /**
     * @hide
     * TODO: makes real freq boundaries
     */
    public boolean is24GHz() {
        return mFrequency < 4000;
    }

    /**
     * @hide
     * TODO: makes real freq boundaries
     */
    public boolean is5GHz() {
        return mFrequency > 4000;
    }

    /**
     * Record the MAC address of the WLAN interface
     * @param macAddress the MAC address in {@code XX:XX:XX:XX:XX:XX} form
@@ -325,8 +439,8 @@ public class WifiInfo implements Parcelable {
            append(", Link speed: ").append(mLinkSpeed).append(LINK_SPEED_UNITS).
            append(", Frequency: ").append(mFrequency).append(FREQUENCY_UNITS).
            append(", Net ID: ").append(mNetworkId).
            append(", Metered hint: ").append(mMeteredHint);

            append(", Metered hint: ").append(mMeteredHint).
            append(", score: ").append(Integer.toString(score));
        return sb.toString();
    }

@@ -356,6 +470,13 @@ public class WifiInfo implements Parcelable {
        dest.writeString(mBSSID);
        dest.writeString(mMacAddress);
        dest.writeInt(mMeteredHint ? 1 : 0);
        dest.writeInt(score);
        dest.writeDouble(txSuccessRate);
        dest.writeDouble(txRetriesRate);
        dest.writeDouble(txBadRate);
        dest.writeDouble(rxSuccessRate);
        dest.writeInt(badRssiCount);
        dest.writeInt(lowRssiCount);
        mSupplicantState.writeToParcel(dest, flags);
    }

@@ -379,6 +500,13 @@ public class WifiInfo implements Parcelable {
                info.mBSSID = in.readString();
                info.mMacAddress = in.readString();
                info.mMeteredHint = in.readInt() != 0;
                info.score = in.readInt();
                info.txSuccessRate = in.readDouble();
                info.txRetriesRate = in.readDouble();
                info.txBadRate = in.readDouble();
                info.rxSuccessRate = in.readDouble();
                info.badRssiCount = in.readInt();
                info.lowRssiCount = in.readInt();
                info.mSupplicantState = SupplicantState.CREATOR.createFromParcel(in);
                return info;
            }
+2 −0
Original line number Diff line number Diff line
@@ -111,6 +111,8 @@ public class WifiLinkLayerStats implements Parcelable {
    /** {@hide} */
    public String toString() {
        StringBuilder sbuf = new StringBuilder();
        sbuf.append(" WifiLinkLayerStats: ").append('\n');

        if (this.SSID != null) {
            sbuf.append(" SSID: ").append(this.SSID).append('\n');
        }