Skip to content

Commit a0b4a74

Browse files
authored
Merge pull request #1675 from OneSignal/user-model/session-manager
[User Model] Session Manager
2 parents a12b55c + 60dbb5a commit a0b4a74

File tree

19 files changed

+353
-179
lines changed

19 files changed

+353
-179
lines changed

Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/MainActivityViewModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,18 +650,18 @@ private void setupOutcomeLayout() {
650650
public boolean onSuccess(OutcomeEvent outcomeEvent, String name, String value) {
651651
switch (outcomeEvent) {
652652
case OUTCOME:
653-
OneSignal.getUser().sendOutcome(name);
653+
OneSignal.getSession().sendOutcome(name);
654654
break;
655655
case UNIQUE_OUTCOME:
656-
OneSignal.getUser().sendUniqueOutcome(name);
656+
OneSignal.getSession().sendUniqueOutcome(name);
657657
break;
658658
case OUTCOME_WITH_VALUE:
659659
if (value.isEmpty()) {
660660
toaster.makeCustomViewToast("Please enter an outcome value!", ToastType.ERROR);
661661
return false;
662662
}
663663

664-
OneSignal.getUser().sendOutcomeWithValue(name, Float.parseFloat(value));
664+
OneSignal.getSession().sendOutcomeWithValue(name, Float.parseFloat(value));
665665
break;
666666
}
667667

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/Continue.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.onesignal.core
22

3+
import android.os.Build
4+
import androidx.annotation.RequiresApi
35
import kotlinx.coroutines.Dispatchers
46
import java.util.function.Consumer
57
import kotlin.coroutines.Continuation
@@ -57,6 +59,7 @@ object Continue {
5759
* @return The [Continuation] which should be provided to the Kotlin coroutine, and will be executed
5860
* once that coroutine has completed.
5961
*/
62+
@RequiresApi(Build.VERSION_CODES.N)
6063
@JvmOverloads
6164
@JvmStatic
6265
fun <R> with(onFinished: Consumer<ContinueResult<R>>, context: CoroutineContext = Dispatchers.Main): Continuation<R> {

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/IOneSignal.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import com.onesignal.core.OneSignal.login
55
import com.onesignal.core.OneSignal.user
66
import com.onesignal.core.debug.IDebugManager
7+
import com.onesignal.core.session.ISessionManager
78
import com.onesignal.core.user.IUserManager
89
import com.onesignal.iam.IIAMManager
910
import com.onesignal.location.ILocationManager
@@ -26,6 +27,11 @@ interface IOneSignal {
2627
*/
2728
val user: IUserManager
2829

30+
/**
31+
* The session manager for accessing session-scoped management.
32+
*/
33+
val session: ISessionManager
34+
2935
/**
3036
* The notification manager for accessing device-scoped
3137
* notification management.
@@ -66,6 +72,11 @@ interface IOneSignal {
6672
*/
6773
var privacyConsent: Boolean
6874

75+
/**
76+
* Whether to disable the "GMS is missing" prompt to the user.
77+
*/
78+
var disableGMSMissingPrompt: Boolean
79+
6980
/**
7081
* Initialize the OneSignal SDK. This should be called during startup of the application.
7182
*

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/OneSignal.kt

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import com.onesignal.core.debug.IDebugManager
55
import com.onesignal.core.internal.OneSignalImp
66
import com.onesignal.core.internal.service.IServiceProvider
7+
import com.onesignal.core.session.ISessionManager
78
import com.onesignal.core.user.IUserManager
89
import com.onesignal.iam.IIAMManager
910
import com.onesignal.location.ILocationManager
@@ -44,6 +45,14 @@ object OneSignal {
4445
val user: IUserManager
4546
get() = oneSignal.user
4647

48+
/**
49+
* The session manager for accessing session-scoped management. Initialized only after [initWithContext]
50+
* has been called.
51+
*/
52+
@JvmStatic
53+
val session: ISessionManager
54+
get() = oneSignal.session
55+
4756
/**
4857
* The notification manager for accessing device-scoped notification management. Initialized
4958
* only after [initWithContext] has been called.
@@ -98,6 +107,14 @@ object OneSignal {
98107
get() = oneSignal.privacyConsent
99108
set(value) { oneSignal.privacyConsent = value }
100109

110+
/**
111+
* Whether to disable the "GMS is missing" prompt to the user.
112+
*/
113+
@JvmStatic
114+
var disableGMSMissingPrompt: Boolean
115+
get() = oneSignal.disableGMSMissingPrompt
116+
set(value) { oneSignal.disableGMSMissingPrompt = value }
117+
101118
/**
102119
* Initialize the OneSignal SDK. This should be called during startup of the application.
103120
*
@@ -126,13 +143,31 @@ object OneSignal {
126143
* because both Push and IAM are owned by the device.
127144
*
128145
* @param externalId The external ID of the user that is to be logged in.
129-
* @param jwtBearerToken The optional JWT bearer token generated by your backend to establish
130-
* trust for the login operation. Required when identity verification has been enabled. See
131-
* [Identity Verification | OneSignal](https://documentation.onesignal.com/docs/identity-verification)
132146
*/
133147
@JvmStatic
134148
suspend fun login(externalId: String) = oneSignal.login(externalId)
135149

150+
/**
151+
* Login to OneSignal under the user identified by the [externalId] provided. The act of
152+
* logging a user into the OneSignal SDK will switch the [user] context to that specific user.
153+
*
154+
* * If the [externalId] exists the user will be retrieved and the context set from that
155+
* user information. If operations have already been performed under a guest user, they
156+
* *will not* be applied to the now logged in user (they will be lost).
157+
* * If the [externalId] does not exist the user will be created and the context set from
158+
* the current local state. If operations have already been performed under a guest user
159+
* those operations *will* be applied to the newly created user.
160+
*
161+
* *Push Notifications and In App Messaging*
162+
* Logging in a new user will automatically transfer push notification and in app messaging
163+
* subscriptions from the current user (if there is one) to the newly logged in user. This is
164+
* because both Push and IAM are owned by the device.
165+
*
166+
* @param externalId The external ID of the user that is to be logged in.
167+
* @param jwtBearerToken The optional JWT bearer token generated by your backend to establish
168+
* trust for the login operation. Required when identity verification has been enabled. See
169+
* [Identity Verification | OneSignal](https://documentation.onesignal.com/docs/identity-verification)
170+
*/
136171
@JvmStatic
137172
suspend fun login(externalId: String, jwtBearerToken: String? = null) = oneSignal.login(externalId, jwtBearerToken)
138173

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/CoreModule.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,22 @@ import com.onesignal.core.internal.outcomes.impl.OutcomeEventsRepository
5454
import com.onesignal.core.internal.permissions.IRequestPermissionService
5555
import com.onesignal.core.internal.permissions.impl.RequestPermissionService
5656
import com.onesignal.core.internal.preferences.IPreferencesService
57-
import com.onesignal.core.internal.preferences.PreferencesService
57+
import com.onesignal.core.internal.preferences.impl.PreferencesService
5858
import com.onesignal.core.internal.purchases.TrackAmazonPurchase
5959
import com.onesignal.core.internal.purchases.TrackGooglePurchase
6060
import com.onesignal.core.internal.service.ServiceBuilder
6161
import com.onesignal.core.internal.session.ISessionService
62+
import com.onesignal.core.internal.session.SessionManager
6263
import com.onesignal.core.internal.session.impl.SessionService
6364
import com.onesignal.core.internal.startup.IBootstrapService
6465
import com.onesignal.core.internal.startup.IStartableService
6566
import com.onesignal.core.internal.startup.StartupService
6667
import com.onesignal.core.internal.time.ITime
67-
import com.onesignal.core.internal.time.Time
68+
import com.onesignal.core.internal.time.impl.Time
6869
import com.onesignal.core.internal.user.ISubscriptionManager
6970
import com.onesignal.core.internal.user.SubscriptionManager
7071
import com.onesignal.core.internal.user.UserManager
72+
import com.onesignal.core.session.ISessionManager
7173
import com.onesignal.core.user.IUserManager
7274

7375
internal object CoreModule {
@@ -121,6 +123,7 @@ internal object CoreModule {
121123
.provides<IStartableService>()
122124
.provides<IBackgroundService>()
123125
builder.register<SessionListener>().provides<IStartableService>()
126+
builder.register<SessionManager>().provides<ISessionManager>()
124127

125128
// Background
126129
builder.register<BackgroundManager>()

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/OneSignalImp.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.onesignal.core.internal.service.IServiceProvider
2929
import com.onesignal.core.internal.service.ServiceBuilder
3030
import com.onesignal.core.internal.service.ServiceProvider
3131
import com.onesignal.core.internal.startup.StartupService
32+
import com.onesignal.core.session.ISessionManager
3233
import com.onesignal.core.user.IUserManager
3334
import com.onesignal.iam.IIAMManager
3435
import com.onesignal.iam.internal.IAMModule
@@ -55,7 +56,15 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
5556
_configModel?.givenPrivacyConsent = value
5657
}
5758

59+
override var disableGMSMissingPrompt: Boolean
60+
get() = _configModel?.disableGMSMissingPrompt ?: (_disableGMSMissingPrompt == true)
61+
set(value) {
62+
_disableGMSMissingPrompt = value
63+
_configModel?.disableGMSMissingPrompt = value
64+
}
65+
5866
override val debug: IDebugManager = DebugManager()
67+
override val session: ISessionManager get() = if (isInitialized) _session!! else throw Exception("Must call 'initWithContext' before use")
5968
override val notifications: INotificationsManager get() = if (isInitialized) _notifications!! else throw Exception("Must call 'initWithContext' before use")
6069
override val location: ILocationManager get() = if (isInitialized) _location!! else throw Exception("Must call 'initWithContext' before use")
6170
override val iam: IIAMManager get() = if (isInitialized) _iam!! else throw Exception("Must call 'initWithContext' before use")
@@ -82,6 +91,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
8291
// Services required by this class
8392
private var _user: IUserManager? = null
8493
private var _hasCreatedBackendUser: Boolean = false
94+
private var _session: ISessionManager? = null
8595
private var _iam: IIAMManager? = null
8696
private var _location: ILocationManager? = null
8797
private var _notifications: INotificationsManager? = null
@@ -97,6 +107,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
97107
private var _sessionModel: SessionModel? = null
98108
private var _requiresPrivacyConsent: Boolean? = null
99109
private var _givenPrivacyConsent: Boolean? = null
110+
private var _disableGMSMissingPrompt: Boolean? = null
100111

101112
init {
102113
val serviceBuilder = ServiceBuilder()
@@ -145,9 +156,14 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
145156
_configModel!!.givenPrivacyConsent = _givenPrivacyConsent!!
146157
}
147158

159+
if (_disableGMSMissingPrompt != null) {
160+
_configModel!!.disableGMSMissingPrompt = _disableGMSMissingPrompt!!
161+
}
162+
148163
// "Inject" the services required by this main class
149164
_location = _services.getService()
150165
_user = _services.getService()
166+
_session = _services.getService()
151167
_iam = _services.getService()
152168
_notifications = _services.getService()
153169
_operationRepo = _services.getService()

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/models/ConfigModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ internal class ConfigModel : Model() {
4040
get() = getProperty(::disableGMSMissingPrompt.name) { false }
4141
set(value) { setProperty(::disableGMSMissingPrompt.name, value) }
4242

43+
/**
44+
* Whether to disable the "GMS is missing" prompt to the user.
45+
*/
46+
var userRejectedGMSUpdate: Boolean
47+
get() = getProperty(::userRejectedGMSUpdate.name) { false }
48+
set(value) { setProperty(::userRejectedGMSUpdate.name, value) }
49+
4350
/**
4451
* Whether to automatically unsubscribe from OneSignal when notifications have been disabled.
4552
*/

0 commit comments

Comments
 (0)