# Advanced configurations

## Manually initialize the SDK

By default, the DriveKit SDK is automatically initialized as soon as you add the TripAnalysis module to your project.&#x20;

In some cases, you may want to manually initialize the SDK. To do this you have to disable the automatic initialization by adding the following lines into your Manifest file:

```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application>
        ...
        <meta-data
            android:name="com.drivekit.sdk.auto_init_enabled"
            android:value="false" />
    </application>
</manifest>

```

Then, you must call the initialization methods in the `onCreate` method of your Application class:

```kotlin
class MyApplication: Application() {
    override fun onCreate() {
        ...
        DriveKit.initialize()

        val tripNotification: TripNotification = ...
        DriveKitTripAnalysis.initialize(tripNotification)

        // Initialize every other DriveKit modules you use:
        // DriveKitDriverData.initialize()
        // DriveKitVehicle.initialize()
        // etc.
    }
}

```

## Check your configuration

You can check if DriveKit is well configured with the following method:

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

```kotlin
fun isConfigured(): Boolean
```

{% endtab %}
{% endtabs %}

This method returns `true` if these three conditions are met:

* DriveKit Core is initialized
* an API key is set
* a userId is set

## Check if user is authenticated

You can check if the user is connected by calling the following method:

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

```kotlin
fun isUserConnected(): Boolean
```

{% endtab %}
{% endtabs %}

This method returns `true` if the user is authenticated to DriveKit.

## Logging

DriveKit comes with a logging feature that is enabled by default. This feature allows you to quickly identify the cause of a problem. We recommend leaving the log enabled as it does not consume memory space and is useful in the support phase. However, if you don't want to use it, it can be disabled.

You can retrieve the `Uri` log file by calling the following method on `DriveKitLog` class:&#x20;

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

```kotlin
fun getLogUriFile(context: Context): Uri?
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
If your device version is on Android 10 or below, you can directly find the log file in Android/data/\<your-app-package-name>/files/\<path-to-my-log-directory>

If your device version is on Android 11 and above and if you have The Permissions Utils component on your app, you can get a log file of the previous month and the current one with the method `getZippedLogUriFiles()`, or by clicking on “Contact support” and change the email receiver. The file will be in attachment of the email.
{% endhint %}

Disable logging by calling the following method on `DriveKit` class:

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

```kotlin
fun disableLogging(showInConsole: Boolean = true)
```

{% endtab %}
{% endtabs %}

To enable logging, call the following method on `DriveKit` class, specifying (if needed) the path of the log directory:

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

```kotlin
fun enableLogging(logPath: String = "/DriveKit", showInConsole: Boolean = true)
```

{% endtab %}
{% endtabs %}

The DriveKit log ZIP file includes a configuration file in JSON format.&#x20;

This file lists the values of all configuration parameters for the DriveKit SDK installed in your user's app.

This [document](https://docs.google.com/spreadsheets/d/1cdU7jM3gLEyFBWpaHf5OH9SSRZkm38YACrohn0Cr-t4/edit?usp=sharing) provides a detailed overview of all the configuration entries included in the config file, along with their definitions and expected values.

## **Listen for permissions and sensors status changes**

If the user disables the sensors or revokes permissions, the application would not be able to detect and record a trip. To avoid this, the SDK identifies important sensor state and permission changes.&#x20;

These events are shared when the user is logged in and you can use them in your application to inform the user via a visual alert or by displaying a notification.

{% hint style="info" %}
Event changes callbacks may not be fired in real time due to technical restrictions of Android.
{% endhint %}

### DKDeviceConfigurationListener

`DKDeviceConfigurationListener` is the interface used to get callbacks when device configuration changes are detected:

```kotlin
interface DKDeviceConfigurationListener {
    fun onDeviceConfigurationChanged(event: DKDeviceConfigurationEvent)
}
```

### Add a listener

To add a listener and get informed for [device configuration events](#docs-internal-guid-959f39f9-7fff-5ef1-6859-d0cd591eb82e), you can call the following method:

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

```kotlin
fun addDeviceConfigurationListener(listener: DKDeviceConfigurationListener)
```

{% endtab %}
{% endtabs %}

### Remove a listener

To remove a specific listener, call the following method:

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

```kotlin
fun removeDeviceConfigurationListener(listener: DKDeviceConfigurationListener)
```

{% endtab %}
{% endtabs %}

### Remove all listeners

To remove all listeners, call the following method:

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

```kotlin
fun removeAllDeviceConfigurationListeners()
```

{% endtab %}
{% endtabs %}

### DKDeviceConfigurationEvent <a href="#docs-internal-guid-959f39f9-7fff-5ef1-6859-d0cd591eb82e" id="docs-internal-guid-959f39f9-7fff-5ef1-6859-d0cd591eb82e"></a>

`DKDeviceConfigurationEvent` is a sealed class that describes a device configuration change event:&#x20;

<pre class="language-kotlin"><code class="lang-kotlin">sealed class DKDeviceConfigurationEvent {
	data class LocationPermission(val isValid: Boolean) : DKDeviceConfigurationEvent()
	data class ActivityPermission(val isValid: Boolean) : DKDeviceConfigurationEvent()
	data class NearbyDevicesPermission(val isValid: Boolean) : DKDeviceConfigurationEvent()
	data class NotificationPermission(val isValid: Boolean) : DKDeviceConfigurationEvent()
<strong>	data class AutoResetPermission(val isValid: Boolean) : DKDeviceConfigurationEvent()
</strong>	data class AppBatteryOptimisation(val isValid: Boolean) : DKDeviceConfigurationEvent()
	data class LocationSensor(val isValid: Boolean) : DKDeviceConfigurationEvent()
	data class BluetoothSensor(val isValid: Boolean) : DKDeviceConfigurationEvent()
}
</code></pre>

Possible events are:

<table><thead><tr><th width="283">Value</th><th>Description</th></tr></thead><tbody><tr><td>LocationPermission</td><td>Location permission status changed</td></tr><tr><td>ActivityPermission</td><td>Activity Recognition permission status changed</td></tr><tr><td>NearbyDevicesPermission</td><td>Nearby Devices permission status changed</td></tr><tr><td>NotificationPermission</td><td>Notification permission status changed</td></tr><tr><td>AutoResetPermission</td><td>Auto-reset permission status changed</td></tr><tr><td>AppBatteryOptimization</td><td>Battery Optimization app status changed</td></tr><tr><td>LocationSensor</td><td>Location sensor status changed</td></tr><tr><td>BluetoothSensor</td><td>Bluetooth sensor status changed </td></tr></tbody></table>

The DriveKit SDK will run optimally if the `isValid` value of each event is `true`. The table below explains the impact of a status that is not `true`:

<table><thead><tr><th width="288.3333333333333">Event</th><th width="106" align="center">Criticality</th><th>Consequence if value is false</th></tr></thead><tbody><tr><td>LocationPermission</td><td align="center">🔴</td><td>No trip recording if app has no access to GPS sensor</td></tr><tr><td>ActivityPermission</td><td align="center">🟡</td><td>Poor trip detection</td></tr><tr><td>NearbyDevicesPermission</td><td align="center">🟡</td><td>No trip detection based on beacon or Bluetooth system</td></tr><tr><td>NotificationPermission</td><td align="center">🟢</td><td>Your application cannot send notification to the user if the permission is revoked.</td></tr><tr><td>AutoResetPermission</td><td align="center">🟢</td><td>Revocation of all permissions if app is not opened for 3 months.</td></tr><tr><td>AppBatteryOptimization</td><td align="center">🟡</td><td>Poor trip detection, application may be killed in background</td></tr><tr><td>LocationSensor</td><td align="center">🔴</td><td>No trip recording if location sensor is disabled</td></tr><tr><td>BluetoothSensor</td><td align="center">🟡</td><td>No trip detection based on beacon or Bluetooth system</td></tr></tbody></table>

## **Get user’s information**

To get the user's information (first name, last name and pseudo), call the `getUserInfo` method. This method will retrieve and save these data locally:

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

```kotlin
fun getUserInfo(
        listener: GetUserInfoQueryListener,
        synchronizationType: SynchronizationType = SynchronizationType.DEFAULT
)
```

{% endtab %}
{% endtabs %}

## **Update user’s information**

You can add information to a user's account such as first name, last name and pseudo.

These details are optional and you can choose to make the user's account anonymous. To update the user's information, call the following method :

{% tabs %}
{% tab title="DriveKit" %}
{% code fullWidth="false" %}

```kotlin
fun updateUserInfo(
        firstname: String? = null,
        lastname: String? = null,
        pseudo: String? = null,
        listener: UpdateUserInfoQueryListener
)
```

{% endcode %}
{% endtab %}
{% endtabs %}

## **Update UserId**

It is possible to update the userId by calling the following method:

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

```kotlin
fun updateUserId(userId: String)
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
To be able to check whenever `userId` got updated and catch the update status you have to use [DriveKitListener](https://docs.drivequant.com/get-started-drivekit/references#drivekitlistener) listener.
{% endhint %}

## Account deletion

You can delete a driver's account in DriveKit. This action deletes all the data related to the account.

&#x20;The deletion can be done instantly or with delay.&#x20;

* In the first case, when the method is called, the account is instantly deleted.&#x20;
* In the second case, the driver has 30 days to log back into the application and reactivate his account.

To delete a driver's account, use the following method:

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

```kotlin
fun deleteAccount(instantDeletion: Boolean = false)
```

{% endtab %}
{% endtabs %}

`instantDeletion` can have 2 values:&#x20;

* `false` : Default value, allows the user to recover the deleted account by logging-in again with the same credentials. Users have 30 days starting from the day when the account was deleted.
* `true` : Allow to delete an account instantly. The account and all the related data will be immediately deleted and no rollback is possible.

{% hint style="info" %}
Your team needs to have the deletion feature activated to use this method. Please contact DriveQuant if you need it.
{% endhint %}

{% hint style="info" %}
To be able to check whenever the account deletion is complete, you have to use the [DriveKitListener](https://docs.drivequant.com/get-started-drivekit/android/references#drivekitlistener) interface.
{% endhint %}

{% hint style="warning" %}
You should restore the DriveKit API key in the `onAccountDeleted()` callback only when the status value is `SUCCESS`.
{% endhint %}

## Retrieving the installation identifier <a href="#retrieving-the-installation-identifier" id="retrieving-the-installation-identifier"></a>

The installation identifier (**installationId**) is not a unique device identifier. It is used to identify an app installation that includes the DriveKit SDK, linked to a specific account on a particular device.

The **installationId** is generated based on the following attributes:&#x20;

* Installation date
* App
* User account
* Device type

The **installationId** helps determine whether a user has logged into a mobile app with the same account across multiple devices.

For a user with one account and a single device, the **installationId** behaves as follows:

* It remains unchanged if the user logs out and logs back in, as long as the app is not uninstalled.
* It is updated when the user uninstalls and reinstalls the app.

\
If a user logs into the app on several devices using the same account, each device will have a different **installationId**.

If the user reconnects to the app on the same device but with a different account, the installationId will be updated.

{% hint style="info" %}
The installationId uses the UUID format. Example: `123e4567-e89b-12d3-a456-426614174000`
{% endhint %}

You can retrieve the **installationId** by calling the following computed property:

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

```kotlin
var installationId: String?
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The returned installationId will be `null` as long as the user is not authenticated to DriveKit.

For example, you can retrieve the identifier after the `onConnected()` callback is triggered. (Read more about the [DriveKitListener](https://docs.drivequant.com/get-started-drivekit/references#drivekitlistener))
{% endhint %}

## Reset

If you need to reset DriveKit configuration (user logout for example), you can call the following method:

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

```kotlin
fun reset()
```

{% endtab %}
{% endtabs %}

All data saved locally will be erased and default configuration for every module will be restored.
