|
12 | 12 | #include <CoreFoundation/CFString.h>
|
13 | 13 | #include "CFPriv.h"
|
14 | 14 | #include "CFInternal.h"
|
| 15 | +#include "CFUtilities.h" |
15 | 16 |
|
16 | 17 | #include <assert.h>
|
17 | 18 |
|
@@ -93,23 +94,26 @@ CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUs
|
93 | 94 |
|
94 | 95 | #elif TARGET_OS_ANDROID
|
95 | 96 |
|
| 97 | + // Android doesn't support users, and apps cannot write outside their |
| 98 | + // sandbox. All the preferences will be local to the application, mapping |
| 99 | + // "any user" and other users by name to different directories inside the |
| 100 | + // sandbox. |
| 101 | + CFURLRef userdir = CFCopyHomeDirectoryURL(); |
96 | 102 | switch (user) {
|
97 |
| - case _kCFKnownLocationUserAny: |
98 |
| - case _kCFKnownLocationUserByName: |
99 |
| - abort(); |
100 |
| - case _kCFKnownLocationUserCurrent: { |
101 |
| - const char *buffer = getenv("CFFIXED_USER_HOME"); |
102 |
| - if (buffer == NULL || *buffer == '\0') { |
103 |
| - CFLog(__kCFLogAssertion, CFSTR("CFFIXED_USER_HOME is unset")); |
104 |
| - HALT; |
105 |
| - } |
106 |
| - |
107 |
| - CFURLRef userdir = CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault, (const unsigned char *)buffer, strlen(buffer), true); |
108 |
| - location = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, CFSTR("/Apple/Library/Preferences"), kCFURLPOSIXPathStyle, true, userdir); |
109 |
| - CFRelease(userdir); |
110 |
| - break; |
111 |
| - } |
| 103 | + case _kCFKnownLocationUserAny: |
| 104 | + location = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, CFSTR("/Apple/Library/Preferences/AnyUser"), kCFURLPOSIXPathStyle, true, userdir); |
| 105 | + break; |
| 106 | + case _kCFKnownLocationUserByName: { |
| 107 | + CFURLRef tmp = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, CFSTR("/Apple/Library/Preferences/ByUser"), kCFURLPOSIXPathStyle, true, userdir); |
| 108 | + location = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, username, kCFURLPOSIXPathStyle, true, tmp); |
| 109 | + CFRelease(tmp); |
| 110 | + break; |
| 111 | + } |
| 112 | + case _kCFKnownLocationUserCurrent: |
| 113 | + location = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, CFSTR("/Apple/Library/Preferences"), kCFURLPOSIXPathStyle, true, userdir); |
| 114 | + break; |
112 | 115 | }
|
| 116 | + CFRelease(userdir); |
113 | 117 |
|
114 | 118 | #else
|
115 | 119 |
|
|
0 commit comments