Add type string to VCN NetworkAgentConfig

This change populates the VCN type string used in NetworkInfo. While
the NetworkInfo API has long been deprecated, some apps apparently still
use this API. Even more unusually, some apps use the NetworkInfo's type
strings, and perform string comparisons on the type string, as opposed
to the type integer/enums to determine network types.

This change ensures maximum backward compatibility.

Bug: 219287843
Test: atest FrameworksVcnTests
Change-Id: I059dbc997f97482f7355fdc29d464d5452933ce3
This commit is contained in:
Benedict Wong
2022-02-15 22:09:46 +00:00
parent 86e1a45b56
commit 37a6ef1cd6
2 changed files with 19 additions and 1 deletions

View File

@@ -78,6 +78,7 @@ import android.os.PowerManager.WakeLock;
import android.os.Process;
import android.os.SystemClock;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.ArraySet;
import android.util.Slog;
@@ -163,6 +164,14 @@ import java.util.function.Consumer;
public class VcnGatewayConnection extends StateMachine {
private static final String TAG = VcnGatewayConnection.class.getSimpleName();
// Matches DataConnection.NETWORK_TYPE private constant, and magic string from
// ConnectivityManager#getNetworkTypeName()
@VisibleForTesting(visibility = Visibility.PRIVATE)
static final String NETWORK_INFO_NETWORK_TYPE_STRING = "MOBILE";
@VisibleForTesting(visibility = Visibility.PRIVATE)
static final String NETWORK_INFO_EXTRA_INFO = "VCN";
@VisibleForTesting(visibility = Visibility.PRIVATE)
static final InetAddress DUMMY_ADDR = InetAddresses.parseNumericAddress("192.0.2.0");
@@ -1631,6 +1640,12 @@ public class VcnGatewayConnection extends StateMachine {
final NetworkAgentConfig nac =
new NetworkAgentConfig.Builder()
.setLegacyType(ConnectivityManager.TYPE_MOBILE)
.setLegacyTypeName(NETWORK_INFO_NETWORK_TYPE_STRING)
.setLegacySubType(TelephonyManager.NETWORK_TYPE_UNKNOWN)
.setLegacySubTypeName(
TelephonyManager.getNetworkTypeName(
TelephonyManager.NETWORK_TYPE_UNKNOWN))
.setLegacyExtraInfo(NETWORK_INFO_EXTRA_INFO)
.build();
final VcnNetworkAgent agent =

View File

@@ -307,7 +307,10 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
ncCaptor.capture(),
lpCaptor.capture(),
any(),
argThat(nac -> nac.getLegacyType() == ConnectivityManager.TYPE_MOBILE),
// Subtype integer/name and extras do not have getters; cannot be tested.
argThat(nac -> nac.getLegacyType() == ConnectivityManager.TYPE_MOBILE
&& nac.getLegacyTypeName().equals(
VcnGatewayConnection.NETWORK_INFO_NETWORK_TYPE_STRING)),
any(),
any(),
any());