File tree Expand file tree Collapse file tree 4 files changed +79
-0
lines changed
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user Expand file tree Collapse file tree 4 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import com.onesignal.user.internal.backend.impl.UserBackendService
17
17
import com.onesignal.user.internal.builduser.IRebuildUserService
18
18
import com.onesignal.user.internal.builduser.impl.RebuildUserService
19
19
import com.onesignal.user.internal.identity.IdentityModelStore
20
+ import com.onesignal.user.internal.migrations.RecoverConfigPushSubscription
20
21
import com.onesignal.user.internal.migrations.RecoverFromDroppedLoginBug
21
22
import com.onesignal.user.internal.operations.impl.executors.IdentityOperationExecutor
22
23
import com.onesignal.user.internal.operations.impl.executors.LoginUserFromSubscriptionOperationExecutor
@@ -74,6 +75,7 @@ internal class UserModule : IModule {
74
75
builder.register<UserRefreshService >().provides<IStartableService >()
75
76
76
77
builder.register<RecoverFromDroppedLoginBug >().provides<IStartableService >()
78
+ builder.register<RecoverConfigPushSubscription >().provides<IStartableService >()
77
79
78
80
// Shared state between Executors
79
81
builder.register<NewRecordsState >().provides<NewRecordsState >()
Original file line number Diff line number Diff line change
1
+ package com.onesignal.user.internal.migrations
2
+
3
+ import com.onesignal.core.internal.startup.IStartableService
4
+
5
+ /* *
6
+ * Purpose: allow to identify and take corrective action for some specific bad states during migration
7
+ *
8
+ * Implement these properties to:
9
+ * - isInBadState(): return true the condition for the bad state has met
10
+ * - recover(): take a recovery action if the bad state has been identified
11
+ * - recoveryMessage: log a message after the bad state is found and the corrective action is taken
12
+ */
13
+ interface IMigrationRecovery : IStartableService {
14
+ fun isInBadState (): Boolean
15
+ fun recover ()
16
+ fun recoveryMessage (): String
17
+ }
Original file line number Diff line number Diff line change
1
+ package com.onesignal.user.internal.migrations
2
+
3
+ import com.onesignal.debug.internal.logging.Logging
4
+
5
+ open class MigrationRecovery : IMigrationRecovery {
6
+ override fun isInBadState (): Boolean {
7
+ return false
8
+ }
9
+
10
+ override fun recover () {
11
+ // left blank intentionally
12
+ }
13
+
14
+ override fun recoveryMessage (): String {
15
+ return " "
16
+ }
17
+
18
+ override fun start () {
19
+ // log a message and take the corrective action if it is determined that app is in a bad state
20
+ if (isInBadState()) {
21
+ Logging .warn(recoveryMessage())
22
+ recover()
23
+ }
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ package com.onesignal.user.internal.migrations
2
+
3
+ import com.onesignal.core.internal.config.ConfigModelStore
4
+ import com.onesignal.core.internal.operations.containsInstanceOf
5
+ import com.onesignal.user.internal.operations.LoginUserOperation
6
+ import com.onesignal.user.internal.subscriptions.SubscriptionModelStore
7
+ import com.onesignal.user.internal.subscriptions.SubscriptionType
8
+ import kotlinx.coroutines.Dispatchers
9
+ import kotlinx.coroutines.GlobalScope
10
+ import kotlinx.coroutines.launch
11
+
12
+ /* *
13
+ * Purpose: Automatically recovers a missing push sub ID in the config model store due
14
+ * to a bug migrating from the SDK 5.2.0-beta
15
+ */
16
+ class RecoverConfigPushSubscription (
17
+ private val _configModelStore : ConfigModelStore ,
18
+ private val _subscriptionModelStore : SubscriptionModelStore ,
19
+ ) : MigrationRecovery() {
20
+
21
+ val activePushSubscription by lazy { _subscriptionModelStore .list().firstOrNull{ it.type == SubscriptionType .PUSH } }
22
+
23
+ override fun isInBadState (): Boolean {
24
+ val isPushSubIdMissing = _configModelStore .model.pushSubscriptionId == null
25
+ return isPushSubIdMissing && activePushSubscription != null
26
+ }
27
+
28
+ override fun recover () {
29
+ _configModelStore .model.pushSubscriptionId = activePushSubscription?.id
30
+ }
31
+
32
+ override fun recoveryMessage (): String {
33
+ return " Recovering missing push subscription ID in the config model store."
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments