Merge "Add an IPC for requesting network scores." am: e89ed4a001
am: 724b26c902
Change-Id: If6284c934cd47257367c614523d4928758ab34e1
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.net;
|
||||
|
||||
import android.net.NetworkKey;
|
||||
import android.net.RecommendationRequest;
|
||||
import android.os.IRemoteCallback;
|
||||
|
||||
@@ -38,4 +39,15 @@ oneway interface INetworkRecommendationProvider {
|
||||
void requestRecommendation(in RecommendationRequest request,
|
||||
in IRemoteCallback callback,
|
||||
int sequence);
|
||||
|
||||
/**
|
||||
* Request scoring for networks.
|
||||
*
|
||||
* Implementations should use {@link NetworkScoreManager#updateScores(ScoredNetwork[])} to
|
||||
* respond to score requests.
|
||||
*
|
||||
* @param networks an array of {@link NetworkKey}s to score
|
||||
* @hide
|
||||
*/
|
||||
void requestScores(in NetworkKey[] networks);
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.net;
|
||||
|
||||
import android.net.INetworkScoreCache;
|
||||
import android.net.NetworkKey;
|
||||
import android.net.RecommendationRequest;
|
||||
import android.net.RecommendationResult;
|
||||
import android.net.ScoredNetwork;
|
||||
@@ -87,4 +88,16 @@ interface INetworkScoreService
|
||||
*/
|
||||
RecommendationResult requestRecommendation(in RecommendationRequest request);
|
||||
|
||||
/**
|
||||
* Request scoring for networks.
|
||||
*
|
||||
* Implementations should delegate to the registered network recommendation provider or
|
||||
* fulfill the request locally if possible.
|
||||
*
|
||||
* @param networks an array of {@link NetworkKey}s to score
|
||||
* @return true if the request was delegated or fulfilled locally, false otherwise
|
||||
* @throws SecurityException if the caller is not the system
|
||||
* @hide
|
||||
*/
|
||||
boolean requestScores(in NetworkKey[] networks);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,15 @@ public abstract class NetworkRecommendationProvider {
|
||||
public abstract void onRequestRecommendation(RecommendationRequest request,
|
||||
ResultCallback callback);
|
||||
|
||||
/**
|
||||
* Invoked when network scores have been requested.
|
||||
* <p>
|
||||
* Use {@link NetworkScoreManager#updateScores(ScoredNetwork[])} to respond to score requests.
|
||||
*
|
||||
* @param networks a non-empty array of {@link NetworkKey}s to score.
|
||||
*/
|
||||
public abstract void onRequestScores(NetworkKey[] networks);
|
||||
|
||||
/**
|
||||
* Services that can handle {@link NetworkScoreManager#ACTION_RECOMMEND_NETWORKS} should
|
||||
* return this Binder from their <code>onBind()</code> method.
|
||||
@@ -118,6 +127,7 @@ public abstract class NetworkRecommendationProvider {
|
||||
|
||||
private final class ServiceHandler extends Handler {
|
||||
static final int MSG_GET_RECOMMENDATION = 1;
|
||||
static final int MSG_REQUEST_SCORES = 2;
|
||||
|
||||
ServiceHandler(Looper looper) {
|
||||
super(looper, null /*callback*/, true /*async*/);
|
||||
@@ -136,6 +146,11 @@ public abstract class NetworkRecommendationProvider {
|
||||
onRequestRecommendation(request, resultCallback);
|
||||
break;
|
||||
|
||||
case MSG_REQUEST_SCORES:
|
||||
final NetworkKey[] networks = (NetworkKey[]) msg.obj;
|
||||
onRequestScores(networks);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown message: " + what);
|
||||
}
|
||||
@@ -162,5 +177,12 @@ public abstract class NetworkRecommendationProvider {
|
||||
msg.setData(data);
|
||||
msg.sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestScores(NetworkKey[] networks) throws RemoteException {
|
||||
if (networks != null && networks.length > 0) {
|
||||
mHandler.obtainMessage(ServiceHandler.MSG_REQUEST_SCORES, networks).sendToTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user