Skip to content

Commit 8fb7ccb

Browse files
authored
Change LCP device name strategy (readium#508)
1 parent d08819a commit 8fb7ccb

File tree

5 files changed

+20
-37
lines changed

5 files changed

+20
-37
lines changed

.idea/.gitignore

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ All notable changes to this project will be documented in this file. Take a look
1616

1717
* All the APIs using or returning a `Date` objects are now using a custom `Instant` type.
1818

19+
#### LCP
20+
21+
* [#493](https://github.com/readium/kotlin-toolkit/discussions/493) The LCP module does not require the Bluetooth permissions anymore to derive the device name.
22+
1923
### Fixed
2024

2125
#### Navigator

readium/lcp/src/main/AndroidManifest.xml

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,4 @@
44
available in the top-level LICENSE file of the project.
55
-->
66

7-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
8-
9-
<!-- Used to get the device's name for LSD "register" -->
10-
<uses-permission android:name="android.permission.BLUETOOTH" />
11-
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
12-
13-
</manifest>
7+
<manifest />

readium/lcp/src/main/java/org/readium/r2/lcp/LcpService.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,15 @@ public interface LcpService {
166166

167167
/**
168168
* LCP service factory.
169+
*
170+
* @param deviceName Device name used when registering a license to an LSD server.
171+
* If not provided, the device name will be generated from the device's manufacturer and
172+
* model.
169173
*/
170174
public operator fun invoke(
171175
context: Context,
172-
assetRetriever: AssetRetriever
176+
assetRetriever: AssetRetriever,
177+
deviceName: String? = null
173178
): LcpService? {
174179
if (!LcpClient.isAvailable()) {
175180
return null
@@ -181,6 +186,7 @@ public interface LcpService {
181186
val licenseRepository = LicensesRepository(db)
182187
val network = NetworkService()
183188
val device = DeviceService(
189+
deviceName = deviceName,
184190
repository = deviceRepository,
185191
network = network,
186192
context = context

readium/lcp/src/main/java/org/readium/r2/lcp/service/DeviceService.kt

+6-29
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,16 @@
99

1010
package org.readium.r2.lcp.service
1111

12-
import android.Manifest
13-
import android.bluetooth.BluetoothManager
1412
import android.content.Context
1513
import android.content.SharedPreferences
16-
import android.content.pm.PackageManager
17-
import androidx.core.app.ActivityCompat
14+
import android.os.Build
1815
import java.io.Serializable
19-
import java.util.*
20-
import kotlin.time.ExperimentalTime
16+
import java.util.UUID
2117
import org.readium.r2.lcp.license.model.LicenseDocument
2218
import org.readium.r2.lcp.license.model.components.Link
23-
import timber.log.Timber
2419

25-
@OptIn(ExperimentalTime::class)
2620
internal class DeviceService(
21+
deviceName: String?,
2722
private val repository: DeviceRepository,
2823
private val network: NetworkService,
2924
val context: Context
@@ -40,27 +35,9 @@ internal class DeviceService(
4035
preferences.edit().putString("lcp_device_id", deviceId).apply()
4136
return deviceId
4237
}
43-
val name: String
44-
get() {
45-
val bluetoothManager =
46-
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
47-
val bluetoothName =
48-
try {
49-
if (ActivityCompat.checkSelfPermission(
50-
context,
51-
Manifest.permission.BLUETOOTH_CONNECT
52-
) != PackageManager.PERMISSION_GRANTED
53-
) {
54-
null
55-
} else {
56-
bluetoothManager.adapter.name
57-
}
58-
} catch (e: Exception) {
59-
Timber.e(e)
60-
null
61-
}
62-
return bluetoothName ?: "Android"
63-
}
38+
39+
val name: String =
40+
deviceName ?: "${Build.MANUFACTURER} ${Build.MODEL}"
6441

6542
val asQueryParameters: URLParameters
6643
get() = mapOf("id" to id, "name" to name)

0 commit comments

Comments
 (0)