Search in sources :

Example 6 with ScanResult

use of android.net.wifi.ScanResult in project robolectric by robolectric.

the class ShadowScanResultTest method shouldConstruct.

@Test
public void shouldConstruct() throws Exception {
    ScanResult scanResult = ShadowScanResult.newInstance("SSID", "BSSID", "Caps", 11, 42);
    assertThat(scanResult.SSID).isEqualTo("SSID");
    assertThat(scanResult.BSSID).isEqualTo("BSSID");
    assertThat(scanResult.capabilities).isEqualTo("Caps");
    assertThat(scanResult.level).isEqualTo(11);
    assertThat(scanResult.frequency).isEqualTo(42);
    assertNotNull(shadowOf(scanResult).realObject);
}
Also used : ScanResult(android.net.wifi.ScanResult) Test(org.junit.Test)

Example 7 with ScanResult

use of android.net.wifi.ScanResult in project routerkeygenAndroid by routerkeygen.

the class WifiListAdapter method getView.

public View getView(int position, View convertView, ViewGroup parent) {
    final ScanResult wifi = getItem(position);
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.item_list_wifi, parent, false);
        convertView.setTag(new ViewHolder((TextView) convertView.findViewById(R.id.wifiName), (TextView) convertView.findViewById(R.id.wifiMAC), (ImageView) convertView.findViewById(R.id.strenght)));
    }
    final ViewHolder holder = (ViewHolder) convertView.getTag();
    holder.ssid.setText(wifi.SSID);
    holder.ssid.setTypeface(typeface);
    holder.ssid.setSelected(true);
    holder.ssid.setEllipsize(TruncateAt.MARQUEE);
    holder.mac.setText(wifi.BSSID.toUpperCase(Locale.getDefault()));
    holder.mac.setTypeface(typeface);
    holder.mac.setSelected(true);
    holder.mac.setEllipsize(TruncateAt.MARQUEE);
    final int strenght = WifiManager.calculateSignalLevel(wifi.level, 4);
    if (isLocked(wifi)) {
        holder.networkStrenght.setImageDrawable(wifiSignalLocked[strenght]);
    } else {
        holder.networkStrenght.setImageDrawable(wifiSignal[strenght]);
    }
    return convertView;
}
Also used : ScanResult(android.net.wifi.ScanResult) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 8 with ScanResult

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

the class AccessPoint method getVisibilityStatus.

/**
     * Returns the visibility status of the WifiConfiguration.
     *
     * @return autojoin debugging information
     * 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() {
    StringBuilder visibility = new StringBuilder();
    StringBuilder scans24GHz = null;
    StringBuilder scans5GHz = null;
    String bssid = null;
    long now = System.currentTimeMillis();
    if (mInfo != null) {
        bssid = mInfo.getBSSID();
        if (bssid != null) {
            visibility.append(" ").append(bssid);
        }
        visibility.append(" rssi=").append(mInfo.getRssi());
        visibility.append(" ");
        visibility.append(" score=").append(mInfo.score);
        visibility.append(String.format(" tx=%.1f,", mInfo.txSuccessRate));
        visibility.append(String.format("%.1f,", mInfo.txRetriesRate));
        visibility.append(String.format("%.1f ", mInfo.txBadRate));
        visibility.append(String.format("rx=%.1f", mInfo.rxSuccessRate));
    }
    int rssi5 = WifiConfiguration.INVALID_RSSI;
    int rssi24 = WifiConfiguration.INVALID_RSSI;
    int num5 = 0;
    int num24 = 0;
    int numBlackListed = 0;
    // Number scan results we included in the string
    int n24 = 0;
    // Number scan results we included in the string
    int n5 = 0;
    evictOldScanResults();
    // TODO: sort list by RSSI or age
    for (ScanResult result : mScanResultCache.values()) {
        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;
        }
        if (result.frequency >= LOWER_FREQ_5GHZ && result.frequency <= HIGHER_FREQ_5GHZ) {
            if (result.level > rssi5) {
                rssi5 = result.level;
            }
            if (n5 < 4) {
                if (scans5GHz == null)
                    scans5GHz = new StringBuilder();
                scans5GHz.append(" \n{").append(result.BSSID);
                if (bssid != null && result.BSSID.equals(bssid))
                    scans5GHz.append("*");
                scans5GHz.append("=").append(result.frequency);
                scans5GHz.append(",").append(result.level);
                scans5GHz.append("}");
                n5++;
            }
        } else if (result.frequency >= LOWER_FREQ_24GHZ && result.frequency <= HIGHER_FREQ_24GHZ) {
            if (result.level > rssi24) {
                rssi24 = result.level;
            }
            if (n24 < 4) {
                if (scans24GHz == null)
                    scans24GHz = new StringBuilder();
                scans24GHz.append(" \n{").append(result.BSSID);
                if (bssid != null && result.BSSID.equals(bssid))
                    scans24GHz.append("*");
                scans24GHz.append("=").append(result.frequency);
                scans24GHz.append(",").append(result.level);
                scans24GHz.append("}");
                n24++;
            }
        }
    }
    visibility.append(" [");
    if (num24 > 0) {
        visibility.append("(").append(num24).append(")");
        if (n24 <= 4) {
            if (scans24GHz != null) {
                visibility.append(scans24GHz.toString());
            }
        } else {
            visibility.append("max=").append(rssi24);
            if (scans24GHz != null) {
                visibility.append(",").append(scans24GHz.toString());
            }
        }
    }
    visibility.append(";");
    if (num5 > 0) {
        visibility.append("(").append(num5).append(")");
        if (n5 <= 4) {
            if (scans5GHz != null) {
                visibility.append(scans5GHz.toString());
            }
        } else {
            visibility.append("max=").append(rssi5);
            if (scans5GHz != null) {
                visibility.append(",").append(scans5GHz.toString());
            }
        }
    }
    if (numBlackListed > 0)
        visibility.append("!").append(numBlackListed);
    visibility.append("]");
    return visibility.toString();
}
Also used : ScanResult(android.net.wifi.ScanResult) SpannableString(android.text.SpannableString)

Example 9 with ScanResult

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

the class AccessPoint method getRssi.

public int getRssi() {
    evictOldScanResults();
    int rssi = Integer.MIN_VALUE;
    for (ScanResult result : mScanResultCache.values()) {
        if (result.level > rssi) {
            rssi = result.level;
        }
    }
    return rssi;
}
Also used : ScanResult(android.net.wifi.ScanResult)

Example 10 with ScanResult

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

the class AccessPoint method getSeen.

public long getSeen() {
    evictOldScanResults();
    long seen = 0;
    for (ScanResult result : mScanResultCache.values()) {
        if (result.timestamp > seen) {
            seen = result.timestamp;
        }
    }
    return seen;
}
Also used : ScanResult(android.net.wifi.ScanResult)

Aggregations

ScanResult (android.net.wifi.ScanResult)75 WifiConfiguration (android.net.wifi.WifiConfiguration)27 ArrayList (java.util.ArrayList)27 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 WifiManager (android.net.wifi.WifiManager)7 WifiInfo (android.net.wifi.WifiInfo)6 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Bundle (android.os.Bundle)5 SpannableString (android.text.SpannableString)5 DhcpInfo (android.net.DhcpInfo)1 NetworkInfo (android.net.NetworkInfo)1 Parcelable (android.os.Parcelable)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 TelephonyManager (android.telephony.TelephonyManager)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1