Merge changes from topic "vcn-code-move" into main

* changes:
  Remove unexpected OWNERS files and VcnUtils
  Move VCN code base to p/m/Connectivity with git history
This commit is contained in:
Yan Yan 2025-08-22 16:16:06 -07:00 • committed by Android (Google) Code Review
commit a759f8b01c
125 changed files with 31001 additions and 0 deletions

6
Vcn/OWNERS Normal file
View file

@ -0,0 +1,6 @@
evitayan@google.com
nharold@google.com
benedictwong@google.com #{LAST_RESORT_SUGGESTION}
yangji@google.com #{LAST_RESORT_SUGGESTION}
include platform/packages/modules/common:/MODULES_OWNERS

26
Vcn/TEST_MAPPING Normal file
View file

@ -0,0 +1,26 @@
{
"presubmit": [
{
"name": "FrameworksVcnTests"
},
{
"name": "CtsVcnTestCases"
}
],
"postsubmit": [
{
"name": "FrameworksVcnTests"
},
{
"name": "CtsVcnTestCases"
}
],
"tethering-mainline-presubmit": [
{
"name": "FrameworksVcnTests"
},
{
"name": "CtsVcnTestCases"
}
]
}

52
Vcn/flags/Android.bp Normal file
View file

@ -0,0 +1,52 @@
//
// Copyright (C) 2024 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package {
default_team: "trendy_team_enigma",
default_applicable_licenses: ["Android-Apache-2.0"],
}
aconfig_declarations {
name: "android.net.vcn.flags-aconfig",
package: "android.net.vcn",
container: "com.android.tethering",
exportable: true,
srcs: [
"flags.aconfig",
],
}
// TODO: b/374174952 Remove this library when VCN modularization is done
java_aconfig_library {
name: "android.net.vcn.flags-aconfig-java-export",
aconfig_declarations: "android.net.vcn.flags-aconfig",
mode: "exported",
min_sdk_version: "35",
defaults: ["framework-minus-apex-aconfig-java-defaults"],
apex_available: [
"//apex_available:platform",
],
}
java_aconfig_library {
name: "android.net.vcn.flags-aconfig-java",
aconfig_declarations: "android.net.vcn.flags-aconfig",
min_sdk_version: "35",
defaults: ["framework-minus-apex-aconfig-java-defaults"],
apex_available: [
"com.android.tethering",
],
}

18
Vcn/flags/flags.aconfig Normal file
View file

@ -0,0 +1,18 @@
package: "android.net.vcn"
container: "com.android.tethering"
flag {
name: "safe_mode_config"
is_exported: true
namespace: "vcn"
description: "Feature flag for safe mode configurability"
bug: "276358140"
}
flag {
name: "mainline_vcn_module_api"
namespace: "vcn"
description: "Expose APIs from VCN for mainline migration"
is_exported: true
bug: "376339506"
}

210
Vcn/framework-b/Android.bp Normal file
View file

@ -0,0 +1,210 @@
//
// Copyright (C) 2024 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package {
default_team: "trendy_team_enigma",
default_applicable_licenses: ["Android-Apache-2.0"],
}
filegroup {
name: "vcn-utils-platform-sources",
srcs: [
"src/android/net/vcn/persistablebundleutils/**/*.java",
"src/android/net/vcn/util/**/*.java",
],
path: "src",
visibility: [
"//frameworks/base", // For VpnProfile.java and Vpn.java
],
}
// Utility library for the IPsec module
java_library {
name: "vcn-utils-framework-ipsec",
sdk_version: "module_current",
min_sdk_version: "30",
srcs: ["src/android/net/vcn/util/PersistableBundleUtils.java"],
libs: [
"framework-annotations-lib",
"net-utils-framework-vcn", // For HexDump.java
],
visibility: [
"//packages/modules/IPsec",
],
apex_available: ["com.android.ipsec"],
}
java_defaults {
name: "framework-connectivity-b-defaults-base",
sdk_version: "module_current",
defaults: ["framework-module-defaults"], // This is a boot jar
srcs: [
"src/**/*.java",
"src/**/*.aidl",
],
libs: [
"android.net.ipsec.ike.stubs.module_lib",
"framework-wifi.stubs.module_lib",
"unsupportedappusage",
],
aidl: {
include_dirs: [
// For connectivity-framework classes such as Network.aidl, NetworkCapabilities.aidl
"packages/modules/Connectivity/framework/aidl-export",
],
},
}
soong_config_module_type {
name: "framework_connectivity_b_defaults_soong_config",
module_type: "java_defaults",
config_namespace: "ANDROID",
bool_variables: [
"is_vcn_in_mainline",
],
properties: [
"min_sdk_version",
"static_libs",
"apex_available",
],
}
framework_connectivity_b_defaults_soong_config {
name: "framework-connectivity-b-defaults",
defaults: [
"framework-connectivity-b-defaults-base",
],
soong_config_variables: {
is_vcn_in_mainline: {
min_sdk_version: "36",
static_libs: ["android.net.vcn.flags-aconfig-java"],
apex_available: ["com.android.tethering"],
conditions_default: {
min_sdk_version: "35",
static_libs: ["android.net.vcn.flags-aconfig-java-export"],
apex_available: ["//apex_available:platform"],
},
},
},
}
soong_config_module_type {
name: "framework_connectivity_b_java_sdk_library_defaults_soong_config",
module_type: "java_defaults",
config_namespace: "ANDROID",
bool_variables: [
"is_vcn_in_mainline",
],
properties: [
"aconfig_declarations",
"jarjar_rules",
],
}
framework_connectivity_b_java_sdk_library_defaults_soong_config {
name: "framework-connectivity-b-java-sdk-library-defaults",
soong_config_variables: {
is_vcn_in_mainline: {
aconfig_declarations: ["android.net.vcn.flags-aconfig-java"],
// TODO: b/375213246 Use the connectivity jarjar rule generator to create the
// jarjar rules. In the end state, use "framework-connectivity-jarjar-rules"
// after VCN code is moved to the Connectivity folder
jarjar_rules: "framework-vcn-jarjar-rules.txt",
conditions_default: {
aconfig_declarations: ["android.net.vcn.flags-aconfig-java-export"],
// Use "android.net.connectivity" as prefix would trigger
// "Hidden API flags are inconsistent" build error
jarjar_rules: "framework-vcn-jarjar-rules-platform.txt",
},
},
},
}
java_sdk_library {
name: "framework-connectivity-b",
defaults: [
"framework-connectivity-b-defaults",
"framework-connectivity-b-java-sdk-library-defaults",
],
permitted_packages: [
"android.net",
"android.net.vcn",
"com.android.server.vcn.util",
],
api_packages: [
"android.net",
"android.net.vcn",
],
// Allow VCN APIs to reference APIs in IKE and Connectivity
stub_only_libs: [
"android.net.ipsec.ike.stubs.module_lib",
"framework-connectivity.stubs.module_lib",
],
// To use non-jarjard names of utilities such as android.util.IndentingPrintWriter
impl_only_libs: [
"framework-connectivity-pre-jarjar",
],
impl_library_visibility: [
// Using for test only
"//cts/tests/netlegacy22.api",
// TODO: b/374174952 Clean up VCN paths when the code location is finalized
"//cts/tests/tests/vcn",
"//packages/modules/Connectivity/Vcn/tests:__subpackages__",
"//external/sl4a:__subpackages__",
"//frameworks/base/core/tests/bandwidthtests",
"//frameworks/base/core/tests/benchmarks",
"//frameworks/base/core/tests/utillib",
"//frameworks/base/services/tests/VpnTests",
"//frameworks/base/tests/vcn",
"//frameworks/opt/telephony/tests/telephonytests",
"//packages/modules/CaptivePortalLogin/tests",
"//packages/modules/Connectivity/staticlibs/testutils",
"//packages/modules/Connectivity/staticlibs/tests:__subpackages__",
"//packages/modules/Connectivity/Tethering/tests:__subpackages__",
"//packages/modules/Connectivity/tests:__subpackages__",
"//packages/modules/Connectivity/thread/tests:__subpackages__",
"//packages/modules/IPsec/tests/iketests",
"//packages/modules/NetworkStack",
"//packages/modules/NetworkStack/tests:__subpackages__",
"//packages/modules/Wifi/service/tests/wifitests",
],
visibility: ["//packages/modules/Connectivity:__subpackages__"],
}
java_library {
name: "framework-connectivity-b-pre-jarjar",
defaults: ["framework-connectivity-b-defaults"],
installable: false,
libs: [
"framework-connectivity-pre-jarjar",
],
}

View file

@ -0,0 +1,123 @@
// Signature format: 2.0
package android.net.vcn {
public final class VcnCellUnderlyingNetworkTemplate extends android.net.vcn.VcnUnderlyingNetworkTemplate {
method public int getCbs();
method public int getDun();
method public int getIms();
method public int getInternet();
method public int getMms();
method @NonNull public java.util.Set<java.lang.String> getOperatorPlmnIds();
method public int getOpportunistic();
method public int getRcs();
method public int getRoaming();
method @NonNull public java.util.Set<java.lang.Integer> getSimSpecificCarrierIds();
}
public static final class VcnCellUnderlyingNetworkTemplate.Builder {
ctor public VcnCellUnderlyingNetworkTemplate.Builder();
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate build();
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setCbs(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setDun(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setIms(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setInternet(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMetered(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMinDownstreamBandwidthKbps(int, int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMinUpstreamBandwidthKbps(int, int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMms(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setOperatorPlmnIds(@NonNull java.util.Set<java.lang.String>);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setOpportunistic(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setRcs(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setRoaming(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setSimSpecificCarrierIds(@NonNull java.util.Set<java.lang.Integer>);
}
public final class VcnConfig implements android.os.Parcelable {
method public int describeContents();
method @NonNull public java.util.Set<android.net.vcn.VcnGatewayConnectionConfig> getGatewayConnectionConfigs();
method @NonNull public java.util.Set<java.lang.Integer> getRestrictedUnderlyingNetworkTransports();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.net.vcn.VcnConfig> CREATOR;
}
public static final class VcnConfig.Builder {
ctor public VcnConfig.Builder(@NonNull android.content.Context);
method @NonNull public android.net.vcn.VcnConfig.Builder addGatewayConnectionConfig(@NonNull android.net.vcn.VcnGatewayConnectionConfig);
method @NonNull public android.net.vcn.VcnConfig build();
method @NonNull public android.net.vcn.VcnConfig.Builder setRestrictedUnderlyingNetworkTransports(@NonNull java.util.Set<java.lang.Integer>);
}
public final class VcnGatewayConnectionConfig {
method @NonNull public int[] getExposedCapabilities();
method @NonNull public String getGatewayConnectionName();
method @IntRange(from=0x500) public int getMaxMtu();
method public int getMinUdpPort4500NatTimeoutSeconds();
method @NonNull public long[] getRetryIntervalsMillis();
method @NonNull public java.util.List<android.net.vcn.VcnUnderlyingNetworkTemplate> getVcnUnderlyingNetworkPriorities();
method public boolean hasGatewayOption(int);
method @FlaggedApi("android.net.vcn.safe_mode_config") public boolean isSafeModeEnabled();
field @FlaggedApi("android.net.vcn.mainline_vcn_module_api") public static final int MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET = -1; // 0xffffffff
field public static final int VCN_GATEWAY_OPTION_ENABLE_DATA_STALL_RECOVERY_WITH_MOBILITY = 0; // 0x0
}
public static final class VcnGatewayConnectionConfig.Builder {
ctor public VcnGatewayConnectionConfig.Builder(@NonNull String, @NonNull android.net.ipsec.ike.IkeTunnelConnectionParams);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder addExposedCapability(int);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder addGatewayOption(int);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig build();
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeExposedCapability(int);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeGatewayOption(int);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setMaxMtu(@IntRange(from=0x500) int);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setMinUdpPort4500NatTimeoutSeconds(@IntRange(from=0x78) int);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setRetryIntervalsMillis(@NonNull long[]);
method @FlaggedApi("android.net.vcn.safe_mode_config") @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setSafeModeEnabled(boolean);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setVcnUnderlyingNetworkPriorities(@NonNull java.util.List<android.net.vcn.VcnUnderlyingNetworkTemplate>);
}
public class VcnManager {
method @RequiresPermission("carrier privileges") public void clearVcnConfig(@NonNull android.os.ParcelUuid) throws java.io.IOException;
method @NonNull public java.util.List<android.os.ParcelUuid> getConfiguredSubscriptionGroups();
method public void registerVcnStatusCallback(@NonNull android.os.ParcelUuid, @NonNull java.util.concurrent.Executor, @NonNull android.net.vcn.VcnManager.VcnStatusCallback);
method @RequiresPermission("carrier privileges") public void setVcnConfig(@NonNull android.os.ParcelUuid, @NonNull android.net.vcn.VcnConfig) throws java.io.IOException;
method public void unregisterVcnStatusCallback(@NonNull android.net.vcn.VcnManager.VcnStatusCallback);
field public static final int VCN_ERROR_CODE_CONFIG_ERROR = 1; // 0x1
field public static final int VCN_ERROR_CODE_INTERNAL_ERROR = 0; // 0x0
field public static final int VCN_ERROR_CODE_NETWORK_ERROR = 2; // 0x2
field public static final int VCN_STATUS_CODE_ACTIVE = 2; // 0x2
field public static final int VCN_STATUS_CODE_INACTIVE = 1; // 0x1
field public static final int VCN_STATUS_CODE_NOT_CONFIGURED = 0; // 0x0
field public static final int VCN_STATUS_CODE_SAFE_MODE = 3; // 0x3
}
public abstract static class VcnManager.VcnStatusCallback {
ctor public VcnManager.VcnStatusCallback();
method public abstract void onGatewayConnectionError(@NonNull String, int, @Nullable Throwable);
method public abstract void onStatusChanged(int);
}
public abstract class VcnUnderlyingNetworkTemplate {
method public int getMetered();
method public int getMinEntryDownstreamBandwidthKbps();
method public int getMinEntryUpstreamBandwidthKbps();
method public int getMinExitDownstreamBandwidthKbps();
method public int getMinExitUpstreamBandwidthKbps();
field public static final int MATCH_ANY = 0; // 0x0
field public static final int MATCH_FORBIDDEN = 2; // 0x2
field public static final int MATCH_REQUIRED = 1; // 0x1
}
public final class VcnWifiUnderlyingNetworkTemplate extends android.net.vcn.VcnUnderlyingNetworkTemplate {
method @NonNull public java.util.Set<java.lang.String> getSsids();
}
public static final class VcnWifiUnderlyingNetworkTemplate.Builder {
ctor public VcnWifiUnderlyingNetworkTemplate.Builder();
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate build();
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setMetered(int);
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setMinDownstreamBandwidthKbps(int, int);
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setMinUpstreamBandwidthKbps(int, int);
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setSsids(@NonNull java.util.Set<java.lang.String>);
}
}

View file

@ -0,0 +1,28 @@
// Signature format: 2.0
package android.net {
@FlaggedApi("android.net.vcn.mainline_vcn_module_api") public final class ConnectivityFrameworkInitializerBaklava {
method @FlaggedApi("android.net.vcn.mainline_vcn_module_api") public static void registerServiceWrappers();
}
}
package android.net.vcn {
@FlaggedApi("android.net.vcn.mainline_vcn_module_api") public final class VcnTransportInfo implements android.os.Parcelable android.net.TransportInfo {
method @FlaggedApi("android.net.vcn.mainline_vcn_module_api") public int describeContents();
method @FlaggedApi("android.net.vcn.mainline_vcn_module_api") public long getApplicableRedactions();
method @FlaggedApi("android.net.vcn.mainline_vcn_module_api") public int getMinUdpPort4500NatTimeoutSeconds();
method @FlaggedApi("android.net.vcn.mainline_vcn_module_api") @NonNull public android.net.TransportInfo makeCopy(long);
method @FlaggedApi("android.net.vcn.mainline_vcn_module_api") public void writeToParcel(@NonNull android.os.Parcel, int);
field @FlaggedApi("android.net.vcn.mainline_vcn_module_api") @NonNull public static final android.os.Parcelable.Creator<android.net.vcn.VcnTransportInfo> CREATOR;
}
@FlaggedApi("android.net.vcn.mainline_vcn_module_api") public static final class VcnTransportInfo.Builder {
ctor @FlaggedApi("android.net.vcn.mainline_vcn_module_api") public VcnTransportInfo.Builder();
method @FlaggedApi("android.net.vcn.mainline_vcn_module_api") @NonNull public android.net.vcn.VcnTransportInfo build();
method @FlaggedApi("android.net.vcn.mainline_vcn_module_api") @NonNull public android.net.vcn.VcnTransportInfo.Builder setMinUdpPort4500NatTimeoutSeconds(@IntRange(from=0x78) int);
}
}

View file

@ -0,0 +1 @@
// Signature format: 2.0

View file

@ -0,0 +1 @@
// Signature format: 2.0

View file

@ -0,0 +1,23 @@
// Signature format: 2.0
package android.net.vcn {
public class VcnManager {
method @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public void addVcnNetworkPolicyChangeListener(@NonNull java.util.concurrent.Executor, @NonNull android.net.vcn.VcnManager.VcnNetworkPolicyChangeListener);
method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public android.net.vcn.VcnNetworkPolicyResult applyVcnNetworkPolicy(@NonNull android.net.NetworkCapabilities, @NonNull android.net.LinkProperties);
method @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public void removeVcnNetworkPolicyChangeListener(@NonNull android.net.vcn.VcnManager.VcnNetworkPolicyChangeListener);
}
public static interface VcnManager.VcnNetworkPolicyChangeListener {
method public void onPolicyChanged();
}
public final class VcnNetworkPolicyResult implements android.os.Parcelable {
method public int describeContents();
method @NonNull public android.net.NetworkCapabilities getNetworkCapabilities();
method public boolean isTeardownRequested();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.net.vcn.VcnNetworkPolicyResult> CREATOR;
}
}

View file

@ -0,0 +1 @@
// Signature format: 2.0

View file

@ -0,0 +1,2 @@
rule android.net.vcn.persistablebundleutils.** android.net.vcn.module.repackaged.persistablebundleutils.@1
rule android.net.vcn.util.** android.net.vcn.module.repackaged.util.@1

View file

@ -0,0 +1,3 @@
rule android.net.vcn.persistablebundleutils.** android.net.connectivity.android.net.vcn.persistablebundleutils.@1
rule android.net.vcn.util.** android.net.connectivity.android.net.vcn.util.@1
rule android.util.IndentingPrintWriter android.net.connectivity.android.util.IndentingPrintWriter

View file

@ -0,0 +1,112 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
import static android.net.vcn.Flags.FLAG_MAINLINE_VCN_MODULE_API;
import android.annotation.FlaggedApi;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.SystemServiceRegistry;
import android.compat.Compatibility;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.vcn.IVcnManagementService;
import android.net.vcn.VcnManager;
import android.os.Build;
import android.os.SystemProperties;
/**
* Class for performing registration for VCN service.
*
* @hide
*/
@FlaggedApi(FLAG_MAINLINE_VCN_MODULE_API)
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public final class ConnectivityFrameworkInitializerBaklava {
// This is a copy of TelephonyFrameworkInitializer.ENABLE_CHECKING_TELEPHONY_FEATURES. This
// ChangeId will replace ENABLE_CHECKING_TELEPHONY_FEATURES_FOR_VCN to gate VcnManager
// feature flag enforcement.
// This replacement is safe because both ChangeIds have been enabled since Android V and serve
// the same purpose: enforcing telephony feature flag checks before using telephony-based
// features. This also simplifies VCN modularization by avoiding the need to handle different
// states, such as: SDK < B vs. SDK >= B; VCN in platform vs. VCN in the apex.
private static final long ENABLE_CHECKING_TELEPHONY_FEATURES = 330583731;
/**
* The corresponding vendor API for Android V
*
* <p>Starting with Android V, the vendor API format has switched to YYYYMM.
*
* @see <a href="https://preview.source.android.com/docs/core/architecture/api-flags">Vendor API
* level</a>
*/
private static final int VENDOR_API_FOR_ANDROID_V = 202404;
private ConnectivityFrameworkInitializerBaklava() {}
// Suppressing AndroidFrameworkCompatChange because we're querying vendor
// partition SDK level, not application's target SDK version (which BTW we
// also check through Compatibility framework a few lines below).
@Nullable
private static String getVcnFeatureDependency() {
// Check SDK version of the client app. Apps targeting pre-V SDK might
// have not checked for existence of these features.
if (!Compatibility.isChangeEnabled(ENABLE_CHECKING_TELEPHONY_FEATURES)) {
return null;
}
// Check SDK version of the vendor partition. Pre-V devices might have
// incorrectly under-declared telephony features.
final int vendorApiLevel =
SystemProperties.getInt(
"ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
if (vendorApiLevel < VENDOR_API_FOR_ANDROID_V) {
return PackageManager.FEATURE_TELEPHONY;
} else {
return PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION;
}
}
/**
* Register VCN service to {@link Context}, so that {@link Context#getSystemService} can return
* a VcnManager.
*
* @throws IllegalStateException if this is called anywhere besides {@link
* SystemServiceRegistry}.
* @hide
*/
@FlaggedApi(FLAG_MAINLINE_VCN_MODULE_API)
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public static void registerServiceWrappers() {
SystemServiceRegistry.registerContextAwareService(
VcnManager.VCN_MANAGEMENT_SERVICE_STRING,
VcnManager.class,
(context, serviceBinder) -> {
final String telephonyFeatureToCheck = getVcnFeatureDependency();
if (telephonyFeatureToCheck != null
&& !context.getPackageManager()
.hasSystemFeature(telephonyFeatureToCheck)) {
return null;
}
IVcnManagementService service =
IVcnManagementService.Stub.asInterface(serviceBinder);
return new VcnManager(context, service);
});
}
}

View file

@ -0,0 +1,43 @@
/*
* Copyright 2020, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.vcn;
import android.net.LinkProperties;
import android.net.NetworkCapabilities;
import android.net.vcn.IVcnStatusCallback;
import android.net.vcn.IVcnUnderlyingNetworkPolicyListener;
import android.net.vcn.VcnConfig;
import android.net.vcn.VcnUnderlyingNetworkPolicy;
import android.os.ParcelUuid;
import java.util.List;
/**
* @hide
*/
interface IVcnManagementService {
void setVcnConfig(in ParcelUuid subscriptionGroup, in VcnConfig config, in String opPkgName);
void clearVcnConfig(in ParcelUuid subscriptionGroup, in String opPkgName);
List<ParcelUuid> getConfiguredSubscriptionGroups(in String opPkgName);
void addVcnUnderlyingNetworkPolicyListener(in IVcnUnderlyingNetworkPolicyListener listener);
void removeVcnUnderlyingNetworkPolicyListener(in IVcnUnderlyingNetworkPolicyListener listener);
VcnUnderlyingNetworkPolicy getUnderlyingNetworkPolicy(in NetworkCapabilities nc, in LinkProperties lp);
void registerVcnStatusCallback(in ParcelUuid subscriptionGroup, in IVcnStatusCallback callback, in String opPkgName);
void unregisterVcnStatusCallback(in IVcnStatusCallback callback);
}

View file

@ -0,0 +1,27 @@
/*
* Copyright 2021, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.vcn;
/** @hide */
oneway interface IVcnStatusCallback {
void onVcnStatusChanged(int statusCode);
void onGatewayConnectionError(
in String gatewayConnectionName,
int errorCode,
in String exceptionClass,
in String exceptionMessage);
}

View file

@ -0,0 +1,22 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.vcn;
/** @hide */
oneway interface IVcnUnderlyingNetworkPolicyListener {
void onPolicyChanged();
}

View file

@ -0,0 +1,25 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.vcn;
/**
* Placeholder class so new framework-vcn isn't empty
*
* @hide
*/
// This class will be removed once source code is migrated
public class Placeholder {}

View file

@ -0,0 +1,740 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.vcn;
import static android.net.NetworkCapabilities.NET_CAPABILITY_CBS;
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
import static android.net.NetworkCapabilities.NET_CAPABILITY_IMS;
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
import static android.net.NetworkCapabilities.NET_CAPABILITY_MMS;
import static android.net.NetworkCapabilities.NET_CAPABILITY_RCS;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.getMatchCriteriaString;
import static android.net.vcn.util.PersistableBundleUtils.INTEGER_DESERIALIZER;
import static android.net.vcn.util.PersistableBundleUtils.INTEGER_SERIALIZER;
import static android.net.vcn.util.PersistableBundleUtils.STRING_DESERIALIZER;
import static android.net.vcn.util.PersistableBundleUtils.STRING_SERIALIZER;
import static com.android.internal.annotations.VisibleForTesting.Visibility;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.net.NetworkCapabilities;
import android.net.vcn.VcnUnderlyingNetworkTemplate.MatchCriteria;
import android.net.vcn.util.PersistableBundleUtils;
import android.os.PersistableBundle;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* This class represents a configuration for a network template class of underlying cellular
* networks.
*
* <p>See {@link VcnUnderlyingNetworkTemplate}
*/
public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetworkTemplate {
private static final String ALLOWED_NETWORK_PLMN_IDS_KEY = "mAllowedNetworkPlmnIds";
@NonNull private final Set<String> mAllowedNetworkPlmnIds;
private static final String ALLOWED_SPECIFIC_CARRIER_IDS_KEY = "mAllowedSpecificCarrierIds";
@NonNull private final Set<Integer> mAllowedSpecificCarrierIds;
private static final String ROAMING_MATCH_KEY = "mRoamingMatchCriteria";
private static final int DEFAULT_ROAMING_MATCH_CRITERIA = MATCH_ANY;
private final int mRoamingMatchCriteria;
private static final String OPPORTUNISTIC_MATCH_KEY = "mOpportunisticMatchCriteria";
private static final int DEFAULT_OPPORTUNISTIC_MATCH_CRITERIA = MATCH_ANY;
private final int mOpportunisticMatchCriteria;
private static final String CAPABILITIES_MATCH_CRITERIA_KEY = "mCapabilitiesMatchCriteria";
@NonNull private final Map<Integer, Integer> mCapabilitiesMatchCriteria;
private static final Map<Integer, Integer> CAPABILITIES_MATCH_CRITERIA_DEFAULT;
static {
Map<Integer, Integer> capsMatchCriteria = new HashMap<>();
capsMatchCriteria.put(NET_CAPABILITY_CBS, MATCH_ANY);
capsMatchCriteria.put(NET_CAPABILITY_DUN, MATCH_ANY);
capsMatchCriteria.put(NET_CAPABILITY_IMS, MATCH_ANY);
capsMatchCriteria.put(NET_CAPABILITY_INTERNET, MATCH_REQUIRED);
capsMatchCriteria.put(NET_CAPABILITY_MMS, MATCH_ANY);
capsMatchCriteria.put(NET_CAPABILITY_RCS, MATCH_ANY);
CAPABILITIES_MATCH_CRITERIA_DEFAULT = Collections.unmodifiableMap(capsMatchCriteria);
}
private VcnCellUnderlyingNetworkTemplate(
int meteredMatchCriteria,
int minEntryUpstreamBandwidthKbps,
int minExitUpstreamBandwidthKbps,
int minEntryDownstreamBandwidthKbps,
int minExitDownstreamBandwidthKbps,
Set<String> allowedNetworkPlmnIds,
Set<Integer> allowedSpecificCarrierIds,
int roamingMatchCriteria,
int opportunisticMatchCriteria,
Map<Integer, Integer> capabilitiesMatchCriteria) {
super(
NETWORK_PRIORITY_TYPE_CELL,
meteredMatchCriteria,
minEntryUpstreamBandwidthKbps,
minExitUpstreamBandwidthKbps,
minEntryDownstreamBandwidthKbps,
minExitDownstreamBandwidthKbps);
mAllowedNetworkPlmnIds = new ArraySet<>(allowedNetworkPlmnIds);
mAllowedSpecificCarrierIds = new ArraySet<>(allowedSpecificCarrierIds);
mRoamingMatchCriteria = roamingMatchCriteria;
mOpportunisticMatchCriteria = opportunisticMatchCriteria;
mCapabilitiesMatchCriteria = new HashMap<>(capabilitiesMatchCriteria);
validate();
}
/** @hide */
@Override
protected void validate() {
super.validate();
validatePlmnIds(mAllowedNetworkPlmnIds);
validateCapabilitiesMatchCriteria(mCapabilitiesMatchCriteria);
Objects.requireNonNull(mAllowedSpecificCarrierIds, "matchingCarrierIds is null");
validateMatchCriteria(mRoamingMatchCriteria, "mRoamingMatchCriteria");
validateMatchCriteria(mOpportunisticMatchCriteria, "mOpportunisticMatchCriteria");
}
private static void validatePlmnIds(Set<String> matchingOperatorPlmnIds) {
Objects.requireNonNull(matchingOperatorPlmnIds, "matchingOperatorPlmnIds is null");
// A valid PLMN is a concatenation of MNC and MCC, and thus consists of 5 or 6 decimal
// digits.
for (String id : matchingOperatorPlmnIds) {
if ((id.length() == 5 || id.length() == 6) && id.matches("[0-9]+")) {
continue;
} else {
throw new IllegalArgumentException("Found invalid PLMN ID: " + id);
}
}
}
private static void validateCapabilitiesMatchCriteria(
Map<Integer, Integer> capabilitiesMatchCriteria) {
Objects.requireNonNull(capabilitiesMatchCriteria, "capabilitiesMatchCriteria is null");
boolean requiredCapabilityFound = false;
for (Map.Entry<Integer, Integer> entry : capabilitiesMatchCriteria.entrySet()) {
final int capability = entry.getKey();
final int matchCriteria = entry.getValue();
Preconditions.checkArgument(
CAPABILITIES_MATCH_CRITERIA_DEFAULT.containsKey(capability),
"NetworkCapability " + capability + "out of range");
validateMatchCriteria(matchCriteria, "capability " + capability);
requiredCapabilityFound |= (matchCriteria == MATCH_REQUIRED);
}
if (!requiredCapabilityFound) {
throw new IllegalArgumentException("No required capabilities found");
}
}
/** @hide */
@NonNull
@VisibleForTesting(visibility = Visibility.PROTECTED)
public static VcnCellUnderlyingNetworkTemplate fromPersistableBundle(
@NonNull PersistableBundle in) {
Objects.requireNonNull(in, "PersistableBundle is null");
final int meteredMatchCriteria = in.getInt(METERED_MATCH_KEY);
final int minEntryUpstreamBandwidthKbps =
in.getInt(MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS_KEY, DEFAULT_MIN_BANDWIDTH_KBPS);
final int minExitUpstreamBandwidthKbps =
in.getInt(MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS_KEY, DEFAULT_MIN_BANDWIDTH_KBPS);
final int minEntryDownstreamBandwidthKbps =
in.getInt(MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS_KEY, DEFAULT_MIN_BANDWIDTH_KBPS);
final int minExitDownstreamBandwidthKbps =
in.getInt(MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS_KEY, DEFAULT_MIN_BANDWIDTH_KBPS);
final PersistableBundle plmnIdsBundle =
in.getPersistableBundle(ALLOWED_NETWORK_PLMN_IDS_KEY);
Objects.requireNonNull(plmnIdsBundle, "plmnIdsBundle is null");
final Set<String> allowedNetworkPlmnIds =
new ArraySet<String>(
PersistableBundleUtils.toList(plmnIdsBundle, STRING_DESERIALIZER));
final PersistableBundle specificCarrierIdsBundle =
in.getPersistableBundle(ALLOWED_SPECIFIC_CARRIER_IDS_KEY);
Objects.requireNonNull(specificCarrierIdsBundle, "specificCarrierIdsBundle is null");
final Set<Integer> allowedSpecificCarrierIds =
new ArraySet<Integer>(
PersistableBundleUtils.toList(
specificCarrierIdsBundle, INTEGER_DESERIALIZER));
final PersistableBundle capabilitiesMatchCriteriaBundle =
in.getPersistableBundle(CAPABILITIES_MATCH_CRITERIA_KEY);
final Map<Integer, Integer> capabilitiesMatchCriteria;
if (capabilitiesMatchCriteriaBundle == null) {
capabilitiesMatchCriteria = CAPABILITIES_MATCH_CRITERIA_DEFAULT;
} else {
capabilitiesMatchCriteria =
PersistableBundleUtils.toMap(
capabilitiesMatchCriteriaBundle,
INTEGER_DESERIALIZER,
INTEGER_DESERIALIZER);
}
final int roamingMatchCriteria = in.getInt(ROAMING_MATCH_KEY);
final int opportunisticMatchCriteria = in.getInt(OPPORTUNISTIC_MATCH_KEY);
return new VcnCellUnderlyingNetworkTemplate(
meteredMatchCriteria,
minEntryUpstreamBandwidthKbps,
minExitUpstreamBandwidthKbps,
minEntryDownstreamBandwidthKbps,
minExitDownstreamBandwidthKbps,
allowedNetworkPlmnIds,
allowedSpecificCarrierIds,
roamingMatchCriteria,
opportunisticMatchCriteria,
capabilitiesMatchCriteria);
}
/** @hide */
@Override
@NonNull
@VisibleForTesting(visibility = Visibility.PROTECTED)
public PersistableBundle toPersistableBundle() {
final PersistableBundle result = super.toPersistableBundle();
final PersistableBundle plmnIdsBundle =
PersistableBundleUtils.fromList(
new ArrayList<>(mAllowedNetworkPlmnIds), STRING_SERIALIZER);
result.putPersistableBundle(ALLOWED_NETWORK_PLMN_IDS_KEY, plmnIdsBundle);
final PersistableBundle specificCarrierIdsBundle =
PersistableBundleUtils.fromList(
new ArrayList<>(mAllowedSpecificCarrierIds), INTEGER_SERIALIZER);
result.putPersistableBundle(ALLOWED_SPECIFIC_CARRIER_IDS_KEY, specificCarrierIdsBundle);
final PersistableBundle capabilitiesMatchCriteriaBundle =
PersistableBundleUtils.fromMap(
mCapabilitiesMatchCriteria, INTEGER_SERIALIZER, INTEGER_SERIALIZER);
result.putPersistableBundle(
CAPABILITIES_MATCH_CRITERIA_KEY, capabilitiesMatchCriteriaBundle);
result.putInt(ROAMING_MATCH_KEY, mRoamingMatchCriteria);
result.putInt(OPPORTUNISTIC_MATCH_KEY, mOpportunisticMatchCriteria);
return result;
}
/**
* Retrieve the matching operator PLMN IDs, or an empty set if any PLMN ID is acceptable.
*
* @see Builder#setOperatorPlmnIds(Set)
*/
@NonNull
public Set<String> getOperatorPlmnIds() {
return Collections.unmodifiableSet(mAllowedNetworkPlmnIds);
}
/**
* Retrieve the matching sim specific carrier IDs, or an empty set if any sim specific carrier
* ID is acceptable.
*
* @see Builder#setSimSpecificCarrierIds(Set)
*/
@NonNull
public Set<Integer> getSimSpecificCarrierIds() {
return Collections.unmodifiableSet(mAllowedSpecificCarrierIds);
}
/**
* Return the matching criteria for roaming networks.
*
* @see Builder#setRoaming(int)
*/
@MatchCriteria
public int getRoaming() {
return mRoamingMatchCriteria;
}
/**
* Return the matching criteria for opportunistic cellular subscriptions.
*
* @see Builder#setOpportunistic(int)
*/
@MatchCriteria
public int getOpportunistic() {
return mOpportunisticMatchCriteria;
}
/**
* Returns the matching criteria for CBS networks.
*
* @see Builder#setCbs(int)
*/
@MatchCriteria
public int getCbs() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_CBS);
}
/**
* Returns the matching criteria for DUN networks.
*
* @see Builder#setDun(int)
*/
@MatchCriteria
public int getDun() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_DUN);
}
/**
* Returns the matching criteria for IMS networks.
*
* @see Builder#setIms(int)
*/
@MatchCriteria
public int getIms() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_IMS);
}
/**
* Returns the matching criteria for INTERNET networks.
*
* @see Builder#setInternet(int)
*/
@MatchCriteria
public int getInternet() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_INTERNET);
}
/**
* Returns the matching criteria for MMS networks.
*
* @see Builder#setMms(int)
*/
@MatchCriteria
public int getMms() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_MMS);
}
/**
* Returns the matching criteria for RCS networks.
*
* @see Builder#setRcs(int)
*/
@MatchCriteria
public int getRcs() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_RCS);
}
/** @hide */
@Override
public Map<Integer, Integer> getCapabilitiesMatchCriteria() {
return Collections.unmodifiableMap(new HashMap<>(mCapabilitiesMatchCriteria));
}
@Override
public int hashCode() {
return Objects.hash(
super.hashCode(),
mAllowedNetworkPlmnIds,
mAllowedSpecificCarrierIds,
mCapabilitiesMatchCriteria,
mRoamingMatchCriteria,
mOpportunisticMatchCriteria);
}
@Override
public boolean equals(@Nullable Object other) {
if (!super.equals(other)) {
return false;
}
if (!(other instanceof VcnCellUnderlyingNetworkTemplate)) {
return false;
}
final VcnCellUnderlyingNetworkTemplate rhs = (VcnCellUnderlyingNetworkTemplate) other;
return Objects.equals(mAllowedNetworkPlmnIds, rhs.mAllowedNetworkPlmnIds)
&& Objects.equals(mAllowedSpecificCarrierIds, rhs.mAllowedSpecificCarrierIds)
&& Objects.equals(mCapabilitiesMatchCriteria, rhs.mCapabilitiesMatchCriteria)
&& mRoamingMatchCriteria == rhs.mRoamingMatchCriteria
&& mOpportunisticMatchCriteria == rhs.mOpportunisticMatchCriteria;
}
/** @hide */
@Override
void dumpTransportSpecificFields(IndentingPrintWriter pw) {
if (!mAllowedNetworkPlmnIds.isEmpty()) {
pw.println("mAllowedNetworkPlmnIds: " + mAllowedNetworkPlmnIds);
}
if (!mAllowedNetworkPlmnIds.isEmpty()) {
pw.println("mAllowedSpecificCarrierIds: " + mAllowedSpecificCarrierIds);
}
pw.println("mCapabilitiesMatchCriteria: " + mCapabilitiesMatchCriteria);
if (mRoamingMatchCriteria != DEFAULT_ROAMING_MATCH_CRITERIA) {
pw.println("mRoamingMatchCriteria: " + getMatchCriteriaString(mRoamingMatchCriteria));
}
if (mOpportunisticMatchCriteria != DEFAULT_OPPORTUNISTIC_MATCH_CRITERIA) {
pw.println(
"mOpportunisticMatchCriteria: "
+ getMatchCriteriaString(mOpportunisticMatchCriteria));
}
}
/** This class is used to incrementally build VcnCellUnderlyingNetworkTemplate objects. */
public static final class Builder {
private int mMeteredMatchCriteria = DEFAULT_METERED_MATCH_CRITERIA;
@NonNull private final Set<String> mAllowedNetworkPlmnIds = new ArraySet<>();
@NonNull private final Set<Integer> mAllowedSpecificCarrierIds = new ArraySet<>();
@NonNull private final Map<Integer, Integer> mCapabilitiesMatchCriteria = new HashMap<>();
private int mRoamingMatchCriteria = DEFAULT_ROAMING_MATCH_CRITERIA;
private int mOpportunisticMatchCriteria = DEFAULT_OPPORTUNISTIC_MATCH_CRITERIA;
private int mMinEntryUpstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS;
private int mMinExitUpstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS;
private int mMinEntryDownstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS;
private int mMinExitDownstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS;
/** Construct a Builder object. */
public Builder() {
mCapabilitiesMatchCriteria.putAll(CAPABILITIES_MATCH_CRITERIA_DEFAULT);
}
/**
* Set the matching criteria for metered networks.
*
* <p>A template where setMetered(MATCH_REQUIRED) will only match metered networks (one
* without NET_CAPABILITY_NOT_METERED). A template where setMetered(MATCH_FORBIDDEN) will
* only match a network that is not metered (one with NET_CAPABILITY_NOT_METERED).
*
* @param matchCriteria the matching criteria for metered networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_NOT_METERED
*/
// The matching getter is defined in the super class. Please see {@link
// VcnUnderlyingNetworkTemplate#getMetered()}
@SuppressLint("MissingGetterMatchingBuilder")
@NonNull
public Builder setMetered(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setMetered");
mMeteredMatchCriteria = matchCriteria;
return this;
}
/**
* Set operator PLMN IDs with which a network can match this template.
*
* <p>This is used to distinguish cases where roaming agreements may dictate a different
* priority from a partner's networks.
*
* @param operatorPlmnIds the matching operator PLMN IDs in String. Network with one of the
* matching PLMN IDs can match this template. If the set is empty, any PLMN ID will
* match. The default is an empty set. A valid PLMN is a concatenation of MNC and MCC,
* and thus consists of 5 or 6 decimal digits.
* @see SubscriptionInfo#getMccString()
* @see SubscriptionInfo#getMncString()
*/
@NonNull
public Builder setOperatorPlmnIds(@NonNull Set<String> operatorPlmnIds) {
validatePlmnIds(operatorPlmnIds);
mAllowedNetworkPlmnIds.clear();
mAllowedNetworkPlmnIds.addAll(operatorPlmnIds);
return this;
}
/**
* Set sim specific carrier IDs with which a network can match this template.
*
* @param simSpecificCarrierIds the matching sim specific carrier IDs. Network with one of
* the sim specific carrier IDs can match this template. If the set is empty, any
* carrier ID will match. The default is an empty set.
* @see TelephonyManager#getSimSpecificCarrierId()
*/
@NonNull
public Builder setSimSpecificCarrierIds(@NonNull Set<Integer> simSpecificCarrierIds) {
Objects.requireNonNull(simSpecificCarrierIds, "simSpecificCarrierIds is null");
mAllowedSpecificCarrierIds.clear();
mAllowedSpecificCarrierIds.addAll(simSpecificCarrierIds);
return this;
}
/**
* Set the matching criteria for roaming networks.
*
* <p>A template where setRoaming(MATCH_REQUIRED) will only match roaming networks (one
* without NET_CAPABILITY_NOT_ROAMING). A template where setRoaming(MATCH_FORBIDDEN) will
* only match a network that is not roaming (one with NET_CAPABILITY_NOT_ROAMING).
*
* @param matchCriteria the matching criteria for roaming networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_NOT_ROAMING
*/
@NonNull
public Builder setRoaming(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setRoaming");
mRoamingMatchCriteria = matchCriteria;
return this;
}
/**
* Set the matching criteria for opportunistic cellular subscriptions.
*
* @param matchCriteria the matching criteria for opportunistic cellular subscriptions.
* Defaults to {@link #MATCH_ANY}.
* @see SubscriptionManager#setOpportunistic(boolean, int)
*/
@NonNull
public Builder setOpportunistic(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setOpportunistic");
mOpportunisticMatchCriteria = matchCriteria;
return this;
}
/**
* Set the minimum upstream bandwidths that this template will match.
*
* <p>This template will not match a network that does not provide at least the bandwidth
* passed as the entry bandwidth, except in the case that the network is selected as the VCN
* Gateway Connection's underlying network, where it will continue to match until the
* bandwidth drops under the exit bandwidth.
*
* <p>The entry criteria MUST be greater than, or equal to the exit criteria to avoid the
* invalid case where a network fulfills the entry criteria, but at the same time fails the
* exit criteria.
*
* <p>Estimated bandwidth of a network is provided by the transport layer, and reported in
* {@link NetworkCapabilities}. The provided estimates will be used without modification.
*
* @param minEntryUpstreamBandwidthKbps the minimum accepted upstream bandwidth for networks
* that ARE NOT the already-selected underlying network, or {@code 0} to disable this
* requirement. Disabled by default.
* @param minExitUpstreamBandwidthKbps the minimum accepted upstream bandwidth for a network
* that IS the already-selected underlying network, or {@code 0} to disable this
* requirement. Disabled by default.
* @return this {@link Builder} instance, for chaining
*/
@NonNull
// The getter for the two integers are separated, and in the superclass. Please see {@link
// VcnUnderlyingNetworkTemplate#getMinEntryUpstreamBandwidthKbps()} and {@link
// VcnUnderlyingNetworkTemplate#getMinExitUpstreamBandwidthKbps()}
@SuppressLint("MissingGetterMatchingBuilder")
public Builder setMinUpstreamBandwidthKbps(
int minEntryUpstreamBandwidthKbps, int minExitUpstreamBandwidthKbps) {
validateMinBandwidthKbps(minEntryUpstreamBandwidthKbps, minExitUpstreamBandwidthKbps);
mMinEntryUpstreamBandwidthKbps = minEntryUpstreamBandwidthKbps;
mMinExitUpstreamBandwidthKbps = minExitUpstreamBandwidthKbps;
return this;
}
/**
* Set the minimum upstream bandwidths that this template will match.
*
* <p>This template will not match a network that does not provide at least the bandwidth
* passed as the entry bandwidth, except in the case that the network is selected as the VCN
* Gateway Connection's underlying network, where it will continue to match until the
* bandwidth drops under the exit bandwidth.
*
* <p>The entry criteria MUST be greater than, or equal to the exit criteria to avoid the
* invalid case where a network fulfills the entry criteria, but at the same time fails the
* exit criteria.
*
* <p>Estimated bandwidth of a network is provided by the transport layer, and reported in
* {@link NetworkCapabilities}. The provided estimates will be used without modification.
*
* @param minEntryDownstreamBandwidthKbps the minimum accepted downstream bandwidth for
* networks that ARE NOT the already-selected underlying network, or {@code 0} to
* disable this requirement. Disabled by default.
* @param minExitDownstreamBandwidthKbps the minimum accepted downstream bandwidth for a
* network that IS the already-selected underlying network, or {@code 0} to disable this
* requirement. Disabled by default.
* @return this {@link Builder} instance, for chaining
*/
@NonNull
// The getter for the two integers are separated, and in the superclass. Please see {@link
// VcnUnderlyingNetworkTemplate#getMinEntryDownstreamBandwidthKbps()} and {@link
// VcnUnderlyingNetworkTemplate#getMinExitDownstreamBandwidthKbps()}
@SuppressLint("MissingGetterMatchingBuilder")
public Builder setMinDownstreamBandwidthKbps(
int minEntryDownstreamBandwidthKbps, int minExitDownstreamBandwidthKbps) {
validateMinBandwidthKbps(
minEntryDownstreamBandwidthKbps, minExitDownstreamBandwidthKbps);
mMinEntryDownstreamBandwidthKbps = minEntryDownstreamBandwidthKbps;
mMinExitDownstreamBandwidthKbps = minExitDownstreamBandwidthKbps;
return this;
}
/**
* Sets the matching criteria for CBS networks.
*
* <p>A template where {@code setCbs(MATCH_REQUIRED)} is called will only match CBS networks
* (ones with NET_CAPABILITY_CBS). A template where {@code setCbs(MATCH_FORBIDDEN)} is
* called will only match networks that do not support CBS (ones without
* NET_CAPABILITY_CBS).
*
* @param matchCriteria the matching criteria for CBS networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_CBS
*/
@NonNull
public Builder setCbs(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setCbs");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_CBS, matchCriteria);
return this;
}
/**
* Sets the matching criteria for DUN networks.
*
* <p>A template where {@code setDun(MATCH_REQUIRED)} is called will only match DUN networks
* (ones with NET_CAPABILITY_DUN). A template where {@code setDun(MATCH_FORBIDDEN)} is
* called will only match networks that do not support DUN (ones without
* NET_CAPABILITY_DUN).
*
* @param matchCriteria the matching criteria for DUN networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_DUN
*/
@NonNull
public Builder setDun(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setDun");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_DUN, matchCriteria);
return this;
}
/**
* Sets the matching criteria for IMS networks.
*
* <p>A template where {@code setIms(MATCH_REQUIRED)} is called will only match IMS networks
* (ones with NET_CAPABILITY_IMS). A template where {@code setIms(MATCH_FORBIDDEN)} is
* called will only match networks that do not support IMS (ones without
* NET_CAPABILITY_IMS).
*
* @param matchCriteria the matching criteria for IMS networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_IMS
*/
@NonNull
public Builder setIms(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setIms");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_IMS, matchCriteria);
return this;
}
/**
* Sets the matching criteria for INTERNET networks.
*
* <p>A template where {@code setInternet(MATCH_REQUIRED)} is called will only match
* INTERNET networks (ones with NET_CAPABILITY_INTERNET). A template where {@code
* setInternet(MATCH_FORBIDDEN)} is called will only match networks that do not support
* INTERNET (ones without NET_CAPABILITY_INTERNET).
*
* @param matchCriteria the matching criteria for INTERNET networks. Defaults to {@link
* #MATCH_REQUIRED}.
* @see NetworkCapabilities#NET_CAPABILITY_INTERNET
*/
@NonNull
public Builder setInternet(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setInternet");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_INTERNET, matchCriteria);
return this;
}
/**
* Sets the matching criteria for MMS networks.
*
* <p>A template where {@code setMms(MATCH_REQUIRED)} is called will only match MMS networks
* (ones with NET_CAPABILITY_MMS). A template where {@code setMms(MATCH_FORBIDDEN)} is
* called will only match networks that do not support MMS (ones without
* NET_CAPABILITY_MMS).
*
* @param matchCriteria the matching criteria for MMS networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_MMS
*/
@NonNull
public Builder setMms(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setMms");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_MMS, matchCriteria);
return this;
}
/**
* Sets the matching criteria for RCS networks.
*
* <p>A template where {@code setRcs(MATCH_REQUIRED)} is called will only match RCS networks
* (ones with NET_CAPABILITY_RCS). A template where {@code setRcs(MATCH_FORBIDDEN)} is
* called will only match networks that do not support RCS (ones without
* NET_CAPABILITY_RCS).
*
* @param matchCriteria the matching criteria for RCS networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_RCS
*/
@NonNull
public Builder setRcs(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setRcs");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_RCS, matchCriteria);
return this;
}
/** Build the VcnCellUnderlyingNetworkTemplate. */
@NonNull
public VcnCellUnderlyingNetworkTemplate build() {
return new VcnCellUnderlyingNetworkTemplate(
mMeteredMatchCriteria,
mMinEntryUpstreamBandwidthKbps,
mMinExitUpstreamBandwidthKbps,
mMinEntryDownstreamBandwidthKbps,
mMinExitDownstreamBandwidthKbps,
mAllowedNetworkPlmnIds,
mAllowedSpecificCarrierIds,
mRoamingMatchCriteria,
mOpportunisticMatchCriteria,
mCapabilitiesMatchCriteria);
}
}
}

View file

@ -0,0 +1,20 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.vcn;
/** @hide */
parcelable VcnConfig;

Some files were not shown because too many files have changed in this diff Show more