Enforce that Backup Subscriptions are only redeemed in the main app

This commit is contained in:
Sasha Weiss 2026-02-17 12:53:06 -08:00 committed by GitHub
parent aeadb98cb4
commit 951a481d45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 14 additions and 1 deletions

View File

@ -397,6 +397,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
)
let globalsContinuation = await schemaMigrationContinuation.migrateDatabaseSchema()
let dataMigrationContinuation = globalsContinuation.initGlobals(
appContext: launchContext.appContext,
appReadiness: appReadiness,
backupArchiveErrorPresenterFactory: BackupArchiveErrorPresenterFactoryInternal(),
deviceBatteryLevelManager: DeviceBatteryLevelManagerImpl(),

View File

@ -56,11 +56,12 @@ class NSEEnvironment {
let finalContinuation = await AppSetup()
.start(
appContext: CurrentAppContext(),
appContext: appContext,
databaseStorage: databaseStorage,
)
.migrateDatabaseSchema()
.initGlobals(
appContext: appContext,
appReadiness: appReadiness,
backupArchiveErrorPresenterFactory: NoOpBackupArchiveErrorPresenterFactory(),
deviceBatteryLevelManager: nil,

View File

@ -170,6 +170,7 @@ extension AppSetup {
extension AppSetup.GlobalsContinuation {
@MainActor
public func initGlobals(
appContext: AppContext,
appReadiness: AppReadiness,
backupArchiveErrorPresenterFactory: BackupArchiveErrorPresenterFactory,
deviceBatteryLevelManager: (any DeviceBatteryLevelManager)?,
@ -478,6 +479,7 @@ extension AppSetup.GlobalsContinuation {
let backupSubscriptionIssueStore = BackupSubscriptionIssueStore()
let backupSubscriptionManager = BackupSubscriptionManagerImpl(
appContext: appContext,
backupPlanManager: backupPlanManager,
backupSubscriptionIssueStore: backupSubscriptionIssueStore,
backupSubscriptionRedeemer: BackupSubscriptionRedeemer(

View File

@ -151,6 +151,7 @@ final class BackupSubscriptionManagerImpl: BackupSubscriptionManager {
private let logger = PrefixedLogger(prefix: "[Backups][Sub]")
private let appContext: AppContext
private let backupPlanManager: BackupPlanManager
private let backupSubscriptionIssueStore: BackupSubscriptionIssueStore
private let backupSubscriptionRedeemer: BackupSubscriptionRedeemer
@ -163,6 +164,7 @@ final class BackupSubscriptionManagerImpl: BackupSubscriptionManager {
private let whoAmIManager: WhoAmIManager
init(
appContext: AppContext,
backupPlanManager: BackupPlanManager,
backupSubscriptionIssueStore: BackupSubscriptionIssueStore,
backupSubscriptionRedeemer: BackupSubscriptionRedeemer,
@ -173,6 +175,7 @@ final class BackupSubscriptionManagerImpl: BackupSubscriptionManager {
tsAccountManager: TSAccountManager,
whoAmIManager: WhoAmIManager,
) {
self.appContext = appContext
self.backupPlanManager = backupPlanManager
self.backupSubscriptionIssueStore = backupSubscriptionIssueStore
self.backupSubscriptionRedeemer = backupSubscriptionRedeemer
@ -573,6 +576,10 @@ final class BackupSubscriptionManagerImpl: BackupSubscriptionManager {
}
private func _redeemSubscriptionIfNecessary() async throws {
guard appContext.isMainApp else {
throw OWSAssertionError("Shouldn't be redeeming subscripions outside the main app process!")
}
if
let preexistingRedemptionContext = db.read(block: {
return BackupSubscriptionRedemptionContext.fetch(tx: $0)

View File

@ -71,6 +71,7 @@ public class MockSSKEnvironment {
keychainStorage: keychainStorage,
),
).migrateDatabaseSchema().initGlobals(
appContext: testAppContext,
appReadiness: appReadiness,
backupArchiveErrorPresenterFactory: NoOpBackupArchiveErrorPresenterFactory(),
deviceBatteryLevelManager: nil,

View File

@ -89,6 +89,7 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA
)
.migrateDatabaseSchema()
.initGlobals(
appContext: appContext,
appReadiness: appReadiness,
backupArchiveErrorPresenterFactory: NoOpBackupArchiveErrorPresenterFactory(),
deviceBatteryLevelManager: nil,