Skip to content

Commit

Permalink
Allow to customize the LCP device name (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed May 24, 2024
1 parent a3635b5 commit 595037d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
15 changes: 13 additions & 2 deletions Sources/LCP/LCPService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import Foundation
import ReadiumShared
import UIKit

/// Service used to acquire and open publications protected with LCP.
///
Expand All @@ -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
Expand All @@ -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)
)
Expand Down
16 changes: 9 additions & 7 deletions Sources/LCP/Services/DeviceService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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] {
[
Expand Down

0 comments on commit 595037d

Please sign in to comment.