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 Original-Change: android-review.googlesource.com/1987026 Test: atest FrameworksVcnTests Change-Id: I059dbc997f97482f7355fdc29d464d5452933ce3 Merged-In: I059dbc997f97482f7355fdc29d464d5452933ce3
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -162,6 +163,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");
|
||||
|
||||
@@ -1625,6 +1634,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 =
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user