Skip to content

Commit

Permalink
Merge pull request #6875 from cheekiatng/timob-16488
Browse files Browse the repository at this point in the history
[TIMOB-16488] iOS: Add FileProtectionKey Feature
  • Loading branch information
pec1985 committed Jun 1, 2015
2 parents 7bec6eb + bc86484 commit 4883c70
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 4 deletions.
29 changes: 29 additions & 0 deletions apidoc/Titanium/Filesystem/File.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ methods:
- type: String
- type: Titanium.Filesystem.File

- name: getProtectionKey
summary: |
Returns the protection key value of this file object. Can be one of the following
constants:
Titanium.Filesystem.IOS_FILE_PROTECTION_NONE
Titanium.Filesystem.IOS_FILE_PROTECTION_COMPLETE
Titanium.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN
Titanium.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION
Returns `null` if there's an error.
returns:
type: String
platforms: [iphone, ipad]
since: "4.1.0"

- name: isDirectory
summary: Returns `true` if this file object represents a directory.
returns:
Expand Down Expand Up @@ -271,6 +285,21 @@ methods:
returns:
type: String

- name: setProtectionKey
summary: Sets the protection key as an attribute to the file identified by this file object.
description: |
Returns `true` if successfully set. Returns `false` if failed.
returns:
type: Boolean
parameters:
- name: fileProtectionType
summary: |
File protection type.
constants: Titanium.Filesystem.IOS_FILE_PROTECTION_*
type: String
platforms: [iphone, ipad]
since: "4.1.0"

- name: spaceAvailable
summary: Returns the amount of free space available on the device where the file
identified by this file object is stored.
Expand Down
42 changes: 42 additions & 0 deletions apidoc/Titanium/Filesystem/Filesystem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,48 @@ properties:
type: Number
permission: read-only

- name: IOS_FILE_PROTECTION_NONE
summary: Constant used to set protection key to NSFileProtectionNone in file attributes.
description: |
File will have no special protection associated with it. Can be read from or written
to at any time.
type: String
permission: read-only
platforms: [iphone, ipad]
since: "4.1.0"

- name: IOS_FILE_PROTECTION_COMPLETE
summary: Constant used to set protection key to NSFileProtectionComplete in file attributes.
description: |
File is stored in an encrypted format on disk. Cannot be read from or written to while
the device is locked or booting.
type: String
permission: read-only
platforms: [iphone, ipad]
since: "4.1.0"

- name: IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN
summary: Constant used to set protection key to NSFileProtectionCompleteUnlessOpen in file attributes.
description: |
File is stored in an encrypted format on disk. Can be created while the device is locked,
but once closed, cannot be opened again until the device is unlocked. If the file is opened when
unlocked, you may continue to access the file normally, even if the user locks the device.
type: String
permission: read-only
platforms: [iphone, ipad]
since: "4.1.0"

- name: IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION
summary: Constant used to set protection key to NSFileProtectionCompleteUntilFirstUserAuthentication in file attributes.
description: |
File is stored in an encrypted format on disk. Cannot be accessed until after the device has booted.
After the user unlocks the device for the first time, your app can access the file and continue to
access it even if the user subsequently locks the device.
type: String
permission: read-only
platforms: [iphone, ipad]
since: "4.1.0"

- name: applicationCacheDirectory
summary: Path to the application's internal cache directory.
description: |
Expand Down
7 changes: 5 additions & 2 deletions iphone/Classes/FilesystemModule.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand All @@ -24,7 +24,10 @@
@property(nonatomic,readonly) NSNumber *MODE_WRITE;
@property(nonatomic,readonly) NSNumber *MODE_READ;


@property(nonatomic,readonly) NSString *IOS_FILE_PROTECTION_NONE;
@property(nonatomic,readonly) NSString *IOS_FILE_PROTECTION_COMPLETE;
@property(nonatomic,readonly) NSString *IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN;
@property(nonatomic,readonly) NSString *IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION;
@end

#endif
22 changes: 21 additions & 1 deletion iphone/Classes/FilesystemModule.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2014 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand Down Expand Up @@ -190,6 +190,26 @@ -(id)getFile:(id)args
return [[[TiFilesystemFileProxy alloc] initWithFile:newpath] autorelease];
}

-(NSString*)IOS_FILE_PROTECTION_NONE
{
return NSFileProtectionNone;
}

-(NSString*)IOS_FILE_PROTECTION_COMPLETE
{
return NSFileProtectionComplete;
}

-(NSString*)IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN
{
return NSFileProtectionCompleteUnlessOpen;
}

-(NSString*)IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION
{
return NSFileProtectionCompleteUntilFirstUserAuthentication;
}

@end

#endif
25 changes: 24 additions & 1 deletion iphone/Classes/TiFilesystemFileProxy.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2014 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand Down Expand Up @@ -153,6 +153,29 @@ -(id)spaceAvailable:(id)args
return [resultDict objectForKey:NSFileSystemFreeSize];
}

-(NSString *)getProtectionKey:(id)args
{
NSError *error = nil;
NSDictionary * resultDict = [fm attributesOfItemAtPath:path error:&error];
if (error != nil) {
NSLog(@"[ERROR] Error getting protection key: %@", [TiUtils messageFromError:error]);
return nil;
}
return [resultDict objectForKey:NSFileProtectionKey];
}

-(NSNumber *)setProtectionKey:(id)args
{
ENSURE_SINGLE_ARG(args, NSString);
NSError *error = nil;
BOOL result = [fm setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:args, NSFileProtectionKey, nil] ofItemAtPath:path error:&error];
if (error != nil) {
NSLog(@"[ERROR] Error setting protection key: %@", [TiUtils messageFromError:error]);
return NUMBOOL(NO);
}
return NUMBOOL(YES);
}

-(id)createDirectory:(id)args
{
BOOL result = NO;
Expand Down

0 comments on commit 4883c70

Please sign in to comment.