public class

TestNavigationManager

extends NavigationManager

 java.lang.Object

androidx.car.app.navigation.NavigationManager

↳androidx.car.app.testing.navigation.TestNavigationManager

Gradle dependencies

compile group: 'androidx.car.app', name: 'app-testing', version: '1.7.0-beta01'

  • groupId: androidx.car.app
  • artifactId: app-testing
  • version: 1.7.0-beta01

Artifact androidx.car.app:app-testing:1.7.0-beta01 it located at Google repository (https://maven.google.com/)

Overview

The NavigationManager that is used for testing.

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

Summary

Constructors
publicTestNavigationManager(TestCarContext testCarContext, HostDispatcher hostDispatcher)

Methods
public voidclearNavigationManagerCallback()

Clears the callback for receiving navigation manager events.

public intgetNavigationEndedCount()

Returns the number of times that navigation was ended via NavigationManager.navigationEnded() since creation or the last call to TestNavigationManager.reset().

public NavigationManagerCallbackgetNavigationManagerCallback()

Returns the callback set via NavigationManager.setNavigationManagerCallback(NavigationManagerCallback).

public intgetNavigationStartedCount()

Returns the number of times that navigation was started via NavigationManager.navigationStarted() since creation or the last call to TestNavigationManager.reset().

public java.util.List<Trip>getTripsSent()

Returns all the Trips sent via NavigationManager.updateTrip(Trip).

public voidnavigationEnded()

Notifies the host that the app has ended active navigation.

public voidnavigationStarted()

Notifies the host that the app has started active navigation.

public voidreset()

Resets the values tracked by this TestNavigationManager.

public voidsetNavigationManagerCallback(java.util.concurrent.Executor executor, NavigationManagerCallback callback)

Sets a callback to start receiving navigation manager events.

public voidupdateTrip(Trip trip)

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

from NavigationManagercreate, getIInterface, onAutoDriveEnabled, onStopNavigation, setNavigationManagerCallback
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public TestNavigationManager(TestCarContext testCarContext, HostDispatcher hostDispatcher)

Methods

public void reset()

Resets the values tracked by this TestNavigationManager.

public java.util.List<Trip> getTripsSent()

Returns all the Trips sent via NavigationManager.updateTrip(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 TestNavigationManager.reset() is called.

public NavigationManagerCallback getNavigationManagerCallback()

Returns the callback set via NavigationManager.setNavigationManagerCallback(NavigationManagerCallback).

The listener will be null if one was never set, or if NavigationManager.clearNavigationManagerCallback() or TestNavigationManager.reset() was called.

public int getNavigationStartedCount()

Returns the number of times that navigation was started via NavigationManager.navigationStarted() since creation or the last call to TestNavigationManager.reset().

public int getNavigationEndedCount()

Returns the number of times that navigation was ended via NavigationManager.navigationEnded() since creation or the last call to TestNavigationManager.reset().

public void updateTrip(Trip trip)

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 NavigationManager.navigationStarted(), or else the updates will be dropped by the host. Once the app has called NavigationManager.navigationEnded() or received NavigationManagerCallback.onStopNavigation() it should stop sending updates.

As the location changes, and in accordance with speed and rounded distance changes, the TravelEstimates in the provided 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 Maneuvers of unknown type may be skipped while on other displays the associated icon may be shown.

Parameters:

trip: destination, steps, and trip estimates to be sent to the host

public void setNavigationManagerCallback(java.util.concurrent.Executor executor, NavigationManagerCallback callback)

Sets a callback to start receiving navigation manager events.

Parameters:

executor: the executor which will be used for invoking the callback
callback: the NavigationManagerCallback to use

public void clearNavigationManagerCallback()

Clears the callback for receiving navigation manager events.

public void navigationStarted()

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 NavigationManager.setNavigationManagerCallback(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 NavigationManagerCallback.onStopNavigation().

This method is idempotent.

public void navigationEnded()

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.

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.car.app.testing.navigation;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.HostDispatcher;
import androidx.car.app.navigation.NavigationManager;
import androidx.car.app.navigation.NavigationManagerCallback;
import androidx.car.app.navigation.model.Trip;
import androidx.car.app.testing.TestCarContext;
import androidx.car.app.utils.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;

/**
 * The {@link NavigationManager} that is used for testing.
 *
 * <p>This class will track the following usages of the {@link NavigationManager} throughout your
 * test:
 *
 * <ul>
 *   <li>All the {@link Trip}s sent via {@link NavigationManager#updateTrip}.
 *   <li>All the {@link NavigationManagerCallback}s set via
 *   {@link NavigationManager#setNavigationManagerCallback}.
 *   <li>Count of times that the navigation was started via {@link
 *       NavigationManager#navigationStarted()}.
 *   <li>Count of times that the navigation was ended via {@link NavigationManager#navigationEnded}.
 * </ul>
 */
public class TestNavigationManager extends NavigationManager {
    private final List<Trip> mTripsSent = new ArrayList<>();
    @Nullable
    private NavigationManagerCallback mCallback;
    private int mNavigationStartedCount;
    private int mNavigationEndedCount;

    /** Resets the values tracked by this {@link TestNavigationManager}. */
    public void reset() {
        mTripsSent.clear();
        mCallback = null;
        mNavigationStartedCount = 0;
        mNavigationEndedCount = 0;
    }

    /**
     * Returns all the {@link Trip}s sent via {@link NavigationManager#updateTrip}.
     *
     * <p>The trips are stored in the order in which they were sent, where the first trip in the
     * list, is the first trip sent.
     *
     * <p>The trips will be stored until {@link #reset} is called.
     */
    @NonNull
    public List<Trip> getTripsSent() {
        return CollectionUtils.unmodifiableCopy(mTripsSent);
    }

    /**
     * Returns the callback set via {@link NavigationManager#setNavigationManagerCallback}.
     *
     * <p>The listener will be {@code null} if one was never set, or if
     * {@link NavigationManager#clearNavigationManagerCallback()}  or {@link #reset} was called.
     */
    @Nullable
    public NavigationManagerCallback getNavigationManagerCallback() {
        return mCallback;
    }

    /**
     * Returns the number of times that navigation was started via {@link
     * NavigationManager#navigationStarted()} since creation or the last call to {@link #reset}.
     */
    public int getNavigationStartedCount() {
        return mNavigationStartedCount;
    }

    /**
     * Returns the number of times that navigation was ended via {@link
     * NavigationManager#navigationEnded()} since creation or the last call to {@link #reset}.
     */
    public int getNavigationEndedCount() {
        return mNavigationEndedCount;
    }

    @Override
    public void updateTrip(@NonNull Trip trip) {
        mTripsSent.add(trip);
        super.updateTrip(trip);
    }

    @Override
    public void setNavigationManagerCallback(@NonNull /* @CallbackExecutor */ Executor executor,
            @NonNull NavigationManagerCallback callback) {
        mCallback = callback;
        super.setNavigationManagerCallback(executor, callback);
    }

    @Override
    public void clearNavigationManagerCallback() {
        mCallback = null;
        super.clearNavigationManagerCallback();
    }

    @Override
    public void navigationStarted() {
        mNavigationStartedCount++;
        super.navigationStarted();
    }

    @Override
    public void navigationEnded() {
        mNavigationEndedCount++;
        super.navigationEnded();
    }

    public TestNavigationManager(@NonNull TestCarContext testCarContext,
            @NonNull HostDispatcher hostDispatcher) {
        super(testCarContext, hostDispatcher, testCarContext.getLifecycleOwner().mRegistry);
    }
}