Skip to content

Commit 3db3e35

Browse files
fix: Remove non-allowed file APIs (#3627)
Remove usage of NSFileSystemFreeSize and NSFileSystemSize because Apple forbids our usage; see https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api?language=objc. Fixes GH-3590
1 parent becc941 commit 3db3e35

19 files changed

+914
-68
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
- Finish TTID span when transaction finishes (#3610)
1313
- Dont take screenshot and view hierarchy for app hanging (#3620)
14+
- Remove `free_storage` and `storage_size` from the device context (#3627), because Apple forbids sending
15+
information retrieved via `NSFileSystemFreeSize` and `NSFileSystemSize` off a device; see
16+
[Apple docs](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api?language=objc).
1417

1518
## 8.20.0
1619

Sources/Sentry/SentryClient.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
628628
// applicable
629629
[self removeExtraDeviceContextFromEvent:event];
630630
} else if (!isCrashEvent) {
631-
// Store the current free memory, free storage, battery level and more mutable properties,
631+
// Store the current free memory battery level and more mutable properties,
632632
// at the time of this event, but not for crashes as the current data isn't guaranteed to be
633633
// the same as when the app crashed.
634634
[self applyExtraDeviceContextToEvent:event];
@@ -842,7 +842,6 @@ - (void)removeExtraDeviceContextFromEvent:(SentryEvent *)event
842842
key:@"device"
843843
block:^(NSMutableDictionary *device) {
844844
[device removeObjectForKey:SentryDeviceContextFreeMemoryKey];
845-
[device removeObjectForKey:@"free_storage"];
846845
[device removeObjectForKey:@"orientation"];
847846
[device removeObjectForKey:@"charging"];
848847
[device removeObjectForKey:@"battery_level"];

Sources/Sentry/SentryCrashIntegration.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ + (void)enrichScope:(SentryScope *)scope crashWrapper:(SentryCrashWrapper *)cras
266266
[deviceData setValue:systemInfo[@"freeMemorySize"] forKey:SentryDeviceContextFreeMemoryKey];
267267
[deviceData setValue:systemInfo[@"usableMemorySize"] forKey:@"usable_memory"];
268268
[deviceData setValue:systemInfo[@"memorySize"] forKey:@"memory_size"];
269-
[deviceData setValue:systemInfo[@"totalStorageSize"] forKey:@"storage_size"];
270-
[deviceData setValue:systemInfo[@"freeStorageSize"] forKey:@"free_storage"];
271269
[deviceData setValue:systemInfo[@"bootTime"] forKey:@"boot_time"];
272270

273271
NSString *locale = [[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleIdentifier];

Sources/Sentry/SentryCrashWrapper.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ - (bytes)freeMemorySize
6666
return sentrycrashcm_system_freememory_size();
6767
}
6868

69-
- (bytes)freeStorageSize
70-
{
71-
return sentrycrashcm_system_freestorage_size();
72-
}
73-
7469
- (bytes)appMemorySize
7570
{
7671
task_vm_info_data_t info;

Sources/Sentry/SentryExtraContextProvider.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ - (NSDictionary *)getExtraDeviceContext
4242
NSMutableDictionary *extraDeviceContext = [[NSMutableDictionary alloc] init];
4343

4444
extraDeviceContext[SentryDeviceContextFreeMemoryKey] = @(self.crashWrapper.freeMemorySize);
45-
extraDeviceContext[@"free_storage"] = @(self.crashWrapper.freeStorageSize);
4645
extraDeviceContext[@"processor_count"] = @([self.processInfoWrapper processorCount]);
4746

4847
#if TARGET_OS_IOS && SENTRY_HAS_UIKIT

Sources/Sentry/include/SentryCrashWrapper.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ SENTRY_NO_INIT
3333

3434
- (bytes)appMemorySize;
3535

36-
- (bytes)freeStorageSize;
37-
3836
@end
3937

4038
NS_ASSUME_NONNULL_END

Sources/SentryCrash/Recording/Monitors/SentryCrashMonitorContext.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ typedef struct SentryCrash_MonitorContext {
198198
int parentProcessID;
199199
const char *deviceAppHash;
200200
const char *buildType;
201-
uint64_t totalStorageSize;
202-
uint64_t freeStorageSize;
203201
uint64_t memorySize;
204202
uint64_t freeMemorySize;
205203
uint64_t usableMemorySize;

Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ SentryCrashMonitorAPI *sentrycrashcm_system_getAPI(void);
4242
bool sentrycrash_isSimulatorBuild(void);
4343

4444
bytes sentrycrashcm_system_freememory_size(void);
45-
bytes sentrycrashcm_system_freestorage_size(void);
4645

4746
#ifdef __cplusplus
4847
}

Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@
7575
int parentProcessID;
7676
const char *deviceAppHash;
7777
const char *buildType;
78-
bytes totalStorageSize;
79-
bytes freeStorageSize;
8078
bytes memorySize;
8179
} SystemData;
8280

@@ -494,30 +492,6 @@
494492
return "unknown";
495493
}
496494

497-
static bytes
498-
getTotalStorageSize(void)
499-
{
500-
NSNumber *storageSize = [[[NSFileManager defaultManager]
501-
attributesOfFileSystemForPath:NSHomeDirectory()
502-
error:nil] objectForKey:NSFileSystemSize];
503-
return storageSize.unsignedLongLongValue;
504-
}
505-
506-
static bytes
507-
getFreeStorageSize(void)
508-
{
509-
NSNumber *storageSize = [[[NSFileManager defaultManager]
510-
attributesOfFileSystemForPath:NSHomeDirectory()
511-
error:nil] objectForKey:NSFileSystemFreeSize];
512-
return storageSize.unsignedLongLongValue;
513-
}
514-
515-
bytes
516-
sentrycrashcm_system_freestorage_size(void)
517-
{
518-
return getFreeStorageSize();
519-
}
520-
521495
// ============================================================================
522496
#pragma mark - API -
523497
// ============================================================================
@@ -598,8 +572,6 @@
598572
g_systemData.parentProcessID = getppid();
599573
g_systemData.deviceAppHash = getDeviceAndAppHash();
600574
g_systemData.buildType = getBuildType();
601-
g_systemData.totalStorageSize = getTotalStorageSize();
602-
g_systemData.freeStorageSize = getFreeStorageSize();
603575
g_systemData.memorySize = sentrycrashsysctl_uint64ForName("hw.memsize");
604576
}
605577
}
@@ -652,8 +624,6 @@
652624
COPY_REFERENCE(parentProcessID);
653625
COPY_REFERENCE(deviceAppHash);
654626
COPY_REFERENCE(buildType);
655-
COPY_REFERENCE(totalStorageSize);
656-
COPY_REFERENCE(freeStorageSize);
657627
COPY_REFERENCE(memorySize);
658628
eventContext->System.freeMemorySize = freeMemorySize();
659629
eventContext->System.usableMemorySize = usableMemorySize();

Sources/SentryCrash/Recording/SentryCrash.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ - (NSDictionary *)systemInfo
210210
COPY_PRIMITIVE(parentProcessID);
211211
COPY_STRING(deviceAppHash);
212212
COPY_STRING(buildType);
213-
COPY_PRIMITIVE(totalStorageSize);
214-
COPY_PRIMITIVE(freeStorageSize);
215213
COPY_PRIMITIVE(memorySize);
216214
COPY_PRIMITIVE(freeMemorySize);
217215
COPY_PRIMITIVE(usableMemorySize);

0 commit comments

Comments
 (0)