# Android

## Integration

The Trip Simulator component includes two modules:

* The first module is used as a testing tool for your debug application.
* The second module is a “no-op” module. It will do nothing and does not include any trip data: it’s an empty implementation that mirrors the public methods and objects of the first module which can be integrated into your release-mode application to maintain a consistent codebase across both debug and release modes without embedding the real trip simulator in production.

To include the Trip Simulator module in your app, insert the following lines into the dependencies section of your application's `build.gradle` file:

```gradle
dependencies {
    debugImplementation 'com.drivequant.drivekit:drivekit-trip-simulator:$drivekit_version'
    releaseImplementation 'com.drivequant.drivekit:drivekit-trip-simulator-noop:$drivekit_version'
}
```

{% hint style="info" %}
Replace `$drivekit_version` with the DriveKit version you are using in your app
{% endhint %}

## Usage

DriveQuant offers the possibility of running simulations from a list of preset trips. After integrating and activating the trip simulation component, you can select a preset trip from those described in the table below. Once the simulation is launched, the Trip Analysis component will receive the configured callbacks automatically.

<table><thead><tr><th width="247.5132933346892">Name</th><th width="107">Duration (min)</th><th width="86.70248040495565">Distance (km)</th><th>Description</th></tr></thead><tbody><tr><td>SHORT_TRIP</td><td>8</td><td>2</td><td>Trip too short that does not allow to rate the driver's behavior</td></tr><tr><td>MIXED_TRIP</td><td>15</td><td>12</td><td>A mixed trip in urban and suburban areas</td></tr><tr><td>CITY_TRIP</td><td>20</td><td>8</td><td>A city trip </td></tr><tr><td>SUBURBAN_TRIP</td><td>30</td><td>30</td><td>A trip performed in a suburban environment mostly</td></tr><tr><td>HIGHWAY_TRIP</td><td>55</td><td>100</td><td>A highway trip </td></tr><tr><td>TRAIN_TRIP</td><td>10</td><td>5</td><td>Trip recorded in a train to test the alternative transportation modes detection</td></tr><tr><td>BUS_TRIP</td><td>13</td><td>3</td><td>Trip recorded in a bus to test the alternative transportation modes detection</td></tr><tr><td>BOAT_TRIP</td><td>40</td><td>25</td><td>Trip recorded in a boat to test the alternative transportation modes detection</td></tr><tr><td>TRIP_WITH_CRASH_1</td><td>5</td><td>1</td><td>A trip to simulate an unconfirmed or a confirmed crash.</td></tr><tr><td>TRIP_WITH_CRASH_2_STILL_DRIVING</td><td>23</td><td>24</td><td>A trip to simulate an accident confirmed less than two minutes after the start of the trip, after which the driver continued driving.</td></tr></tbody></table>

### Enable Developer Mode

The user must enable the developer mode in Android. The [official documentation](https://developer.android.com/studio/debug/dev-options#enable) explains well how to proceed.

### Mock Location App

In the *Debugging* category, tap on *Select mock location app* and select yours. It sometimes appears that you might uninstall and reinstall your app on the device in order to register it as a mock location app.

### Simulate a trip

To simulate a trip, call the following method with a appropriate configuration with the `PresetTrip` parameter.

{% tabs %}
{% tab title="DriveKitTripSimulator" %}

```kotlin
fun start(presetTrip: PresetTrip, listener: DKTripSimulatorListener? = null): Boolean
```

{% endtab %}
{% endtabs %}

### Stop the simulation

To stop the trip simulation, you must call the following metho&#x64;**:**

{% tabs %}
{% tab title="DriveKitTripSimulator" %}

```kotlin
fun stop()
```

{% endtab %}
{% endtabs %}

Otherwise you can manually remove your app as the mock location app in the developers settings.

### Simulate a crash during a trip

In order to mock an accident to check your integration, you must choose between `TRIP_WITH_CRASH_1` or `TRIP_WITH_CRASH_2_STILL_DRIVING`  as `PresetTrip` parameter:

Possible values for `PresetTripCrash1` enum used by `TRIP_WITH_CRASH_1` are described in the table below:

<table><thead><tr><th width="275.09788437524355">Name</th><th>Description</th></tr></thead><tbody><tr><td>CONFIRMED_40KMH</td><td>A short trip with a collision at 40 km/h that occurs 132 seconds after the trip begins and that corresponds to a confirmed accident.</td></tr><tr><td>CONFIRMED_30KMH</td><td>A short trip with a collision at 30 km/h that occurs 137 seconds after the trip begins and that corresponds to a confirmed accident.</td></tr><tr><td>CONFIRMED_20KMH</td><td>A short trip with a collision at 20 km/h that occurs 141 seconds after the trip begins and that corresponds to a confirmed accident.</td></tr><tr><td>UNCONFIRMED_0KMH</td><td>A short trip with a collision during a vehicle stop that occurs 159 seconds after the trip begins and that corresponds to an unconfirmed accident.</td></tr></tbody></table>

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
DriveKitTripSimulator.start(PresetTrip.TRIP_WITH_CRASH_1(PresetTripCrash1.CONFIRMED_30KMH))
```

{% endtab %}

{% tab title="Java" %}

```java
DriveKitTripSimulator.INSTANCE.start(new PresetTrip.TRIP_WITH_CRASH_1(PresetTripCrash1.CONFIRMED_30KMH));
```

{% endtab %}
{% endtabs %}

### Check if it’s the no-op module <a href="#docs-internal-guid-119ea02b-7fff-c896-c348-46d5b787d500" id="docs-internal-guid-119ea02b-7fff-c896-c348-46d5b787d500"></a>

To check whether the "no-op" module is embedded, you can execute the following code:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val isNoop = DriveKitTripSimulator.isNoop
```

{% endtab %}

{% tab title="Java" %}

```java
final boolean isNoop = DriveKitTripSimulator.INSTANCE.isNoop();
```

{% endtab %}
{% endtabs %}
