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..bc6200e02 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,38 @@ interface IOneSignal { * should be set to `true` prior to the invocation of * [initWithContext] to ensure compliance. */ + @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 functions getConsentRequired() " + + "and setConsentRequired(required) instead.", + replaceWith = ReplaceWith("getConsentRequired()"), + ) 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]. */ + @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 functions getConsentGiven() " + + "and setConsentGiven(value) instead.", + replaceWith = ReplaceWith("getConsentGiven()"), + ) var consentGiven: Boolean /** * Whether to disable the "GMS is missing" prompt to the user. */ + @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 functions getDisableGMSMissingPrompt() " + + "and setDisableGMSMissingPrompt(value) instead.", + replaceWith = ReplaceWith("getDisableGMSMissingPrompt()"), + ) var disableGMSMissingPrompt: Boolean /** @@ -83,6 +134,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 +173,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 +205,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 +222,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..f4e9ffa97 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,14 @@ object OneSignal { * [initWithContext] to ensure compliance. */ @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 functions getConsentRequiredSuspend() " + + "and setConsentRequiredSuspend(required) instead.", + replaceWith = ReplaceWith("getConsentRequiredSuspend()"), + ) + @Suppress("DEPRECATION") var consentRequired: Boolean get() = oneSignal.consentRequired set(value) { @@ -105,6 +148,14 @@ object OneSignal { * the application has opted into data privacy protections. See [requiresPrivacyConsent]. */ @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 functions getConsentGivenSuspend() " + + "and setConsentGivenSuspend(value) instead.", + replaceWith = ReplaceWith("getConsentGivenSuspend()"), + ) + @Suppress("DEPRECATION") var consentGiven: Boolean get() = oneSignal.consentGiven set(value) { @@ -115,6 +166,14 @@ object OneSignal { * Whether to disable the "GMS is missing" prompt to the user. */ @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 functions getDisableGMSMissingPromptSuspend() " + + "and setDisableGMSMissingPromptSuspend(value) instead.", + replaceWith = ReplaceWith("getDisableGMSMissingPromptSuspend()"), + ) + @Suppress("DEPRECATION") var disableGMSMissingPrompt: Boolean get() = oneSignal.disableGMSMissingPrompt set(value) { @@ -128,6 +187,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 +371,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 +402,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 +421,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 +440,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 89934bf9b..4452a20c8 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,13 @@ internal class OneSignalImp( override val isInitialized: Boolean get() = initState == InitState.SUCCESS + @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 functions getConsentRequired() " + + "and setConsentRequired(required) instead.", + replaceWith = ReplaceWith("getConsentRequired()"), + ) override var consentRequired: Boolean get() = if (isInitialized) { @@ -86,6 +93,13 @@ internal class OneSignalImp( } } + @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 functions getConsentGiven() " + + "and setConsentGiven(value) instead.", + replaceWith = ReplaceWith("getConsentGiven()"), + ) override var consentGiven: Boolean get() = if (isInitialized) { @@ -104,6 +118,13 @@ internal class OneSignalImp( } } + @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 functions getDisableGMSMissingPrompt() " + + "and setDisableGMSMissingPrompt(value) instead.", + replaceWith = ReplaceWith("getDisableGMSMissingPrompt()"), + ) override var disableGMSMissingPrompt: Boolean get() = if (isInitialized) { @@ -121,22 +142,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 +355,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,11 +506,20 @@ 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, 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)})") + Logging.warn( + "login(externalId, jwtBearerToken) is deprecated and should no longer be used. " + + "Use the suspend function loginSuspend(externalId, jwtBearerToken) instead.", + ) if (isBackgroundThreadingEnabled) { waitForInit(operationName = "login") @@ -471,8 +540,17 @@ 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()") + Logging.warn( + "logout() is deprecated and should no longer be used. " + + "Use the suspend function logoutSuspend() instead.", + ) if (isBackgroundThreadingEnabled) { waitForInit(operationName = "logout") @@ -493,11 +571,20 @@ 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)})") + Logging.warn( + "updateUserJwt(externalId, token) is deprecated and should no longer be used. " + + "Use the suspend function updateUserJwtSuspend(externalId, token) instead.", + ) if (isBackgroundThreadingEnabled) { waitForInit(operationName = "updateUserJwt")