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

Commit 5f65a440 authored by Cody Kesting's avatar Cody Kesting
Browse files

Specify if a VCN is in 'test-mode' in VcnContext.

This CL updates VcnContext to include whether the VCN instance
it is created for is in test-mode (as specified by the VcnConfig).
This also changes the lifetime of VcnContext to be created uniquely
for each VCN instance (as opposed to a single VcnContext created in
VcnManagementService and used for all VCNs).

Bug: 182291467
Test: atest FrameworksVcnTests CtsVcnTestCases
Change-Id: I6fc6a266bf67ab2aa64202153c3c109ee98a16ca
parent fd57083e
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -167,7 +167,6 @@ public class VcnManagementService extends IVcnManagementService.Stub {
    @NonNull private final VcnNetworkProvider mNetworkProvider;
    @NonNull private final TelephonySubscriptionTrackerCallback mTelephonySubscriptionTrackerCb;
    @NonNull private final TelephonySubscriptionTracker mTelephonySubscriptionTracker;
    @NonNull private final VcnContext mVcnContext;
    @NonNull private final BroadcastReceiver mPkgChangeReceiver;

    @NonNull
@@ -212,7 +211,6 @@ public class VcnManagementService extends IVcnManagementService.Stub {
                mContext, mLooper, mTelephonySubscriptionTrackerCb);

        mConfigDiskRwHelper = mDeps.newPersistableBundleLockingReadWriteHelper(VCN_CONFIG_FILE);
        mVcnContext = mDeps.newVcnContext(mContext, mLooper, mNetworkProvider);

        mPkgChangeReceiver = new BroadcastReceiver() {
            @Override
@@ -336,8 +334,9 @@ public class VcnManagementService extends IVcnManagementService.Stub {
        public VcnContext newVcnContext(
                @NonNull Context context,
                @NonNull Looper looper,
                @NonNull VcnNetworkProvider vcnNetworkProvider) {
            return new VcnContext(context, looper, vcnNetworkProvider);
                @NonNull VcnNetworkProvider vcnNetworkProvider,
                boolean getIsInTestMode) {
            return new VcnContext(context, looper, vcnNetworkProvider, getIsInTestMode);
        }

        /** Creates a new Vcn instance using the provided configuration */
@@ -551,8 +550,11 @@ public class VcnManagementService extends IVcnManagementService.Stub {

        final VcnCallbackImpl vcnCallback = new VcnCallbackImpl(subscriptionGroup);

        final VcnContext vcnContext =
                mDeps.newVcnContext(
                        mContext, mLooper, mNetworkProvider, config.isTestModeProfile());
        final Vcn newInstance =
                mDeps.newVcn(mVcnContext, subscriptionGroup, config, mLastSnapshot, vcnCallback);
                mDeps.newVcn(vcnContext, subscriptionGroup, config, mLastSnapshot, vcnCallback);
        mVcns.put(subscriptionGroup, newInstance);

        // Now that a new VCN has started, notify all registered listeners to refresh their
+8 −1
Original line number Diff line number Diff line
@@ -31,14 +31,17 @@ public class VcnContext {
    @NonNull private final Context mContext;
    @NonNull private final Looper mLooper;
    @NonNull private final VcnNetworkProvider mVcnNetworkProvider;
    private final boolean mIsInTestMode;

    public VcnContext(
            @NonNull Context context,
            @NonNull Looper looper,
            @NonNull VcnNetworkProvider vcnNetworkProvider) {
            @NonNull VcnNetworkProvider vcnNetworkProvider,
            boolean isInTestMode) {
        mContext = Objects.requireNonNull(context, "Missing context");
        mLooper = Objects.requireNonNull(looper, "Missing looper");
        mVcnNetworkProvider = Objects.requireNonNull(vcnNetworkProvider, "Missing networkProvider");
        mIsInTestMode = isInTestMode;
    }

    @NonNull
@@ -56,6 +59,10 @@ public class VcnContext {
        return mVcnNetworkProvider;
    }

    public boolean isInTestMode() {
        return mIsInTestMode;
    }

    /**
     * Verifies that the caller is running on the VcnContext Thread.
     *
+9 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
@@ -198,7 +199,8 @@ public class VcnManagementServiceTest {
                .newVcnContext(
                        eq(mMockContext),
                        eq(mTestLooper.getLooper()),
                        any(VcnNetworkProvider.class));
                        any(VcnNetworkProvider.class),
                        anyBoolean());
        doReturn(mSubscriptionTracker)
                .when(mMockDeps)
                .newTelephonySubscriptionTracker(
@@ -371,6 +373,12 @@ public class VcnManagementServiceTest {
    public void testTelephonyNetworkTrackerCallbackStartsInstances() throws Exception {
        TelephonySubscriptionSnapshot snapshot =
                triggerSubscriptionTrackerCbAndGetSnapshot(Collections.singleton(TEST_UUID_1));
        verify(mMockDeps)
                .newVcnContext(
                        eq(mMockContext),
                        eq(mTestLooper.getLooper()),
                        any(VcnNetworkProvider.class),
                        anyBoolean());
        verify(mMockDeps)
                .newVcn(eq(mVcnContext), eq(TEST_UUID_1), eq(TEST_VCN_CONFIG), eq(snapshot), any());
    }
+7 −1
Original line number Diff line number Diff line
@@ -112,7 +112,13 @@ public class UnderlyingNetworkTrackerTest {
        MockitoAnnotations.initMocks(this);

        mTestLooper = new TestLooper();
        mVcnContext = spy(new VcnContext(mContext, mTestLooper.getLooper(), mVcnNetworkProvider));
        mVcnContext =
                spy(
                        new VcnContext(
                                mContext,
                                mTestLooper.getLooper(),
                                mVcnNetworkProvider,
                                false /* isInTestMode */));
        doNothing().when(mVcnContext).ensureRunningOnLooperThread();

        setupSystemService(