import org.chromium.base.CalledByNative;
import org.chromium.base.CalledByNativeUnchecked;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URLConnection;
}
/**
- * @return the network interfaces list (if any) string. The items in
- * the list string are delimited by a new line, each item
- * is tab separated network interface name, address with network
- * prefix length and network interface index.
- * as "name\taddress/prefix\tindex". e.g.
- * eth0\t10.0.0.2/8\t5\neth0\tfe80::5054:ff:fe12:3456/16\t5
- * represents a network list string with two items.
- */
- @CalledByNative
- public static String getNetworkList() {
- Enumeration<NetworkInterface> list = null;
- try {
- list = NetworkInterface.getNetworkInterfaces();
- if (list == null) return "";
- } catch (SocketException e) {
- Log.w(TAG, "Unable to get network interfaces: " + e);
- return "";
- }
-
- StringBuilder result = new StringBuilder();
- while (list.hasMoreElements()) {
- NetworkInterface netIf = list.nextElement();
- try {
- // Skip loopback interfaces, and ones which are down.
- if (!netIf.isUp() || netIf.isLoopback())
- continue;
- for (InterfaceAddress interfaceAddress : netIf.getInterfaceAddresses()) {
- InetAddress address = interfaceAddress.getAddress();
- // Skip loopback addresses configured on non-loopback interfaces.
- if (address.isLoopbackAddress())
- continue;
- StringBuilder addressString = new StringBuilder();
- addressString.append(netIf.getName());
- addressString.append("\t");
-
- String ipAddress = address.getHostAddress();
- if (address instanceof Inet6Address && ipAddress.contains("%")) {
- ipAddress = ipAddress.substring(0, ipAddress.lastIndexOf("%"));
- }
- addressString.append(ipAddress);
- addressString.append("/");
- addressString.append(interfaceAddress.getNetworkPrefixLength());
- addressString.append("\t");
-
- // TODO(vitalybuka): use netIf.getIndex() when API level 19 is availible.
- addressString.append("0");
-
- if (result.length() != 0)
- result.append("\n");
- result.append(addressString.toString());
- }
- } catch (SocketException e) {
- continue;
- }
- }
- return result.toString();
- }
-
- /**
* Validate the server's certificate chain is trusted. Note that the caller
* must still verify the name matches that of the leaf certificate.
*
try {
return X509Util.verifyServerCertificates(certChain, authType, host);
} catch (KeyStoreException e) {
- return new AndroidCertVerifyResult(CertVerifyStatusAndroid.VERIFY_FAILED);
+ return new AndroidCertVerifyResult(CertVerifyStatusAndroid.FAILED);
} catch (NoSuchAlgorithmException e) {
- return new AndroidCertVerifyResult(CertVerifyStatusAndroid.VERIFY_FAILED);
+ return new AndroidCertVerifyResult(CertVerifyStatusAndroid.FAILED);
}
}
*/
@CalledByNative
private static String getNetworkCountryIso(Context context) {
- TelephonyManager telephonyManager =
- (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- if (telephonyManager != null) {
+ TelephonyManager telephonyManager =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ if (telephonyManager == null) return "";
return telephonyManager.getNetworkCountryIso();
- }
- return "";
}
/**
*/
@CalledByNative
private static String getNetworkOperator(Context context) {
- TelephonyManager telephonyManager =
- (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- if (telephonyManager != null) {
+ TelephonyManager telephonyManager =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ if (telephonyManager == null) return "";
return telephonyManager.getNetworkOperator();
- }
- return "";
}
}