diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/IOneSignal.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/IOneSignal.kt index 6b38326c8..bc9149396 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/IOneSignal.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/IOneSignal.kt @@ -23,29 +23,59 @@ interface IOneSignal { * The user manager for accessing user-scoped * management. */ + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getUser() instead.", + replaceWith = ReplaceWith("getUser()"), + ) val user: IUserManager /** * The session manager for accessing session-scoped management. */ + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getSession() instead.", + replaceWith = ReplaceWith("getSession()"), + ) val session: ISessionManager /** * The notification manager for accessing device-scoped * notification management. */ + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getNotifications() instead.", + replaceWith = ReplaceWith("getNotifications()"), + ) val notifications: INotificationsManager /** * The location manager for accessing device-scoped * location management. */ + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getLocation() instead.", + replaceWith = ReplaceWith("getLocation()"), + ) val location: ILocationManager /** * The In App Messaging manager for accessing device-scoped * IAP management. */ + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getInAppMessages() instead.", + replaceWith = ReplaceWith("getInAppMessages()"), + ) val inAppMessages: IInAppMessagesManager /** @@ -62,17 +92,47 @@ interface IOneSignal { * should be set to `true` prior to the invocation of * [initWithContext] to ensure compliance. */ + @get:Deprecated( + message = + "Reading this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getConsentRequired() instead.", + replaceWith = ReplaceWith("getConsentRequired()"), + ) + @set:Deprecated( + message = "Use the suspend function setConsentRequired(value) instead.", + replaceWith = ReplaceWith("setConsentRequired(value)"), + ) var consentRequired: Boolean /** * Indicates whether privacy consent has been granted. This field is only relevant when * the application has opted into data privacy protections. See [consentRequired]. */ + @get:Deprecated( + message = + "Reading this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getConsentGiven() instead.", + replaceWith = ReplaceWith("getConsentGiven()"), + ) + @set:Deprecated( + message = "Use the suspend function setConsentGiven(value) instead.", + replaceWith = ReplaceWith("setConsentGiven(value)"), + ) var consentGiven: Boolean /** * Whether to disable the "GMS is missing" prompt to the user. */ + @get:Deprecated( + message = + "Reading this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getDisableGMSMissingPrompt() instead.", + replaceWith = ReplaceWith("getDisableGMSMissingPrompt()"), + ) + @set:Deprecated( + message = "Use the suspend function setDisableGMSMissingPrompt(value) instead.", + replaceWith = ReplaceWith("setDisableGMSMissingPrompt(value)"), + ) var disableGMSMissingPrompt: Boolean /** @@ -83,6 +143,12 @@ interface IOneSignal { * * @return true if the SDK could be successfully initialized, false otherwise. */ + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function initWithContextSuspend(context, appId) instead.", + replaceWith = ReplaceWith("initWithContextSuspend(context, appId)"), + ) fun initWithContext( context: Context, appId: String, @@ -116,11 +182,30 @@ interface IOneSignal { * trust for the login operation. Required when identity verification has been enabled. See * [Identity Verification | OneSignal](https://documentation.onesignal.com/docs/identity-verification) */ + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function loginSuspend(externalId, jwtBearerToken) instead.", + replaceWith = ReplaceWith("loginSuspend(externalId, jwtBearerToken)"), + ) fun login( externalId: String, jwtBearerToken: String? = null, ) + /** + * Login to OneSignal under the user identified by the [externalId] provided, without a JWT + * bearer token. Convenience overload of [login] equivalent to calling it with a `null` token. + * + * @param externalId The external ID of the user that is to be logged in. + */ + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function loginSuspend(externalId) instead.", + replaceWith = ReplaceWith("loginSuspend(externalId)"), + ) + @Suppress("DEPRECATION") fun login(externalId: String) = login(externalId, null) /** @@ -129,6 +214,12 @@ interface IOneSignal { * be retrieved, except through this device as long as the app remains installed and the app * data is not cleared. */ + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function logoutSuspend() instead.", + replaceWith = ReplaceWith("logoutSuspend()"), + ) fun logout() /** @@ -140,6 +231,12 @@ interface IOneSignal { * @param externalId The external ID the JWT belongs to. * @param token The new JWT bearer token issued by your backend. */ + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function updateUserJwtSuspend(externalId, token) instead.", + replaceWith = ReplaceWith("updateUserJwtSuspend(externalId, token)"), + ) fun updateUserJwt( externalId: String, token: String, diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/OneSignal.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/OneSignal.kt index ed049b550..562657ac4 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/OneSignal.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/OneSignal.kt @@ -42,6 +42,13 @@ object OneSignal { * called. */ @JvmStatic + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getUserSuspend() instead.", + replaceWith = ReplaceWith("getUserSuspend()"), + ) + @Suppress("DEPRECATION") val User: IUserManager get() = oneSignal.user @@ -50,6 +57,13 @@ object OneSignal { * has been called. */ @JvmStatic + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getSessionSuspend() instead.", + replaceWith = ReplaceWith("getSessionSuspend()"), + ) + @Suppress("DEPRECATION") val Session: ISessionManager get() = oneSignal.session @@ -58,6 +72,13 @@ object OneSignal { * only after [initWithContext] has been called. */ @JvmStatic + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getNotificationsSuspend() instead.", + replaceWith = ReplaceWith("getNotificationsSuspend()"), + ) + @Suppress("DEPRECATION") val Notifications: INotificationsManager get() = oneSignal.notifications @@ -66,6 +87,13 @@ object OneSignal { * only after [initWithContext] has been called. */ @JvmStatic + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getLocationSuspend() instead.", + replaceWith = ReplaceWith("getLocationSuspend()"), + ) + @Suppress("DEPRECATION") val Location: ILocationManager get() = oneSignal.location @@ -74,6 +102,13 @@ object OneSignal { * only after [initWithContext] has been called. */ @JvmStatic + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getInAppMessagesSuspend() instead.", + replaceWith = ReplaceWith("getInAppMessagesSuspend()"), + ) + @Suppress("DEPRECATION") val InAppMessages: IInAppMessagesManager get() = oneSignal.inAppMessages @@ -94,6 +129,17 @@ object OneSignal { * [initWithContext] to ensure compliance. */ @JvmStatic + @get:Deprecated( + message = + "Reading this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getConsentRequiredSuspend() instead.", + replaceWith = ReplaceWith("getConsentRequiredSuspend()"), + ) + @set:Deprecated( + message = "Use the suspend function setConsentRequiredSuspend(value) instead.", + replaceWith = ReplaceWith("setConsentRequiredSuspend(value)"), + ) + @Suppress("DEPRECATION") var consentRequired: Boolean get() = oneSignal.consentRequired set(value) { @@ -105,6 +151,17 @@ object OneSignal { * the application has opted into data privacy protections. See [requiresPrivacyConsent]. */ @JvmStatic + @get:Deprecated( + message = + "Reading this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getConsentGivenSuspend() instead.", + replaceWith = ReplaceWith("getConsentGivenSuspend()"), + ) + @set:Deprecated( + message = "Use the suspend function setConsentGivenSuspend(value) instead.", + replaceWith = ReplaceWith("setConsentGivenSuspend(value)"), + ) + @Suppress("DEPRECATION") var consentGiven: Boolean get() = oneSignal.consentGiven set(value) { @@ -115,6 +172,17 @@ object OneSignal { * Whether to disable the "GMS is missing" prompt to the user. */ @JvmStatic + @get:Deprecated( + message = + "Reading this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getDisableGMSMissingPromptSuspend() instead.", + replaceWith = ReplaceWith("getDisableGMSMissingPromptSuspend()"), + ) + @set:Deprecated( + message = "Use the suspend function setDisableGMSMissingPromptSuspend(value) instead.", + replaceWith = ReplaceWith("setDisableGMSMissingPromptSuspend(value)"), + ) + @Suppress("DEPRECATION") var disableGMSMissingPrompt: Boolean get() = oneSignal.disableGMSMissingPrompt set(value) { @@ -128,6 +196,13 @@ object OneSignal { * @param appId The application ID the OneSignal SDK is bound to. */ @JvmStatic + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function initWithContextSuspend(context, appId) instead.", + replaceWith = ReplaceWith("initWithContextSuspend(context, appId)"), + ) + @Suppress("DEPRECATION") fun initWithContext( context: Context, appId: String, @@ -305,6 +380,13 @@ object OneSignal { * @param externalId The external ID of the user that is to be logged in. */ @JvmStatic + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function loginSuspend(externalId) instead.", + replaceWith = ReplaceWith("loginSuspend(externalId)"), + ) + @Suppress("DEPRECATION") fun login(externalId: String) = oneSignal.login(externalId) /** @@ -329,6 +411,13 @@ object OneSignal { * [Identity Verification | OneSignal](https://documentation.onesignal.com/docs/identity-verification) */ @JvmStatic + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function loginSuspend(externalId, jwtBearerToken) instead.", + replaceWith = ReplaceWith("loginSuspend(externalId, jwtBearerToken)"), + ) + @Suppress("DEPRECATION") fun login( externalId: String, jwtBearerToken: String? = null, @@ -341,6 +430,13 @@ object OneSignal { * data is not cleared. */ @JvmStatic + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function logoutSuspend() instead.", + replaceWith = ReplaceWith("logoutSuspend()"), + ) + @Suppress("DEPRECATION") fun logout() = oneSignal.logout() /** @@ -353,6 +449,13 @@ object OneSignal { * @param token The new JWT bearer token issued by your backend. */ @JvmStatic + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function updateUserJwtSuspend(externalId, token) instead.", + replaceWith = ReplaceWith("updateUserJwtSuspend(externalId, token)"), + ) + @Suppress("DEPRECATION") fun updateUserJwt( externalId: String, token: String, diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt index 05b2cb378..4ea4fbeb6 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt @@ -72,6 +72,16 @@ internal class OneSignalImp( override val isInitialized: Boolean get() = initState == InitState.SUCCESS + @get:Deprecated( + message = + "Reading this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getConsentRequired() instead.", + replaceWith = ReplaceWith("getConsentRequired()"), + ) + @set:Deprecated( + message = "Use the suspend function setConsentRequired(value) instead.", + replaceWith = ReplaceWith("setConsentRequired(value)"), + ) override var consentRequired: Boolean get() = if (isInitialized) { @@ -86,6 +96,16 @@ internal class OneSignalImp( } } + @get:Deprecated( + message = + "Reading this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getConsentGiven() instead.", + replaceWith = ReplaceWith("getConsentGiven()"), + ) + @set:Deprecated( + message = "Use the suspend function setConsentGiven(value) instead.", + replaceWith = ReplaceWith("setConsentGiven(value)"), + ) override var consentGiven: Boolean get() = if (isInitialized) { @@ -104,6 +124,16 @@ internal class OneSignalImp( } } + @get:Deprecated( + message = + "Reading this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getDisableGMSMissingPrompt() instead.", + replaceWith = ReplaceWith("getDisableGMSMissingPrompt()"), + ) + @set:Deprecated( + message = "Use the suspend function setDisableGMSMissingPrompt(value) instead.", + replaceWith = ReplaceWith("setDisableGMSMissingPrompt(value)"), + ) override var disableGMSMissingPrompt: Boolean get() = if (isInitialized) { @@ -121,22 +151,52 @@ internal class OneSignalImp( // we hardcode the DebugManager implementation so it can be used prior to calling `initWithContext` override val debug: IDebugManager = DebugManager() + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getSession() instead.", + replaceWith = ReplaceWith("getSession()"), + ) override val session: ISessionManager get() = getServiceWithFeatureGate { services.getService() } + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getNotifications() instead.", + replaceWith = ReplaceWith("getNotifications()"), + ) override val notifications: INotificationsManager get() = getServiceWithFeatureGate { services.getService() } + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getLocation() instead.", + replaceWith = ReplaceWith("getLocation()"), + ) override val location: ILocationManager get() = getServiceWithFeatureGate { services.getService() } + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getInAppMessages() instead.", + replaceWith = ReplaceWith("getInAppMessages()"), + ) override val inAppMessages: IInAppMessagesManager get() = getServiceWithFeatureGate { services.getService() } + @Deprecated( + message = + "Accessing this property may block the calling thread until the SDK is initialized and " + + "cause ANRs when called on the main thread. Use the suspend function getUser() instead.", + replaceWith = ReplaceWith("getUser()"), + ) override val user: IUserManager get() = getServiceWithFeatureGate { services.getService() } @@ -304,12 +364,21 @@ internal class OneSignalImp( return startupService } + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function initWithContextSuspend(context, appId) instead.", + replaceWith = ReplaceWith("initWithContextSuspend(context, appId)"), + ) @Suppress("ReturnCount", "TooGenericExceptionCaught") override fun initWithContext( context: Context, appId: String, ): Boolean { - Logging.log(LogLevel.DEBUG, "Calling deprecated initWithContext(context: $context, appId: $appId)") + Logging.warn( + "initWithContext(context, appId) is deprecated and should no longer be used. " + + "Use the suspend function initWithContextSuspend(context, appId) instead.", + ) // Warm OneSignalDispatchers on a dedicated daemon thread so the first production caller // of suspendifyOnIO / launchOnSerialIO doesn't pay the ThreadPoolExecutor + dispatcher + @@ -446,18 +515,54 @@ internal class OneSignalImp( } } + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function loginSuspend(externalId) instead.", + replaceWith = ReplaceWith("loginSuspend(externalId)"), + ) + override fun login(externalId: String) { + loginInternal( + externalId = externalId, + jwtBearerToken = null, + deprecationMessage = + "login(externalId) is deprecated and should no longer be used. " + + "Use the suspend function loginSuspend(externalId) instead.", + ) + } + + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function loginSuspend(externalId, jwtBearerToken) instead.", + replaceWith = ReplaceWith("loginSuspend(externalId, jwtBearerToken)"), + ) override fun login( externalId: String, jwtBearerToken: String?, ) { - Logging.log(LogLevel.DEBUG, "Calling deprecated login(externalId: $externalId, jwtBearerToken: ...${jwtBearerToken?.takeLast(8)})") + loginInternal( + externalId = externalId, + jwtBearerToken = jwtBearerToken, + deprecationMessage = + "login(externalId, jwtBearerToken) is deprecated and should no longer be used. " + + "Use the suspend function loginSuspend(externalId, jwtBearerToken) instead.", + ) + } + private fun loginInternal( + externalId: String, + jwtBearerToken: String?, + deprecationMessage: String, + ) { if (isBackgroundThreadingEnabled) { waitForInit(operationName = "login") } else { requireInitForOperation("login") } + Logging.warn(deprecationMessage) + val context = loginHelper.switchUser(externalId, jwtBearerToken) ?: return if (isBackgroundThreadingEnabled) { @@ -471,15 +576,24 @@ internal class OneSignalImp( } } + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function logoutSuspend() instead.", + replaceWith = ReplaceWith("logoutSuspend()"), + ) override fun logout() { - Logging.log(LogLevel.DEBUG, "Calling deprecated logout()") - if (isBackgroundThreadingEnabled) { waitForInit(operationName = "logout") } else { requireInitForOperation("logout") } + Logging.warn( + "logout() is deprecated and should no longer be used. " + + "Use the suspend function logoutSuspend() instead.", + ) + val context = logoutHelper.switchUser() ?: return if (isBackgroundThreadingEnabled) { @@ -493,12 +607,16 @@ internal class OneSignalImp( } } + @Deprecated( + message = + "This blocking method may block the calling thread and cause ANRs when called on the " + + "main thread. Use the suspend function updateUserJwtSuspend(externalId, token) instead.", + replaceWith = ReplaceWith("updateUserJwtSuspend(externalId, token)"), + ) override fun updateUserJwt( externalId: String, token: String, ) { - Logging.log(LogLevel.DEBUG, "updateUserJwt(externalId: $externalId, token: ...${token.takeLast(8)})") - if (isBackgroundThreadingEnabled) { waitForInit(operationName = "updateUserJwt") } else { @@ -507,6 +625,11 @@ internal class OneSignalImp( } } + Logging.warn( + "updateUserJwt(externalId, token) is deprecated and should no longer be used. " + + "Use the suspend function updateUserJwtSuspend(externalId, token) instead.", + ) + jwtTokenStore.putJwt(externalId, token) // Wake the queue so any deferred ops can dispatch with the fresh token. operationRepo.forceExecuteOperations()