-
Notifications
You must be signed in to change notification settings - Fork 378
chore: [SDK-4783] deprecate blocking OneSignal APIs in favor of suspend variants #2662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abdulraqeeb33
wants to merge
3
commits into
main
Choose a base branch
from
chore/SDK-4783-deprecate-blocking-apis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+273
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 The three deprecated
varproperties (consentRequired,consentGiven,disableGMSMissingPrompt) carry a single property-level@Deprecatedannotation, which Kotlin applies to both the getter and the setter. This causes two related issues for setter callers: (1) the "may block the calling thread… cause ANRs" message is inaccurate — the setters are non-blocking direct field writes (OneSignalImp.ktlines 89-94, 110-122, 134-140), and (2) theReplaceWithonly encodes the getter form, so applying the IDE quick-fix toOneSignal.consentRequired = truerewrites toOneSignal.getConsentRequiredSuspend() = true, which doesn'''t compile. Fix by splitting into@get:Deprecated/@set:Deprecatedwith accessor-specific messages andReplaceWithexpressions (e.g.setConsentRequiredSuspend(value)for the setter); the same pattern needs to be applied acrossOneSignal.kt,IOneSignal.kt, andOneSignalImp.kt.Extended reasoning...
What the bug is
For the three deprecated mutable properties —
consentRequired,consentGiven, anddisableGMSMissingPrompt— the@Deprecatedannotation is placed at the property level. In Kotlin, a property-level annotation on avarapplies the samemessageandReplaceWithto both the getter and the setter. That is fine forvals and for the blockingfuns in this PR, but it produces two distinct problems for thesevars.Problem 1 —
ReplaceWithquick-fix produces invalid code on setter usageEach property uses a getter-only
ReplaceWithexpression, e.g. inOneSignal.kt:When a developer applies the IntelliJ/Android Studio quick-fix to a setter usage like:
the IDE mechanically substitutes the LHS using the
ReplaceWithexpression, producing:This affects setter calls that already exist in the codebase, e.g.
examples/.../MainApplication.kt:65(OneSignal.consentRequired = SharedPreferenceUtil.getCachedConsentRequired(this)),OneSignalRepository.kt:222, and theOneSignalImpTests, so it is not hypothetical.Problem 2 — message overstates harm for setter callers
The message claims:
But the setters in
OneSignalImp.ktnever block. Reviewing the implementation:set(value) { _consentRequired = value if (isInitialized) { configModel.consentRequired = value } }This writes a local backing field and (when initialized) the in-memory
ConfigModeldirectly. None ofconsentRequired,consentGiven, ordisableGMSMissingPromptsetters invokeblockingGet,runBlocking, orwaitForInit. The only non-trivial side effect,operationRepo.forceExecuteOperations()in theconsentGivensetter, just callswake()on two waiters — also non-blocking. Only the getters route throughblockingGet { ... }, which is where the ANR risk actually lives.A common, legitimate calling pattern looks like:
The write here cannot block on init (init has not run yet — the setter falls through to the
_consentRequired = valueno-init branch). Telling that caller they risk ANRs is misleading.Step-by-step proof — Problem 1
OneSignal.consentRequired = truesomewhere in their app.ReplaceWithtext —"getConsentRequiredSuspend()"— and substitutes the property reference on the LHS.OneSignal.getConsentRequiredSuspend() = true, which fails to compile (error: variable expected).getConsentRequiredSuspend()andsetConsentRequiredSuspend(required), so a reader can manually correct it — but the quick-fix UX is broken.How to fix
Replace the property-level annotation with accessor-targeted ones, e.g. in
OneSignal.kt:@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(required) instead.", replaceWith = ReplaceWith("setConsentRequiredSuspend(value)"), ) @JvmStatic @Suppress("DEPRECATION") var consentRequired: Boolean get() = oneSignal.consentRequired set(value) { oneSignal.consentRequired = value }The same shape needs to be applied in
IOneSignal.kt(with the non-suspend namessetConsentRequired(required)) and inOneSignalImp.kt. With accessor-targeted annotations, the IDE quick-fix on a setter usage rewrites toOneSignal.setConsentRequiredSuspend(value)(which compiles), and the messages can be honest per accessor.Severity / impact
No runtime impact — SDK behavior is unchanged. Compilation of existing user code is unaffected (the warning level is
WARNING). What is broken is the IDE-assisted migration UX, plus message accuracy. Since the readable deprecation message does name the correct setter function, a developer who reads the warning can migrate manually. Filing as a nit.