package android.net;
import android.annotation.SystemApi;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@SystemApi
public abstract class NetworkRecommendationProvider {
private static final String TAG = "NetworkRecProvider";
+ private static final boolean VERBOSE = Build.IS_DEBUGGABLE && Log.isLoggable(TAG, Log.VERBOSE);
/** The key into the callback Bundle where the RecommendationResult will be found. */
public static final String EXTRA_RECOMMENDATION_RESULT =
"android.net.extra.RECOMMENDATION_RESULT";
* @param result a {@link RecommendationResult} instance.
*/
public void onResult(RecommendationResult result) {
+ if (VERBOSE) Log.v(TAG, "onResult(seq=" + mSequence + ")");
if (!mCallbackRun.compareAndSet(false, true)) {
- throw new IllegalStateException("The callback cannot be run more than once.");
+ throw new IllegalStateException("The callback cannot be run more than once. "
+ + "seq=" + mSequence);
}
final Bundle data = new Bundle();
data.putInt(EXTRA_SEQUENCE, mSequence);
} catch (RemoteException e) {
Log.w(TAG, "Callback failed for seq: " + mSequence, e);
}
+ if (VERBOSE) Log.v(TAG, "onResult() complete. seq=" + mSequence);
}
@Override
@Override
public void requestRecommendation(final RecommendationRequest request,
final IRemoteCallback callback, final int sequence) throws RemoteException {
+ if (VERBOSE) Log.v(TAG, "requestRecommendation(seq=" + sequence + ")");
mHandler.post(new Runnable() {
@Override
public void run() {
+ if (VERBOSE) {
+ Log.v(TAG, "requestRecommendation(seq=" + sequence + ") running...");
+ }
ResultCallback resultCallback = new ResultCallback(callback, sequence);
onRequestRecommendation(request, resultCallback);
}
return;
}
writer.println("Current scorer: " + currentScorer);
+ writer.println("RecommendationRequestTimeoutMs: " + mRecommendationRequestTimeoutMs);
sendCacheUpdateCallback(new BiConsumer<INetworkScoreCache, Object>() {
@Override
final RecommendationResult result =
data.getParcelable(EXTRA_RECOMMENDATION_RESULT);
final int sequence = data.getInt(EXTRA_SEQUENCE, -1);
+ if (VERBOSE) Log.v(TAG, "callback received for sequence " + sequence);
onRemoteMethodResult(result, sequence);
}
};
RecommendationResult getRecommendationResult(INetworkRecommendationProvider target,
RecommendationRequest request) throws RemoteException, TimeoutException {
final int sequence = onBeforeRemoteCall();
+ if (VERBOSE) Log.v(TAG, "getRecommendationResult() seq=" + sequence);
target.requestRecommendation(request, mCallback, sequence);
return getResultTimed(sequence);
}