Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.BroadcastReceiver; | 7 import android.content.BroadcastReceiver; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.IntentFilter; | 10 import android.content.IntentFilter; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Extract a ProxyConfig object from the supplied Intent's extra data | 96 // Extract a ProxyConfig object from the supplied Intent's extra data |
| 97 // bundle. The android.net.ProxyProperties class is not exported from | 97 // bundle. The android.net.ProxyProperties class is not exported from |
| 98 // the Android SDK, so we have to use reflection to get at it and invoke | 98 // the Android SDK, so we have to use reflection to get at it and invoke |
| 99 // methods on it. If we fail, return an empty proxy config (meaning | 99 // methods on it. If we fail, return an empty proxy config (meaning |
| 100 // 'direct'). | 100 // 'direct'). |
| 101 // TODO(sgurun): once android.net.ProxyInfo is public, rewrite this. | 101 // TODO(sgurun): once android.net.ProxyInfo is public, rewrite this. |
| 102 private ProxyConfig extractNewProxy(Intent intent) { | 102 private ProxyConfig extractNewProxy(Intent intent) { |
| 103 try { | 103 try { |
| 104 final String GET_HOST_NAME = "getHost"; | 104 final String getHostName = "getHost"; |
|
Yaron
2014/09/25 00:12:05
this doesn't match item 5.2.7 of java style guide.
| |
| 105 final String GET_PORT_NAME = "getPort"; | 105 final String getPortName = "getPort"; |
| 106 final String GET_PAC_FILE_URL = "getPacFileUrl"; | 106 final String getPacFileUrl = "getPacFileUrl"; |
| 107 String className; | 107 String className; |
| 108 String proxyInfo; | 108 String proxyInfo; |
| 109 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { | 109 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { |
| 110 className = "android.net.ProxyProperties"; | 110 className = "android.net.ProxyProperties"; |
| 111 proxyInfo = "proxy"; | 111 proxyInfo = "proxy"; |
| 112 } else { | 112 } else { |
| 113 className = "android.net.ProxyInfo"; | 113 className = "android.net.ProxyInfo"; |
| 114 proxyInfo = "android.intent.extra.PROXY_INFO"; | 114 proxyInfo = "android.intent.extra.PROXY_INFO"; |
| 115 } | 115 } |
| 116 | 116 |
| 117 Object props = intent.getExtras().get(proxyInfo); | 117 Object props = intent.getExtras().get(proxyInfo); |
| 118 if (props == null) { | 118 if (props == null) { |
| 119 return null; | 119 return null; |
| 120 } | 120 } |
| 121 | 121 |
| 122 Class<?> cls = Class.forName(className); | 122 Class<?> cls = Class.forName(className); |
| 123 Method getHostMethod = cls.getDeclaredMethod(GET_HOST_NAME); | 123 Method getHostMethod = cls.getDeclaredMethod(getHostName); |
| 124 Method getPortMethod = cls.getDeclaredMethod(GET_PORT_NAME); | 124 Method getPortMethod = cls.getDeclaredMethod(getPortName); |
| 125 | 125 |
| 126 String host = (String) getHostMethod.invoke(props); | 126 String host = (String) getHostMethod.invoke(props); |
| 127 int port = (Integer) getPortMethod.invoke(props); | 127 int port = (Integer) getPortMethod.invoke(props); |
| 128 | 128 |
| 129 // TODO(xunjieli): rewrite this once the API is public. | 129 // TODO(xunjieli): rewrite this once the API is public. |
| 130 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { | 130 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { |
| 131 Method getPacFileUrlMethod = | 131 Method getPacFileUrlMethod = |
| 132 cls.getDeclaredMethod(GET_PAC_FILE_URL); | 132 cls.getDeclaredMethod(getPacFileUrl); |
| 133 String pacFileUrl = (String) getPacFileUrlMethod.invoke(prop s); | 133 String pacFileUrl = (String) getPacFileUrlMethod.invoke(prop s); |
| 134 if (!TextUtils.isEmpty(pacFileUrl)) { | 134 if (!TextUtils.isEmpty(pacFileUrl)) { |
| 135 return new ProxyConfig(host, port, pacFileUrl); | 135 return new ProxyConfig(host, port, pacFileUrl); |
| 136 } | 136 } |
| 137 } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { | 137 } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { |
| 138 Method getPacFileUrlMethod = | 138 Method getPacFileUrlMethod = |
| 139 cls.getDeclaredMethod(GET_PAC_FILE_URL); | 139 cls.getDeclaredMethod(getPacFileUrl); |
| 140 Uri pacFileUrl = (Uri) getPacFileUrlMethod.invoke(props); | 140 Uri pacFileUrl = (Uri) getPacFileUrlMethod.invoke(props); |
| 141 if (!Uri.EMPTY.equals(pacFileUrl)) { | 141 if (!Uri.EMPTY.equals(pacFileUrl)) { |
| 142 return new ProxyConfig(host, port, pacFileUrl.toString()); | 142 return new ProxyConfig(host, port, pacFileUrl.toString()); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 return new ProxyConfig(host, port, null); | 145 return new ProxyConfig(host, port, null); |
| 146 } catch (ClassNotFoundException ex) { | 146 } catch (ClassNotFoundException ex) { |
| 147 Log.e(TAG, "Using no proxy configuration due to exception:" + ex ); | 147 Log.e(TAG, "Using no proxy configuration due to exception:" + ex ); |
| 148 return null; | 148 return null; |
| 149 } catch (NoSuchMethodException ex) { | 149 } catch (NoSuchMethodException ex) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 */ | 204 */ |
| 205 @NativeClassQualifiedName("ProxyConfigServiceAndroid::JNIDelegate") | 205 @NativeClassQualifiedName("ProxyConfigServiceAndroid::JNIDelegate") |
| 206 private native void nativeProxySettingsChangedTo(long nativePtr, | 206 private native void nativeProxySettingsChangedTo(long nativePtr, |
| 207 String host, | 207 String host, |
| 208 int port, | 208 int port, |
| 209 String pacUrl); | 209 String pacUrl); |
| 210 | 210 |
| 211 @NativeClassQualifiedName("ProxyConfigServiceAndroid::JNIDelegate") | 211 @NativeClassQualifiedName("ProxyConfigServiceAndroid::JNIDelegate") |
| 212 private native void nativeProxySettingsChanged(long nativePtr); | 212 private native void nativeProxySettingsChanged(long nativePtr); |
| 213 } | 213 } |
| OLD | NEW |