[NS04.7] Reinstate a necessary change

NS04.5 removed a security that it shouldn't have. Reinstate it.

Bug: 167544279
Test: ConnectivityServiceTest
Change-Id: If614da813a96d1b50a16fa4be5659e1647d9469d
This commit is contained in:
Chalard Jean
2021-03-24 14:31:38 +09:00
parent f4315edf43
commit 31acbce474

View File

@@ -6467,6 +6467,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
private boolean isNetworkProviderWithIdRegistered(final int providerId) {
for (final NetworkProviderInfo npi : mNetworkProviderInfos.values()) {
if (npi.providerId == providerId) return true;
}
return false;
}
/**
* Register or update a network offer.
* @param newOffer The new offer. If the callback member is the same as an existing
@@ -6474,7 +6481,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
*/
private void handleRegisterNetworkOffer(@NonNull final NetworkOffer newOffer) {
ensureRunningOnConnectivityServiceThread();
if (!isNetworkProviderWithIdRegistered(newOffer.providerId)) {
// This may actually happen if a provider updates its score or registers and then
// immediately unregisters. The offer would still be in the handler queue, but the
// provider would have been removed.
if (DBG) log("Received offer from an unregistered provider");
return;
}
final NetworkOfferInfo existingOffer = findNetworkOfferInfoByCallback(newOffer.callback);
if (null != existingOffer) {
handleUnregisterNetworkOffer(existingOffer);