# QuotaManager

Artifact: [androidx.wear.protolayout:protolayout-expression-pipeline](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/expression/pipeline/QuotaManager.java+class:androidx.wear.protolayout.expression.pipeline.QuotaManager) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

*** ** * ** ***


```
public interface QuotaManager
```

<br />

*** ** * ** ***

Interface responsible for managing quota. Before initiating some action (e.g. starting an animation) that uses a limited resource, `https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/QuotaManager#tryAcquireQuota(int)` should be called to see if the target quota cap has been reached and if not, it will be updated. When action/resource is finished, it should be release with `https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/QuotaManager#releaseQuota(int)`.

For example, this can be used for limiting the number of concurrently running animations. Every time new animations is due to be played, it should request quota from `https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/QuotaManager` in amount that is equal to the number of animations that should be played (e.g. playing fade in and slide in animation on one object should request amount of 2 quota.

It is callers responsibility to release acquired quota after limited resource has been finished. For example, when animation is running, but surface became invisible, caller should return acquired quota.

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/QuotaManager#releaseQuota(int)(int quota)` Releases the given amount of quota. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/wear/protolayout/expression/pipeline/QuotaManager#tryAcquireQuota(int)(int quota)` Tries to acquire the given amount of quota and returns true if successful. |

## Public methods

### releaseQuota

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
abstract void releaseQuota(int quota)
```

Releases the given amount of quota.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the given quota amount exceeds the amount of acquired quota. |

### tryAcquireQuota

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
abstract boolean tryAcquireQuota(int quota)
```

Tries to acquire the given amount of quota and returns true if successful. Otherwise, returns false meaning that quota cap has already been reached and the quota won't be acquired.

It is callers responsibility to release acquired quota after limited resource has been finished. For example, when animation is running, but surface became invisible, caller should return acquired quota.