# ProxyController

Artifact: [androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit) [View Source](https://cs.android.com/search?q=file:androidx/webkit/ProxyController.java+class:androidx.webkit.ProxyController) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

*** ** * ** ***


```
@AnyThread
public abstract class ProxyController
```

<br />

*** ** * ** ***

Manages setting and clearing a process-specific override for the Android system-wide proxy settings that govern network requests made by `https://developer.android.com/reference/android/webkit/WebView.html`.

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 methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/webkit/ProxyController#clearProxyOverride(java.util.concurrent.Executor,java.lang.Runnable)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Runnable.html listener)` Clears the proxy settings. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyController` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/androidx/webkit/WebViewFeature.PROXY_OVERRIDE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/androidx/webkit/ProxyController#getInstance()()` Returns the `https://developer.android.com/reference/androidx/webkit/ProxyController` instance. |
| `abstract void` | `https://developer.android.com/reference/androidx/webkit/ProxyController#setProxyOverride(androidx.webkit.ProxyConfig,java.util.concurrent.Executor,java.lang.Runnable)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig proxyConfig, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Runnable.html listener )` Sets `https://developer.android.com/reference/androidx/webkit/ProxyConfig` which will be used by all WebViews in the app. |

## Public methods

### clearProxyOverride

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public abstract void clearProxyOverride(@NonNull Executor executor, @NonNull Runnable listener)
```

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | Executor for the listener to be executed in |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Runnable.html listener` | Listener called when the proxy setting change has been applied |

### getInstance

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
@RequiresFeature(name = WebViewFeature.PROXY_OVERRIDE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public static @NonNull ProxyController getInstance()
```

Returns the `https://developer.android.com/reference/androidx/webkit/ProxyController` instance.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/androidx/webkit/WebViewFeature#PROXY_OVERRIDE()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### setProxyOverride

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public abstract void setProxyOverride(
    @NonNull ProxyConfig proxyConfig,
    @NonNull Executor executor,
    @NonNull Runnable listener
)
```

Sets `https://developer.android.com/reference/androidx/webkit/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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/ProxyConfig proxyConfig` | Proxy config to be applied |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | Executor for the listener to be executed in |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Runnable.html listener` | Listener called when the proxy setting change has been applied |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | If the proxyConfig is invalid |