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.
Last updated
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")
}
}
}fun getLinkDevices() {
viewModelScope.launch {
udmRepository?.getLinkDevices()
?.collect { devices ->
Log.d("MainActivityViewModel", "Link devices response: $devices")
}
}
}fun getLinkDevice(uniqueId: String) {
viewModelScope.launch {
udmRepository?.getLinkDevice(uniqueId)
?.collect { device ->
Log.d("MainActivityViewModel", "Link device response: $device")
}
}
}fun updateLastOnline(uniqueId: String) {
viewModelScope.launch {
udmRepository?.updateLastOnline(uniqueId)
?.collect {
Log.d("MainActivityViewModel", "Last online updated for device: $uniqueId")
}
}
}fun updateDeviceName(uniqueId: String, name: String) {
viewModelScope.launch {
udmRepository?.updateDeviceName(uniqueId, name)
?.collect {
Log.d("MainActivityViewModel", "Device name updated for device: $uniqueId")
}
}
}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")
}
}
}fun getLinkDevicesHistory() {
viewModelScope.launch {
udmRepository?.getLinkDevicesHistory()
?.collect { history ->
Log.d("MainActivityViewModel", "Link devices history response: $history")
}
}
}// 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
}
}