Replace subnet mask calculation to Inet4AddressUtils
There is existing helper method in Inet4AddressUtils to calculate the subnet mask from IPv4 prefix calculation. Replace the implementation in caller side to simplify design in callers. Bug: 172183305 Test: atest SettingsRoboTests Test: Verify the method return the same value Change-Id: I38d7d09be612fa4788cf4052bf304d17f0ae79f4
This commit is contained in:
@@ -63,7 +63,7 @@ import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.net.module.util.NetUtils;
|
||||
import com.android.net.module.util.Inet4AddressUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
@@ -99,7 +99,6 @@ import com.android.wifitrackerlib.WifiEntry.WifiEntryCallback;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
@@ -873,10 +872,8 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
|
||||
|
||||
private static String ipv4PrefixLengthToSubnetMask(int prefixLength) {
|
||||
try {
|
||||
InetAddress all = InetAddress.getByAddress(
|
||||
new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255});
|
||||
return NetUtils.getNetworkPart(all, prefixLength).getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
return Inet4AddressUtils.getPrefixMaskAsInet4Address(prefixLength).getHostAddress();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user