Notify policy listeners when VCN subIds change.

This CL updates VcnManagementService to notify policy listeners
when the subIds for any VCN instances change. This is necessary to
ensure that NetworkFactories properly update their Networks in the
event that a Network comes up under an existing VCN are properly
marked as VCN-managed.

Bug: 187112989
Test: atest FrameworksVcnTests CtsVcnTestCases
Change-Id: Iecab1226119c8fd876131c381647267f18339db2
This commit is contained in:
Cody Kesting
2021-05-03 15:18:08 -07:00
parent 2e67798711
commit 2225648d47
2 changed files with 45 additions and 0 deletions

View File

@@ -87,6 +87,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
@@ -431,6 +432,7 @@ public class VcnManagementService extends IVcnManagementService.Stub {
public void onNewSnapshot(@NonNull TelephonySubscriptionSnapshot snapshot) {
// Startup VCN instances
synchronized (mLock) {
final TelephonySubscriptionSnapshot oldSnapshot = mLastSnapshot;
mLastSnapshot = snapshot;
// Start any VCN instances as necessary
@@ -478,10 +480,28 @@ public class VcnManagementService extends IVcnManagementService.Stub {
entry.getValue().updateSubscriptionSnapshot(mLastSnapshot);
}
}
final Map<ParcelUuid, Set<Integer>> oldSubGrpMappings =
getSubGroupToSubIdMappings(oldSnapshot);
final Map<ParcelUuid, Set<Integer>> currSubGrpMappings =
getSubGroupToSubIdMappings(mLastSnapshot);
if (!currSubGrpMappings.equals(oldSubGrpMappings)) {
notifyAllPolicyListenersLocked();
}
}
}
}
@GuardedBy("mLock")
private Map<ParcelUuid, Set<Integer>> getSubGroupToSubIdMappings(
@NonNull TelephonySubscriptionSnapshot snapshot) {
final Map<ParcelUuid, Set<Integer>> subGrpMappings = new ArrayMap<>();
for (ParcelUuid subGrp : mVcns.keySet()) {
subGrpMappings.put(subGrp, snapshot.getAllSubIdsInGroup(subGrp));
}
return subGrpMappings;
}
@GuardedBy("mLock")
private void stopVcnLocked(@NonNull ParcelUuid uuidToTeardown) {
final Vcn vcnToTeardown = mVcns.remove(uuidToTeardown);

View File

@@ -77,6 +77,7 @@ import android.os.test.TestLooper;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.ArraySet;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -98,6 +99,7 @@ import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
@@ -326,6 +328,17 @@ public class VcnManagementServiceTest {
return subIdToGroupMap.get(invocation.getArgument(0));
}).when(snapshot).getGroupForSubId(anyInt());
doAnswer(invocation -> {
final ParcelUuid subGrp = invocation.getArgument(0);
final Set<Integer> subIds = new ArraySet<>();
for (Entry<Integer, ParcelUuid> entry : subIdToGroupMap.entrySet()) {
if (entry.getValue().equals(subGrp)) {
subIds.add(entry.getKey());
}
}
return subIds;
}).when(snapshot).getAllSubIdsInGroup(any());
final TelephonySubscriptionTrackerCallback cb = getTelephonySubscriptionTrackerCallback();
cb.onNewSnapshot(snapshot);
@@ -914,6 +927,18 @@ public class VcnManagementServiceTest {
verify(mMockPolicyListener).onPolicyChanged();
}
@Test
public void testVcnSubIdChangeUpdatesPolicyListener() throws Exception {
startAndGetVcnInstance(TEST_UUID_2);
mVcnMgmtSvc.addVcnUnderlyingNetworkPolicyListener(mMockPolicyListener);
triggerSubscriptionTrackerCbAndGetSnapshot(
Collections.singleton(TEST_UUID_2),
Collections.singletonMap(TEST_SUBSCRIPTION_ID, TEST_UUID_2));
verify(mMockPolicyListener).onPolicyChanged();
}
private void triggerVcnSafeMode(
@NonNull ParcelUuid subGroup,
@NonNull TelephonySubscriptionSnapshot snapshot,