import java.util.Map;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
/**
private final Context mContext;
private final NetworkScorerAppManager mNetworkScorerAppManager;
- private final RequestRecommendationCaller mRequestRecommendationCaller;
+ private final AtomicReference<RequestRecommendationCaller> mReqRecommendationCallerRef;
@GuardedBy("mScoreCaches")
private final Map<Integer, RemoteCallbackList<INetworkScoreCache>> mScoreCaches;
/** Lock used to update mPackageMonitor when scorer package changes occur. */
mContext.registerReceiverAsUser(
mUserIntentReceiver, UserHandle.SYSTEM, filter, null /* broadcastPermission*/,
null /* scheduler */);
- mRequestRecommendationCaller =
- new RequestRecommendationCaller(TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS);
+ mReqRecommendationCallerRef = new AtomicReference<>(
+ new RequestRecommendationCaller(TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS));
mRecommendationRequestTimeoutMs = TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS;
mHandler = new ServiceHandler(looper);
mContentObserver = new DispatchingContentObserver(context, mHandler);
final INetworkRecommendationProvider provider = getRecommendationProvider();
if (provider != null) {
try {
- return mRequestRecommendationCaller.getRecommendationResult(provider, request);
+ final RequestRecommendationCaller caller = mReqRecommendationCallerRef.get();
+ return caller.getRecommendationResult(provider, request);
} catch (RemoteException | TimeoutException e) {
Log.w(TAG, "Failed to request a recommendation.", e);
// TODO(jjoslin): 12/15/16 - Keep track of failures.
}
if (DBG) Log.d(TAG, "Updating the recommendation request timeout to " + timeoutMs + " ms");
mRecommendationRequestTimeoutMs = timeoutMs;
+ mReqRecommendationCallerRef.set(new RequestRecommendationCaller(timeoutMs));
}
private static class ScoringServiceConnection implements ServiceConnection {