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
Original file line number Diff line number Diff line change
Expand Up @@ -650,18 +650,18 @@ private void setupOutcomeLayout() {
public boolean onSuccess(OutcomeEvent outcomeEvent, String name, String value) {
switch (outcomeEvent) {
case OUTCOME:
OneSignal.getUser().sendOutcome(name);
OneSignal.getSession().sendOutcome(name);
break;
case UNIQUE_OUTCOME:
OneSignal.getUser().sendUniqueOutcome(name);
OneSignal.getSession().sendUniqueOutcome(name);
break;
case OUTCOME_WITH_VALUE:
if (value.isEmpty()) {
toaster.makeCustomViewToast("Please enter an outcome value!", ToastType.ERROR);
return false;
}

OneSignal.getUser().sendOutcomeWithValue(name, Float.parseFloat(value));
OneSignal.getSession().sendOutcomeWithValue(name, Float.parseFloat(value));
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.onesignal.core

import android.os.Build
import androidx.annotation.RequiresApi
import kotlinx.coroutines.Dispatchers
import java.util.function.Consumer
import kotlin.coroutines.Continuation
Expand Down Expand Up @@ -57,6 +59,7 @@ object Continue {
* @return The [Continuation] which should be provided to the Kotlin coroutine, and will be executed
* once that coroutine has completed.
*/
@RequiresApi(Build.VERSION_CODES.N)
@JvmOverloads
@JvmStatic
fun <R> with(onFinished: Consumer<ContinueResult<R>>, context: CoroutineContext = Dispatchers.Main): Continuation<R> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import com.onesignal.core.OneSignal.login
import com.onesignal.core.OneSignal.user
import com.onesignal.core.debug.IDebugManager
import com.onesignal.core.session.ISessionManager
import com.onesignal.core.user.IUserManager
import com.onesignal.iam.IIAMManager
import com.onesignal.location.ILocationManager
Expand All @@ -26,6 +27,11 @@ interface IOneSignal {
*/
val user: IUserManager

/**
* The session manager for accessing session-scoped management.
*/
val session: ISessionManager

/**
* The notification manager for accessing device-scoped
* notification management.
Expand Down Expand Up @@ -66,6 +72,11 @@ interface IOneSignal {
*/
var privacyConsent: Boolean

/**
* Whether to disable the "GMS is missing" prompt to the user.
*/
var disableGMSMissingPrompt: Boolean

/**
* Initialize the OneSignal SDK. This should be called during startup of the application.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import com.onesignal.core.debug.IDebugManager
import com.onesignal.core.internal.OneSignalImp
import com.onesignal.core.internal.service.IServiceProvider
import com.onesignal.core.session.ISessionManager
import com.onesignal.core.user.IUserManager
import com.onesignal.iam.IIAMManager
import com.onesignal.location.ILocationManager
Expand Down Expand Up @@ -44,6 +45,14 @@ object OneSignal {
val user: IUserManager
get() = oneSignal.user

/**
* The session manager for accessing session-scoped management. Initialized only after [initWithContext]
* has been called.
*/
@JvmStatic
val session: ISessionManager
get() = oneSignal.session

/**
* The notification manager for accessing device-scoped notification management. Initialized
* only after [initWithContext] has been called.
Expand Down Expand Up @@ -98,6 +107,14 @@ object OneSignal {
get() = oneSignal.privacyConsent
set(value) { oneSignal.privacyConsent = value }

/**
* Whether to disable the "GMS is missing" prompt to the user.
*/
@JvmStatic
var disableGMSMissingPrompt: Boolean
get() = oneSignal.disableGMSMissingPrompt
set(value) { oneSignal.disableGMSMissingPrompt = value }

/**
* Initialize the OneSignal SDK. This should be called during startup of the application.
*
Expand Down Expand Up @@ -126,13 +143,31 @@ object OneSignal {
* because both Push and IAM are owned by the device.
*
* @param externalId The external ID of the user that is to be logged in.
* @param jwtBearerToken The optional JWT bearer token generated by your backend to establish
* trust for the login operation. Required when identity verification has been enabled. See
* [Identity Verification | OneSignal](https://documentation.onesignal.com/docs/identity-verification)
*/
@JvmStatic
suspend fun login(externalId: String) = oneSignal.login(externalId)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,22 @@ import com.onesignal.core.internal.outcomes.impl.OutcomeEventsRepository
import com.onesignal.core.internal.permissions.IRequestPermissionService
import com.onesignal.core.internal.permissions.impl.RequestPermissionService
import com.onesignal.core.internal.preferences.IPreferencesService
import com.onesignal.core.internal.preferences.PreferencesService
import com.onesignal.core.internal.preferences.impl.PreferencesService
import com.onesignal.core.internal.purchases.TrackAmazonPurchase
import com.onesignal.core.internal.purchases.TrackGooglePurchase
import com.onesignal.core.internal.service.ServiceBuilder
import com.onesignal.core.internal.session.ISessionService
import com.onesignal.core.internal.session.SessionManager
import com.onesignal.core.internal.session.impl.SessionService
import com.onesignal.core.internal.startup.IBootstrapService
import com.onesignal.core.internal.startup.IStartableService
import com.onesignal.core.internal.startup.StartupService
import com.onesignal.core.internal.time.ITime
import com.onesignal.core.internal.time.Time
import com.onesignal.core.internal.time.impl.Time
import com.onesignal.core.internal.user.ISubscriptionManager
import com.onesignal.core.internal.user.SubscriptionManager
import com.onesignal.core.internal.user.UserManager
import com.onesignal.core.session.ISessionManager
import com.onesignal.core.user.IUserManager

internal object CoreModule {
Expand Down Expand Up @@ -121,6 +123,7 @@ internal object CoreModule {
.provides<IStartableService>()
.provides<IBackgroundService>()
builder.register<SessionListener>().provides<IStartableService>()
builder.register<SessionManager>().provides<ISessionManager>()

// Background
builder.register<BackgroundManager>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.onesignal.core.internal.service.IServiceProvider
import com.onesignal.core.internal.service.ServiceBuilder
import com.onesignal.core.internal.service.ServiceProvider
import com.onesignal.core.internal.startup.StartupService
import com.onesignal.core.session.ISessionManager
import com.onesignal.core.user.IUserManager
import com.onesignal.iam.IIAMManager
import com.onesignal.iam.internal.IAMModule
Expand All @@ -55,7 +56,15 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
_configModel?.givenPrivacyConsent = value
}

override var disableGMSMissingPrompt: Boolean
get() = _configModel?.disableGMSMissingPrompt ?: (_disableGMSMissingPrompt == true)
set(value) {
_disableGMSMissingPrompt = value
_configModel?.disableGMSMissingPrompt = value
}

override val debug: IDebugManager = DebugManager()
override val session: ISessionManager get() = if (isInitialized) _session!! else throw Exception("Must call 'initWithContext' before use")
override val notifications: INotificationsManager get() = if (isInitialized) _notifications!! else throw Exception("Must call 'initWithContext' before use")
override val location: ILocationManager get() = if (isInitialized) _location!! else throw Exception("Must call 'initWithContext' before use")
override val iam: IIAMManager get() = if (isInitialized) _iam!! else throw Exception("Must call 'initWithContext' before use")
Expand All @@ -82,6 +91,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
// Services required by this class
private var _user: IUserManager? = null
private var _hasCreatedBackendUser: Boolean = false
private var _session: ISessionManager? = null
private var _iam: IIAMManager? = null
private var _location: ILocationManager? = null
private var _notifications: INotificationsManager? = null
Expand All @@ -97,6 +107,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
private var _sessionModel: SessionModel? = null
private var _requiresPrivacyConsent: Boolean? = null
private var _givenPrivacyConsent: Boolean? = null
private var _disableGMSMissingPrompt: Boolean? = null

init {
var serviceBuilder = ServiceBuilder()
Expand Down Expand Up @@ -141,9 +152,14 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
_configModel!!.givenPrivacyConsent = _givenPrivacyConsent!!
}

if (_disableGMSMissingPrompt != null) {
_configModel!!.disableGMSMissingPrompt = _disableGMSMissingPrompt!!
}

// "Inject" the services required by this main class
_location = _services.getService()
_user = _services.getService()
_session = _services.getService()
_iam = _services.getService()
_notifications = _services.getService()
_operationRepo = _services.getService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ internal class ConfigModel : Model() {
get() = getProperty(::disableGMSMissingPrompt.name) { false }
set(value) { setProperty(::disableGMSMissingPrompt.name, value) }

/**
* Whether to disable the "GMS is missing" prompt to the user.
*/
var userRejectedGMSUpdate: Boolean
get() = getProperty(::userRejectedGMSUpdate.name) { false }
set(value) { setProperty(::userRejectedGMSUpdate.name, value) }

/**
* Whether to automatically unsubscribe from OneSignal when notifications have been disabled.
*/
Expand Down
Loading