FileDocCategorySizeDatePackage
WifiNetworkScoreCache.javaAPI DocAndroid 5.1 API6512Thu Mar 12 22:22:52 GMT 2015com.android.server.wifi

WifiNetworkScoreCache

public class WifiNetworkScoreCache extends INetworkScoreCache.Stub

Fields Summary
public static int
INVALID_NETWORK_SCORE
private static String
TAG
private boolean
DBG
private final android.content.Context
mContext
private final Map
mNetworkCache
Constructors Summary
public WifiNetworkScoreCache(android.content.Context context)


       
        mContext = context;
        mNetworkCache = new HashMap<String, ScoredNetwork>();
    
Methods Summary
private java.lang.StringbuildNetworkKey(android.net.wifi.ScanResult result)

        if (result.SSID == null) {
            return null;
        }
        StringBuilder key = new StringBuilder("\"");
        key.append(result.SSID);
        key.append("\"");
        if (result.BSSID != null) {
            key.append(result.BSSID);
        }
        return key.toString();
    
private java.lang.StringbuildNetworkKey(android.net.ScoredNetwork network)

        if (network.networkKey == null) return null;
        if (network.networkKey.wifiKey == null) return null;
        if (network.networkKey.type == NetworkKey.TYPE_WIFI) {
            String key = network.networkKey.wifiKey.ssid;
            if (key == null) return null;
            if (network.networkKey.wifiKey.bssid != null) {
                key = key + network.networkKey.wifiKey.bssid;
            }
            return key;
        }
        return null;
    
public final voidclearScores()

         synchronized (mNetworkCache) {
             mNetworkCache.clear();
         }
     
protected final voiddump(java.io.FileDescriptor fd, java.io.PrintWriter writer, java.lang.String[] args)

        mContext.enforceCallingOrSelfPermission(permission.DUMP, TAG);
        writer.println("WifiNetworkScoreCache");
        writer.println("  All score curves:");
        for (Map.Entry<String, ScoredNetwork> entry : mNetworkCache.entrySet()) {
            writer.println("    " + entry.getKey() + ": " + entry.getValue().rssiCurve);
        }
        writer.println("  Current network scores:");
        WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
        for (ScanResult scanResult : wifiManager.getScanResults()) {
            writer.println("    " + buildNetworkKey(scanResult) + ": " + getNetworkScore(scanResult));
        }
    
public intgetNetworkScore(android.net.wifi.ScanResult result)


        int score = INVALID_NETWORK_SCORE;

        ScoredNetwork network = getScoredNetwork(result);
        if (network != null && network.rssiCurve != null) {
            score = network.rssiCurve.lookupScore(result.level);
            if (DBG) {
                Log.e(TAG, "getNetworkScore found scored network " + network.networkKey
                        + " score " + Integer.toString(score)
                        + " RSSI " + result.level);
            }
        }
        return score;
    
public intgetNetworkScore(android.net.wifi.ScanResult result, boolean isActiveNetwork)


        int score = INVALID_NETWORK_SCORE;

        ScoredNetwork network = getScoredNetwork(result);
        if (network != null && network.rssiCurve != null) {
            score = network.rssiCurve.lookupScore(result.level, isActiveNetwork);
            if (DBG) {
                Log.e(TAG, "getNetworkScore found scored network " + network.networkKey
                        + " score " + Integer.toString(score)
                        + " RSSI " + result.level
                        + " isActiveNetwork " + isActiveNetwork);
            }
        }
        return score;
    
private android.net.ScoredNetworkgetScoredNetwork(android.net.wifi.ScanResult result)

        String key = buildNetworkKey(result);
        if (key == null) return null;

        //find it
        synchronized(mNetworkCache) {
            ScoredNetwork network = mNetworkCache.get(key);
            return network;
        }
    
public booleanhasScoreCurve(android.net.wifi.ScanResult result)
Returns whether there is a non-null score curve for the given ScanResult. A null score curve has special meaning - we should never connect to an ephemeral network if the score curve is null.

        ScoredNetwork network = getScoredNetwork(result);
        return network != null && network.rssiCurve != null;
    
public booleanisScoredNetwork(android.net.wifi.ScanResult result)
Returns whether there is any score info for the given ScanResult. This includes null-score info, so it should only be used when determining whether to request scores from the network scorer.

        return getScoredNetwork(result) != null;
    
public final voidupdateScores(java.util.List networks)

        if (networks == null) {
            return;
        }
        Log.e(TAG, "updateScores list size=" + networks.size());

        synchronized(mNetworkCache) {
            for (ScoredNetwork network : networks) {
                String networkKey = buildNetworkKey(network);
                if (networkKey == null) continue;
                mNetworkCache.put(networkKey, network);
            }
        }