Skip to content

Commit 9138b66

Browse files
authored
Add support for automatic resetting incremental backoff when network status changes (#1491)
1 parent 2ce9a27 commit 9138b66

File tree

43 files changed

+880
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+880
-418
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if the content is the same. Custom implementations of these methods will be resp
2828
* Support for performing geospatial queries using the new classes: `GeoPoint`, `GeoCircle`, `GeoBox`, and `GeoPolygon`. See `GeoPoint` documentation on how to persist locations. (Issue [#1403](https://github.com/realm/realm-kotlin/pull/1403))
2929
* Support for automatic resolution of embedded object constraints during migration through `RealmConfiguration.Builder.migration(migration: AutomaticSchemaMigration, resolveEmbeddedObjectConstraints: Boolean)`. (Issue [#1464](https://github.com/realm/realm-kotlin/issues/1464)
3030
* [Sync] Add support for customizing authorization headers and adding additional custom headers to all Atlas App service requests with `AppConfiguration.Builder.authorizationHeaderName()` and `AppConfiguration.Builder.addCustomRequestHeader(...)`. (Issue [#1453](https://github.com/realm/realm-kotlin/pull/1453))
31+
* [Sync] Added support for manually triggering a reconnect attempt for Device Sync. This is done through a new `App.Sync.reconnect()` method. This method is also now called automatically when a mobile device toggles off airplane mode. (Issue [#1479](https://github.com/realm/realm-kotlin/issues/1479))
3132

3233
### Fixed
3334
* None.

packages/cinterop/src/commonMain/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,11 @@ expect object RealmInterop {
707707
callback: AppCallback<String>
708708
)
709709

710+
// Sync Client
711+
fun realm_app_sync_client_reconnect(app: RealmAppPointer)
712+
fun realm_app_sync_client_has_sessions(app: RealmAppPointer): Boolean
713+
fun realm_app_sync_client_wait_for_sessions_to_terminate(app: RealmAppPointer)
714+
710715
// Sync config
711716
fun realm_config_set_sync_config(
712717
realmConfiguration: RealmConfigurationPointer,

packages/cinterop/src/jvm/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,17 @@ actual object RealmInterop {
15581558
)
15591559
}
15601560

1561+
actual fun realm_app_sync_client_reconnect(app: RealmAppPointer) {
1562+
realmc.realm_app_sync_client_reconnect(app.cptr())
1563+
}
1564+
actual fun realm_app_sync_client_has_sessions(app: RealmAppPointer): Boolean {
1565+
return realmc.realm_app_sync_client_has_sessions(app.cptr())
1566+
}
1567+
1568+
actual fun realm_app_sync_client_wait_for_sessions_to_terminate(app: RealmAppPointer) {
1569+
realmc.realm_app_sync_client_wait_for_sessions_to_terminate(app.cptr())
1570+
}
1571+
15611572
actual fun realm_sync_config_new(user: RealmUserPointer, partition: String): RealmSyncConfigurationPointer {
15621573
return LongPointerWrapper<RealmSyncConfigT>(realmc.realm_sync_config_new(user.cptr(), partition)).also { ptr ->
15631574
// Stop the session immediately when the Realm is closed, so the lifecycle of the

packages/cinterop/src/nativeDarwin/kotlin/io/realm/kotlin/internal/interop/RealmInterop.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,6 +2948,17 @@ actual object RealmInterop {
29482948
}
29492949
}
29502950

2951+
actual fun realm_app_sync_client_reconnect(app: RealmAppPointer) {
2952+
realm_wrapper.realm_app_sync_client_reconnect(app.cptr())
2953+
}
2954+
actual fun realm_app_sync_client_has_sessions(app: RealmAppPointer): Boolean {
2955+
return realm_wrapper.realm_app_sync_client_has_sessions(app.cptr())
2956+
}
2957+
2958+
actual fun realm_app_sync_client_wait_for_sessions_to_terminate(app: RealmAppPointer) {
2959+
realm_wrapper.realm_app_sync_client_wait_for_sessions_to_terminate(app.cptr())
2960+
}
2961+
29512962
actual fun realm_config_set_sync_config(realmConfiguration: RealmConfigurationPointer, syncConfiguration: RealmSyncConfigurationPointer) {
29522963
realm_wrapper.realm_config_set_sync_config(realmConfiguration.cptr(), syncConfiguration.cptr())
29532964
}

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/RealmInstantImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public data class RealmInstantImpl(override val seconds: Long, override val nano
3232
}
3333
}
3434

35-
internal fun RealmInstant.toDuration(): Duration {
35+
public fun RealmInstant.toDuration(): Duration {
3636
return epochSeconds.seconds + nanosecondsOfSecond.nanoseconds
3737
}
3838

packages/library-base/src/commonMain/kotlin/io/realm/kotlin/internal/platform/SystemUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public expect fun epochInSeconds(): Long
131131
/**
132132
* Returns a RealmInstant representing the time that has passed since the Unix epoch.
133133
*/
134-
internal expect fun currentTime(): RealmInstant
134+
public expect fun currentTime(): RealmInstant
135135

136136
/**
137137
* Returns the type of a mutable property.

packages/library-base/src/jvm/kotlin/io/realm/kotlin/internal/platform/SystemUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public actual fun epochInSeconds(): Long =
2828
* Since internalNow() should only logically return a value after the Unix epoch, it is safe to create a RealmInstant
2929
* without considering having to pass negative nanoseconds.
3030
*/
31-
internal actual fun currentTime(): RealmInstant {
31+
public actual fun currentTime(): RealmInstant {
3232
val jtInstant = systemUTC().instant()
3333
return RealmInstantImpl(jtInstant.epochSecond, jtInstant.nano)
3434
}

packages/library-base/src/nativeDarwin/kotlin/io/realm/kotlin/internal/platform/SystemUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public actual fun epochInSeconds(): Long =
6868
* without considering having to pass negative nanoseconds.
6969
*/
7070
@Suppress("MagicNumber")
71-
internal actual fun currentTime(): RealmInstant {
71+
public actual fun currentTime(): RealmInstant {
7272
val secs: Double = NSDate().timeIntervalSince1970
7373
return when {
7474
// We can't convert the MIN value to ms - it is initialized with Long.MIN_VALUE and

packages/library-sync/src/androidMain/AndroidManifest.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@
1616
-->
1717

1818
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:tools="http://schemas.android.com/tools"
1920
package="io.realm.kotlin.mongodb">
2021

22+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2123
<uses-permission android:name="android.permission.INTERNET" />
2224

25+
<application>
26+
<provider
27+
android:name="androidx.startup.InitializationProvider"
28+
tools:node="merge"
29+
android:authorities="${applicationId}.androidx-startup"
30+
android:exported="false">
31+
<meta-data
32+
android:name="io.realm.kotlin.mongodb.internal.RealmSyncInitializer"
33+
android:value="androidx.startup" />
34+
</provider>
35+
</application>
36+
2337
</manifest>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.realm.kotlin.mongodb.internal
2+
3+
internal actual fun registerSystemNetworkObserver() {
4+
// Registering network state listeners are done in io.realm.kotlin.mongodb.RealmSyncInitializer
5+
// so we do not have to store the Android Context.
6+
}

0 commit comments

Comments
 (0)