From d5ff85237b506d0e97fce875dbbdaa367f207200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Menu?= Date: Wed, 15 May 2024 11:07:47 +0200 Subject: [PATCH] Allow to customize the LCP device name --- Sources/LCP/LCPService.swift | 15 +++++++++++++-- Sources/LCP/Services/DeviceService.swift | 16 +++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Sources/LCP/LCPService.swift b/Sources/LCP/LCPService.swift index 56abf7998..e765d77df 100644 --- a/Sources/LCP/LCPService.swift +++ b/Sources/LCP/LCPService.swift @@ -6,6 +6,7 @@ import Foundation import ReadiumShared +import UIKit /// Service used to acquire and open publications protected with LCP. /// @@ -20,7 +21,13 @@ public final class LCPService: Loggable { private let licenses: LicensesService private let passphrases: PassphrasesRepository - public init(client: LCPClient, httpClient: HTTPClient = DefaultHTTPClient()) { + /// - Parameter deviceName: Device name used when registering a license to an LSD server. + /// If not provided, the device name will be the default `UIDevice.current.name`. + public init( + client: LCPClient, + httpClient: HTTPClient = DefaultHTTPClient(), + deviceName: String? = nil + ) { // Determine whether the embedded liblcp.a is in production mode, by attempting to open a production license. let isProduction: Bool = { guard @@ -40,7 +47,11 @@ public final class LCPService: Loggable { client: client, licenses: db.licenses, crl: CRLService(httpClient: httpClient), - device: DeviceService(repository: db.licenses, httpClient: httpClient), + device: DeviceService( + deviceName: deviceName ?? UIDevice.current.name, + repository: db.licenses, + httpClient: httpClient + ), httpClient: httpClient, passphrases: PassphrasesService(client: client, repository: passphrases) ) diff --git a/Sources/LCP/Services/DeviceService.swift b/Sources/LCP/Services/DeviceService.swift index 7ced5696d..185bc8d4b 100644 --- a/Sources/LCP/Services/DeviceService.swift +++ b/Sources/LCP/Services/DeviceService.swift @@ -6,13 +6,20 @@ import Foundation import ReadiumShared -import UIKit final class DeviceService { private let repository: DeviceRepository private let httpClient: HTTPClient - init(repository: DeviceRepository, httpClient: HTTPClient) { + /// Returns the device's name. + var name: String + + init( + deviceName: String, + repository: DeviceRepository, + httpClient: HTTPClient + ) { + name = deviceName self.repository = repository self.httpClient = httpClient } @@ -28,11 +35,6 @@ final class DeviceService { return deviceId } - // Returns the device's name. - var name: String { - UIDevice.current.name - } - // Device ID and name as query parameters for HTTP requests. var asQueryParameters: [String: String] { [