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

Commit 1761a873 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes Icb59b15d,I6fc6a266,I5cc340e5,I94db52a8 am: b79dcb24 am: 5804521e am: 32c2d343

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1700309

Change-Id: Ifab0469fb2687cae7b361b5009abe152a35048c5
parents fa13c6c4 32c2d343
Loading
Loading
Loading
Loading
+39 −4
Original line number Original line Diff line number Diff line
@@ -52,12 +52,17 @@ public final class VcnConfig implements Parcelable {
    private static final String GATEWAY_CONNECTION_CONFIGS_KEY = "mGatewayConnectionConfigs";
    private static final String GATEWAY_CONNECTION_CONFIGS_KEY = "mGatewayConnectionConfigs";
    @NonNull private final Set<VcnGatewayConnectionConfig> mGatewayConnectionConfigs;
    @NonNull private final Set<VcnGatewayConnectionConfig> mGatewayConnectionConfigs;


    private static final String IS_TEST_MODE_PROFILE_KEY = "mIsTestModeProfile";
    private final boolean mIsTestModeProfile;

    private VcnConfig(
    private VcnConfig(
            @NonNull String packageName,
            @NonNull String packageName,
            @NonNull Set<VcnGatewayConnectionConfig> gatewayConnectionConfigs) {
            @NonNull Set<VcnGatewayConnectionConfig> gatewayConnectionConfigs,
            boolean isTestModeProfile) {
        mPackageName = packageName;
        mPackageName = packageName;
        mGatewayConnectionConfigs =
        mGatewayConnectionConfigs =
                Collections.unmodifiableSet(new ArraySet<>(gatewayConnectionConfigs));
                Collections.unmodifiableSet(new ArraySet<>(gatewayConnectionConfigs));
        mIsTestModeProfile = isTestModeProfile;


        validate();
        validate();
    }
    }
@@ -77,6 +82,7 @@ public final class VcnConfig implements Parcelable {
                new ArraySet<>(
                new ArraySet<>(
                        PersistableBundleUtils.toList(
                        PersistableBundleUtils.toList(
                                gatewayConnectionConfigsBundle, VcnGatewayConnectionConfig::new));
                                gatewayConnectionConfigsBundle, VcnGatewayConnectionConfig::new));
        mIsTestModeProfile = in.getBoolean(IS_TEST_MODE_PROFILE_KEY);


        validate();
        validate();
    }
    }
@@ -103,6 +109,15 @@ public final class VcnConfig implements Parcelable {
        return Collections.unmodifiableSet(mGatewayConnectionConfigs);
        return Collections.unmodifiableSet(mGatewayConnectionConfigs);
    }
    }


    /**
     * Returns whether or not this VcnConfig is restricted to test networks.
     *
     * @hide
     */
    public boolean isTestModeProfile() {
        return mIsTestModeProfile;
    }

    /**
    /**
     * Serializes this object to a PersistableBundle.
     * Serializes this object to a PersistableBundle.
     *
     *
@@ -119,13 +134,14 @@ public final class VcnConfig implements Parcelable {
                        new ArrayList<>(mGatewayConnectionConfigs),
                        new ArrayList<>(mGatewayConnectionConfigs),
                        VcnGatewayConnectionConfig::toPersistableBundle);
                        VcnGatewayConnectionConfig::toPersistableBundle);
        result.putPersistableBundle(GATEWAY_CONNECTION_CONFIGS_KEY, gatewayConnectionConfigsBundle);
        result.putPersistableBundle(GATEWAY_CONNECTION_CONFIGS_KEY, gatewayConnectionConfigsBundle);
        result.putBoolean(IS_TEST_MODE_PROFILE_KEY, mIsTestModeProfile);


        return result;
        return result;
    }
    }


    @Override
    @Override
    public int hashCode() {
    public int hashCode() {
        return Objects.hash(mPackageName, mGatewayConnectionConfigs);
        return Objects.hash(mPackageName, mGatewayConnectionConfigs, mIsTestModeProfile);
    }
    }


    @Override
    @Override
@@ -136,7 +152,8 @@ public final class VcnConfig implements Parcelable {


        final VcnConfig rhs = (VcnConfig) other;
        final VcnConfig rhs = (VcnConfig) other;
        return mPackageName.equals(rhs.mPackageName)
        return mPackageName.equals(rhs.mPackageName)
                && mGatewayConnectionConfigs.equals(rhs.mGatewayConnectionConfigs);
                && mGatewayConnectionConfigs.equals(rhs.mGatewayConnectionConfigs)
                && mIsTestModeProfile == rhs.mIsTestModeProfile;
    }
    }


    // Parcelable methods
    // Parcelable methods
@@ -172,6 +189,8 @@ public final class VcnConfig implements Parcelable {
        @NonNull
        @NonNull
        private final Set<VcnGatewayConnectionConfig> mGatewayConnectionConfigs = new ArraySet<>();
        private final Set<VcnGatewayConnectionConfig> mGatewayConnectionConfigs = new ArraySet<>();


        private boolean mIsTestModeProfile = false;

        public Builder(@NonNull Context context) {
        public Builder(@NonNull Context context) {
            Objects.requireNonNull(context, "context was null");
            Objects.requireNonNull(context, "context was null");


@@ -206,6 +225,22 @@ public final class VcnConfig implements Parcelable {
            return this;
            return this;
        }
        }


        /**
         * Restricts this VcnConfig to matching with test networks (only).
         *
         * <p>This method is for testing only, and must not be used by apps. Calling {@link
         * VcnManager#setVcnConfig(ParcelUuid, VcnConfig)} with a VcnConfig where test-network usage
         * is enabled will require the MANAGE_TEST_NETWORKS permission.
         *
         * @return this {@link Builder} instance, for chaining
         * @hide
         */
        @NonNull
        public Builder setIsTestModeProfile() {
            mIsTestModeProfile = true;
            return this;
        }

        /**
        /**
         * Builds and validates the VcnConfig.
         * Builds and validates the VcnConfig.
         *
         *
@@ -213,7 +248,7 @@ public final class VcnConfig implements Parcelable {
         */
         */
        @NonNull
        @NonNull
        public VcnConfig build() {
        public VcnConfig build() {
            return new VcnConfig(mPackageName, mGatewayConnectionConfigs);
            return new VcnConfig(mPackageName, mGatewayConnectionConfigs, mIsTestModeProfile);
        }
        }
    }
    }
}
}
+8 −0
Original line number Original line Diff line number Diff line
@@ -15,6 +15,8 @@
 */
 */
package android.net.vcn;
package android.net.vcn;


import static android.net.ipsec.ike.IkeSessionParams.IKE_OPTION_MOBIKE;

import static com.android.internal.annotations.VisibleForTesting.Visibility;
import static com.android.internal.annotations.VisibleForTesting.Visibility;


import android.annotation.IntDef;
import android.annotation.IntDef;
@@ -438,6 +440,8 @@ public final class VcnGatewayConnectionConfig {
         *     distinguish between VcnGatewayConnectionConfigs configured on a single {@link
         *     distinguish between VcnGatewayConnectionConfigs configured on a single {@link
         *     VcnConfig}. This will be used as the identifier in VcnStatusCallback invocations.
         *     VcnConfig}. This will be used as the identifier in VcnStatusCallback invocations.
         * @param tunnelConnectionParams the IKE tunnel connection configuration
         * @param tunnelConnectionParams the IKE tunnel connection configuration
         * @throws IllegalArgumentException if the provided IkeTunnelConnectionParams is not
         *     configured to support MOBIKE
         * @see IkeTunnelConnectionParams
         * @see IkeTunnelConnectionParams
         * @see VcnManager.VcnStatusCallback#onGatewayConnectionError
         * @see VcnManager.VcnStatusCallback#onGatewayConnectionError
         */
         */
@@ -446,6 +450,10 @@ public final class VcnGatewayConnectionConfig {
                @NonNull IkeTunnelConnectionParams tunnelConnectionParams) {
                @NonNull IkeTunnelConnectionParams tunnelConnectionParams) {
            Objects.requireNonNull(gatewayConnectionName, "gatewayConnectionName was null");
            Objects.requireNonNull(gatewayConnectionName, "gatewayConnectionName was null");
            Objects.requireNonNull(tunnelConnectionParams, "tunnelConnectionParams was null");
            Objects.requireNonNull(tunnelConnectionParams, "tunnelConnectionParams was null");
            if (!tunnelConnectionParams.getIkeSessionParams().hasIkeOption(IKE_OPTION_MOBIKE)) {
                throw new IllegalArgumentException(
                        "MOBIKE must be configured for the provided IkeSessionParams");
            }


            mGatewayConnectionName = gatewayConnectionName;
            mGatewayConnectionName = gatewayConnectionName;
            mTunnelConnectionParams = tunnelConnectionParams;
            mTunnelConnectionParams = tunnelConnectionParams;
+16 −5
Original line number Original line Diff line number Diff line
@@ -167,7 +167,6 @@ public class VcnManagementService extends IVcnManagementService.Stub {
    @NonNull private final VcnNetworkProvider mNetworkProvider;
    @NonNull private final VcnNetworkProvider mNetworkProvider;
    @NonNull private final TelephonySubscriptionTrackerCallback mTelephonySubscriptionTrackerCb;
    @NonNull private final TelephonySubscriptionTrackerCallback mTelephonySubscriptionTrackerCb;
    @NonNull private final TelephonySubscriptionTracker mTelephonySubscriptionTracker;
    @NonNull private final TelephonySubscriptionTracker mTelephonySubscriptionTracker;
    @NonNull private final VcnContext mVcnContext;
    @NonNull private final BroadcastReceiver mPkgChangeReceiver;
    @NonNull private final BroadcastReceiver mPkgChangeReceiver;


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


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


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


        /** Creates a new Vcn instance using the provided configuration */
        /** Creates a new Vcn instance using the provided configuration */
@@ -419,6 +418,14 @@ public class VcnManagementService extends IVcnManagementService.Stub {
                "Carrier privilege required for subscription group to set VCN Config");
                "Carrier privilege required for subscription group to set VCN Config");
    }
    }


    private void enforceManageTestNetworksForTestMode(@NonNull VcnConfig vcnConfig) {
        if (vcnConfig.isTestModeProfile()) {
            mContext.enforceCallingPermission(
                    android.Manifest.permission.MANAGE_TEST_NETWORKS,
                    "Test-mode require the MANAGE_TEST_NETWORKS permission");
        }
    }

    private class VcnSubscriptionTrackerCallback implements TelephonySubscriptionTrackerCallback {
    private class VcnSubscriptionTrackerCallback implements TelephonySubscriptionTrackerCallback {
        /**
        /**
         * Handles subscription group changes, as notified by {@link TelephonySubscriptionTracker}
         * Handles subscription group changes, as notified by {@link TelephonySubscriptionTracker}
@@ -542,8 +549,11 @@ public class VcnManagementService extends IVcnManagementService.Stub {


        final VcnCallbackImpl vcnCallback = new VcnCallbackImpl(subscriptionGroup);
        final VcnCallbackImpl vcnCallback = new VcnCallbackImpl(subscriptionGroup);


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


        // Now that a new VCN has started, notify all registered listeners to refresh their
        // Now that a new VCN has started, notify all registered listeners to refresh their
@@ -587,6 +597,7 @@ public class VcnManagementService extends IVcnManagementService.Stub {


        mContext.getSystemService(AppOpsManager.class)
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(mDeps.getBinderCallingUid(), config.getProvisioningPackageName());
                .checkPackage(mDeps.getBinderCallingUid(), config.getProvisioningPackageName());
        enforceManageTestNetworksForTestMode(config);
        enforceCallingUserAndCarrierPrivilege(subscriptionGroup, opPkgName);
        enforceCallingUserAndCarrierPrivilege(subscriptionGroup, opPkgName);


        Binder.withCleanCallingIdentity(() -> {
        Binder.withCleanCallingIdentity(() -> {
+17 −0
Original line number Original line Diff line number Diff line
@@ -158,8 +158,15 @@ public class UnderlyingNetworkTracker {
     * carrier owned networks may be selected, as the request specifies only subIds in the VCN's
     * carrier owned networks may be selected, as the request specifies only subIds in the VCN's
     * subscription group, while the VCN networks are excluded by virtue of not having subIds set on
     * subscription group, while the VCN networks are excluded by virtue of not having subIds set on
     * the VCN-exposed networks.
     * the VCN-exposed networks.
     *
     * <p>If the VCN that this UnderlyingNetworkTracker belongs to is in test-mode, this will return
     * a NetworkRequest that only matches Test Networks.
     */
     */
    private NetworkRequest getRouteSelectionRequest() {
    private NetworkRequest getRouteSelectionRequest() {
        if (mVcnContext.isInTestMode()) {
            return getTestNetworkRequest(mLastSnapshot.getAllSubIdsInGroup(mSubscriptionGroup));
        }

        return getBaseNetworkRequestBuilder()
        return getBaseNetworkRequestBuilder()
                .setSubscriptionIds(mLastSnapshot.getAllSubIdsInGroup(mSubscriptionGroup))
                .setSubscriptionIds(mLastSnapshot.getAllSubIdsInGroup(mSubscriptionGroup))
                .build();
                .build();
@@ -210,6 +217,16 @@ public class UnderlyingNetworkTracker {
                .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED);
                .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED);
    }
    }


    /** Builds and returns a NetworkRequest for the given subIds to match Test Networks. */
    private NetworkRequest getTestNetworkRequest(@NonNull Set<Integer> subIds) {
        return getBaseNetworkRequestBuilder()
                .addTransportType(NetworkCapabilities.TRANSPORT_TEST)
                .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
                .setSubscriptionIds(subIds)
                .build();
    }

    /**
    /**
     * Update this UnderlyingNetworkTracker's TelephonySubscriptionSnapshot.
     * Update this UnderlyingNetworkTracker's TelephonySubscriptionSnapshot.
     *
     *
+8 −1
Original line number Original line Diff line number Diff line
@@ -31,14 +31,17 @@ public class VcnContext {
    @NonNull private final Context mContext;
    @NonNull private final Context mContext;
    @NonNull private final Looper mLooper;
    @NonNull private final Looper mLooper;
    @NonNull private final VcnNetworkProvider mVcnNetworkProvider;
    @NonNull private final VcnNetworkProvider mVcnNetworkProvider;
    private final boolean mIsInTestMode;


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


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


    public boolean isInTestMode() {
        return mIsInTestMode;
    }

    /**
    /**
     * Verifies that the caller is running on the VcnContext Thread.
     * Verifies that the caller is running on the VcnContext Thread.
     *
     *
Loading