TestAppManager


class TestAppManager : AppManager


The AppManager that is used for testing.

This class will track the following usages of the AppManager throughout your test:

Summary

Public functions

SurfaceCallback?

Returns the callback set via setSurfaceCallback, or null if not set.

(Mutable)List<Pair<Screen!, Template!>!>

Returns all the Templates returned from onGetTemplate due to a call to invalidate, and the respective Screen instance that returned it.

(Mutable)List<CharSequence!>

Returns all the toasts shown via showToast.

Unit

Resets the values tracked by this TestAppManager and all ScreenControllers.

Unit

Sets the SurfaceCallback to get changes and updates to the surface on which the app can draw custom content, or null to reset the listener.

Unit
showToast(text: CharSequence, duration: Int)

Shows a toast on the car screen.

Inherited functions

From androidx.car.app.AppManager
Unit
@RequiresCarApi(value = 5)
dismissAlert(alertId: Int)

Dismisses the alert with the given id.

Unit

Requests the current template to be invalidated, which eventually triggers a call to onGetTemplate to get the new template to display.

Unit
@RequiresCarApi(value = 5)
showAlert(alert: Alert)

Shows an alert on the car screen.

Public functions

getSurfaceCallback

Added in 1.1.0
fun getSurfaceCallback(): SurfaceCallback?

Returns the callback set via setSurfaceCallback, or null if not set.

getTemplatesReturned

Added in 1.1.0
fun getTemplatesReturned(): (Mutable)List<Pair<Screen!, Template!>!>

Returns all the Templates returned from onGetTemplate due to a call to invalidate, and the respective Screen instance that returned it. The results are stored in the order in which they were returned from onGetTemplate, where the first template in the list, is the first template returned.

The results will be stored until reset is called.

getToastsShown

Added in 1.1.0
fun getToastsShown(): (Mutable)List<CharSequence!>

Returns all the toasts shown via showToast.

The toasts are stored in the order in which they are sent via showToast, where the first toast in the list is the first toast that was sent.

The toasts will be stored until reset is called.

reset

Added in 1.1.0
fun reset(): Unit

Resets the values tracked by this TestAppManager and all ScreenControllers.

setSurfaceCallback

fun setSurfaceCallback(surfaceCallback: SurfaceCallback?): Unit

Sets the SurfaceCallback to get changes and updates to the surface on which the app can draw custom content, or null to reset the listener.

This call requires the androidx.car.app.ACCESS_SURFACE permission to be declared.

The Surface can be used to draw custom content such as a navigation app's map.

Note that the listener relates to UI events and will be executed on the main thread using getMainLooper.

Throws
java.lang.SecurityException

if the app does not have the required permissions to access the surface

androidx.car.app.HostException

if the remote call fails

showToast

fun showToast(text: CharSequence, duration: Int): Unit

Shows a toast on the car screen.

Parameters
text: CharSequence

the text to show

duration: Int

how long to display the message

Throws
androidx.car.app.HostException

if the remote call fails

java.lang.NullPointerException

if text is null