Search in sources :

Example 6 with ScoredNetwork

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

the class WifiNetworkScoreCacheTest method getMeteredHintShouldReturnTrue.

@Test
public void getMeteredHintShouldReturnTrue() {
    ScoredNetwork network = new ScoredNetwork(new NetworkKey(VALID_KEY), mockRssiCurve, true);
    mScoreCache.updateScores(ImmutableList.of(network));
    assertTrue(mScoreCache.getMeteredHint(VALID_SCAN_RESULT));
}
Also used : NetworkKey(android.net.NetworkKey) ScoredNetwork(android.net.ScoredNetwork) SmallTest(android.support.test.filters.SmallTest) Test(org.junit.Test)

Example 7 with ScoredNetwork

use of android.net.ScoredNetwork in project android_frameworks_base by crdroidandroid.

the class NetworkScoreService method updateScores.

@Override
public boolean updateScores(ScoredNetwork[] networks) {
    if (!NetworkScorerAppManager.isCallerActiveScorer(mContext, getCallingUid())) {
        throw new SecurityException("Caller with UID " + getCallingUid() + " is not the active scorer.");
    }
    // Separate networks by type.
    Map<Integer, List<ScoredNetwork>> networksByType = new HashMap<>();
    for (ScoredNetwork network : networks) {
        List<ScoredNetwork> networkList = networksByType.get(network.networkKey.type);
        if (networkList == null) {
            networkList = new ArrayList<>();
            networksByType.put(network.networkKey.type, networkList);
        }
        networkList.add(network);
    }
    // Pass the scores of each type down to the appropriate network scorer.
    for (Map.Entry<Integer, List<ScoredNetwork>> entry : networksByType.entrySet()) {
        INetworkScoreCache scoreCache = mScoreCaches.get(entry.getKey());
        if (scoreCache != null) {
            try {
                scoreCache.updateScores(entry.getValue());
            } catch (RemoteException e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "Unable to update scores of type " + entry.getKey(), e);
                }
            }
        } else if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "No scorer registered for type " + entry.getKey() + ", discarding");
        }
    }
    return true;
}
Also used : INetworkScoreCache(android.net.INetworkScoreCache) HashMap(java.util.HashMap) ScoredNetwork(android.net.ScoredNetwork) ArrayList(java.util.ArrayList) List(java.util.List) RemoteException(android.os.RemoteException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with ScoredNetwork

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

the class WifiNetworkScoreCacheTest method updateScoresShouldAddNewNetwork.

@Test
public void updateScoresShouldAddNewNetwork() {
    WifiKey key2 = new WifiKey("\"ssid2\"", BSSID);
    ScoredNetwork network2 = buildScoredNetwork(key2, mockRssiCurve);
    ScanResult result2 = buildScanResult("ssid2", BSSID);
    mScoreCache.updateScores(ImmutableList.of(network2));
    assertTrue(mScoreCache.isScoredNetwork(VALID_SCAN_RESULT));
    assertTrue(mScoreCache.isScoredNetwork(result2));
}
Also used : WifiKey(android.net.WifiKey) ScoredNetwork(android.net.ScoredNetwork) SmallTest(android.support.test.filters.SmallTest) Test(org.junit.Test)

Example 9 with ScoredNetwork

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

the class WifiNetworkScoreCacheTest method hasScoreCurveShouldReturnFalseWhenScoredNetworkHasNoCurve.

@Test
public void hasScoreCurveShouldReturnFalseWhenScoredNetworkHasNoCurve() {
    ScoredNetwork noCurve = buildScoredNetwork(VALID_KEY, null);
    mScoreCache.updateScores(ImmutableList.of(noCurve));
    assertFalse(mScoreCache.hasScoreCurve(VALID_SCAN_RESULT));
}
Also used : ScoredNetwork(android.net.ScoredNetwork) SmallTest(android.support.test.filters.SmallTest) Test(org.junit.Test)

Example 10 with ScoredNetwork

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

the class NetworkScoreService method updateScores.

@Override
public boolean updateScores(ScoredNetwork[] networks) {
    if (!isCallerActiveScorer(getCallingUid())) {
        throw new SecurityException("Caller with UID " + getCallingUid() + " is not the active scorer.");
    }
    final long token = Binder.clearCallingIdentity();
    try {
        // Separate networks by type.
        Map<Integer, List<ScoredNetwork>> networksByType = new ArrayMap<>();
        for (ScoredNetwork network : networks) {
            List<ScoredNetwork> networkList = networksByType.get(network.networkKey.type);
            if (networkList == null) {
                networkList = new ArrayList<>();
                networksByType.put(network.networkKey.type, networkList);
            }
            networkList.add(network);
        }
        // Pass the scores of each type down to the appropriate network scorer.
        for (final Map.Entry<Integer, List<ScoredNetwork>> entry : networksByType.entrySet()) {
            final RemoteCallbackList<INetworkScoreCache> callbackList;
            final boolean isEmpty;
            synchronized (mScoreCaches) {
                callbackList = mScoreCaches.get(entry.getKey());
                isEmpty = callbackList == null || callbackList.getRegisteredCallbackCount() == 0;
            }
            if (isEmpty) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "No scorer registered for type " + entry.getKey() + ", discarding");
                }
                continue;
            }
            sendCallback(new Consumer<INetworkScoreCache>() {

                @Override
                public void accept(INetworkScoreCache networkScoreCache) {
                    try {
                        networkScoreCache.updateScores(entry.getValue());
                    } catch (RemoteException e) {
                        if (Log.isLoggable(TAG, Log.VERBOSE)) {
                            Log.v(TAG, "Unable to update scores of type " + entry.getKey(), e);
                        }
                    }
                }
            }, Collections.singleton(callbackList));
        }
        return true;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : INetworkScoreCache(android.net.INetworkScoreCache) ScoredNetwork(android.net.ScoredNetwork) ArrayMap(android.util.ArrayMap) RemoteCallbackList(android.os.RemoteCallbackList) List(java.util.List) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException) Map(java.util.Map) ArrayMap(android.util.ArrayMap)

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