Skip to content

Commit f8181e6

Browse files
committed
Merge branch 'main' into new-session-events
2 parents 9673c8c + 330726b commit f8181e6

35 files changed

Lines changed: 2221 additions & 92 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build/
77
local.properties
88
OneSignalSDK/local.properties
99
examples/demo/local.properties
10+
google-services.json
1011

1112
# Google services
1213
google-services.json

‎OneSignalSDK/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010
]
1111
androidGradlePluginVersion = '8.8.2'
1212
detektVersion = '1.21.0'
13-
googleServicesGradlePluginVersion = '4.3.10'
13+
googleServicesGradlePluginVersion = '4.4.2'
1414
huaweiAgconnectVersion = '1.9.1.304'
1515
huaweiHMSPushVersion = '6.3.0.304'
1616
huaweiHMSLocationVersion = '4.0.0.300'

‎OneSignalSDK/detekt/detekt-baseline-core.xml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@
260260
<ID>MagicNumber:SubscriptionModel.kt$SubscriptionStatus.FIREBASE_FCM_ERROR_IOEXCEPTION_OTHER$11</ID>
261261
<ID>MagicNumber:SubscriptionModel.kt$SubscriptionStatus.FIREBASE_FCM_ERROR_IOEXCEPTION_SERVICE_NOT_AVAILABLE$9</ID>
262262
<ID>MagicNumber:SubscriptionModel.kt$SubscriptionStatus.FIREBASE_FCM_ERROR_MISC_EXCEPTION$12</ID>
263+
<ID>MagicNumber:SubscriptionModel.kt$SubscriptionStatus.FIREBASE_FCM_FID_DEFAULT_APP_MISSING$32</ID>
264+
<ID>MagicNumber:SubscriptionModel.kt$SubscriptionStatus.FIREBASE_FCM_FID_REGISTER_API_UNAVAILABLE$33</ID>
265+
<ID>MagicNumber:SubscriptionModel.kt$SubscriptionStatus.FIREBASE_FCM_FID_REGISTRATION_FAILED$34</ID>
263266
<ID>MagicNumber:SubscriptionModel.kt$SubscriptionStatus.FIREBASE_FCM_INIT_ERROR$8</ID>
264267
<ID>MagicNumber:SubscriptionModel.kt$SubscriptionStatus.HMS_API_EXCEPTION_OTHER$27</ID>
265268
<ID>MagicNumber:SubscriptionModel.kt$SubscriptionStatus.HMS_ARGUMENTS_INVALID$26</ID>

‎OneSignalSDK/gradle.properties‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ onesignalPublishSharedKmp = true
5252
# This is the name of the SDK to use when building your project.
5353
# This will be fed from the GitHub Actions workflow.
5454
SDK_VERSION=5.10.2
55+
56+
# Enabled parallel sync for Gradle 9.4+
57+
org.gradle.tooling.parallel=true

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ interface IOneSignal {
251251
)
252252

253253
/**
254-
* Login with [externalId] plus [profile]. Email/SMS create or transfer that address; an alias owned elsewhere fails the request.
255-
* Create User upsert (anonymous is not merged). Same id is a no-op once a backend ID exists. Failure still leaves this identity local.
254+
* Login with [externalId] plus [profile] as one Create User upsert (anonymous is not merged). Email/SMS create or transfer; a foreign alias fails it.
255+
* Same id is a no-op once a backend ID exists. Backend failure leaves this identity local; INVALID_ARGUMENT and NOT_INITIALIZED change nothing.
256256
*/
257257
suspend fun login(
258-
externalId: String,
258+
externalId: String?,
259259
profile: OneSignalUserProfile,
260260
jwtBearerToken: String? = null,
261261
): OneSignalResult<LoginData>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,13 @@ object OneSignal {
425425
}
426426

427427
/**
428-
* Login with [externalId] plus [profile]. Email/SMS create or transfer that address; an alias owned elsewhere fails the request.
429-
* Create User upsert (anonymous is not merged). Same id is a no-op once a backend ID exists. Failure still leaves this identity local.
428+
* Login with [externalId] plus [profile] as one Create User upsert (anonymous is not merged). Email/SMS create or transfer; a foreign alias fails it.
429+
* Same id is a no-op once a backend ID exists. Backend failure leaves this identity local; INVALID_ARGUMENT and NOT_INITIALIZED change nothing.
430430
*/
431431
@JvmStatic
432432
@JvmOverloads
433433
suspend fun login(
434-
externalId: String,
434+
externalId: String?,
435435
profile: OneSignalUserProfile,
436436
jwtBearerToken: String? = null,
437437
): OneSignalResult<LoginData> = oneSignal.login(externalId, profile, jwtBearerToken)

‎OneSignalSDK/onesignal/core/src/main/java/com/onesignal/OneSignalError.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ enum class ErrorSource {
3030
* `else` branch.
3131
*/
3232
enum class ErrorCode(val source: ErrorSource) {
33-
/** [IOneSignal.initWithContextSuspend] has not been called. */
33+
/** [IOneSignal.initWithContextSuspend] was never called, or it failed. */
3434
NOT_INITIALIZED(ErrorSource.CLIENT),
3535

3636
/**

‎OneSignalSDK/onesignal/core/src/main/java/com/onesignal/OneSignalUserProfile.kt‎

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

33
import com.onesignal.common.OneSignalUtils
4+
import com.onesignal.common.hasNullByte
45
import java.util.Collections
56

67
/**
@@ -25,9 +26,14 @@ class OneSignalUserProfile private constructor(builder: Builder) {
2526
when {
2627
email != null && !OneSignalUtils.isValidEmail(email) -> "Invalid email address"
2728
sms != null && !OneSignalUtils.isValidPhoneNumber(sms) -> "Invalid SMS number"
29+
// Java callers can put nulls in these maps despite the non-null types.
30+
tags.any { (key, value) -> isBadKey(key) || (value as String?) == null } -> "Tag keys must be non-empty and values non-null"
31+
aliases.any { (label, id) -> isBadKey(label) || isBadKey(id) } -> "Alias labels and IDs must be non-empty"
2832
else -> null
2933
}
3034

35+
private fun isBadKey(value: String?) = value.isNullOrEmpty() || hasNullByte(value)
36+
3137
override fun equals(other: Any?): Boolean {
3238
if (this === other) return true
3339
if (other !is OneSignalUserProfile) return false

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import com.onesignal.user.internal.jwt.JwtTokenStore
5353
import com.onesignal.user.internal.properties.PropertiesModelStore
5454
import com.onesignal.user.internal.resolveAppId
5555
import com.onesignal.user.internal.subscriptions.SubscriptionModelStore
56+
import kotlinx.coroutines.CancellationException
5657
import kotlinx.coroutines.CompletableDeferred
5758
import kotlinx.coroutines.CoroutineDispatcher
5859
import kotlinx.coroutines.runBlocking
@@ -826,20 +827,21 @@ internal class OneSignalImp : IOneSignal,
826827
}
827828

828829
override suspend fun login(
829-
externalId: String,
830+
externalId: String?,
830831
profile: OneSignalUserProfile,
831832
jwtBearerToken: String?,
832833
): OneSignalResult<LoginData> =
833834
withContext(ioDispatcher) {
834835
Logging.log(LogLevel.DEBUG, "login(externalId: $externalId, profile: $profile, jwtBearerToken: ...${jwtBearerToken?.takeLast(8)})")
835836

836837
profile.validationError()?.let {
838+
Logging.error("login(externalId, profile) rejected: $it")
837839
return@withContext OneSignalResult.failure(ErrorCode.INVALID_ARGUMENT, it)
838840
}
839841

840-
suspendUntilInit(operationName = "login")
842+
awaitInitForLogin()?.let { return@withContext it }
841843

842-
if (isMissing(externalId, "login: externalId")) {
844+
if (isMissing(externalId, "login: externalId") || externalId == null) {
843845
return@withContext OneSignalResult.failure(
844846
ErrorCode.INVALID_ARGUMENT,
845847
"login: externalId is required",
@@ -869,6 +871,20 @@ internal class OneSignalImp : IOneSignal,
869871
OneSignalResult.success(loginHelper.loginData(externalId, profile, fallbackOnesignalId = switched.onesignalId))
870872
}
871873

874+
/** Waits for init; returns a NOT_INITIALIZED failure instead of throwing when it never started or failed. */
875+
internal suspend fun awaitInitForLogin(): OneSignalResult<LoginData>? =
876+
try {
877+
suspendUntilInit(operationName = "login")
878+
null
879+
} catch (e: CancellationException) {
880+
// A subclass of IllegalStateException, so it must be rethrown before the catch below.
881+
throw e
882+
} catch (e: IllegalStateException) {
883+
// Callers can ignore the result, so the failure has to show up in the log.
884+
Logging.error("login(externalId, profile) skipped: ${e.message}", e)
885+
OneSignalResult.failure(ErrorCode.NOT_INITIALIZED, e.message, cause = e)
886+
}
887+
872888
private fun loginFailureMessage(wait: OperationWaitResult): String =
873889
wait.httpStatusCode?.let { "Login did not complete (HTTP $it)." } ?: "Login did not complete."
874890

‎OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/UserSwitcher.kt‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ class UserSwitcher(
107107
optedIn = notificationTypes != SubscriptionStatus.NO_PERMISSION.value &&
108108
notificationTypes != SubscriptionStatus.UNSUBSCRIBE.value
109109
address = legacyUserSyncJSON.safeString("identifier") ?: ""
110-
status = notificationTypes?.let { SubscriptionStatus.fromInt(it) }
111-
?: SubscriptionStatus.SUBSCRIBED
110+
status =
111+
notificationTypes?.let { SubscriptionStatus.fromNotificationTypes(it) }
112+
?: SubscriptionStatus.SUBSCRIBED
112113
sdk = OneSignalUtils.sdkVersion
113114
deviceOS = this@UserSwitcher.deviceOS ?: ""
114115
carrier = carrierName ?: ""

0 commit comments

Comments
 (0)