TestAppManager


public class TestAppManager extends AppManager


The AppManager that is used for testing.

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

Summary

Public methods

@Nullable SurfaceCallback

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

@NonNull List<Pair<ScreenTemplate>>

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

@NonNull List<CharSequence>

Returns all the toasts shown via showToast.

void

Resets the values tracked by this TestAppManager and all ScreenControllers.

void

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.

void
showToast(@NonNull CharSequence text, int duration)

Shows a toast on the car screen.

Inherited methods

From androidx.car.app.AppManager
void
@RequiresCarApi(value = 5)
dismissAlert(int alertId)

Dismisses the alert with the given id.

void

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

void
@RequiresCarApi(value = 5)
showAlert(@NonNull Alert alert)

Shows an alert on the car screen.

Public methods

getSurfaceCallback

Added in 1.1.0
public @Nullable SurfaceCallback getSurfaceCallback()

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

getTemplatesReturned

Added in 1.1.0
public @NonNull List<Pair<ScreenTemplate>> getTemplatesReturned()

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
public @NonNull List<CharSequencegetToastsShown()

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
public void reset()

Resets the values tracked by this TestAppManager and all ScreenControllers.

setSurfaceCallback

public void setSurfaceCallback(@Nullable SurfaceCallback surfaceCallback)

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

public void showToast(@NonNull CharSequence text, int duration)

Shows a toast on the car screen.

Parameters
@NonNull CharSequence text

the text to show

int duration

how long to display the message

Throws
androidx.car.app.HostException

if the remote call fails

java.lang.NullPointerException

if text is null