User Device Management (UDM)
The User Device Management (UDM) module provides functionality to manage and track user devices, including registration, monitoring, and removal of devices.
Table of Contents
registerDevice
getLinkDevices
getLinkDevice
updateLastOnline
updateDeviceName
removeDevice
getLinkDevicesHistory
Methods
registerDevice
Registers a new device with the system.
Parameters:
body
: ARegisterDeviceRequest
object containing:uniqueId
: The unique identifier of the deviceuniqueIdType
: The type of unique identifier ( "uuid", "imei")label
: The device labeltype
: The device type ("mobile", "cloud", "browser")customName
: The custom name of the deviceos
: The operating system versionbrowserName
: The browser name (if applicable)
fun registerDevice(context: Context, username: String) {
viewModelScope.launch {
passkey?.authenticate(username)
?.flatMapLatest {
udmRepository = UDMRepositoryImpl("https://trust-fabric.mpc-dev.cramiumtech.com", it.accessToken)
udmRepository!!.registerDevice(context)
}
?.collect { response ->
Log.d("MainActivityViewModel", "Register device response: $response")
}
}
}
getLinkDevices
Retrieves a list of all linked devices for the current user.
fun getLinkDevices() {
viewModelScope.launch {
udmRepository?.getLinkDevices()
?.collect { devices ->
Log.d("MainActivityViewModel", "Link devices response: $devices")
}
}
}
getLinkDevice
Retrieves details of a specific linked device.
Parameters:
uniqueId
: The unique identifier of the device
fun getLinkDevice(uniqueId: String) {
viewModelScope.launch {
udmRepository?.getLinkDevice(uniqueId)
?.collect { device ->
Log.d("MainActivityViewModel", "Link device response: $device")
}
}
}
updateLastOnline
Updates the last online timestamp for a specific device.
Parameters:
uniqueId
: The unique identifier of the device
fun updateLastOnline(uniqueId: String) {
viewModelScope.launch {
udmRepository?.updateLastOnline(uniqueId)
?.collect {
Log.d("MainActivityViewModel", "Last online updated for device: $uniqueId")
}
}
}
updateDeviceName
Updates the display name of a specific device.
Parameters:
uniqueId
: The unique identifier of the devicename
: The new name for the device
fun updateDeviceName(uniqueId: String, name: String) {
viewModelScope.launch {
udmRepository?.updateDeviceName(uniqueId, name)
?.collect {
Log.d("MainActivityViewModel", "Device name updated for device: $uniqueId")
}
}
}
removeDevice
Removes a device from the linked devices list.
Parameters:
uniqueId
: The unique identifier of the device
fun unlink(username: String) {
viewModelScope.launch {
passkey?.authenticate(username)
?.flatMapLatest {
udmRepository = UDMRepositoryImpl("https://trust-fabric.mpc-dev.cramiumtech.com", it.accessToken)
udmRepository!!.getLinkDevices()
}
?.flatMapLatest { devices ->
udmRepository!!.removeDevice(devices.last().uniqueId)
}
?.collect {
Log.d("MainActivityViewModel", "Device removed successfully")
}
}
}
getLinkDevicesHistory
Retrieves the history of device linking and unlinking events.
fun getLinkDevicesHistory() {
viewModelScope.launch {
udmRepository?.getLinkDevicesHistory()
?.collect { history ->
Log.d("MainActivityViewModel", "Link devices history response: $history")
}
}
}
Complete Example
Here's a complete example of how to use the UDM features:
// Initialize the repository
val udmRepository = UDMRepositoryImpl(
baseUrl = "https://trust-fabric.mpc-dev.cramiumtech.com",
accessToken = "your_access_token"
)
// Register a new device
viewModelScope.launch {
udmRepository.registerDevice(
RegisterDeviceRequest(
uniqueId = context.getDeviceUuid(),
uniqueIdType = "uuid",
label = Build.DEVICE,
type = "mobile",
customName = Build.MODEL,
os = Build.VERSION.RELEASE,
browserName = "browser"
)
).collect { device ->
// Handle the registered device
}
}
// Get all linked devices
viewModelScope.launch {
udmRepository.getLinkDevices().collect { devices ->
// Handle the list of devices
}
}
// Update device name
viewModelScope.launch {
udmRepository.updateDeviceName(
uniqueId = "device_id",
name = "New Device Name"
).collect {
// Handle the update result
}
}
// Remove a device
viewModelScope.launch {
udmRepository.removeDevice("device_id").collect {
// Handle the removal result
}
}
Last updated