Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove available storage and total storage from platform context (close #824) #825

Merged
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
6 changes: 0 additions & 6 deletions Sources/Core/Subject/PlatformContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ class PlatformContext {
if shouldTrack(.carrier) {
platformDict[kSPMobileCarrier] = deviceInfoMonitor.carrierName
}
if shouldTrack(.totalStorage) {
platformDict[kSPMobileTotalStorage] = deviceInfoMonitor.totalStorage
}
if shouldTrack(.physicalMemory) {
platformDict[kSPMobilePhysicalMemory] = deviceInfoMonitor.physicalMemory
}
Expand All @@ -135,9 +132,6 @@ class PlatformContext {
if shouldTrack(.lowPowerMode) {
platformDict[kSPMobileLowPowerMode] = deviceInfoMonitor.isLowPowerModeEnabled
}
if shouldTrack(.availableStorage) {
platformDict[kSPMobileAvailableStorage] = deviceInfoMonitor.availableStorage
}
if shouldTrack(.appAvailableMemory) {
platformDict[kSPMobileAppAvailableMemory] = deviceInfoMonitor.appAvailableMemory
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/Core/TrackerConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ let kSPMobileAppAvailableMemory = "appAvailableMemory"
let kSPMobileBatteryLevel = "batteryLevel"
let kSPMobileBatteryState = "batteryState"
let kSPMobileLowPowerMode = "lowPowerMode"
let kSPMobileAvailableStorage = "availableStorage"
let kSPMobileTotalStorage = "totalStorage"
let kSPMobileIsPortrait = "isPortrait"
let kSPMobileResolution = "resolution"
let kSPMobileLanguage = "language"
Expand Down
30 changes: 0 additions & 30 deletions Sources/Core/Utils/DeviceInfoMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,36 +221,6 @@ class DeviceInfoMonitor {
// #endif
return nil
}

/// Returns number of bytes of storage remaining. The information is requested from the home directory.
/// - Returns: Bytes of storage remaining.
var availableStorage: Int64? {
#if os(iOS)
let fileURL = URL(fileURLWithPath: NSHomeDirectory() as String)
do {
let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey])
return values.volumeAvailableCapacityForImportantUsage
} catch {
logError(message: "Failed to read available storage size: \(error.localizedDescription)")
}
#endif
return nil
}

/// Returns the total number of bytes of storage. The information is requested from the home directory.
/// - Returns: Total size of storage in bytes.
var totalStorage: Int? {
#if os(iOS)
let fileURL = URL(fileURLWithPath: NSHomeDirectory() as String)
do {
let values = try fileURL.resourceValues(forKeys: [.volumeTotalCapacityKey])
return values.volumeTotalCapacity
} catch {
logError(message: "Failed to read available storage size: \(error.localizedDescription)")
}
#endif
return nil
}

/// Whether the device orientation is portrait (either upright or upside down)
var isPortrait: Bool? {
Expand Down
4 changes: 0 additions & 4 deletions Sources/Snowplow/Configurations/PlatformContextProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public enum PlatformContextProperty: Int {
case batteryState
/// A Boolean indicating whether Low Power Mode is enabled
case lowPowerMode
/// Bytes of storage remaining
case availableStorage
/// Total size of storage in bytes
case totalStorage
/// A Boolean indicating whether the device orientation is portrait (either upright or upside down)
case isPortrait
/// Screen resolution in pixels. Arrives in the form of WIDTHxHEIGHT (e.g., 1200x900). Doesn't change when device orientation changes
Expand Down
9 changes: 4 additions & 5 deletions Tests/TestPlatformContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ class TestPlatformContext: XCTestCase {
let deviceInfoMonitor = MockDeviceInfoMonitor()
let context = PlatformContext(mobileDictUpdateFrequency: 0, networkDictUpdateFrequency: 0, deviceInfoMonitor: deviceInfoMonitor)
XCTAssertEqual(1, deviceInfoMonitor.accessCount("physicalMemory"))
XCTAssertEqual(1, deviceInfoMonitor.accessCount("totalStorage"))
XCTAssertEqual(1, deviceInfoMonitor.accessCount("carrierName"))
_ = context.fetchPlatformDict(userAnonymisation: false, advertisingIdentifierRetriever: nil)
XCTAssertEqual(1, deviceInfoMonitor.accessCount("physicalMemory"))
XCTAssertEqual(1, deviceInfoMonitor.accessCount("totalStorage"))
XCTAssertEqual(1, deviceInfoMonitor.accessCount("carrierName"))
_ = context.fetchPlatformDict(userAnonymisation: false, advertisingIdentifierRetriever: nil)
XCTAssertEqual(1, deviceInfoMonitor.accessCount("physicalMemory"))
XCTAssertEqual(1, deviceInfoMonitor.accessCount("totalStorage"))
XCTAssertEqual(1, deviceInfoMonitor.accessCount("carrierName"))
}

func testDoesntUpdateIdfvIfNotNil() {
Expand Down Expand Up @@ -198,7 +198,7 @@ class TestPlatformContext: XCTestCase {
func testOnlyAddsRequestedProperties() {
let deviceInfoMonitor = MockDeviceInfoMonitor()
let context = PlatformContext(
platformContextProperties: [.appAvailableMemory, .availableStorage, .language],
platformContextProperties: [.appAvailableMemory, .language],
mobileDictUpdateFrequency: 0,
networkDictUpdateFrequency: 1,
deviceInfoMonitor: deviceInfoMonitor)
Expand All @@ -213,7 +213,6 @@ class TestPlatformContext: XCTestCase {
XCTAssertNil(platformDict[kSPMobileScale])
XCTAssertNil(platformDict[kSPMobileResolution])
XCTAssertNotNil(platformDict[kSPMobileAppAvailableMemory])
XCTAssertNotNil(platformDict[kSPMobileAvailableStorage])
XCTAssertNil(platformDict[kSPMobilePhysicalMemory])
XCTAssertNil(platformDict[kSPMobileIsPortrait])
XCTAssertNil(platformDict[kSPMobileAppleIdfa])
Expand Down
10 changes: 0 additions & 10 deletions Tests/Utils/MockDeviceInfoMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ class MockDeviceInfoMonitor: DeviceInfoMonitor {
increaseMethodAccessCount("appAvailableMemory")
return 1000
}

override var availableStorage: Int64? {
increaseMethodAccessCount("availableStorage")
return 9000
}

override var totalStorage: Int? {
increaseMethodAccessCount("totalStorage")
return 900000
}

override var isPortrait: Bool? {
return true
Expand Down