Search in sources :

Example 1 with ScoredNetwork

use of android.net.ScoredNetwork in project platform_frameworks_base by android.

the class WifiNetworkScoreCacheTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    when(mockContext.getApplicationContext()).thenReturn(mockApplicationContext);
    mValidScoredNetwork = buildScoredNetwork(VALID_KEY, mockRssiCurve);
    mScoreCache = new WifiNetworkScoreCache(mockContext);
    initializeCacheWithValidScoredNetwork();
    HandlerThread thread = new HandlerThread("WifiNetworkScoreCacheTest Handler Thread");
    thread.start();
    mHandler = new Handler(thread.getLooper());
    mLatch = new CountDownLatch(1);
    mCacheListener = new CacheListener(mHandler) {

        @Override
        public void networkCacheUpdated(List<ScoredNetwork> updatedNetworks) {
            mUpdatedNetworksCaptor = updatedNetworks;
            mLatch.countDown();
        }
    };
}
Also used : HandlerThread(android.os.HandlerThread) ScoredNetwork(android.net.ScoredNetwork) Handler(android.os.Handler) CountDownLatch(java.util.concurrent.CountDownLatch) CacheListener(android.net.wifi.WifiNetworkScoreCache.CacheListener) Before(org.junit.Before)

Example 2 with ScoredNetwork

use of android.net.ScoredNetwork in project platform_frameworks_base by android.

the class WifiNetworkScoreCache method getNetworkScore.

public int getNetworkScore(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;
}
Also used : ScoredNetwork(android.net.ScoredNetwork)

Example 3 with ScoredNetwork

use of android.net.ScoredNetwork in project platform_frameworks_base by android.

the class WifiNetworkScoreCache method getNetworkScore.

public int getNetworkScore(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;
}
Also used : ScoredNetwork(android.net.ScoredNetwork)

Example 4 with ScoredNetwork

use of android.net.ScoredNetwork in project platform_frameworks_base by android.

the class WifiNetworkScoreCache method updateScores.

@Override
public final void updateScores(List<ScoredNetwork> networks) {
    if (networks == null || networks.isEmpty()) {
        return;
    }
    Log.d(TAG, "updateScores list size=" + networks.size());
    synchronized (mNetworkCache) {
        for (ScoredNetwork network : networks) {
            String networkKey = buildNetworkKey(network);
            if (networkKey == null)
                continue;
            mNetworkCache.put(networkKey, network);
        }
    }
    synchronized (mCacheLock) {
        if (mListener != null) {
            mListener.post(networks);
        }
    }
}
Also used : ScoredNetwork(android.net.ScoredNetwork)

Example 5 with ScoredNetwork

use of android.net.ScoredNetwork in project platform_frameworks_base by android.

the class WifiNetworkScoreCache method dump.

@Override
protected final void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
    mContext.enforceCallingOrSelfPermission(permission.DUMP, TAG);
    String header = String.format("WifiNetworkScoreCache (%s/%d)", mContext.getPackageName(), Process.myUid());
    writer.println(header);
    writer.println("  All score curves:");
    for (Map.Entry<String, ScoredNetwork> entry : mNetworkCache.entrySet()) {
        ScoredNetwork scoredNetwork = entry.getValue();
        writer.println("    " + entry.getKey() + ": " + scoredNetwork.rssiCurve + ", meteredHint=" + scoredNetwork.meteredHint);
    }
    writer.println("  Current network scores:");
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    for (ScanResult scanResult : wifiManager.getScanResults()) {
        writer.println("    " + buildNetworkKey(scanResult) + ": " + getNetworkScore(scanResult));
    }
}
Also used : ScoredNetwork(android.net.ScoredNetwork) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ScoredNetwork (android.net.ScoredNetwork)13 Map (java.util.Map)6 INetworkScoreCache (android.net.INetworkScoreCache)5 RemoteException (android.os.RemoteException)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 SmallTest (android.support.test.filters.SmallTest)3 Test (org.junit.Test)3 NetworkKey (android.net.NetworkKey)1 WifiKey (android.net.WifiKey)1 CacheListener (android.net.wifi.WifiNetworkScoreCache.CacheListener)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 RemoteCallbackList (android.os.RemoteCallbackList)1 ArrayMap (android.util.ArrayMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1