Skip to content

Add RevenueCatBackupAgent#2625

Merged
tonidero merged 18 commits into
mainfrom
add-revenuecat-proactive-backup-agent
Sep 10, 2025
Merged

Add RevenueCatBackupAgent#2625
tonidero merged 18 commits into
mainfrom
add-revenuecat-proactive-backup-agent

Conversation

@tonidero

@tonidero tonidero commented Aug 22, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds a new RevenueCatBackupAgent that consumers of this library can optionally use to backup revenuecat data accross installations. To use it, developers need to add this in the application's AndroidManifest <application> tag:

android:backupAgent="com.revenuecat.purchases.backup.RevenueCatBackupAgent"

After that, the shared preferences file with the main content from RevenueCat will be saved using the device's backup system. See official docs for this type of backup here: https://developer.android.com/identity/data/keyvaluebackup.

If users already have their own BackupAgentHelper configured for their app, they can just add a line to backup the com_revenuecat_purchases_preferences preferences file to their BackupAgentHelper, like:

SharedPreferencesBackupHelper(this, RevenueCatBackupAgent.REVENUECAT_PREFS_FILE_NAME).also {
   addHelper("revenuecat_prefs_backup", it)
}

This will allow customers, specially for apps using anonymous users, to immediately regain access to any entitlements they had before changing devices or uninstalling and reinstalling, effectively removing the need for these users to "restore purchases".

@tonidero tonidero added the pr:feat A new feature label Aug 22, 2025
@tonidero tonidero force-pushed the add-revenuecat-proactive-backup-agent branch from fad6c36 to 36a54ab Compare August 22, 2025 10:58
@codecov

codecov Bot commented Aug 22, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 35.71429% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.47%. Comparing base (7c41870) to head (7d5dea8).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...venuecat/purchases/backup/RevenueCatBackupAgent.kt 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2625      +/-   ##
==========================================
- Coverage   78.53%   78.47%   -0.06%     
==========================================
  Files         304      305       +1     
  Lines       11362    11375      +13     
  Branches     1577     1577              
==========================================
+ Hits         8923     8927       +4     
- Misses       1749     1758       +9     
  Partials      690      690              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Base automatically changed from migrate-shared-preferences-to-separate-file to main August 22, 2025 13:48
@tonidero tonidero force-pushed the add-revenuecat-proactive-backup-agent branch 3 times, most recently from 1f36912 to c88152b Compare August 26, 2025 13:06
@tonidero tonidero marked this pull request as ready for review August 27, 2025 11:15
@tonidero tonidero requested a review from a team August 27, 2025 11:16
Comment thread purchases/api-defauts.txt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think there is a typo in the filename api-defauts.txt -> api-defaults.txt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do this in a separate PR, since it could cause conflicts otherwise. Good catch!

Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/PurchasesOrchestrator.kt Outdated
@tonidero tonidero changed the title Add RevenueCatProactiveBackupAgent Add RevenueCatBackupAgent Aug 29, 2025
Comment thread purchases/src/test/java/com/revenuecat/purchases/PurchasesCommonTest.kt Outdated
}

@Test
fun `login called with different appUserID notifies backup manager`() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe we need a test for logout as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I kinda reused the existing logout called with identified user makes right calls test, which tests a few things... Might be worth splitting up in multiple tests, but I think that might be better to do on a separate PR?

@tonidero tonidero added this pull request to the merge queue Sep 10, 2025
Merged via the queue into main with commit f19c9b0 Sep 10, 2025
21 checks passed
@tonidero tonidero deleted the add-revenuecat-proactive-backup-agent branch September 10, 2025 01:13
tonidero added a commit that referenced this pull request Sep 10, 2025
### Description
This PR adds a new `RevenueCatBackupAgent` that consumers of this
library can optionally use to backup revenuecat data accross
installations. To use it, developers need to add this in the
application's AndroidManifest `<application>` tag:
```
android:backupAgent="com.revenuecat.purchases.backup.RevenueCatBackupAgent"
```

After that, the shared preferences file with the main content from
RevenueCat will be saved using the device's backup system. See official
docs for this type of backup here:
https://developer.android.com/identity/data/keyvaluebackup.

If users already have their own BackupAgentHelper configured for their
app, they can just add a line to backup the
`com_revenuecat_purchases_preferences` preferences file to their
BackupAgentHelper, like:
```
SharedPreferencesBackupHelper(this, RevenueCatBackupAgent.REVENUECAT_PREFS_FILE_NAME).also {
   addHelper("revenuecat_prefs_backup", it)
}
```

This will allow customers, specially for apps using anonymous users, to
immediately regain access to any entitlements they had before changing
devices or uninstalling and reinstalling, effectively removing the need
for these users to "restore purchases".
@tonidero tonidero mentioned this pull request Sep 10, 2025
tonidero pushed a commit that referenced this pull request Sep 10, 2025
**This is an automatic release.**

## RevenueCat SDK
### ✨ New Features
* Add `RevenueCatBackupAgent` (#2625) via Toni Rico (@tonidero)

### 🔄 Other Changes
* Fix CoroutineCreationDuringComposition lint error on AGP 8.13.0
(#2659) via Cesar de la Vega (@vegaro)
* Support setting null offering id on PaywallView (#2658) via Toni Rico
(@tonidero)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants