# Services

## **Detection Services**

### **Start Automatic Detection**

Starts the required detection services stated in the [MoveConfig](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveconfig) passed on initialization. Starting the service will set the [MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) to `Running`.

{% hint style="warning" %}
**Precondition**: SDK should be in`READY`[MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate).
{% endhint %}

```kotlin
fun startAutomaticDetection()
```

### **Stop Automatic Detection**

Stops the automatic detection service, including all SDK services like driving detection, points of interest, walking and places. Stopping the service will set the [MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) back to `Ready`.&#x20;

{% hint style="warning" %}
**Precondition**: SDK should be in`Running`[MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate).
{% endhint %}

```kotlin
fun stopAutomaticDetection()
```

### **Force Trip Recognition**

Temporarily calibrates the SDK to the highest detection mode.

In order to optimize battery consumption, the SDK goes through different detection modes with different battery consumption levels, depending on the user's current behavior and activity. In general, the SDK is responsible for alternating between those different detection modes.&#x20;

The SDK also provides hosting apps this API to call if they have their own reasons (like buttons, sensors or beacons) to believe that the user is starting a trip. This will make sure the SDK is on the highest detection state to detect the trip faster.

{% hint style="warning" %}
&#x20;**Precondition**: SDK should be in`RUNNING` [MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate).
{% endhint %}

```kotlin
fun forceTripRecognition()
fun forceTripRecognition(duration: Long) 
```

| **Parameters** |      | Description                                                                                                                         |
| -------------- | ---- | ----------------------------------------------------------------------------------------------------------------------------------- |
| duration       | Long | Limit the high power detection to a certain amount of time in milliseconds, to not drain the battery. Default one minute (60 000ms) |

### **Finish Current Trip**

Ends the current ongoing trip.

This API will end the ongoing trip and set [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) back to `.idle`. The SDK is responsible for detecting the trip start and end points. The SDK also provides hosting apps this API to call if they have their own reasons (like sensors or beacons) to believe that the user's trip has ended.

{% hint style="warning" %}
**Precondition**:[ MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) should be in an active trip.
{% endhint %}

```kotlin
fun finishCurrentTrip()
```

{% hint style="info" %}
If this API is called while the user is active on a driving trip, a new trip will start again right away. If the intention is to un-track the ongoing trip, call `ignoreCurrentTrip`API.

More information about trip states can be found in [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate).
{% endhint %}

### **Ignore Current Trip**

Ignores the current ongoing trip.&#x20;

This API will set the ongoing [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) to `.ignored`. Data of ignored trips is purged and not sent to the server.

{% hint style="warning" %}
**Precondition**: [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) should be in an active trip.
{% endhint %}

```kotlin
fun ignoreCurrentTrip()
```

## Processing Services

### **Keep in foreground**

When an Android application is in the background it may receive limited data (location, sensors, etc.). To improve this behavior, it is possible to put the application always in the foreground with a visible notification that cannot be discarded. Just because it's visible it doesn't mean that it is performing any data collection at all. So this should not have any significant battery impact at all.

{% hint style="info" %}
Disabled by default.
{% endhint %}

{% hint style="warning" %}
Since it may be annoying to the user, it should only be enabled in case of problems.
{% endhint %}

```kotlin
fun keepInForeground(enabled: Boolean)
```

### **Keep active**

To save battery consumption, the SDK is using several triggers to start its data listeners. In case of trouble, these triggers can be circumvented by allowing the MoveSdk to stay active all the time. In that case the SDK is always monitoring required data and is therefore consuming more battery. Depending on the configuration, it may happen that the notification (see[ notification handling](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/appendix/android/notification-managment)) is always visible to the user.

{% hint style="info" %}
Disabled by default.
{% endhint %}

{% hint style="warning" %}
Since this is consuming more battery, it should only be enabled in case of problems.
{% endhint %}

```kotlin
fun keepActive(enabled: Boolean)
```

### **Console logging**

Toggles whether the MOVE SDK is allowed to log into the console or not.&#x20;

{% hint style="info" %}
Enabled by default.
{% endhint %}

```kotlin
fun consoleLogging(enabled: Boolean)
```

| Parameter |                                                          |
| --------- | -------------------------------------------------------- |
| enabled   | Boolean that sets SDK console logging to enabled or not. |

### **Get SDK State**

Gets the current[ MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate).

```kotlin
fun getSDKState() : MoveSDKState
```

| **Return**                                                                               |                                                                                                  |
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| [MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) | Latest [MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate). |

### **Get Trip State**

Gets the current [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate).

```kotlin
fun getTripState(): MoveTripState
```

| **Return**                                                                                    |                                                                                                       |
| --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) | Latest [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate). |

### Get Device Status

Gets the current [MoveDeviceStatus](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movedevicestatus)*.*

```kotlin
fun getDeviceStatus(): MoveDeviceStatus
```

| Return                                                                                              |                                                                                                              |
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| [MoveDeviceStatus](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movedevicestatus) | Latest  [MoveDeviceStatus](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movedevicestatus). |

### **Delete Local Data**

Deletes all the collected user SDK data stored on the device. This doesn't affect the [MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate).

{% hint style="warning" %}
**Precondition:** SDK should be initialized.
{% endhint %}

```kotlin
fun deleteLocalData()
```

### **Shutdown SDK**

Shutdown SDK shared instance.

Stops SDK services, send the queued user data, and de-initializes the SDK. After that is executed,  the [MoveSdkState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) will transit to `Uninitialised`.

{% hint style="warning" %}
**Precondition:** SDK should be initialized.
{% endhint %}

```kotlin
fun shutdown()
```

### **Synchronize User Data**

Used to force synchronizing user data with the SDK server. Limited to once per 2 minutes.

```kotlin
fun synchronizeUserData()
```

Returns FALSE in case there are Timeline-relevant packages in the queue that remain to be sent to the SDK Backend; and it returns TRUE in case the queue is empty.

## Configuration services

### Update authentication

Updates SDK [MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth). On SDK auth expiry, the Builder.authStateListener will trigger expired state. The host app is expected to fetch a new [MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) using its product API key and pass it to the MoveSdk using the following API:

```kotlin
fun updateAuth(auth: MoveSdk.Auth, onError: (MoveConfigurationError) -> Unit)
```

| **Parameters** |                        |
| -------------- | ---------------------- |
| auth           | Valid auth credentials |

| **Callback** |                                                                                                                                                                                                               |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| onError      | Block that gets invoked on auth update completion error. On completion with error, [MoveConfigurationError](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveconfigurationerror) is passed. |
