Skip to main content

Usage

connect(), status(), and disconnect() are suspend functions, so call them from a coroutine (lifecycleScope, viewModelScope, and so on). connect() and disconnect() can throw a WiDASException; status() never does.

Configure

Build one WiDAS instance with the application context and reuse it.

import com.widas.sdk.WiDAS

val widas = WiDAS.configure(
context = applicationContext,
partnerId = "partner-acme",
baseUrl = "https://partner-api.wi-das.com/",
cloudProjectNumber = 123456789L,
)
ParameterRequiredNotes
contextAny context; the SDK keeps the application context.
partnerIdYour Wi-DAS-issued public identifier.
baseUrlThe Certificate API base URL, with a trailing slash.
cloudProjectNumberrecommendedGoogle Cloud project number for Play Integrity (required for non-Play builds).

Connect

connect() is idempotent. Call it on launch, and again after any EXPIRED or REVOKED status. requestedValidity is an optional ISO-8601 duration; leave it out (or pass null) to let Wi-DAS clamp to policy.

lifecycleScope.launch {
try {
val result = widas.connect(user = "user-42", requestedValidity = "P365D")
Log.i("WiDAS", "Onboarded. Serial ${result.serial}, expires ${result.notAfter}")
} catch (e: WiDASException) {
handle(e) // see Error handling
}
}

ConnectionResult carries the certificate serial and its notAfter expiry.

Status

status() is advisory and never throws, so it's safe to call whenever you're rendering UI.

lifecycleScope.launch {
when (widas.status().state) {
WiDAS.Status.State.NONE -> promptToConnect()
WiDAS.Status.State.VALID -> showConnected()
WiDAS.Status.State.EXPIRED,
WiDAS.Status.State.REVOKED -> widas.connect(user = "user-42") // re-onboard
}
}

Status gives you state (NONE/VALID/EXPIRED/REVOKED), the serial, and the expiry. Remember the network is the real authority; status() is for the UI.

Disconnect

Remove the installed profile when the user asks, or after a REVOKED result.

lifecycleScope.launch {
widas.disconnect()
}

Play Integrity keeps no state, so a later connect() just re-runs the usual onboarding.

A complete launch flow

fun onLaunch(userId: String) {
lifecycleScope.launch {
try {
// Idempotent: first run, renewal or recovery — one call.
widas.connect(user = userId, requestedValidity = "P365D")
} catch (e: WiDASException.AttestationUnavailable) {
showUnsupported() // no Play Services / unsupported device
} catch (e: WiDASException) {
handle(e)
}

render(widas.status()) // reflect real state in the UI
}
}
Play Integrity needs Play Services

On a device without Google Play Services, connect() fails with AttestationUnavailable. There's no fallback path, so detect this and degrade the UI rather than looping on it.

Next: Error handling.