From e54eb3f18c6570c1b5e2185b0b48e94f46a26e1e Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Fri, 23 Aug 2024 09:16:19 -0700 Subject: [PATCH] `Custom Entitlements Computation`: fix support display on debug screen --- Sources/Misc/SystemInfo.swift | 4 ++++ .../OfflineEntitlementsManager.swift | 3 +-- Sources/Purchasing/Purchases/Purchases.swift | 2 +- .../Purchases/PurchasesConfiguringTests.swift | 17 ++++++++++++++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Sources/Misc/SystemInfo.swift b/Sources/Misc/SystemInfo.swift index ac00918377..586148bcf1 100644 --- a/Sources/Misc/SystemInfo.swift +++ b/Sources/Misc/SystemInfo.swift @@ -153,6 +153,10 @@ class SystemInfo { self.preferredLocalesProvider = preferredLocalesProvider } + var supportsOfflineEntitlements: Bool { + !self.observerMode && !self.dangerousSettings.customEntitlementComputation + } + /// Asynchronous API if caller can't ensure that it's invoked in the `@MainActor` /// - Seealso: `isApplicationBackgrounded` func isApplicationBackgrounded(completion: @escaping @Sendable (Bool) -> Void) { diff --git a/Sources/OfflineEntitlements/OfflineEntitlementsManager.swift b/Sources/OfflineEntitlements/OfflineEntitlementsManager.swift index 22c1802ec7..dd40fa13f9 100644 --- a/Sources/OfflineEntitlements/OfflineEntitlementsManager.swift +++ b/Sources/OfflineEntitlements/OfflineEntitlementsManager.swift @@ -35,8 +35,7 @@ class OfflineEntitlementsManager { completion: (@MainActor @Sendable (Result<(), Error>) -> Void)? ) { guard #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *), - !self.systemInfo.observerMode, - !self.systemInfo.dangerousSettings.customEntitlementComputation else { + self.systemInfo.supportsOfflineEntitlements else { Logger.debug(Strings.offlineEntitlements.product_entitlement_mapping_unavailable) self.dispatchCompletionOnMainThreadIfPossible(completion, result: .failure(.notAvailable)) diff --git a/Sources/Purchasing/Purchases/Purchases.swift b/Sources/Purchasing/Purchases/Purchases.swift index 72a476490c..a82efc7ea5 100644 --- a/Sources/Purchasing/Purchases/Purchases.swift +++ b/Sources/Purchasing/Purchases/Purchases.swift @@ -1732,7 +1732,7 @@ internal extension Purchases { } var offlineCustomerInfoEnabled: Bool { - return self.backend.offlineCustomerInfoEnabled + return self.backend.offlineCustomerInfoEnabled && self.systemInfo.supportsOfflineEntitlements } var publicKey: Signing.PublicKey? { diff --git a/Tests/UnitTests/Purchasing/Purchases/PurchasesConfiguringTests.swift b/Tests/UnitTests/Purchasing/Purchases/PurchasesConfiguringTests.swift index 1ed0c50e7a..e38fac8880 100644 --- a/Tests/UnitTests/Purchasing/Purchases/PurchasesConfiguringTests.swift +++ b/Tests/UnitTests/Purchasing/Purchases/PurchasesConfiguringTests.swift @@ -516,10 +516,25 @@ class PurchasesConfiguringTests: BasePurchasesTests { expect(Self.create(purchasesAreCompletedBy: .revenueCat).offlineCustomerInfoEnabled) == true } - private static func create(purchasesAreCompletedBy: PurchasesAreCompletedBy) -> Purchases { + func testOfflineCustomerInfoDisabledForCustomEntitlementsComputation() throws { + try AvailabilityChecks.iOS15APIAvailableOrSkipTest() + + expect( + Self.create( + purchasesAreCompletedBy: .revenueCat, + dangerousSettings: .init(customEntitlementComputation: true) + ).offlineCustomerInfoEnabled + ) == false + } + + private static func create( + purchasesAreCompletedBy: PurchasesAreCompletedBy, + dangerousSettings: DangerousSettings = .init() + ) -> Purchases { return Purchases.configure( with: .init(withAPIKey: "") .with(purchasesAreCompletedBy: purchasesAreCompletedBy, storeKitVersion: .storeKit1) + .with(dangerousSettings: dangerousSettings) ) }