Skip to content

Commit

Permalink
Removed usage of APIs that Apple discorages
Browse files Browse the repository at this point in the history
This isn't a permanent removal. At the moment we detect usage on the server and will add them. But Appstore submission will fail since a privacy file is also required. Based on user demand we can implicitly add a privacy statement file if necessary.
Fixed #3800
  • Loading branch information
shai-almog committed Apr 2, 2024
1 parent f07dec5 commit b8e00b4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 61 deletions.
2 changes: 2 additions & 0 deletions CodenameOne/src/com/codename1/io/FileSystemStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public long getLength(String file) {
* last modified.
* @return A long value representing the time the file was last modified,
* measured in milliseconds
* @deprecated this API requires additional privacy permissions on iOS
* and might cause problems with iOS submissions
*/
public long getLastModified(String file) {
return Util.getImplementation().getFileLastModified(file);
Expand Down
4 changes: 3 additions & 1 deletion CodenameOne/src/com/codename1/ui/CN.java
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,9 @@ public static long getFileLength(String file) {
* last modified.
* @return A long value representing the time the file was last modified,
* measured in milliseconds
*/
* @deprecated this API requires additional privacy permissions on iOS
* and might cause problems with iOS submissions
*/
public static long getFileLastModifiedFile(String file) {
return FileSystemStorage.getInstance().getLastModified(file);
}
Expand Down
5 changes: 5 additions & 0 deletions Ports/iOSPort/nativeSources/IOSNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "java_util_ArrayList.h"
#include "com_codename1_ui_Font.h"
#include "java_util_Vector.h"
#include "permission_apis.h"
//#import "QRCodeReaderOC.h"
#define AUTO_PLAY_VIDEO
#ifdef ENABLE_WKWEBVIEW
Expand Down Expand Up @@ -1469,6 +1470,7 @@ JAVA_INT com_codename1_impl_ios_IOSNative_getFileSize___java_lang_String(CN1_THR
}

JAVA_LONG com_codename1_impl_ios_IOSNative_getFileLastModified___java_lang_String(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject, JAVA_OBJECT path) {
#ifdef checkModificationDatePermission
POOL_BEGIN();
NSString* ns = toNSString(CN1_THREAD_STATE_PASS_ARG path);
if([ns hasPrefix:@"file:"]) {
Expand All @@ -1489,6 +1491,9 @@ JAVA_LONG com_codename1_impl_ios_IOSNative_getFileLastModified___java_lang_Strin
#endif
POOL_END();
return result;
#else
return 0;
#endif
}

void com_codename1_impl_ios_IOSNative_readFile___java_lang_String_byte_1ARRAY(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject, JAVA_OBJECT path, JAVA_OBJECT n1) {
Expand Down
65 changes: 5 additions & 60 deletions Ports/iOSPort/nativeSources/OpenUDID.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ + (NSString*) _generateFreshOpenUDID {
// Next we generate a UUID.
// UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) or IIDs
// (Interface Identifiers), are 128-bit values guaranteed to be unique. A UUID is made unique over
// both space and time by combining a value unique to the computer on which it was generatedusually the
// Ethernet hardware addressand a value representing the number of 100-nanosecond intervals since
// both space and time by combining a value unique to the computer on which it was generatedusually the
// Ethernet hardware addressand a value representing the number of 100-nanosecond intervals since
// October 15, 1582 at 00:00:00.
// We then hash this UUID with md5 to get 32 bytes, and then add 4 extra random bytes
// Collision is possible of course, but unlikely and suitable for most industry needs (e.g. aggregate tracking)
Expand Down Expand Up @@ -176,40 +176,16 @@ + (NSString*) valueWithError:(NSError **)error {
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"OpenUDID in cache from first call",@"description", nil]];
return kOpenUDIDSessionCache;
}

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

// The AppUID will uniquely identify this app within the pastebins
//
NSString * appUID = (NSString *) [defaults objectForKey:kOpenUDIDAppUIDKey];
if(appUID == nil)
{
// generate a new uuid and store it in user defaults
CFUUIDRef uuid = CFUUIDCreate(NULL);
appUID = (NSString *) CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
}



NSString* openUDID = nil;
NSString* myRedundancySlotPBid = nil;
NSDate* optedOutDate = nil;
BOOL optedOut = NO;
BOOL saveLocalDictToDefaults = NO;
BOOL isCompromised = NO;

// Do we have a local copy of the OpenUDID dictionary?
// This local copy contains a copy of the openUDID, myRedundancySlotPBid (and unused in this block, the local bundleid, and the timestamp)
//
id localDict = [defaults objectForKey:kOpenUDIDKey];
if ([localDict isKindOfClass:[NSDictionary class]]) {
localDict = [NSMutableDictionary dictionaryWithDictionary:localDict]; // we might need to set/overwrite the redundancy slot
openUDID = [localDict objectForKey:kOpenUDIDKey];
myRedundancySlotPBid = [localDict objectForKey:kOpenUDIDSlotKey];
optedOutDate = [localDict objectForKey:kOpenUDIDOOTSKey];
optedOut = optedOutDate!=nil;
OpenUDIDLog(@"localDict = %@",localDict);
}


// Here we go through a sequence of slots, each of which being a UIPasteboard created by each participating app
// The idea behind this is to both multiple and redundant representations of OpenUDIDs, as well as serve as placeholder for potential opt-out
//
Expand Down Expand Up @@ -314,11 +290,6 @@ + (NSString*) valueWithError:(NSError **)error {
[OpenUDID _setDict:localDict forPasteboard:slotPB];
}

// Save the dictionary locally if applicable
//
if (localDict && saveLocalDictToDefaults)
[defaults setObject:localDict forKey:kOpenUDIDKey];

// If the UIPasteboard external representation marks this app as opted-out, then to respect privacy, we return the ZERO OpenUDID, a sequence of 40 zeros...
// This is a *new* case that developers have to deal with. Unlikely, statistically low, but still.
// To circumvent this and maintain good tracking (conversion ratios, etc.), developers are invited to calculate how many of their users have opted-out from the full set of users.
Expand Down Expand Up @@ -351,33 +322,7 @@ + (NSString*) valueWithError:(NSError **)error {

+ (void) setOptOut:(BOOL)optOutValue {

// init call
[OpenUDID value];

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

// load the dictionary from local cache or create one
id dict = [defaults objectForKey:kOpenUDIDKey];
if ([dict isKindOfClass:[NSDictionary class]]) {
dict = [NSMutableDictionary dictionaryWithDictionary:dict];
} else {
dict = [NSMutableDictionary dictionaryWithCapacity:2];
}

// set the opt-out date or remove key, according to parameter
if (optOutValue)
[dict setObject:[NSDate date] forKey:kOpenUDIDOOTSKey];
else
[dict removeObjectForKey:kOpenUDIDOOTSKey];

// store the dictionary locally
[defaults setObject:dict forKey:kOpenUDIDKey];

OpenUDIDLog(@"Local dict after opt-out = %@",dict);

// reset memory cache
kOpenUDIDSessionCache = nil;

}

@end
6 changes: 6 additions & 0 deletions Ports/iOSPort/nativeSources/permission_apis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef PERMISSION_APIS__HH
#define PERMISSION_APIS__HH

//#define checkModificationDatePermission

#endif // PERMISSION_APIS__HH

0 comments on commit b8e00b4

Please sign in to comment.