NetworkScoreManager: Expose SCORE_FILTER_* consts

am: 16fc91a1c1

Change-Id: Ibeb6f983417da745766a50a4b06b846f92721cec
This commit is contained in:
David Su
2020-01-15 10:18:07 -08:00
committed by android-build-merger
4 changed files with 34 additions and 33 deletions

View File

@@ -4526,6 +4526,9 @@ package android.net {
field @Deprecated public static final String EXTRA_NETWORKS_TO_SCORE = "networksToScore"; field @Deprecated public static final String EXTRA_NETWORKS_TO_SCORE = "networksToScore";
field public static final String EXTRA_NEW_SCORER = "newScorer"; field public static final String EXTRA_NEW_SCORER = "newScorer";
field @Deprecated public static final String EXTRA_PACKAGE_NAME = "packageName"; field @Deprecated public static final String EXTRA_PACKAGE_NAME = "packageName";
field public static final int SCORE_FILTER_CURRENT_NETWORK = 1; // 0x1
field public static final int SCORE_FILTER_NONE = 0; // 0x0
field public static final int SCORE_FILTER_SCAN_RESULTS = 2; // 0x2
} }
public static interface NetworkScoreManager.NetworkScoreCallback { public static interface NetworkScoreManager.NetworkScoreCallback {

View File

@@ -163,27 +163,26 @@ public class NetworkScoreManager {
public static final String EXTRA_NEW_SCORER = "newScorer"; public static final String EXTRA_NEW_SCORER = "newScorer";
/** @hide */ /** @hide */
@IntDef({CACHE_FILTER_NONE, CACHE_FILTER_CURRENT_NETWORK, CACHE_FILTER_SCAN_RESULTS}) @IntDef({SCORE_FILTER_NONE, SCORE_FILTER_CURRENT_NETWORK, SCORE_FILTER_SCAN_RESULTS})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface CacheUpdateFilter {} public @interface ScoreUpdateFilter {}
/** /**
* Do not filter updates sent to the cache. * Do not filter updates sent to the {@link NetworkScoreCallback}].
* @hide
*/ */
public static final int CACHE_FILTER_NONE = 0; public static final int SCORE_FILTER_NONE = 0;
/** /**
* Only send cache updates when the network matches the connected network. * Only send updates to the {@link NetworkScoreCallback} when the network matches the connected
* @hide * network.
*/ */
public static final int CACHE_FILTER_CURRENT_NETWORK = 1; public static final int SCORE_FILTER_CURRENT_NETWORK = 1;
/** /**
* Only send cache updates when the network is part of the current scan result set. * Only send updates to the {@link NetworkScoreCallback} when the network is part of the
* @hide * current scan result set.
*/ */
public static final int CACHE_FILTER_SCAN_RESULTS = 2; public static final int SCORE_FILTER_SCAN_RESULTS = 2;
/** @hide */ /** @hide */
@IntDef({RECOMMENDATIONS_ENABLED_FORCED_OFF, RECOMMENDATIONS_ENABLED_OFF, @IntDef({RECOMMENDATIONS_ENABLED_FORCED_OFF, RECOMMENDATIONS_ENABLED_OFF,
@@ -404,13 +403,13 @@ public class NetworkScoreManager {
* @throws SecurityException if the caller does not hold the * @throws SecurityException if the caller does not hold the
* {@link permission#REQUEST_NETWORK_SCORES} permission. * {@link permission#REQUEST_NETWORK_SCORES} permission.
* @throws IllegalArgumentException if a score cache is already registered for this type. * @throws IllegalArgumentException if a score cache is already registered for this type.
* @deprecated equivalent to registering for cache updates with CACHE_FILTER_NONE. * @deprecated equivalent to registering for cache updates with {@link #SCORE_FILTER_NONE}.
* @hide * @hide
*/ */
@RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES) @RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES)
@Deprecated // migrate to registerNetworkScoreCache(int, INetworkScoreCache, int) @Deprecated // migrate to registerNetworkScoreCache(int, INetworkScoreCache, int)
public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) { public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) {
registerNetworkScoreCache(networkType, scoreCache, CACHE_FILTER_NONE); registerNetworkScoreCache(networkType, scoreCache, SCORE_FILTER_NONE);
} }
/** /**
@@ -418,7 +417,7 @@ public class NetworkScoreManager {
* *
* @param networkType the type of network this cache can handle. See {@link NetworkKey#type} * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}
* @param scoreCache implementation of {@link INetworkScoreCache} to store the scores * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores
* @param filterType the {@link CacheUpdateFilter} to apply * @param filterType the {@link ScoreUpdateFilter} to apply
* @throws SecurityException if the caller does not hold the * @throws SecurityException if the caller does not hold the
* {@link permission#REQUEST_NETWORK_SCORES} permission. * {@link permission#REQUEST_NETWORK_SCORES} permission.
* @throws IllegalArgumentException if a score cache is already registered for this type. * @throws IllegalArgumentException if a score cache is already registered for this type.
@@ -426,7 +425,7 @@ public class NetworkScoreManager {
*/ */
@RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES) @RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES)
public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache, public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache,
@CacheUpdateFilter int filterType) { @ScoreUpdateFilter int filterType) {
try { try {
mService.registerNetworkScoreCache(networkType, scoreCache, filterType); mService.registerNetworkScoreCache(networkType, scoreCache, filterType);
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -510,7 +509,7 @@ public class NetworkScoreManager {
* Register a network score callback. * Register a network score callback.
* *
* @param networkType the type of network this cache can handle. See {@link NetworkKey#type} * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}
* @param filterType the {@link CacheUpdateFilter} to apply * @param filterType the {@link ScoreUpdateFilter} to apply
* @param callback implementation of {@link NetworkScoreCallback} that will be invoked when the * @param callback implementation of {@link NetworkScoreCallback} that will be invoked when the
* scores change. * scores change.
* @param executor The executor on which to execute the callbacks. * @param executor The executor on which to execute the callbacks.
@@ -522,7 +521,7 @@ public class NetworkScoreManager {
@SystemApi @SystemApi
@RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES) @RequiresPermission(android.Manifest.permission.REQUEST_NETWORK_SCORES)
public void registerNetworkScoreCallback(@NetworkKey.NetworkType int networkType, public void registerNetworkScoreCallback(@NetworkKey.NetworkType int networkType,
@CacheUpdateFilter int filterType, @ScoreUpdateFilter int filterType,
@NonNull @CallbackExecutor Executor executor, @NonNull @CallbackExecutor Executor executor,
@NonNull NetworkScoreCallback callback) throws SecurityException { @NonNull NetworkScoreCallback callback) throws SecurityException {
if (callback == null || executor == null) { if (callback == null || executor == null) {

View File

@@ -54,7 +54,6 @@ import android.provider.Settings.Global;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.IntArray;
import android.util.Log; import android.util.Log;
import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy;
@@ -527,7 +526,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
@Override @Override
public void accept(INetworkScoreCache networkScoreCache, Object cookie) { public void accept(INetworkScoreCache networkScoreCache, Object cookie) {
int filterType = NetworkScoreManager.CACHE_FILTER_NONE; int filterType = NetworkScoreManager.SCORE_FILTER_NONE;
if (cookie instanceof Integer) { if (cookie instanceof Integer) {
filterType = (Integer) cookie; filterType = (Integer) cookie;
} }
@@ -551,17 +550,17 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
private List<ScoredNetwork> filterScores(List<ScoredNetwork> scoredNetworkList, private List<ScoredNetwork> filterScores(List<ScoredNetwork> scoredNetworkList,
int filterType) { int filterType) {
switch (filterType) { switch (filterType) {
case NetworkScoreManager.CACHE_FILTER_NONE: case NetworkScoreManager.SCORE_FILTER_NONE:
return scoredNetworkList; return scoredNetworkList;
case NetworkScoreManager.CACHE_FILTER_CURRENT_NETWORK: case NetworkScoreManager.SCORE_FILTER_CURRENT_NETWORK:
if (mCurrentNetworkFilter == null) { if (mCurrentNetworkFilter == null) {
mCurrentNetworkFilter = mCurrentNetworkFilter =
new CurrentNetworkScoreCacheFilter(new WifiInfoSupplier(mContext)); new CurrentNetworkScoreCacheFilter(new WifiInfoSupplier(mContext));
} }
return mCurrentNetworkFilter.apply(scoredNetworkList); return mCurrentNetworkFilter.apply(scoredNetworkList);
case NetworkScoreManager.CACHE_FILTER_SCAN_RESULTS: case NetworkScoreManager.SCORE_FILTER_SCAN_RESULTS:
if (mScanResultsFilter == null) { if (mScanResultsFilter == null) {
mScanResultsFilter = new ScanResultsScoreCacheFilter( mScanResultsFilter = new ScanResultsScoreCacheFilter(
new ScanResultsSupplier(mContext)); new ScanResultsSupplier(mContext));

View File

@@ -16,7 +16,7 @@
package com.android.server; package com.android.server;
import static android.net.NetworkScoreManager.CACHE_FILTER_NONE; import static android.net.NetworkScoreManager.SCORE_FILTER_NONE;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertFalse;
@@ -304,7 +304,7 @@ public class NetworkScoreServiceTest {
bindToScorer(true /*callerIsScorer*/); bindToScorer(true /*callerIsScorer*/);
mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI,
mNetworkScoreCache, CACHE_FILTER_NONE); mNetworkScoreCache, SCORE_FILTER_NONE);
mNetworkScoreService.updateScores(new ScoredNetwork[]{SCORED_NETWORK}); mNetworkScoreService.updateScores(new ScoredNetwork[]{SCORED_NETWORK});
@@ -319,9 +319,9 @@ public class NetworkScoreServiceTest {
bindToScorer(true /*callerIsScorer*/); bindToScorer(true /*callerIsScorer*/);
mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI,
mNetworkScoreCache, CACHE_FILTER_NONE); mNetworkScoreCache, SCORE_FILTER_NONE);
mNetworkScoreService.registerNetworkScoreCache( mNetworkScoreService.registerNetworkScoreCache(
NetworkKey.TYPE_WIFI, mNetworkScoreCache2, CACHE_FILTER_NONE); NetworkKey.TYPE_WIFI, mNetworkScoreCache2, SCORE_FILTER_NONE);
// updateScores should update both caches // updateScores should update both caches
mNetworkScoreService.updateScores(new ScoredNetwork[]{SCORED_NETWORK}); mNetworkScoreService.updateScores(new ScoredNetwork[]{SCORED_NETWORK});
@@ -376,7 +376,7 @@ public class NetworkScoreServiceTest {
bindToScorer(true /*callerIsScorer*/); bindToScorer(true /*callerIsScorer*/);
mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache, mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache,
CACHE_FILTER_NONE); SCORE_FILTER_NONE);
mNetworkScoreService.clearScores(); mNetworkScoreService.clearScores();
verify(mNetworkScoreCache).clearScores(); verify(mNetworkScoreCache).clearScores();
@@ -390,7 +390,7 @@ public class NetworkScoreServiceTest {
.thenReturn(PackageManager.PERMISSION_GRANTED); .thenReturn(PackageManager.PERMISSION_GRANTED);
mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache, mNetworkScoreService.registerNetworkScoreCache(NetworkKey.TYPE_WIFI, mNetworkScoreCache,
CACHE_FILTER_NONE); SCORE_FILTER_NONE);
mNetworkScoreService.clearScores(); mNetworkScoreService.clearScores();
verify(mNetworkScoreCache).clearScores(); verify(mNetworkScoreCache).clearScores();
@@ -470,7 +470,7 @@ public class NetworkScoreServiceTest {
try { try {
mNetworkScoreService.registerNetworkScoreCache( mNetworkScoreService.registerNetworkScoreCache(
NetworkKey.TYPE_WIFI, mNetworkScoreCache, CACHE_FILTER_NONE); NetworkKey.TYPE_WIFI, mNetworkScoreCache, SCORE_FILTER_NONE);
fail("SecurityException expected"); fail("SecurityException expected");
} catch (SecurityException e) { } catch (SecurityException e) {
// expected // expected
@@ -613,7 +613,7 @@ public class NetworkScoreServiceTest {
new ArrayList<>(scoredNetworkList), new ArrayList<>(scoredNetworkList),
NetworkKey.TYPE_WIFI, mCurrentNetworkFilter, mScanResultsFilter); NetworkKey.TYPE_WIFI, mCurrentNetworkFilter, mScanResultsFilter);
consumer.accept(mNetworkScoreCache, NetworkScoreManager.CACHE_FILTER_NONE); consumer.accept(mNetworkScoreCache, NetworkScoreManager.SCORE_FILTER_NONE);
verify(mNetworkScoreCache).updateScores(scoredNetworkList); verify(mNetworkScoreCache).updateScores(scoredNetworkList);
verifyZeroInteractions(mCurrentNetworkFilter, mScanResultsFilter); verifyZeroInteractions(mCurrentNetworkFilter, mScanResultsFilter);
@@ -654,7 +654,7 @@ public class NetworkScoreServiceTest {
Collections.emptyList(), Collections.emptyList(),
NetworkKey.TYPE_WIFI, mCurrentNetworkFilter, mScanResultsFilter); NetworkKey.TYPE_WIFI, mCurrentNetworkFilter, mScanResultsFilter);
consumer.accept(mNetworkScoreCache, NetworkScoreManager.CACHE_FILTER_NONE); consumer.accept(mNetworkScoreCache, NetworkScoreManager.SCORE_FILTER_NONE);
verifyZeroInteractions(mNetworkScoreCache, mCurrentNetworkFilter, mScanResultsFilter); verifyZeroInteractions(mNetworkScoreCache, mCurrentNetworkFilter, mScanResultsFilter);
} }
@@ -671,7 +671,7 @@ public class NetworkScoreServiceTest {
List<ScoredNetwork> filteredList = new ArrayList<>(scoredNetworkList); List<ScoredNetwork> filteredList = new ArrayList<>(scoredNetworkList);
filteredList.remove(SCORED_NETWORK); filteredList.remove(SCORED_NETWORK);
when(mCurrentNetworkFilter.apply(scoredNetworkList)).thenReturn(filteredList); when(mCurrentNetworkFilter.apply(scoredNetworkList)).thenReturn(filteredList);
consumer.accept(mNetworkScoreCache, NetworkScoreManager.CACHE_FILTER_CURRENT_NETWORK); consumer.accept(mNetworkScoreCache, NetworkScoreManager.SCORE_FILTER_CURRENT_NETWORK);
verify(mNetworkScoreCache).updateScores(filteredList); verify(mNetworkScoreCache).updateScores(filteredList);
verifyZeroInteractions(mScanResultsFilter); verifyZeroInteractions(mScanResultsFilter);
@@ -689,7 +689,7 @@ public class NetworkScoreServiceTest {
List<ScoredNetwork> filteredList = new ArrayList<>(scoredNetworkList); List<ScoredNetwork> filteredList = new ArrayList<>(scoredNetworkList);
filteredList.remove(SCORED_NETWORK); filteredList.remove(SCORED_NETWORK);
when(mScanResultsFilter.apply(scoredNetworkList)).thenReturn(filteredList); when(mScanResultsFilter.apply(scoredNetworkList)).thenReturn(filteredList);
consumer.accept(mNetworkScoreCache, NetworkScoreManager.CACHE_FILTER_SCAN_RESULTS); consumer.accept(mNetworkScoreCache, NetworkScoreManager.SCORE_FILTER_SCAN_RESULTS);
verify(mNetworkScoreCache).updateScores(filteredList); verify(mNetworkScoreCache).updateScores(filteredList);
verifyZeroInteractions(mCurrentNetworkFilter); verifyZeroInteractions(mCurrentNetworkFilter);