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();
}
};
}
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;
}
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;
}
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);
}
}
}
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));
}
}
Aggregations