Skip to content
Merged
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
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