Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* The Realm Transformer and Realm Gradle Plugin now supports the Gradle Configuration Cache. (Issue [#7299](https://github.com/realm/realm-java/issues/7299))

### Fixed
* [RealmApp] Setting `AppConfiguration.syncRootDirectory()` didn't have any effect beside creating the new folder. Realms were still placed in the default location.
* [RealmApp] Bug where progress notifiers continue to be called after the download of a synced realm is complete. (Issue [Realm Core #4919](https://github.com/realm/realm-core/issues/4919))
* [RealmApp] User being left in the logged in state when the user's refresh token expires. (Issue [Realm Core #4882](https://github.com/realm/realm-core/issues/4882), since v10)
* Using "sort", "distinct", or "limit" as field name in query expression would cause an "Invalid predicate" error. (Issue [#7545](), since v10.X.X)
Expand Down
2 changes: 1 addition & 1 deletion dependencies.list
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ REALM_CORE=11.6.0

# Version of MongoDB Realm used by integration tests
# See https://github.com/realm/ci/packages/147854 for available versions
MONGODB_REALM_SERVER=2021-11-28
MONGODB_REALM_SERVER=2021-12-01

# Common Android settings across projects
GRADLE_BUILD_TOOLS=7.1.0-beta03
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AppConfigurationTests {
@Test
fun syncRootDirectory_default() {
val config = AppConfiguration.Builder("app-id").build()
val expectedDefaultRoot = File(InstrumentationRegistry.getInstrumentation().targetContext.filesDir, "mongodb-realm")
val expectedDefaultRoot = InstrumentationRegistry.getInstrumentation().targetContext.filesDir
assertEquals(expectedDefaultRoot, config.syncRootDirectory)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,31 @@ class SyncedRealmTests {
}
}

@Test
fun customSyncRoot() {
app.close()
Realm.init(InstrumentationRegistry.getInstrumentation().targetContext)
val defaultRoot = File(Realm.getApplicationContext()!!.filesDir, "mongodb-realm")
val root = File(Realm.getApplicationContext()!!.filesDir, "my-custom-dir")
if (defaultRoot.exists()) { assertTrue(defaultRoot.deleteRecursively()) }
if (root.exists()) { assertTrue(root.deleteRecursively()) }

app = TestApp(builder = { it.syncRootDirectory(root) })
assertTrue("Root folder wasn't created", root.exists())
assertFalse("Default folder was created", defaultRoot.exists())

try {
val user: User = createNewUser()
val config = createDefaultConfig(user)
assertTrue("Wrong path: ${config.path}", config.path.contains("/my-custom-dir/mongodb-realm/"))
Realm.getInstance(config).close()
assertTrue(File(config.path).exists())
assertFalse("Default folder was created", defaultRoot.exists())
} finally {
assertTrue(root.deleteRecursively())
}
}

private fun createDefaultConfig(user: User, partitionValue: String = defaultPartitionValue): SyncConfiguration {
return SyncConfiguration.Builder(user, partitionValue)
.modules(DefaultSyncSchema())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ public App(AppConfiguration config) {
private OsApp init(AppConfiguration config) {
String userAgentBindingInfo = getBindingInfo();
String appDefinedUserAgent = getAppInfo(config);
String syncDir = getSyncBaseDirectory();
String syncDir = getSyncBaseDirectory(config);

return new OsApp(config, userAgentBindingInfo, appDefinedUserAgent, syncDir);
}

private String getSyncBaseDirectory() {
private String getSyncBaseDirectory(AppConfiguration config) {
Context context = Realm.getApplicationContext();
if (context == null) {
throw new IllegalStateException("Call Realm.init() first.");
Expand All @@ -213,7 +213,7 @@ private String getSyncBaseDirectory() {
throw new IllegalStateException(e);
}
} else {
syncDir = context.getFilesDir().getPath();
syncDir = config.getSyncRootDirectory().getPath();
}
return syncDir;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,6 @@ public Builder(String appId) {
if (context == null) {
throw new IllegalStateException("Call `Realm.init(Context)` before calling this method.");
}
File rootDir = new File(context.getFilesDir(), "mongodb-realm");
if (!rootDir.exists() && !rootDir.mkdir()) {
throw new IllegalStateException("Could not create Sync root dir: " + rootDir.getAbsolutePath());
}
syncRootDir = rootDir;
}

/**
Expand Down Expand Up @@ -638,6 +633,11 @@ public Builder httpLogObfuscator(@Nullable HttpLogObfuscator httpLogObfuscator)
* @return the AppConfiguration that can be used to create a {@link App}.
*/
public AppConfiguration build() {
// Initialize default sync root if none has been defined.
if (syncRootDir == null) {
syncRootDir = Realm.getApplicationContext().getFilesDir();
}

return new AppConfiguration(appId,
appName,
appVersion,
Expand Down