[Oztechan/CCC#4833] Retry UMP consent-info update on failure - #4834
[Oztechan/CCC#4833] Retry UMP consent-info update on failure#4834mustafaozhan wants to merge 4 commits into
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 5 |
🟢 Coverage 0.00% diff coverage · -0.22% coverage variation
Metric Results Coverage variation ✅ -0.22% coverage variation Diff coverage ✅ 0.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (e3d5777) 3340 1746 52.28% Head commit (2f6ab7a) 3354 (+14) 1746 (+0) 52.06% (-0.22%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#4834) 22 0 0.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull request overview
This PR improves ad-consent initialization reliability by extracting the UMP requestConsentInfoUpdate call into a dedicated helper and adding a bounded, delayed retry when the consent-info update fails, reducing the chance that transient network errors prevent ads from being requestable for the entire session.
Changes:
- Extracted consent-info update logic into
requestConsentInfoUpdate(activity). - Added bounded retry (
MAX_CONSENT_RETRY_COUNT) with fixed delay (CONSENT_RETRY_DELAY_MS) on consent-info update failure. - Introduced retry state (
consentRetryCount) and retry-related constants.
Suppressed comments (2)
android/core/ad/src/google/kotlin/com/oztechan/ccc/android/core/ad/AdManagerImpl.kt:46
- initAds() resets the retry budget, but any previously scheduled postDelayed retry will still run. That can trigger requestConsentInfoUpdate() for a stale Activity instance or effectively exceed the intended per-launch retry budget. Cancel any pending retry callback when starting a new initAds() sequence.
override fun initAds(activity: Activity) {
Logger.v { "AdManagerImpl initAds" }
consentRetryCount = 0
requestConsentInfoUpdate(activity)
android/core/ad/src/google/kotlin/com/oztechan/ccc/android/core/ad/AdManagerImpl.kt:88
- retryConsentInfoUpdate() currently schedules an anonymous lambda, so multiple in-flight failures can stack multiple delayed retries, and there’s no stored reference to cancel/replace a pending retry. Store the Runnable and post it via the shared Handler so only one retry is pending at a time.
private fun retryConsentInfoUpdate(activity: Activity) {
if (consentRetryCount >= MAX_CONSENT_RETRY_COUNT) return
consentRetryCount++
Logger.v { "AdManagerImpl retry consent info update #$consentRetryCount" }
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private var consentRetryCount = 0 | ||
|
|
Addresses Copilot review: single main-thread scope with a stored Job so the retry is cancellable; cancelled on a new initAds (no stale-Activity/over-budget retry) and before scheduling the next (only one pending at a time).
Use the app's DI CoroutineScope (single<CoroutineScope> { GlobalScope }) and launch the retry
on Dispatchers.Main. singleOf(::AdManagerImpl) resolves it by type, so no Koin change and the
Huawei no-arg impl is unaffected.
- Move java import after the kotlinx block (ImportOrdering). - @Suppress("TooManyFunctions") on the class, matching sibling BillingManagerImpl.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4834 +/- ##
========================================
Coverage 55.29% 55.29%
========================================
Files 169 169
Lines 3033 3033
Branches 452 452
========================================
Hits 1677 1677
Misses 1331 1331
Partials 25 25 🚀 New features to boost your workflow:
|
|



What
Extract the consent-info request into
requestConsentInfoUpdateand retry it (bounded + delayed) when it fails.Why
A failed
requestConsentInfoUpdatepreviously only logged. For a first-time EEA user, a transient network error leftcanRequestAds()false for the whole session — no ads until a later launch. Now it retries up toMAX_CONSENT_RETRY_COUNT(3) times,CONSENT_RETRY_DELAY_MS(3s) apart, so a momentary failure doesn't cost impressions.Notes
initAds(per launch).!isFinishing && !isDestroyedbefore touching the Activity.Closes #4833