From 46a62378ecbc2991554fcb3ca823d877cdf12480 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 10 Dec 2019 21:25:24 +0900 Subject: [PATCH] [NS B06] Simplification This check is now unnecessary, seeing how the code adding these changes is now guaranteed to only add at most one change for each request. Test: FrameworksNetTests Change-Id: Ia0443602d9c89ee413e956df9c7b79f8f74813f7 --- .../android/server/ConnectivityService.java | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index bcac2b5036..90c38fce13 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -155,7 +155,6 @@ import android.security.Credentials; import android.security.KeyStore; import android.telephony.TelephonyManager; import android.text.TextUtils; -import android.util.ArrayMap; import android.util.ArraySet; import android.util.LocalLog; import android.util.Log; @@ -6547,37 +6546,30 @@ public class ConnectivityService extends IConnectivityManager.Stub } @NonNull private final Set mRematchedNetworks = new ArraySet<>(); - @NonNull private final Map mReassignments = - new ArrayMap<>(); + @NonNull private final ArrayList mReassignments = new ArrayList<>(); @NonNull Iterable getRematchedNetworks() { return mRematchedNetworks; } @NonNull Iterable getRequestReassignments() { - return mReassignments.values(); + return mReassignments; } void addRequestReassignment(@NonNull final RequestReassignment reassignment) { - final RequestReassignment oldChange = mReassignments.get(reassignment.mRequest); - if (null == oldChange) { - mReassignments.put(reassignment.mRequest, reassignment); - return; + if (!Build.IS_USER) { + // The code is never supposed to add two reassignments of the same request. Make + // sure this stays true, but without imposing this expensive check on all + // reassignments on all user devices. + for (final RequestReassignment existing : mReassignments) { + if (existing.mRequest.equals(reassignment.mRequest)) { + throw new IllegalStateException("Trying to reassign [" + + reassignment + "] but already have [" + + existing + "]"); + } + } } - if (oldChange.mNewNetwork != reassignment.mOldNetwork) { - throw new IllegalArgumentException("Reassignment <" + reassignment.mRequest + "> [" - + reassignment.mOldNetwork + " -> " + reassignment.mNewNetwork - + "] conflicts with [" - + oldChange.mOldNetwork + " -> " + oldChange.mNewNetwork + "]"); - } - // There was already a note to reassign this request from a network A to a network B, - // and a reassignment is added from network B to some other network C. The following - // synthesizes the merged reassignment that goes A -> C. An interesting (but not - // special) case to think about is when B is null, which can happen when the rematch - // loop notices the current satisfier doesn't satisfy the request any more, but - // hasn't yet encountered another network that could. - mReassignments.put(reassignment.mRequest, new RequestReassignment(reassignment.mRequest, - oldChange.mOldNetwork, reassignment.mNewNetwork)); + mReassignments.add(reassignment); } void addRematchedNetwork(@NonNull final NetworkBgStatePair network) {