Merge "API for network cache subsystems."
This commit is contained in:
committed by
Android (Google) Code Review
commit
4cd4110f20
43
core/java/android/net/INetworkScoreCache.aidl
Normal file
43
core/java/android/net/INetworkScoreCache.aidl
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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 android.net;
|
||||
|
||||
import android.net.ScoredNetwork;
|
||||
|
||||
/**
|
||||
* A service which stores a subset of scored networks from the active network scorer.
|
||||
*
|
||||
* <p>To be implemented by network subsystems (e.g. Wi-Fi). NetworkScoreService will propagate
|
||||
* scores down to each subsystem depending on the network type. Implementations may register for
|
||||
* a given network type by calling NetworkScoreManager.registerNetworkSubsystem.
|
||||
*
|
||||
* <p>A proper implementation should throw SecurityException whenever the caller is not privileged.
|
||||
* It may request scores by calling NetworkScoreManager#requestScores(NetworkKey[]); a call to
|
||||
* updateScores may follow but may not depending on the active scorer's implementation, and in
|
||||
* general this method may be called at any time.
|
||||
*
|
||||
* <p>Implementations should also override dump() so that "adb shell dumpsys network_score" includes
|
||||
* the current scores for each network for debugging purposes.
|
||||
* @hide
|
||||
*/
|
||||
interface INetworkScoreCache
|
||||
{
|
||||
void updateScores(in List<ScoredNetwork> networks);
|
||||
|
||||
void clearScores();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.net;
|
||||
|
||||
import android.net.INetworkScoreCache;
|
||||
import android.net.ScoredNetwork;
|
||||
|
||||
/**
|
||||
@@ -34,8 +35,7 @@ interface INetworkScoreService
|
||||
/**
|
||||
* Clear all scores.
|
||||
* @return whether the clear was successful.
|
||||
* @throws SecurityException if the caller is neither the current active scorer nor the scorer
|
||||
* manager.
|
||||
* @throws SecurityException if the caller is neither the current active scorer nor the system.
|
||||
*/
|
||||
boolean clearScores();
|
||||
|
||||
@@ -43,7 +43,19 @@ interface INetworkScoreService
|
||||
* Set the active scorer and clear existing scores.
|
||||
* @param packageName the package name of the new scorer to use.
|
||||
* @return true if the operation succeeded, or false if the new package is not a valid scorer.
|
||||
* @throws SecurityException if the caller is not the scorer manager.
|
||||
* @throws SecurityException if the caller is not the system.
|
||||
*/
|
||||
boolean setActiveScorer(in String packageName);
|
||||
|
||||
/**
|
||||
* Register a network subsystem for scoring.
|
||||
*
|
||||
* @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
|
||||
* @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
|
||||
* @throws SecurityException if the caller is not the system.
|
||||
* @throws IllegalArgumentException if a score cache is already registed for this type.
|
||||
* @hide
|
||||
*/
|
||||
void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package android.net;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
@@ -101,7 +102,7 @@ public class NetworkScoreManager {
|
||||
* determine the current scorer and offer the user the ability to select a different scorer via
|
||||
* the {@link #ACTION_CHANGE_ACTIVE} intent.
|
||||
* @return the full package name of the current active scorer, or null if there is no active
|
||||
* scorer.
|
||||
* scorer.
|
||||
*/
|
||||
public String getActiveScorerPackage() {
|
||||
return NetworkScorerAppManager.getActiveScorer(mContext);
|
||||
@@ -151,8 +152,8 @@ public class NetworkScoreManager {
|
||||
*
|
||||
* @return true if the operation succeeded, or false if the new package is not a valid scorer.
|
||||
* @throws SecurityException if the caller does not hold the
|
||||
* {@link android.Manifest.permission#BROADCAST_SCORE_NETWORKS} permission indicating that
|
||||
* it can manage scorer applications.
|
||||
* {@link android.Manifest.permission#BROADCAST_SCORE_NETWORKS} permission indicating
|
||||
* that it can manage scorer applications.
|
||||
* @hide
|
||||
*/
|
||||
public boolean setActiveScorer(String packageName) throws SecurityException {
|
||||
@@ -162,4 +163,44 @@ public class NetworkScoreManager {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request scoring for networks.
|
||||
*
|
||||
* <p>Note that this is just a helper method to assemble the broadcast, and will run in the
|
||||
* calling process.
|
||||
*
|
||||
* @return true if the broadcast was sent, or false if there is no active scorer.
|
||||
* @throws SecurityException if the caller does not hold the
|
||||
* {@link android.Manifest.permission#BROADCAST_SCORE_NETWORKS} permission.
|
||||
* @hide
|
||||
*/
|
||||
public boolean requestScores(NetworkKey[] networks) throws SecurityException {
|
||||
String activeScorer = getActiveScorerPackage();
|
||||
if (activeScorer == null) {
|
||||
return false;
|
||||
}
|
||||
Intent intent = new Intent(ACTION_SCORE_NETWORKS);
|
||||
intent.setPackage(activeScorer);
|
||||
intent.putExtra(EXTRA_NETWORKS_TO_SCORE, networks);
|
||||
mContext.sendBroadcast(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a network score cache.
|
||||
*
|
||||
* @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
|
||||
* @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
|
||||
* @throws SecurityException if the caller does not hold the
|
||||
* {@link android.Manifest.permission#BROADCAST_SCORE_NETWORKS} permission.
|
||||
* @throws IllegalArgumentException if a score cache is already registered for this type.
|
||||
* @hide
|
||||
*/
|
||||
public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) {
|
||||
try {
|
||||
mService.registerNetworkScoreCache(networkType, scoreCache);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,27 @@ public class RssiCurve implements Parcelable {
|
||||
out.writeByteArray(rssiBuckets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup the score for a given RSSI value.
|
||||
*
|
||||
* @param rssi The RSSI to lookup. If the RSSI falls below the start of the curve, the score at
|
||||
* the start of the curve will be returned. If it falls after the end of the curve, the
|
||||
* score at the end of the curve will be returned.
|
||||
* @return the score for the given RSSI.
|
||||
*/
|
||||
public byte lookupScore(int rssi) {
|
||||
int index = (rssi - start) / bucketWidth;
|
||||
|
||||
// Snap the index to the closest bucket if it falls outside the curve.
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
} else if (index > rssiBuckets.length - 1) {
|
||||
index = rssiBuckets.length - 1;
|
||||
}
|
||||
|
||||
return rssiBuckets[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if two RSSI curves are defined in the same way.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user