Fields Summary |
---|
private static final String | LOGTAG |
private static Network | sNetworkStatic instance of a Network object. |
private static boolean | sPlatformNotificationsFlag to store the state of platform notifications, for the case
when the Network object has not been constructed yet |
private static int | sPlatformNotificationEnableRefCountReference count for platform notifications as the network class is a
static and can exist over multiple activities, thus over multiple
onPause/onResume pairs. |
private String | mProxyUsernameProxy username if known (used for pre-emptive proxy authentication). |
private String | mProxyPasswordProxy password if known (used for pre-emptive proxy authentication). |
private RequestQueue | mRequestQueueNetwork request queue (requests are added from the browser thread). |
private SslErrorHandler | mSslErrorHandlerSSL error handler: takes care of synchronization of multiple async
loaders with SSL-related problems. |
private HttpAuthHandler | mHttpAuthHandlerHTTP authentication handler: takes care of synchronization of HTTP
authentication requests. |
Methods Summary |
---|
public void | clearUserSslPrefTable()Clears user SSL-error preference table.
mSslErrorHandler.clear();
|
public static void | disablePlatformNotifications()If platform notifications are enabled, this should be called
from onPause() or onStop()
if (--sPlatformNotificationEnableRefCount == 0) {
if (sNetwork != null) {
sNetwork.mRequestQueue.disablePlatformNotifications();
} else {
sPlatformNotifications = false;
}
}
|
public static void | enablePlatformNotifications()Enables data state and proxy tracking
if (++sPlatformNotificationEnableRefCount == 1) {
if (sNetwork != null) {
sNetwork.mRequestQueue.enablePlatformNotifications();
} else {
sPlatformNotifications = true;
}
}
|
public static synchronized android.webkit.Network | getInstance(android.content.Context context)
if (sNetwork == null) {
// Note Context of the Application is used here, rather than
// the what is passed in (usually a Context derived from an
// Activity) so the intent receivers belong to the application
// rather than an activity - this fixes the issue where
// Activities are created and destroyed during the lifetime of
// an Application
sNetwork = new Network(context.getApplicationContext());
if (sPlatformNotifications) {
// Adjust the ref count before calling enable as it is already
// taken into account when the static function was called
// directly
--sPlatformNotificationEnableRefCount;
enablePlatformNotifications();
}
}
return sNetwork;
|
public java.lang.String | getProxyHostname()Get the proxy hostname.
return mRequestQueue.getProxyHost().getHostName();
|
public synchronized java.lang.String | getProxyPassword()
return mProxyPassword;
|
public synchronized java.lang.String | getProxyUsername()
return mProxyUsername;
|
public void | handleAuthRequest(LoadListener loader)Handles authentication requests on their way up to the user (the user
must provide credentials).
if (Config.DEBUG) Assert.assertNotNull(loader);
if (loader != null) {
mHttpAuthHandler.handleAuthRequest(loader);
}
|
public void | handleSslErrorRequest(LoadListener loader)Handles SSL error(s) on the way up to the user: the user must decide
whether errors should be ignored or not.
if (Config.DEBUG) Assert.assertNotNull(loader);
if (loader != null) {
mSslErrorHandler.handleSslErrorRequest(loader);
}
|
public boolean | isValidProxySet()
// The proxy host and port can be set within a different thread during
// an Intent broadcast.
synchronized (mRequestQueue) {
return mRequestQueue.getProxyHost() != null;
}
|
public boolean | requestURL(java.lang.String method, java.util.Map headers, byte[] postData, LoadListener loader, boolean isHighPriority)Request a url from either the network or the file system.
String url = loader.url();
// Not a valid url, return false because we won't service the request!
if (!URLUtil.isValidUrl(url)) {
return false;
}
// asset, file system or data stream are handled in the other code path.
// This only handles network request.
if (URLUtil.isAssetUrl(url) || URLUtil.isFileUrl(url) ||
URLUtil.isDataUrl(url)) {
return false;
}
/* FIXME: this is lame. Pass an InputStream in, rather than
making this lame one here */
InputStream bodyProvider = null;
int bodyLength = 0;
if (postData != null) {
bodyLength = postData.length;
bodyProvider = new ByteArrayInputStream(postData);
}
RequestQueue q = mRequestQueue;
if (loader.isSynchronous()) {
q = new RequestQueue(loader.getContext(), 1);
}
RequestHandle handle = q.queueRequest(
url, loader.getWebAddress(), method, headers, loader,
bodyProvider, bodyLength, isHighPriority);
loader.attachRequestHandle(handle);
if (loader.isSynchronous()) {
handle.waitUntilComplete();
loader.loadSynchronousMessages();
q.shutdown();
}
return true;
|
public boolean | restoreState(Bundle inState)Restores the state of network handlers (user SSL and HTTP-authentication
preferences).
if (Config.LOGV) {
Log.v(LOGTAG, "Network.restoreState()");
}
return mSslErrorHandler.restoreState(inState);
|
public boolean | saveState(Bundle outState)Saves the state of network handlers (user SSL and HTTP-authentication
preferences).
if (Config.LOGV) {
Log.v(LOGTAG, "Network.saveState()");
}
return mSslErrorHandler.saveState(outState);
|
public synchronized void | setProxyPassword(java.lang.String proxyPassword)Sets the proxy password.
if (Config.DEBUG) {
Assert.assertTrue(isValidProxySet());
}
mProxyPassword = proxyPassword;
|
public synchronized void | setProxyUsername(java.lang.String proxyUsername)Sets the proxy username.
if (Config.DEBUG) {
Assert.assertTrue(isValidProxySet());
}
mProxyUsername = proxyUsername;
|
public void | startTiming()
mRequestQueue.startTiming();
|
public void | stopTiming()
mRequestQueue.stopTiming();
|