Skip to content

Commit 69cab76

Browse files
author
Conrad Kramer
committed
Update file protection check
It now works with NSFileProtectionCompleteUntilFirstUserAuthentication when the device is locked.
1 parent 82706f3 commit 69cab76

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

FastImageCache/FastImageCache/FastImageCache/FICImageTable.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,16 @@ - (BOOL)canAccessEntryData {
519519
if ([_fileDataProtectionMode isEqualToString:NSFileProtectionCompleteUntilFirstUserAuthentication] && _canAccessData)
520520
return YES;
521521

522+
// -[UIApplication isProtectedDataAvailable] checks whether the keybag is locked or not
522523
UIApplication *application = [UIApplication performSelector:@selector(sharedApplication)];
523524
if (application) {
524525
_canAccessData = [application isProtectedDataAvailable];
525-
} else {
526+
}
527+
528+
// We have to fallback to a direct check on the file if either:
529+
// - The application doesn't exist (happens in some extensions)
530+
// - The keybag is locked, but the file might still be accessible because the mode is "until first user authentication"
531+
if (!application || (!_canAccessData && [_fileDataProtectionMode isEqualToString:NSFileProtectionCompleteUntilFirstUserAuthentication])) {
526532
int fd;
527533
_canAccessData = ((fd = open([_filePath fileSystemRepresentation], O_RDONLY)) != -1);
528534
if (_canAccessData)

0 commit comments

Comments
 (0)