# Huawei Android SDK

## 1. Integrate dependencies

To integrate our SDK into your application edit your build.gradle:

* Add this block to the *root* section:

```
allprojects {
    repositories {
        //...
        maven {
            url "https://jitpack.io"
        }
    }
}
```

* Add this block to the *dependencies* section:

```
implementation 'com.github.FendAiCorp.fendvpn-android:sdk:<VERSION>'
```

## 2. Configurate SDK

To start using the SDK, you need to create a WireSdk instance. Initialize FendSDK with a  WireConfi&#x67;**:**

```
val sdk = WireSdk.provide(
    WireConfig("backend url", "project id", "app version")
)
```

| Value       | Description                                                  |
| ----------- | ------------------------------------------------------------ |
| backend URL | Base URL for the API calls (login, fetching locations, etc.) |
| project id  | A unique identifier of the project                           |
| app version | The application version for analytics purposes               |

{% hint style="info" %}
For backend URL and project ID please contact <partners@fend.ai>
{% endhint %}

## 3. Use API

After SDK initialization you need to authenticate the user on the backend and acquire the list of available locations to connect.

### 3.1 Authentication

```
sdk.api().login(WireAuth.AuthAnonymous).fold(
    onSuccess = {
        //success
    },
    onFailure = {
        //error
    }
)

sdk.api().logout() // logout the user
sdk.api().isLoggedIn() // check if user is logged in
```

### 3.2 Available locations

```
sdk.api().locations().fold(
    onSuccess = { locations ->
        // select location to connect to
    },
    onFailure = {
        // error
    }
)
```

## 4. Manage VPN

After getting a virtual location configuration, you are ready to start a VPN session.

### 4.1 Start / Stop

```
val location: VirtualLocation = //use location fetched 
                                // on the previous step
sdk.vpn().start(SessionConfig(location)).fold(onSuccess = {
    // connected
}, onFailure = {
    // connection error
})

sdk.vpn().stop() // to stop vpn session
```

### 4.2 Statistics

An active VPN connection provides statistics on the amount of traffic, connection start time, and the chosen VPN server IP.

```
val stats = sdk.vpn().stats()
stats.fold(
    onSuccess = {
        // update traffic data
    },
    onFailure = {
        // error
    }
)
```

### 4.3 State

The SDK can provide information on the current VPN tunnel state.

```
sdk.vpn().state().collect { state->
    // state updated
}
```

| Value               | Description                                |
| ------------------- | ------------------------------------------ |
| VpnState.IDLE       | No active VPN connection exists            |
| VpnState.CONNECTING | Establishing a VPN connection right now    |
| VpnState.CONNECTED  | A VPN connection is established and active |
| VpnState.ERROR      | A VPN connection process has failed        |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fendai.gitbook.io/fendvpn-docs/huawei-android-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
