Merge "Replace the RequestRecommendationCaller if the timeout changes."
This commit is contained in:
@@ -75,6 +75,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +88,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final NetworkScorerAppManager mNetworkScorerAppManager;
|
private final NetworkScorerAppManager mNetworkScorerAppManager;
|
||||||
private final RequestRecommendationCaller mRequestRecommendationCaller;
|
private final AtomicReference<RequestRecommendationCaller> mReqRecommendationCallerRef;
|
||||||
@GuardedBy("mScoreCaches")
|
@GuardedBy("mScoreCaches")
|
||||||
private final Map<Integer, RemoteCallbackList<INetworkScoreCache>> mScoreCaches;
|
private final Map<Integer, RemoteCallbackList<INetworkScoreCache>> mScoreCaches;
|
||||||
/** Lock used to update mPackageMonitor when scorer package changes occur. */
|
/** Lock used to update mPackageMonitor when scorer package changes occur. */
|
||||||
@@ -249,8 +250,8 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
|
|||||||
mContext.registerReceiverAsUser(
|
mContext.registerReceiverAsUser(
|
||||||
mUserIntentReceiver, UserHandle.SYSTEM, filter, null /* broadcastPermission*/,
|
mUserIntentReceiver, UserHandle.SYSTEM, filter, null /* broadcastPermission*/,
|
||||||
null /* scheduler */);
|
null /* scheduler */);
|
||||||
mRequestRecommendationCaller =
|
mReqRecommendationCallerRef = new AtomicReference<>(
|
||||||
new RequestRecommendationCaller(TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS);
|
new RequestRecommendationCaller(TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS));
|
||||||
mRecommendationRequestTimeoutMs = TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS;
|
mRecommendationRequestTimeoutMs = TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS;
|
||||||
mHandler = new ServiceHandler(looper);
|
mHandler = new ServiceHandler(looper);
|
||||||
mContentObserver = new DispatchingContentObserver(context, mHandler);
|
mContentObserver = new DispatchingContentObserver(context, mHandler);
|
||||||
@@ -569,7 +570,8 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
|
|||||||
final INetworkRecommendationProvider provider = getRecommendationProvider();
|
final INetworkRecommendationProvider provider = getRecommendationProvider();
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
try {
|
try {
|
||||||
return mRequestRecommendationCaller.getRecommendationResult(provider, request);
|
final RequestRecommendationCaller caller = mReqRecommendationCallerRef.get();
|
||||||
|
return caller.getRecommendationResult(provider, request);
|
||||||
} catch (RemoteException | TimeoutException e) {
|
} catch (RemoteException | TimeoutException e) {
|
||||||
Log.w(TAG, "Failed to request a recommendation.", e);
|
Log.w(TAG, "Failed to request a recommendation.", e);
|
||||||
// TODO(jjoslin): 12/15/16 - Keep track of failures.
|
// TODO(jjoslin): 12/15/16 - Keep track of failures.
|
||||||
@@ -748,6 +750,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
|
|||||||
}
|
}
|
||||||
if (DBG) Log.d(TAG, "Updating the recommendation request timeout to " + timeoutMs + " ms");
|
if (DBG) Log.d(TAG, "Updating the recommendation request timeout to " + timeoutMs + " ms");
|
||||||
mRecommendationRequestTimeoutMs = timeoutMs;
|
mRecommendationRequestTimeoutMs = timeoutMs;
|
||||||
|
mReqRecommendationCallerRef.set(new RequestRecommendationCaller(timeoutMs));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ScoringServiceConnection implements ServiceConnection {
|
private static class ScoringServiceConnection implements ServiceConnection {
|
||||||
|
|||||||
Reference in New Issue
Block a user