Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a5786a15 authored by Cody Kesting's avatar Cody Kesting Committed by Gerrit Code Review
Browse files

Merge changes I01ffdde2,Iecab1226

* changes:
  Set NOT_VCN_MANAGED capability for Networks in VcnMgmtSvc.
  Notify policy listeners when VCN subIds change.
parents 2a46c649 5b021003
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -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,8 +480,26 @@ 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")
@@ -815,6 +835,8 @@ public class VcnManagementService extends IVcnManagementService.Stub {
            if (isVcnManagedNetwork) {
                ncBuilder.removeCapability(
                        NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED);
            } else {
                ncBuilder.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED);
            }

            if (isRestrictedCarrierWifi) {
+25 −0
Original line number Diff line number Diff line
@@ -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,