# TestNavigationManager

Artifact: [androidx.car.app:app-testing](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/testing/navigation/TestNavigationManager.java+class:androidx.car.app.testing.navigation.TestNavigationManager) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

*** ** * ** ***


```
class TestNavigationManager : NavigationManager
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.car.app.navigation.NavigationManager](https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager) ||
|   | ↳ | [androidx.car.app.testing.navigation.TestNavigationManager](https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager) |

*** ** * ** ***

The `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager` that is used for testing.

This class will track the following usages of the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager` throughout your test:

- All the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/Trip`s sent via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#updateTrip(androidx.car.app.navigation.model.Trip)`.
- All the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationVoiceAssistantCapabilities` sent via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#setVoiceAssistantCapabilities(androidx.car.app.navigation.model.NavigationVoiceAssistantCapabilities)`.
- All the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManagerCallback`s set via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#setNavigationManagerCallback(androidx.car.app.navigation.NavigationManagerCallback)`.
- Count of times that the navigation was started via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationStarted()`.
- Count of times that the navigation was ended via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationEnded()`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#TestNavigationManager(androidx.car.app.testing.TestCarContext,androidx.car.app.HostDispatcher)( testCarContext: https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestCarContext, hostDispatcher: https://developer.android.com/reference/kotlin/androidx/car/app/HostDispatcher )` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#clearNavigationManagerCallback()()` Clears the callback for receiving navigation manager events. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#getNavigationEndedCount()()` Returns the number of times that navigation was ended via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationEnded()` since creation or the last call to `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#reset()`. |
| `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManagerCallback?` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#getNavigationManagerCallback()()` Returns the callback set via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#setNavigationManagerCallback(androidx.car.app.navigation.NavigationManagerCallback)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#getNavigationStartedCount()()` Returns the number of times that navigation was started via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationStarted()` since creation or the last call to `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#reset()`. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/Trip!>` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#getTripsSent()()` Returns all the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/Trip`s sent via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#updateTrip(androidx.car.app.navigation.model.Trip)`. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationVoiceAssistantCapabilities!>` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/ExperimentalCarApi @https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 9) https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#getVoiceAssistantCapabilitiesSent()()` Returns all the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationVoiceAssistantCapabilities` sent via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#setVoiceAssistantCapabilities(androidx.car.app.navigation.model.NavigationVoiceAssistantCapabilities)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#navigationEnded()()` Notifies the host that the app has ended active navigation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#navigationStarted()()` Notifies the host that the app has started active navigation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#reset()()` Resets the values tracked by this `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#setNavigationManagerCallback(java.util.concurrent.Executor,androidx.car.app.navigation.NavigationManagerCallback)( executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, callback: https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManagerCallback )` Sets a callback to start receiving navigation manager events. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/ExperimentalCarApi @https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 9) https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#setVoiceAssistantCapabilities(androidx.car.app.navigation.model.NavigationVoiceAssistantCapabilities)( capabilities: https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationVoiceAssistantCapabilities )` Sends the voice assistant capabilities and consent state of the navigation app to the host. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#updateTrip(androidx.car.app.navigation.model.Trip)(trip: https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/Trip)` Sends the destinations, steps, and trip estimates to the host. |

### Inherited functions

From [androidx.car.app.navigation.NavigationManager](https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/ExperimentalCarApi
@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 9)
https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#canSetVoiceAssistantCapabilities()()`

Returns whether the host supports setting voice assistant capabilities.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread
https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#setNavigationManagerCallback(androidx.car.app.navigation.NavigationManagerCallback)(callback: https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManagerCallback)`

Sets a callback to start receiving navigation manager events.

## Public constructors

### TestNavigationManager

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

```
TestNavigationManager(
    testCarContext: TestCarContext,
    hostDispatcher: HostDispatcher
)
```

## Public functions

### clearNavigationManagerCallback

```
fun clearNavigationManagerCallback(): Unit
```

Clears the callback for receiving navigation manager events.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if navigation is started (see `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationStarted()` for more info), or if the current thread is not the main thread |

### getNavigationEndedCount

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

```
fun getNavigationEndedCount(): Int
```

Returns the number of times that navigation was ended via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationEnded()` since creation or the last call to `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#reset()`.

### getNavigationManagerCallback

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

```
fun getNavigationManagerCallback(): NavigationManagerCallback?
```

Returns the callback set via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#setNavigationManagerCallback(androidx.car.app.navigation.NavigationManagerCallback)`.

The listener will be `null` if one was never set, or if `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#clearNavigationManagerCallback()` or `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#reset()` was called.

### getNavigationStartedCount

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

```
fun getNavigationStartedCount(): Int
```

Returns the number of times that navigation was started via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationStarted()` since creation or the last call to `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#reset()`.

### getTripsSent

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

```
fun getTripsSent(): (Mutable)List<Trip!>
```

Returns all the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/Trip`s sent via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#updateTrip(androidx.car.app.navigation.model.Trip)`.

The trips are stored in the order in which they were sent, where the first trip in the list, is the first trip sent.

The trips will be stored until `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#reset()` is called.

### getVoiceAssistantCapabilitiesSent

Added in [1.9.0-alpha03](https://developer.android.com/jetpack/androidx/releases/car-app#1.9.0-alpha03)

```
@ExperimentalCarApi
@RequiresCarApi(value = 9)
fun getVoiceAssistantCapabilitiesSent(): (Mutable)List<NavigationVoiceAssistantCapabilities!>
```

Returns all the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationVoiceAssistantCapabilities` sent via `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#setVoiceAssistantCapabilities(androidx.car.app.navigation.model.NavigationVoiceAssistantCapabilities)`.

The capabilities are stored in the order in which they were sent, where the first in the list, is the first capabilities sent.

The capabilities will be stored until `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager#reset()` is called.

### navigationEnded

```
fun navigationEnded(): Unit
```

Notifies the host that the app has ended active navigation.

Only one app may be actively navigating in the car at any time and ownership is managed by the host. The app must call this method to inform the system that it has ended navigation, for example, in response to the user cancelling navigation or upon reaching the destination.

This method is idempotent.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the current thread is not the main thread |

### navigationStarted

```
fun navigationStarted(): Unit
```

Notifies the host that the app has started active navigation.

Only one app may be actively navigating in the car at any time and ownership is managed by the host. The app must call this method to inform the system that it has started navigation in response to user action.

This function can only called if `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#setNavigationManagerCallback(androidx.car.app.navigation.NavigationManagerCallback)` has been called with a non-`null` value. The callback is required so that a signal to stop navigation from the host can be handled using `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManagerCallback#onStopNavigation()`.

This method is idempotent.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if no navigation manager callback has been set, or if the current thread is not the main thread |

### reset

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

```
fun reset(): Unit
```

Resets the values tracked by this `https://developer.android.com/reference/kotlin/androidx/car/app/testing/navigation/TestNavigationManager`.

### setNavigationManagerCallback

```
fun setNavigationManagerCallback(
    executor: Executor,
    callback: NavigationManagerCallback
): Unit
```

Sets a callback to start receiving navigation manager events.

| Parameters |
|---|---|
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | the executor which will be used for invoking the callback |
| `callback: https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManagerCallback` | the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManagerCallback` to use |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the current thread is not the main thread |

### setVoiceAssistantCapabilities

```
@ExperimentalCarApi
@RequiresCarApi(value = 9)
fun setVoiceAssistantCapabilities(
    capabilities: NavigationVoiceAssistantCapabilities
): Unit
```

Sends the voice assistant capabilities and consent state of the navigation app to the host.

This allows the app to dynamically toggle whether the voice assistant can access the active navigation state, and declares the actions and disruptions the app supports.

| Parameters |
|---|---|
| `capabilities: https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/NavigationVoiceAssistantCapabilities` | The capabilities and consent state to send to the host. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the current thread is not the main thread, or if the host does not support voice assistant capabilities |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the provided capabilities cannot be serialized |
| `https://developer.android.com/reference/kotlin/androidx/car/app/HostException` | if the call is invoked by an app that is not declared as a navigation app in the manifest |

### updateTrip

```
fun updateTrip(trip: Trip): Unit
```

Sends the destinations, steps, and trip estimates to the host.

The data **may** be rendered at different places in the car such as the instrument cluster screen or the heads-up display.

This method should only be invoked once the navigation app has called `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationStarted()`, or else the updates will be dropped by the host. Once the app has called `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationEnded()` or received `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManagerCallback#onStopNavigation()` it should stop sending updates.

As the location changes, and in accordance with speed and rounded distance changes, the `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/TravelEstimate`s in the provided `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/Trip` should be rebuilt and this method called again. For example, when the next step is greater than 10 kilometers away and the display unit is kilometers, updates should occur roughly every kilometer.

Data provided to the cluster display depends on the vehicle capabilities. In some instances the information may not be shown at all. On some vehicles `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/Maneuver`s of unknown type may be skipped while on other displays the associated icon may be shown.

| Parameters |
|---|---|
| `trip: https://developer.android.com/reference/kotlin/androidx/car/app/navigation/model/Trip` | destination, steps, and trip estimates to be sent to the host |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/HostException` | if the call is invoked by an app that is not declared as a navigation app in the manifest |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the call occurs when navigation is not started (see `https://developer.android.com/reference/kotlin/androidx/car/app/navigation/NavigationManager#navigationStarted()` for more info), or if the current thread is not the main thread |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if any of the destinations, steps, or trip position is not well formed |