diff options
author | Sundeep Ghuman <sghuman@google.com> | 2016-12-05 13:58:18 -0800 |
---|---|---|
committer | Sundeep Ghuman <sghuman@google.com> | 2016-12-12 16:17:32 -0800 |
commit | c8701c8ad058ec7fa69a2e3c60495f27708bced5 (patch) | |
tree | 0dd5a2adbd7a9ff4aed308bf0fb138816e3a56ec | |
parent | d0258ee4816148ff4ab9ac6b854fc5c51ea53be3 (diff) |
Remove old WifiNetworkScoreCache.java
Updates references to this file to use the score cache defined in
frameworks/base.
Bug: 33050254
Test: Compiles successfully
Change-Id: Id8b3eed40c3f0005fa289e0a2ae67297b4e4434f
Topic: WifiNetworkScoreCacheMove
8 files changed, 7 insertions, 192 deletions
diff --git a/service/java/com/android/server/wifi/ExternalScoreEvaluator.java b/service/java/com/android/server/wifi/ExternalScoreEvaluator.java index ec0d46bea..5bac8ac5d 100644 --- a/service/java/com/android/server/wifi/ExternalScoreEvaluator.java +++ b/service/java/com/android/server/wifi/ExternalScoreEvaluator.java @@ -23,6 +23,7 @@ import android.net.NetworkScoreManager; import android.net.WifiKey; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiNetworkScoreCache; import android.os.Process; import android.text.TextUtils; import android.util.LocalLog; diff --git a/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java b/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java index 840c5bba3..95f17b364 100644 --- a/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java @@ -23,6 +23,7 @@ import android.net.RecommendationResult; import android.net.WifiKey; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiNetworkScoreCache; import android.util.LocalLog; import android.util.Pair; diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 4742c1299..37d8aa024 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -24,6 +24,7 @@ import android.net.wifi.IWifiScanner; import android.net.wifi.IWificond; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; +import android.net.wifi.WifiNetworkScoreCache; import android.net.wifi.WifiScanner; import android.os.HandlerThread; import android.os.IBinder; diff --git a/service/java/com/android/server/wifi/WifiNetworkScoreCache.java b/service/java/com/android/server/wifi/WifiNetworkScoreCache.java deleted file mode 100644 index ed3793579..000000000 --- a/service/java/com/android/server/wifi/WifiNetworkScoreCache.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.wifi; - -import android.Manifest.permission; -import android.content.Context; -import android.net.INetworkScoreCache; -import android.net.NetworkKey; -import android.net.ScoredNetwork; -import android.net.wifi.ScanResult; -import android.net.wifi.WifiManager; -import android.util.Log; - -import java.io.FileDescriptor; -import java.io.PrintWriter; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class WifiNetworkScoreCache extends INetworkScoreCache.Stub { - private static final String TAG = "WifiNetworkScoreCache"; - private static final boolean DBG = false; - - // A Network scorer returns a score in the range [-128, +127] - // We treat the lowest possible score as though there were no score, effectively allowing the - // scorer to provide an RSSI threshold below which a network should not be used. - public static final int INVALID_NETWORK_SCORE = Byte.MIN_VALUE; - private final Context mContext; - - // The key is of the form "<ssid>"<bssid> - // TODO: What about SSIDs that can't be encoded as UTF-8? - private final Map<String, ScoredNetwork> mNetworkCache; - - public WifiNetworkScoreCache(Context context) { - mContext = context; - mNetworkCache = new HashMap<String, ScoredNetwork>(); - } - - @Override public final void updateScores(List<android.net.ScoredNetwork> 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); - } - } - } - - @Override public final void clearScores() { - synchronized (mNetworkCache) { - mNetworkCache.clear(); - } - } - - /** - * 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. - */ - public boolean isScoredNetwork(ScanResult result) { - return getScoredNetwork(result) != null; - } - - /** - * 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. - */ - public boolean hasScoreCurve(ScanResult result) { - ScoredNetwork network = getScoredNetwork(result); - return network != null && network.rssiCurve != null; - } - - 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; - } - - /** - * Returns the ScoredNetwork metered hint for a given ScanResult. - * - * If there is no ScoredNetwork associated with the ScanResult then false will be returned. - */ - public boolean getMeteredHint(ScanResult result) { - ScoredNetwork network = getScoredNetwork(result); - return network != null && network.meteredHint; - } - - 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; - } - - private ScoredNetwork getScoredNetwork(ScanResult result) { - String key = buildNetworkKey(result); - if (key == null) return null; - - //find it - synchronized(mNetworkCache) { - ScoredNetwork network = mNetworkCache.get(key); - return network; - } - } - - private String buildNetworkKey(ScoredNetwork network) { - if (network == null || 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; - } - - private String buildNetworkKey(ScanResult result) { - if (result == null || 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(); - } - - @Override protected final void dump(FileDescriptor fd, PrintWriter writer, String[] args) { - mContext.enforceCallingOrSelfPermission(permission.DUMP, TAG); - writer.println("WifiNetworkScoreCache"); - 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)); - } - } - -} diff --git a/tests/wifitests/src/com/android/server/wifi/ExternalScoreEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/ExternalScoreEvaluatorTest.java index 238930d1b..2829f0170 100644 --- a/tests/wifitests/src/com/android/server/wifi/ExternalScoreEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ExternalScoreEvaluatorTest.java @@ -27,6 +27,7 @@ import android.content.res.Resources; import android.net.NetworkScoreManager; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiNetworkScoreCache; import android.os.SystemClock; import android.test.suitebuilder.annotation.SmallTest; diff --git a/tests/wifitests/src/com/android/server/wifi/RecommendedNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/RecommendedNetworkEvaluatorTest.java index 97614ae30..6c7b18255 100644 --- a/tests/wifitests/src/com/android/server/wifi/RecommendedNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/RecommendedNetworkEvaluatorTest.java @@ -31,6 +31,7 @@ import android.net.RecommendationRequest; import android.net.RecommendationResult; import android.net.WifiKey; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiNetworkScoreCache; import android.net.wifi.WifiSsid; import android.test.suitebuilder.annotation.SmallTest; import android.util.LocalLog; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index f70c09b16..56af3fbb9 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -32,6 +32,7 @@ import android.net.wifi.ScanResult.InformationElement; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; +import android.net.wifi.WifiNetworkScoreCache; import android.net.wifi.WifiScanner; import android.net.wifi.WifiScanner.PnoScanListener; import android.net.wifi.WifiScanner.PnoSettings; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java index 16f5e0c34..865344506 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java @@ -29,6 +29,7 @@ import android.net.WifiKey; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; +import android.net.wifi.WifiNetworkScoreCache; import android.net.wifi.WifiSsid; import android.test.suitebuilder.annotation.SmallTest; import android.text.TextUtils; |