Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ captures/
.idea/jarRepositories.xml
.idea/misc.xml
.idea/migrations.xml
.idea/markdown.xml
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
Expand Down
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ All notable changes to this project will be documented in this file. Take a look

**Warning:** Features marked as *experimental* may change or be removed in a future release without notice. Use with caution.

<!-- ## [Unreleased] -->
## [Unreleased]

### Added

#### LCP

* Added a constructor parameter to pass a custom device id.

### Changed

#### LCP

* Set device id only once after generating.

## [3.1.2]

Expand Down
4 changes: 4 additions & 0 deletions readium/lcp/src/main/java/org/readium/r2/lcp/LcpService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ public interface LcpService {
* @param deviceName Device name used when registering a license to an LSD server.
* If not provided, the device name will be generated from the device's manufacturer and
* model.
* @param deviceId Device ID used when registering a liceense to an LSD server.
* If not provided, the device id will be generated as a random UUID.
*/
public operator fun invoke(
context: Context,
assetRetriever: AssetRetriever,
deviceName: String? = null,
deviceId: String? = null,
): LcpService? {
if (!LcpClient.isAvailable()) {
return null
Expand All @@ -152,6 +155,7 @@ public interface LcpService {
val network = NetworkService()
val device = DeviceService(
deviceName = deviceName,
deviceId = deviceId,
repository = deviceRepository,
network = network,
context = context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ package org.readium.r2.lcp.service
import android.content.Context
import android.content.SharedPreferences
import android.os.Build
import androidx.core.content.edit
import java.io.Serializable
import java.util.UUID
import org.readium.r2.lcp.license.model.LicenseDocument
import org.readium.r2.lcp.license.model.components.Link

internal class DeviceService(
deviceName: String?,
deviceId: String?,
private val repository: DeviceRepository,
private val network: NetworkService,
val context: Context,
) : Serializable {

private val preferences: SharedPreferences = context.getSharedPreferences(
"org.readium.r2.settings",
Context.MODE_PRIVATE
)
private val preferences: SharedPreferences by lazy {
context.getSharedPreferences("org.readium.r2.settings", Context.MODE_PRIVATE)
}

val id: String
get() {
val deviceId = preferences.getString("lcp_device_id", UUID.randomUUID().toString())!!
preferences.edit().putString("lcp_device_id", deviceId).apply()
return deviceId
}
val id: String = deviceId ?: run {
val deviceId = preferences.getString("lcp_device_id", UUID.randomUUID().toString())!!
preferences.edit { putString("lcp_device_id", deviceId) }
deviceId
}

val name: String =
deviceName ?: "${Build.MANUFACTURER} ${Build.MODEL}"
Expand Down