Skip to content

[Oztechan/CCC#4833] Retry UMP consent-info update on failure - #4834

Open
mustafaozhan wants to merge 4 commits into
developfrom
4833-Retry_consent_info_update_on_failure
Open

[Oztechan/CCC#4833] Retry UMP consent-info update on failure#4834
mustafaozhan wants to merge 4 commits into
developfrom
4833-Retry_consent_info_update_on_failure

Conversation

@mustafaozhan

Copy link
Copy Markdown
Member

What

Extract the consent-info request into requestConsentInfoUpdate and retry it (bounded + delayed) when it fails.

Why

A failed requestConsentInfoUpdate previously only logged. For a first-time EEA user, a transient network error left canRequestAds() false for the whole session — no ads until a later launch. Now it retries up to MAX_CONSENT_RETRY_COUNT (3) times, CONSENT_RETRY_DELAY_MS (3s) apart, so a momentary failure doesn't cost impressions.

Notes

  • Retry budget resets each initAds (per launch).
  • The delayed retry re-checks !isFinishing && !isDestroyed before touching the Activity.
  • Constants are tunable; open to a different backoff if you'd prefer exponential.

Closes #4833

@mustafaozhan
mustafaozhan requested a review from a team as a code owner August 6, 2026 09:35
Copilot AI lite review requested due to automatic review settings August 6, 2026 09:35
@mustafaozhan mustafaozhan self-assigned this Aug 6, 2026
@mustafaozhan mustafaozhan added this to the 2.13.0 milestone Aug 6, 2026
@codacy-production

codacy-production Bot commented Aug 6, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity

Metric Results
Complexity 5

View in Codacy

🟢 Coverage 0.00% diff coverage · -0.22% coverage variation

Metric Results
Coverage variation -0.22% coverage variation
Diff coverage 0.00% diff coverage

View coverage diff in Codacy

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +29 to +30
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

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.29%. Comparing base (e3d5777) to head (2f6ab7a).
⚠️ Report is 2 commits behind head on develop.

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           

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

sonarqubecloud Bot commented Aug 9, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Retry UMP consent-info update on failure

2 participants