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

Commit 37a6ef1c authored by Benedict Wong's avatar Benedict Wong
Browse files

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
parent 86e1a45b
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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 =
+4 −1
Original line number Diff line number Diff line
@@ -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());