Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Side by Side Diff: net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java

Issue 10905207: Implement net::GetNetworkList() for Android. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix the nits Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.content.ActivityNotFoundException; 7 import android.content.ActivityNotFoundException;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.util.Log; 10 import android.util.Log;
11 11
12 import org.chromium.base.CalledByNative; 12 import org.chromium.base.CalledByNative;
13 import org.chromium.base.CalledByNativeUnchecked; 13 import org.chromium.base.CalledByNativeUnchecked;
14 14
15 import java.net.Inet6Address;
16 import java.net.InetAddress;
15 import java.net.NetworkInterface; 17 import java.net.NetworkInterface;
16 import java.net.SocketException; 18 import java.net.SocketException;
17 import java.net.URLConnection; 19 import java.net.URLConnection;
18 import java.security.KeyStoreException; 20 import java.security.KeyStoreException;
19 import java.security.NoSuchAlgorithmException; 21 import java.security.NoSuchAlgorithmException;
20 import java.security.cert.CertificateException; 22 import java.security.cert.CertificateException;
21 import java.util.Enumeration; 23 import java.util.Enumeration;
22 24
23 /** 25 /**
24 * This class implements net utilities required by the net component. 26 * This class implements net utilities required by the net component.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 try { 82 try {
81 if (netIf.isUp() && !netIf.isLoopback()) return false; 83 if (netIf.isUp() && !netIf.isLoopback()) return false;
82 } catch (SocketException e) { 84 } catch (SocketException e) {
83 continue; 85 continue;
84 } 86 }
85 } 87 }
86 return true; 88 return true;
87 } 89 }
88 90
89 /** 91 /**
92 * @return the network interfaces list (if any) string. The items in
93 * the list string are delimited by a semicolon ";", each item
94 * is a network interface name and address pair and formatted
95 * as "name,address". i.e.
wtc 2012/09/11 23:04:49 Nit: change "i.e." to "For example" or "e.g.".
Shouqun Liu 2012/09/12 01:06:08 Done.
96 * eth0,10.0.0.2;eth0,fe80::5054:ff:fe12:3456
97 * represents a network list string which containts two items.
98 */
99 @CalledByNative
100 static public String getNetworkList() {
101 Enumeration<NetworkInterface> list = null;
102 try {
103 list = NetworkInterface.getNetworkInterfaces();
104 if (list == null) return "";
105 } catch (SocketException e) {
106 Log.w(TAG, "Unable to get network interfaces: " + e);
107 return "";
108 }
109
110 StringBuilder result = new StringBuilder();
111 while (list.hasMoreElements()) {
112 NetworkInterface netIf = list.nextElement();
113 try {
114 // Skip loopback interfaces, and ones which are down.
115 if (!netIf.isUp() || netIf.isLoopback())
116 continue;
117 Enumeration<InetAddress> addressList = netIf.getInetAddresses();
118 while (addressList.hasMoreElements()) {
119 InetAddress address = addressList.nextElement();
120 // Skip loopback addresses configured on non-loopback interf aces.
121 if (address.isLoopbackAddress())
122 continue;
123 StringBuilder addressString = new StringBuilder();
124 addressString.append(netIf.getName());
125 addressString.append(",");
126
127 String ipAddress = address.getHostAddress();
128 if (address instanceof Inet6Address && ipAddress.contains("% ")) {
129 ipAddress = ipAddress.substring(0, ipAddress.lastIndexOf ("%"));
130 }
131 addressString.append(ipAddress);
132
133 result.append(addressString.toString());
134 if (addressList.hasMoreElements())
135 result.append(";");
wtc 2012/09/11 23:04:49 This may result in extraneous semicolons because t
Shouqun Liu 2012/09/12 01:06:08 oh, yes, I did not consider all the cases, fixed.
136 }
137 } catch (SocketException e) {
138 continue;
139 }
140 }
141 return result.toString();
142 }
143
144 /**
90 * Validate the server's certificate chain is trusted. 145 * Validate the server's certificate chain is trusted.
91 * 146 *
92 * @param certChain The ASN.1 DER encoded bytes for certificates. 147 * @param certChain The ASN.1 DER encoded bytes for certificates.
93 * @param authType The key exchange algorithm name (e.g. RSA) 148 * @param authType The key exchange algorithm name (e.g. RSA)
94 * @return true if the server is trusted 149 * @return true if the server is trusted
95 * @throws CertificateException,KeyStoreException,NoSuchAlgorithmException 150 * @throws CertificateException,KeyStoreException,NoSuchAlgorithmException
96 * on error initializing the TrustManager or reading the 151 * on error initializing the TrustManager or reading the
97 * certChain 152 * certChain
98 */ 153 */
99 @CalledByNativeUnchecked 154 @CalledByNativeUnchecked
100 public static boolean verifyServerCertificates(byte[][] certChain, String au thType) 155 public static boolean verifyServerCertificates(byte[][] certChain, String au thType)
101 throws CertificateException, KeyStoreException, NoSuchAlgorithmExcep tion { 156 throws CertificateException, KeyStoreException, NoSuchAlgorithmExcep tion {
102 return X509Util.verifyServerCertificates(certChain, authType); 157 return X509Util.verifyServerCertificates(certChain, authType);
103 } 158 }
104 159
105 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698