Skip to content

Commit

Permalink
Merge pull request #46 from fingerprintjs/topic/MOBILE-162-disk-space…
Browse files Browse the repository at this point in the history
…-info

Drop the use of disk space APIs

In response to Apple's introduction of a list of required reason API,
a decision was made to drop the use of APIs that require declared
reasons.

This is a device fingerprint breaking change.
  • Loading branch information
mgutski authored Nov 21, 2023
2 parents 92c2198 + f90883c commit cb9555e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 152 deletions.
16 changes: 0 additions & 16 deletions Sources/FingerprintJS/Fingerprints/DeviceInfoTreeProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,6 @@ extension HardwareInfoHarvester: DeviceInfoTreeProvider {
stabilityLevel: .stable,
versions: .all
),
AnnotatedInfoItem(
DeviceInfoItem(
label: "Free disk space (B)",
value: .info(String(describing: freeDiskSpace))
),
stabilityLevel: .unique,
versions: .since(.v2)
),
AnnotatedInfoItem(
DeviceInfoItem(
label: "Total disk space (B)",
value: .info(String(describing: totalDiskSpace))
),
stabilityLevel: .stable,
versions: .since(.v2)
),
AnnotatedInfoItem(
DeviceInfoItem(
label: "Device hostname",
Expand Down
10 changes: 7 additions & 3 deletions Sources/FingerprintJS/Harvesters/DataExchange/DeviceInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ public struct DeviceInfo: Equatable, Encodable {
/// The style associated with the user interface of the app.
public let userInterfaceStyle: UserInterfaceStyle

public let diskSpace: DiskSpaceInfo?
@available(
*,
deprecated,
message: "DeviceInfo.diskSpace is always nil and will be removed in a future library version"
)
public let diskSpace: DiskSpaceInfo? = nil

public let screenResolution: CGSize?
/// The native scale factor for the screen.
public let screenScale: CGFloat
Expand Down Expand Up @@ -101,7 +107,6 @@ extension DeviceInfo {
vendorIdentifier: UUID?,
localeIdentifier: String,
userInterfaceStyle: UserInterfaceStyle,
diskSpace: DiskSpaceInfo?,
screenResolution: CGSize?,
screenScale: CGFloat,
deviceName: String,
Expand All @@ -125,7 +130,6 @@ extension DeviceInfo {
self.vendorIdentifier = vendorIdentifier
self.localeIdentifier = localeIdentifier
self.userInterfaceStyle = userInterfaceStyle
self.diskSpace = diskSpace
self.screenResolution = screenResolution
self.screenScale = screenScale
self.deviceName = deviceName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@available(*, deprecated, message: "DiskSpaceInfo will be removed in a future library version")
public struct DiskSpaceInfo: Equatable, Encodable {
public let freeDiskSpace: UInt64
public let totalDiskSpace: UInt64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ protocol HardwareInfoHarvesting {
/// The native scale factor for the display.
var displayScale: CGFloat { get }

/// Free disk space on the device or 0 if a permission problem occurs
var freeDiskSpace: UInt64 { get }

/// Total disk space on the device or 0 if a permission problem occurs
var totalDiskSpace: UInt64 { get }

/// Disk space information (free and total)
var diskSpaceInfo: DiskSpaceInfo? { get }

/// Number of physical CPU cores
var cpuCount: String { get }

Expand Down Expand Up @@ -69,24 +60,6 @@ struct HardwareInfoHarvester {
processInfo: ProcessInfo.processInfo
)
}

var diskSpaceInfo: DiskSpaceInfo? {
do {
let dict = try fileManager.documentsDirectoryAttributes()
if let fileSystemSizeInBytes = dict[.systemSize] as? UInt64,
let fileSystemFreeSizeInBytes = dict[.systemFreeSize] as? UInt64
{
return DiskSpaceInfo(
freeDiskSpace: fileSystemFreeSizeInBytes,
totalDiskSpace: fileSystemSizeInBytes
)
}
} catch {
print("Failed to obtain disk space info: \(error)")
}

return nil
}
}

extension HardwareInfoHarvester: HardwareInfoHarvesting {
Expand Down Expand Up @@ -136,14 +109,6 @@ extension HardwareInfoHarvester: HardwareInfoHarvesting {
return "\(cpuFrequency)"
}

var freeDiskSpace: UInt64 {
return diskSpaceInfo?.freeDiskSpace ?? 0
}

var totalDiskSpace: UInt64 {
return diskSpaceInfo?.totalDiskSpace ?? 0
}

var kernelHostname: String {
systemControl.hostname ?? "Undefined"
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/FingerprintJS/Library/DeviceInfoProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ extension DeviceInfoProvider: DeviceInfoProviding {
vendorIdentifier: identifierHarvester.vendorIdentifier,
localeIdentifier: appInfoHarvester.localeIdentifier,
userInterfaceStyle: appInfoHarvester.userInterfaceStyle,
diskSpace: hardwareInfoHarvester.diskSpaceInfo,
screenResolution: hardwareInfoHarvester.displayResolution,
screenScale: hardwareInfoHarvester.displayScale,
deviceName: hardwareInfoHarvester.deviceName,
Expand Down Expand Up @@ -121,7 +120,6 @@ extension DeviceInfoProvider: DeviceInfoProviding {
vendorIdentifier: identifierHarvester.vendorIdentifier,
localeIdentifier: appInfoHarvester.localeIdentifier,
userInterfaceStyle: appInfoHarvester.userInterfaceStyle,
diskSpace: hardwareInfoHarvester.diskSpaceInfo,
screenResolution: hardwareInfoHarvester.displayResolution,
screenScale: hardwareInfoHarvester.displayScale,
deviceName: hardwareInfoHarvester.deviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,84 +94,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
XCTAssertEqual(1, screenInfoProviderSpy.nativeScaleCallCount)
}

func testFreeDiskSpaceReturnsZeroIfDocumentsDirAttributesEmpty() {
XCTAssertEqual(sut.freeDiskSpace, 0)
}

func testFreeDiskSpaceReturnsZeroIfDocumentsAttributesThrowsError() {
mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributesError =
DocumentsDirectoryError.documentsDirectoryNotFound
XCTAssertEqual(sut.freeDiskSpace, 0)
}

func testFreeDiskSpaceReturnsZeroIfDocumentsAttributesPresentButThrowError() {
mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [
.systemFreeSize: UInt64(100),
.systemSize: UInt64(100),
]

mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributesError =
DocumentsDirectoryError.documentsDirectoryNotFound

XCTAssertEqual(sut.freeDiskSpace, 0)
}

func testFreeDiskSpaceReturnsCorrectValuesOnSuccess() {
mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [
.systemFreeSize: UInt64(100),
.systemSize: UInt64(100),
]

XCTAssertEqual(sut.freeDiskSpace, 100)
}

func testFreeDiskSpaceReturnsZeroIfOtherValueMissing() {
mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [
.systemFreeSize: UInt64(100)
]

XCTAssertEqual(sut.freeDiskSpace, 0)
}

func testTotalDiskSpaceReturnsZeroIfDocumentsDirAttributesEmpty() {
XCTAssertEqual(sut.totalDiskSpace, 0)
}

func testTotalDiskSpaceReturnsZeroIfDocumentsAttributesThrowsError() {
mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributesError =
DocumentsDirectoryError.documentsDirectoryNotFound
XCTAssertEqual(sut.totalDiskSpace, 0)
}

func testTotalDiskSpaceReturnsZeroIfDocumentsAttributesPresentButThrowError() {
mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [
.systemFreeSize: UInt64(100),
.systemSize: UInt64(100),
]

mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributesError =
DocumentsDirectoryError.documentsDirectoryNotFound

XCTAssertEqual(sut.totalDiskSpace, 0)
}

func testTotalDiskSpaceReturnsCorrectValuesOnSuccess() {
mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [
.systemFreeSize: UInt64(100),
.systemSize: UInt64(100),
]

XCTAssertEqual(sut.totalDiskSpace, 100)
}

func testTotalDiskSpaceReturnZeroIfOneValueMissing() {
mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [
.systemSize: UInt64(100)
]

XCTAssertEqual(sut.totalDiskSpace, 0)
}

func test_givenConfigurationWithVersionOneAndUniqueStabilityLevel_whenBuildTree_thenReturnsExpectedItems() {
// given
let config = Configuration(version: .v1, stabilityLevel: .unique)
Expand Down Expand Up @@ -244,8 +166,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display resolution",
"Physical memory",
"Processor count",
"Free disk space (B)",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand All @@ -265,8 +185,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display resolution",
"Physical memory",
"Processor count",
"Free disk space (B)",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand All @@ -286,8 +204,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display resolution",
"Physical memory",
"Processor count",
"Free disk space (B)",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand All @@ -309,8 +225,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display scale",
"Physical memory",
"Processor count",
"Free disk space (B)",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand All @@ -331,7 +245,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display scale",
"Physical memory",
"Processor count",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand All @@ -352,7 +265,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display scale",
"Physical memory",
"Processor count",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand All @@ -374,8 +286,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display scale",
"Physical memory",
"Processor count",
"Free disk space (B)",
"Total disk space (B)",
"Device hostname",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
Expand All @@ -397,7 +307,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display scale",
"Physical memory",
"Processor count",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand All @@ -418,7 +327,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display scale",
"Physical memory",
"Processor count",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand All @@ -440,8 +348,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display scale",
"Physical memory",
"Processor count",
"Free disk space (B)",
"Total disk space (B)",
"Device hostname",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
Expand All @@ -463,7 +369,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display scale",
"Physical memory",
"Processor count",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand All @@ -484,7 +389,6 @@ final class HardwareInfoHarvesterTests: XCTestCase {
"Display scale",
"Physical memory",
"Processor count",
"Total disk space (B)",
]
XCTAssertEqual(expectedItemLabels, itemLabels)
}
Expand Down

0 comments on commit cb9555e

Please sign in to comment.