diff --git a/Signal/AppLaunch/AppDelegate.swift b/Signal/AppLaunch/AppDelegate.swift index aafb9f0a3b..d6b15507d4 100644 --- a/Signal/AppLaunch/AppDelegate.swift +++ b/Signal/AppLaunch/AppDelegate.swift @@ -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(), diff --git a/SignalNSE/NSEEnvironment.swift b/SignalNSE/NSEEnvironment.swift index 762278fed4..369b85a38c 100644 --- a/SignalNSE/NSEEnvironment.swift +++ b/SignalNSE/NSEEnvironment.swift @@ -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, diff --git a/SignalServiceKit/Environment/AppSetup.swift b/SignalServiceKit/Environment/AppSetup.swift index cda93ac8f3..dbae6ead26 100644 --- a/SignalServiceKit/Environment/AppSetup.swift +++ b/SignalServiceKit/Environment/AppSetup.swift @@ -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( diff --git a/SignalServiceKit/Subscriptions/Backups/BackupSubscriptionManager.swift b/SignalServiceKit/Subscriptions/Backups/BackupSubscriptionManager.swift index bbfa6a19ea..1ef467649f 100644 --- a/SignalServiceKit/Subscriptions/Backups/BackupSubscriptionManager.swift +++ b/SignalServiceKit/Subscriptions/Backups/BackupSubscriptionManager.swift @@ -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) diff --git a/SignalServiceKit/TestUtils/MockSSKEnvironment.swift b/SignalServiceKit/TestUtils/MockSSKEnvironment.swift index 7f793f32c4..a3bdc0ed15 100644 --- a/SignalServiceKit/TestUtils/MockSSKEnvironment.swift +++ b/SignalServiceKit/TestUtils/MockSSKEnvironment.swift @@ -71,6 +71,7 @@ public class MockSSKEnvironment { keychainStorage: keychainStorage, ), ).migrateDatabaseSchema().initGlobals( + appContext: testAppContext, appReadiness: appReadiness, backupArchiveErrorPresenterFactory: NoOpBackupArchiveErrorPresenterFactory(), deviceBatteryLevelManager: nil, diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index 2189be81e8..88a7860b58 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -89,6 +89,7 @@ public class ShareViewController: OWSNavigationController, ShareViewDelegate, SA ) .migrateDatabaseSchema() .initGlobals( + appContext: appContext, appReadiness: appReadiness, backupArchiveErrorPresenterFactory: NoOpBackupArchiveErrorPresenterFactory(), deviceBatteryLevelManager: nil,