ProxyController


@AnyThread
abstract class ProxyController


Manages setting and clearing a process-specific override for the Android system-wide proxy settings that govern network requests made by android.webkit.WebView.

WebView may make network requests in order to fetch content that is not otherwise read from the file system or provided directly by application code. In this case by default the system-wide Android network proxy settings are used to redirect requests to appropriate proxy servers.

In the rare case that it is necessary for an application to explicitly specify its proxy configuration, this API may be used to explicitly specify the proxy rules that govern WebView initiated network requests.

Example usage:

ProxyConfig proxyConfig = new ProxyConfig.Builder().addProxyRule("myproxy.com")
                                                   .addBypassRule("www.excluded.*")
                                                   .build();
Executor executor = ...
Runnable listener = ...
ProxyController.getInstance().setProxyOverride(proxyConfig, executor, listener);
...
ProxyController.getInstance().clearProxyOverride(executor, listener);

Summary

Public functions

abstract Unit
clearProxyOverride(executor: Executor, listener: Runnable)

Clears the proxy settings.

java-static ProxyController
@RequiresFeature(name = WebViewFeature.PROXY_OVERRIDE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
getInstance()

Returns the ProxyController instance.

abstract Unit
setProxyOverride(
    proxyConfig: ProxyConfig,
    executor: Executor,
    listener: Runnable
)

Sets ProxyConfig which will be used by all WebViews in the app.

Public functions

clearProxyOverride

Added in 1.1.0
abstract fun clearProxyOverride(executor: Executor, listener: Runnable): Unit

Clears the proxy settings. Network connections are not guaranteed to immediately use the new proxy setting; wait for the listener before loading a page. This listener will be called in the provided executor.

Parameters
executor: Executor

Executor for the listener to be executed in

listener: Runnable

Listener called when the proxy setting change has been applied

getInstance

Added in 1.1.0
@RequiresFeature(name = WebViewFeature.PROXY_OVERRIDE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getInstance(): ProxyController

Returns the ProxyController instance.

This method should only be called if isFeatureSupported returns true for PROXY_OVERRIDE.

setProxyOverride

Added in 1.1.0
abstract fun setProxyOverride(
    proxyConfig: ProxyConfig,
    executor: Executor,
    listener: Runnable
): Unit

Sets ProxyConfig which will be used by all WebViews in the app. URLs that match patterns in the bypass list will not be directed to any proxy. Instead, the request will be made directly to the origin specified by the URL. Network connections are not guaranteed to immediately use the new proxy setting; wait for the listener before loading a page. This listener will be called in the provided executor.

Note: calling setProxyOverride will cause any existing system wide setting to be ignored.

Parameters
proxyConfig: ProxyConfig

Proxy config to be applied

executor: Executor

Executor for the listener to be executed in

listener: Runnable

Listener called when the proxy setting change has been applied

Throws
java.lang.IllegalArgumentException

If the proxyConfig is invalid