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

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

Merge changes I34ef76ec,Icf686c3d

* changes:
  Notify VcnStatusCallback#onVcnStatusChanged for Safe Mode.
  Define VcnStatusCallback#onVcnStatusChanged.
parents f8ab9c89 7458bf88
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -17,8 +17,9 @@
package android.net.vcn;

/** @hide */
interface IVcnStatusCallback {
oneway interface IVcnStatusCallback {
    void onEnteredSafeMode();
    void onVcnStatusChanged(int statusCode);
    void onGatewayConnectionError(
            in int[] gatewayNetworkCapabilities,
            int errorCode,
+72 −1
Original line number Diff line number Diff line
@@ -346,6 +346,56 @@ public class VcnManager {
                policy.isTeardownRequested(), policy.getMergedNetworkCapabilities());
    }

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
        VCN_STATUS_CODE_NOT_CONFIGURED,
        VCN_STATUS_CODE_INACTIVE,
        VCN_STATUS_CODE_ACTIVE,
        VCN_STATUS_CODE_SAFE_MODE
    })
    public @interface VcnStatusCode {}

    /**
     * Value indicating that the VCN for the subscription group is not configured, or that the
     * callback is not privileged for the subscription group.
     *
     * @hide
     */
    public static final int VCN_STATUS_CODE_NOT_CONFIGURED = 0;

    /**
     * Value indicating that the VCN for the subscription group is inactive.
     *
     * <p>A VCN is inactive if a {@link VcnConfig} is present for the subscription group, but the
     * provisioning package is not privileged.
     *
     * @hide
     */
    public static final int VCN_STATUS_CODE_INACTIVE = 1;

    /**
     * Value indicating that the VCN for the subscription group is active.
     *
     * <p>A VCN is active if a {@link VcnConfig} is present for the subscription, the provisioning
     * package is privileged, and the VCN is not in Safe Mode. In other words, a VCN is considered
     * active while it is connecting, fully connected, and disconnecting.
     *
     * @hide
     */
    public static final int VCN_STATUS_CODE_ACTIVE = 2;

    /**
     * Value indicating that the VCN for the subscription group is in Safe Mode.
     *
     * <p>A VCN will be put into Safe Mode if any of the gateway connections were unable to
     * establish a connection within a system-determined timeout (while underlying networks were
     * available).
     *
     * @hide
     */
    public static final int VCN_STATUS_CODE_SAFE_MODE = 3;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
@@ -403,8 +453,18 @@ public class VcnManager {
         *
         * <p>A VCN-configuring app may opt to exit safe mode by (re)setting the VCN configuration
         * via {@link #setVcnConfig(ParcelUuid, VcnConfig)}.
         *
         * @hide
         */
        public void onEnteredSafeMode() {}

        /**
         * Invoked when status of the VCN for this callback's subscription group changes.
         *
         * @param statusCode the code for the status change encountered by this {@link
         *     VcnStatusCallback}'s subscription group.
         */
        public abstract void onEnteredSafeMode();
        public abstract void onVcnStatusChanged(@VcnStatusCode int statusCode);

        /**
         * Invoked when a VCN Gateway Connection corresponding to this callback's subscription
@@ -436,6 +496,11 @@ public class VcnManager {
     * <p>A {@link VcnStatusCallback} will only be invoked if the registering package has carrier
     * privileges for the specified subscription at the time of invocation.
     *
     * <p>{@link VcnStatusCallback#onVcnStatusChanged(int)} will be invoked on registration with the
     * current status for the specified subscription group's VCN. If the registrant is not
     * privileged for this subscription group, {@link #VCN_STATUS_CODE_NOT_CONFIGURED} will be
     * returned.
     *
     * @param subscriptionGroup The subscription group to match for callbacks
     * @param executor The {@link Executor} to be used for invoking callbacks
     * @param callback The VcnStatusCallback to be registered
@@ -539,6 +604,12 @@ public class VcnManager {
                    () -> mExecutor.execute(() -> mCallback.onEnteredSafeMode()));
        }

        @Override
        public void onVcnStatusChanged(@VcnStatusCode int statusCode) {
            Binder.withCleanCallingIdentity(
                    () -> mExecutor.execute(() -> mCallback.onVcnStatusChanged(statusCode)));
        }

        // TODO(b/180521637): use ServiceSpecificException for safer Exception 'parceling'
        @Override
        public void onGatewayConnectionError(
+6 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server;

import static android.net.vcn.VcnManager.VCN_STATUS_CODE_SAFE_MODE;

import static com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot;
import static com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionTrackerCallback;

@@ -837,7 +839,10 @@ public class VcnManagementService extends IVcnManagementService.Stub {
                // Notify all registered StatusCallbacks for this subGroup
                for (VcnStatusCallbackInfo cbInfo : mRegisteredStatusCallbacks.values()) {
                    if (isCallbackPermissioned(cbInfo)) {
                        Binder.withCleanCallingIdentity(() -> cbInfo.mCallback.onEnteredSafeMode());
                        Binder.withCleanCallingIdentity(
                                () ->
                                        cbInfo.mCallback.onVcnStatusChanged(
                                                VCN_STATUS_CODE_SAFE_MODE));
                    }
                }
            }
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.net.vcn;

import static android.net.vcn.VcnManager.VCN_STATUS_CODE_ACTIVE;

import static androidx.test.InstrumentationRegistry.getContext;

import static org.junit.Assert.assertEquals;
@@ -204,6 +206,9 @@ public class VcnManagerTest {
        cbBinder.onEnteredSafeMode();
        verify(mMockStatusCallback).onEnteredSafeMode();

        cbBinder.onVcnStatusChanged(VCN_STATUS_CODE_ACTIVE);
        verify(mMockStatusCallback).onVcnStatusChanged(VCN_STATUS_CODE_ACTIVE);

        cbBinder.onGatewayConnectionError(
                UNDERLYING_NETWORK_CAPABILITIES,
                VcnManager.VCN_ERROR_CODE_NETWORK_ERROR,
+6 −4
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -59,6 +58,7 @@ import android.net.vcn.IVcnStatusCallback;
import android.net.vcn.IVcnUnderlyingNetworkPolicyListener;
import android.net.vcn.VcnConfig;
import android.net.vcn.VcnConfigTest;
import android.net.vcn.VcnManager;
import android.net.vcn.VcnUnderlyingNetworkPolicy;
import android.net.wifi.WifiInfo;
import android.os.IBinder;
@@ -783,7 +783,7 @@ public class VcnManagementServiceTest {
                true /* hasPermissionsforSubGroup */,
                true /* hasLocationPermission */);

        verify(mMockStatusCallback, times(1)).onEnteredSafeMode();
        verify(mMockStatusCallback).onVcnStatusChanged(VcnManager.VCN_STATUS_CODE_SAFE_MODE);
    }

    @Test
@@ -795,7 +795,8 @@ public class VcnManagementServiceTest {
                false /* hasPermissionsforSubGroup */,
                true /* hasLocationPermission */);

        verify(mMockStatusCallback, never()).onEnteredSafeMode();
        verify(mMockStatusCallback, never())
                .onVcnStatusChanged(VcnManager.VCN_STATUS_CODE_SAFE_MODE);
    }

    @Test
@@ -807,7 +808,8 @@ public class VcnManagementServiceTest {
                true /* hasPermissionsforSubGroup */,
                false /* hasLocationPermission */);

        verify(mMockStatusCallback, never()).onEnteredSafeMode();
        verify(mMockStatusCallback, never())
                .onVcnStatusChanged(VcnManager.VCN_STATUS_CODE_SAFE_MODE);
    }

    @Test