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

Commit 06030c18 authored by Narayan Kamath's avatar Narayan Kamath Committed by android-build-merger
Browse files

Merge "DataConnection: Use InetAddress.isNumeric rather than a regex." am: 39eda215

am: 1f2b12fe

Change-Id: I01bc1dd0786fadbe81676dc2fe732031c36dd571
parents e2d8e4c1 1f2b12fe
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -36,9 +36,9 @@ import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Pair;
import android.util.Patterns;
import android.util.TimeUtils;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CallTracker;
import com.android.internal.telephony.CarrierSignalAgent;
import com.android.internal.telephony.CommandException;
@@ -976,10 +976,14 @@ public class DataConnection extends StateMachine {
        return result;
    }

    private boolean isIpAddress(String address) {
    /**
     * @return {@code} true iff. {@code address} is a literal IPv4 or IPv6 address.
     */
    @VisibleForTesting
    public static boolean isIpAddress(String address) {
        if (address == null) return false;

        return Patterns.IP_ADDRESS.matcher(address).matches();
        return InetAddress.isNumeric(address);
    }

    private DataCallResponse.SetupResult setLinkProperties(DataCallResponse response,
+12 −1
Original line number Diff line number Diff line
@@ -314,4 +314,15 @@ public class DataConnectionTest extends TelephonyTest {
                .hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
        assertFalse(getNetworkInfo().isMetered());
    }

    @SmallTest
    public void testIsIpAddress() throws Exception {
        // IPv4
        assertTrue(DataConnection.isIpAddress("1.2.3.4"));
        assertTrue(DataConnection.isIpAddress("127.0.0.1"));

        // IPv6
        assertTrue(DataConnection.isIpAddress("::1"));
        assertTrue(DataConnection.isIpAddress("2001:4860:800d::68"));
    }
}