[NS A26] Move available callbacks out of the rematch computation
Bug: 113554781 Test: ConnectivityServiceTest Change-Id: I3a804a9f6eaf50a3995eaaf6469a1c2b9387be14
This commit is contained in:
@@ -6323,12 +6323,34 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class RequestReassignment {
|
||||||
|
@NonNull public final NetworkRequestInfo mRequest;
|
||||||
|
@Nullable public final NetworkAgentInfo mOldNetwork;
|
||||||
|
@Nullable public final NetworkAgentInfo mNewNetwork;
|
||||||
|
RequestReassignment(@NonNull final NetworkRequestInfo request,
|
||||||
|
@Nullable final NetworkAgentInfo oldNetwork,
|
||||||
|
@Nullable final NetworkAgentInfo newNetwork) {
|
||||||
|
mRequest = request;
|
||||||
|
mOldNetwork = oldNetwork;
|
||||||
|
mNewNetwork = newNetwork;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull private final Set<NetworkBgStatePair> mRematchedNetworks = new ArraySet<>();
|
@NonNull private final Set<NetworkBgStatePair> mRematchedNetworks = new ArraySet<>();
|
||||||
|
@NonNull private final List<RequestReassignment> mReassignments = new ArrayList<>();
|
||||||
|
|
||||||
@NonNull Iterable<NetworkBgStatePair> getRematchedNetworks() {
|
@NonNull Iterable<NetworkBgStatePair> getRematchedNetworks() {
|
||||||
return mRematchedNetworks;
|
return mRematchedNetworks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull Iterable<RequestReassignment> getRequestReassignments() {
|
||||||
|
return mReassignments;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addRequestReassignment(@NonNull final RequestReassignment reassignment) {
|
||||||
|
mReassignments.add(reassignment);
|
||||||
|
}
|
||||||
|
|
||||||
void addRematchedNetwork(@NonNull final NetworkBgStatePair network) {
|
void addRematchedNetwork(@NonNull final NetworkBgStatePair network) {
|
||||||
mRematchedNetworks.add(network);
|
mRematchedNetworks.add(network);
|
||||||
}
|
}
|
||||||
@@ -6417,7 +6439,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// Find and migrate to this Network any NetworkRequests for
|
// Find and migrate to this Network any NetworkRequests for
|
||||||
// which this network is now the best.
|
// which this network is now the best.
|
||||||
final ArrayList<NetworkAgentInfo> removedRequests = new ArrayList<>();
|
final ArrayList<NetworkAgentInfo> removedRequests = new ArrayList<>();
|
||||||
final ArrayList<NetworkRequestInfo> addedRequests = new ArrayList<>();
|
|
||||||
for (final Map.Entry<NetworkRequestInfo, NetworkAgentInfo> entry :
|
for (final Map.Entry<NetworkRequestInfo, NetworkAgentInfo> entry :
|
||||||
reassignedRequests.entrySet()) {
|
reassignedRequests.entrySet()) {
|
||||||
final NetworkRequestInfo nri = entry.getKey();
|
final NetworkRequestInfo nri = entry.getKey();
|
||||||
@@ -6440,7 +6461,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (!newSatisfier.addRequest(nri.request)) {
|
if (!newSatisfier.addRequest(nri.request)) {
|
||||||
Slog.wtf(TAG, "BUG: " + newSatisfier.name() + " already has " + nri.request);
|
Slog.wtf(TAG, "BUG: " + newSatisfier.name() + " already has " + nri.request);
|
||||||
}
|
}
|
||||||
addedRequests.add(nri);
|
changes.addRequestReassignment(new NetworkReassignment.RequestReassignment(
|
||||||
|
nri, previousSatisfier, newSatisfier));
|
||||||
// Tell NetworkProviders about the new score, so they can stop
|
// Tell NetworkProviders about the new score, so they can stop
|
||||||
// trying to connect if they know they cannot match it.
|
// trying to connect if they know they cannot match it.
|
||||||
// TODO - this could get expensive if we have a lot of requests for this
|
// TODO - this could get expensive if we have a lot of requests for this
|
||||||
@@ -6508,10 +6530,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
"BUG: %s changed score during rematch: %d -> %d",
|
"BUG: %s changed score during rematch: %d -> %d",
|
||||||
newNetwork.name(), score, newNetwork.getCurrentScore()));
|
newNetwork.name(), score, newNetwork.getCurrentScore()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify requested networks are available after the default net is switched, but
|
|
||||||
// before LegacyTypeTracker sends legacy broadcasts
|
|
||||||
for (NetworkRequestInfo nri : addedRequests) notifyNetworkAvailable(newNetwork, nri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6540,6 +6558,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
final NetworkAgentInfo newDefaultNetwork = getDefaultNetwork();
|
final NetworkAgentInfo newDefaultNetwork = getDefaultNetwork();
|
||||||
|
|
||||||
|
// Notify requested networks are available after the default net is switched, but
|
||||||
|
// before LegacyTypeTracker sends legacy broadcasts
|
||||||
|
for (final NetworkReassignment.RequestReassignment event :
|
||||||
|
changes.getRequestReassignments()) {
|
||||||
|
if (null != event.mNewNetwork) {
|
||||||
|
notifyNetworkAvailable(event.mNewNetwork, event.mRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (final NetworkReassignment.NetworkBgStatePair event : changes.getRematchedNetworks()) {
|
for (final NetworkReassignment.NetworkBgStatePair event : changes.getRematchedNetworks()) {
|
||||||
// Process listen requests and update capabilities if the background state has
|
// Process listen requests and update capabilities if the background state has
|
||||||
// changed for this network. For consistency with previous behavior, send onLost
|
// changed for this network. For consistency with previous behavior, send onLost
|
||||||
|
|||||||
Reference in New Issue
Block a user