From 2b6a83dc9aafe641b22a7d0bc6b95b0284a4b4f2 Mon Sep 17 00:00:00 2001 From: Felix Schwarz Date: Wed, 17 Nov 2021 13:32:52 +0100 Subject: [PATCH] [feature/appstore-buildflag] Remove App Store / IAP code via build flag (#1052) * - add support and documentation for DISABLE_APPSTORE_LICENSING build flag * - ReleaseNotesHostViewController: remove unused reference to StoreKit - OCLicenseDuration: make sure SKProductSubscriptionPeriod conversion code is excluded when using the DISABLE_APPSTORE_LICENSING build flag --- doc/APP_BUILD_FLAGS.md | 6 ++++++ ownCloud/Client/Actions/Action+UserInterface.swift | 2 ++ ownCloud/Licensing/Offers/LicenseOfferButton.swift | 4 ++++ ownCloud/Licensing/Offers/LicenseOfferView.swift | 4 ++++ ownCloud/Licensing/Offers/LicenseOffersViewController.swift | 6 ++++++ .../LicenseInAppProductListViewController.swift | 4 ++++ .../Product List/LicenseInAppPurchaseFeatureView.swift | 4 ++++ ownCloud/Licensing/Tools/OCLicenseManager+AppStore.swift | 5 ++++- .../Transactions/LicenseTransactionsViewController.swift | 4 ++++ ownCloud/Release Notes/ReleaseNotesHostViewController.swift | 1 - ownCloud/Settings/PurchasesSettingsSection.swift | 2 ++ ownCloud/Settings/SettingsViewController.swift | 2 ++ ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.h | 5 +++++ ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.m | 3 +++ .../Providers/App Store/Items/OCLicenseAppStoreItem.h | 4 ++++ .../Providers/App Store/Items/OCLicenseAppStoreItem.m | 4 ++++ .../Providers/App Store/OCLicenseAppStoreProvider.h | 3 +++ .../Providers/App Store/OCLicenseAppStoreProvider.m | 4 ++++ .../Licensing/Providers/App Store/Parser Support/OCASN1.h | 4 ++++ .../Licensing/Providers/App Store/Parser Support/OCASN1.m | 4 ++++ .../Providers/App Store/Receipt/OCLicenseAppStoreReceipt.h | 4 ++++ .../Providers/App Store/Receipt/OCLicenseAppStoreReceipt.m | 4 ++++ .../Receipt/OCLicenseAppStoreReceiptInAppPurchase.h | 4 ++++ .../Receipt/OCLicenseAppStoreReceiptInAppPurchase.m | 4 ++++ ownCloudAppShared/Intent/OCLicenseManager+Setup.swift | 2 ++ 25 files changed, 91 insertions(+), 2 deletions(-) diff --git a/doc/APP_BUILD_FLAGS.md b/doc/APP_BUILD_FLAGS.md index a29056c94..7aa76ff4f 100644 --- a/doc/APP_BUILD_FLAGS.md +++ b/doc/APP_BUILD_FLAGS.md @@ -24,3 +24,9 @@ Removes the following from the app: - the location description keys from the app's `Info.plist` Not used by default. + +### `DISABLE_APPSTORE_LICENSING` + +Removes the following from the app: +- App Store integration for OCLicense +- App Store related view controllers and settings section diff --git a/ownCloud/Client/Actions/Action+UserInterface.swift b/ownCloud/Client/Actions/Action+UserInterface.swift index 9e3f3be29..8613c82d7 100644 --- a/ownCloud/Client/Actions/Action+UserInterface.swift +++ b/ownCloud/Client/Actions/Action+UserInterface.swift @@ -94,6 +94,7 @@ extension Action { if !isLicensed { if let core = core, let requirements = type(of:self).licenseRequirements { OnMainThread { + #if !DISABLE_APPSTORE_LICENSING OCLicenseManager.appStoreProvider?.refreshProductsIfNeeded(completionHandler: { (error) in OnMainThread { if error != nil { @@ -107,6 +108,7 @@ extension Action { } } }) + #endif } } diff --git a/ownCloud/Licensing/Offers/LicenseOfferButton.swift b/ownCloud/Licensing/Offers/LicenseOfferButton.swift index a95dd2ffb..02dc0ee5e 100644 --- a/ownCloud/Licensing/Offers/LicenseOfferButton.swift +++ b/ownCloud/Licensing/Offers/LicenseOfferButton.swift @@ -16,6 +16,8 @@ * */ +#if !DISABLE_APPSTORE_LICENSING + import UIKit import ownCloudAppShared @@ -61,3 +63,5 @@ class LicenseOfferButton: ThemeButton { fatalError("init(coder:) has not been implemented") } } + +#endif diff --git a/ownCloud/Licensing/Offers/LicenseOfferView.swift b/ownCloud/Licensing/Offers/LicenseOfferView.swift index d766d631f..b5ad9de7c 100644 --- a/ownCloud/Licensing/Offers/LicenseOfferView.swift +++ b/ownCloud/Licensing/Offers/LicenseOfferView.swift @@ -16,6 +16,8 @@ * */ +#if !DISABLE_APPSTORE_LICENSING + import UIKit import ownCloudApp import ownCloudAppShared @@ -288,3 +290,5 @@ class LicenseOfferView: UIView, Themeable { } } } + +#endif diff --git a/ownCloud/Licensing/Offers/LicenseOffersViewController.swift b/ownCloud/Licensing/Offers/LicenseOffersViewController.swift index df5449bde..d3f2c1168 100644 --- a/ownCloud/Licensing/Offers/LicenseOffersViewController.swift +++ b/ownCloud/Licensing/Offers/LicenseOffersViewController.swift @@ -16,6 +16,8 @@ * */ +#if !DISABLE_APPSTORE_LICENSING + import UIKit import ownCloudApp import ownCloudAppShared @@ -116,6 +118,7 @@ class LicenseOffersViewController: StaticTableViewController { sections.append(subSection) } + #if !DISABLE_APPSTORE_LICENSING let restoreSection = StaticTableViewSection() restoreSection.add(row: StaticTableViewRow(rowWithAction: { (_, _) in @@ -125,6 +128,7 @@ class LicenseOffersViewController: StaticTableViewController { }, title: "Restore purchases".localized, alignment: .center)) sections.append(restoreSection) + #endif // Set sections self.sections = sections @@ -153,3 +157,5 @@ class LicenseOffersViewController: StaticTableViewController { self.tableView.contentInsetAdjustmentBehavior = .never } } + +#endif diff --git a/ownCloud/Licensing/Product List/LicenseInAppProductListViewController.swift b/ownCloud/Licensing/Product List/LicenseInAppProductListViewController.swift index a2845702e..fb1d4e84c 100644 --- a/ownCloud/Licensing/Product List/LicenseInAppProductListViewController.swift +++ b/ownCloud/Licensing/Product List/LicenseInAppProductListViewController.swift @@ -16,6 +16,8 @@ * */ +#if !DISABLE_APPSTORE_LICENSING + import UIKit import ownCloudApp import ownCloudAppShared @@ -132,3 +134,5 @@ class LicenseInAppProductListViewController: StaticTableViewController { } } + +#endif diff --git a/ownCloud/Licensing/Product List/LicenseInAppPurchaseFeatureView.swift b/ownCloud/Licensing/Product List/LicenseInAppPurchaseFeatureView.swift index 37f7afd61..d1fda2fac 100644 --- a/ownCloud/Licensing/Product List/LicenseInAppPurchaseFeatureView.swift +++ b/ownCloud/Licensing/Product List/LicenseInAppPurchaseFeatureView.swift @@ -16,6 +16,8 @@ * */ +#if !DISABLE_APPSTORE_LICENSING + import UIKit import ownCloudApp import ownCloudAppShared @@ -134,3 +136,5 @@ class LicenseInAppPurchaseFeatureView: UIView, Themeable { baseViewController?.present(asCard: FrameViewController(header: offersViewController.cardHeaderView!, viewController: offersViewController), animated: true) } } + +#endif diff --git a/ownCloud/Licensing/Tools/OCLicenseManager+AppStore.swift b/ownCloud/Licensing/Tools/OCLicenseManager+AppStore.swift index 51123047c..371f2ca2c 100644 --- a/ownCloud/Licensing/Tools/OCLicenseManager+AppStore.swift +++ b/ownCloud/Licensing/Tools/OCLicenseManager+AppStore.swift @@ -16,6 +16,8 @@ * */ +#if !DISABLE_APPSTORE_LICENSING + import UIKit import ownCloudApp import ownCloudAppShared @@ -52,5 +54,6 @@ extension OCLicenseManager { }) } } - } + +#endif diff --git a/ownCloud/Licensing/Transactions/LicenseTransactionsViewController.swift b/ownCloud/Licensing/Transactions/LicenseTransactionsViewController.swift index 74facdfe5..6bc5a8ad6 100644 --- a/ownCloud/Licensing/Transactions/LicenseTransactionsViewController.swift +++ b/ownCloud/Licensing/Transactions/LicenseTransactionsViewController.swift @@ -16,6 +16,8 @@ * */ +#if !DISABLE_APPSTORE_LICENSING + import UIKit import ownCloudApp import ownCloudAppShared @@ -111,3 +113,5 @@ class LicenseTransactionsViewController: StaticTableViewController { } } } + +#endif diff --git a/ownCloud/Release Notes/ReleaseNotesHostViewController.swift b/ownCloud/Release Notes/ReleaseNotesHostViewController.swift index ef74a896d..e82f00fc2 100644 --- a/ownCloud/Release Notes/ReleaseNotesHostViewController.swift +++ b/ownCloud/Release Notes/ReleaseNotesHostViewController.swift @@ -19,7 +19,6 @@ import UIKit import ownCloudSDK import ownCloudAppShared -import StoreKit class ReleaseNotesHostViewController: UIViewController { diff --git a/ownCloud/Settings/PurchasesSettingsSection.swift b/ownCloud/Settings/PurchasesSettingsSection.swift index c3aece033..d2b6936ad 100644 --- a/ownCloud/Settings/PurchasesSettingsSection.swift +++ b/ownCloud/Settings/PurchasesSettingsSection.swift @@ -20,6 +20,7 @@ import UIKit import ownCloudApp import ownCloudAppShared +#if !DISABLE_APPSTORE_LICENSING class PurchasesSettingsSection: SettingsSection { // MARK: - More Settings Cells @@ -62,3 +63,4 @@ class PurchasesSettingsSection: SettingsSection { add(rows: rows) } } +#endif diff --git a/ownCloud/Settings/SettingsViewController.swift b/ownCloud/Settings/SettingsViewController.swift index 0089eb349..9a4ef7c8e 100644 --- a/ownCloud/Settings/SettingsViewController.swift +++ b/ownCloud/Settings/SettingsViewController.swift @@ -41,6 +41,7 @@ class SettingsViewController: StaticTableViewController { self.addSection(DisplaySettingsSection(userDefaults: userDefaults)) self.addSection(MediaFilesSettingsSection(userDefaults: userDefaults)) + #if !DISABLE_APPSTORE_LICENSING if #available(iOS 13, *), // Require iOS 13 !OCLicenseEMMProvider.isEMMVersion, // Do not show purchases in the EMM version // Do only show purchases section if there's at least one non-Enterprise account @@ -48,6 +49,7 @@ class SettingsViewController: StaticTableViewController { { self.addSection(PurchasesSettingsSection(userDefaults: userDefaults)) } + #endif self.addSection(MoreSettingsSection(userDefaults: userDefaults)) } diff --git a/ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.h b/ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.h index a7f31b221..7f580deb3 100644 --- a/ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.h +++ b/ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.h @@ -17,7 +17,10 @@ */ #import + +#ifndef DISABLE_APPSTORE_LICENSING #import +#endif /* DISABLE_APPSTORE_LICENSING */ typedef NS_ENUM(NSUInteger, OCLicenseDurationUnit) { @@ -48,10 +51,12 @@ NS_ASSUME_NONNULL_BEGIN @end +#ifndef DISABLE_APPSTORE_LICENSING @interface SKProductSubscriptionPeriod (OCLicenseDuration) @property(readonly,nonatomic,nullable) OCLicenseDuration *licenseDuration; @end +#endif /* DISABLE_APPSTORE_LICENSING */ NS_ASSUME_NONNULL_END diff --git a/ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.m b/ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.m index a570d3b55..59668db8e 100644 --- a/ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.m +++ b/ownCloudAppFramework/Licensing/Offer/OCLicenseDuration.m @@ -191,6 +191,7 @@ - (NSDate *)dateWithDurationAddedTo:(NSDate *)date @end +#ifndef DISABLE_APPSTORE_LICENSING @implementation SKProductSubscriptionPeriod (OCLicenseDuration) @@ -226,3 +227,5 @@ - (nullable OCLicenseDuration *)licenseDuration } @end + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/Items/OCLicenseAppStoreItem.h b/ownCloudAppFramework/Licensing/Providers/App Store/Items/OCLicenseAppStoreItem.h index 06452b1be..eace46430 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/Items/OCLicenseAppStoreItem.h +++ b/ownCloudAppFramework/Licensing/Providers/App Store/Items/OCLicenseAppStoreItem.h @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import #import #import "OCLicenseOffer.h" @@ -47,3 +49,5 @@ typedef NSString* OCLicenseAppStoreProductIdentifier; @end NS_ASSUME_NONNULL_END + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/Items/OCLicenseAppStoreItem.m b/ownCloudAppFramework/Licensing/Providers/App Store/Items/OCLicenseAppStoreItem.m index 449f68e47..748e15693 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/Items/OCLicenseAppStoreItem.m +++ b/ownCloudAppFramework/Licensing/Providers/App Store/Items/OCLicenseAppStoreItem.m @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import "OCLicenseAppStoreItem.h" @implementation OCLicenseAppStoreItem @@ -50,3 +52,5 @@ - (instancetype)initWithType:(OCLicenseType)type identifier:(OCLicenseAppStorePr } @end + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/OCLicenseAppStoreProvider.h b/ownCloudAppFramework/Licensing/Providers/App Store/OCLicenseAppStoreProvider.h index 4e13f61ed..eb349e971 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/OCLicenseAppStoreProvider.h +++ b/ownCloudAppFramework/Licensing/Providers/App Store/OCLicenseAppStoreProvider.h @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import #import "OCLicenseProvider.h" @@ -70,3 +72,4 @@ extern NSErrorDomain OCLicenseAppStoreProviderErrorDomain; NS_ASSUME_NONNULL_END +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/OCLicenseAppStoreProvider.m b/ownCloudAppFramework/Licensing/Providers/App Store/OCLicenseAppStoreProvider.m index e2eb9535a..75a7bf723 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/OCLicenseAppStoreProvider.m +++ b/ownCloudAppFramework/Licensing/Providers/App Store/OCLicenseAppStoreProvider.m @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import #import @@ -936,3 +938,5 @@ + (OCLicenseAppStoreProvider *)appStoreProvider OCLicenseProviderIdentifier OCLicenseProviderIdentifierAppStore = @"app-store"; NSErrorDomain OCLicenseAppStoreProviderErrorDomain = @"OCLicenseAppStoreProviderError"; + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/Parser Support/OCASN1.h b/ownCloudAppFramework/Licensing/Providers/App Store/Parser Support/OCASN1.h index 62a6333b1..2155e0827 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/Parser Support/OCASN1.h +++ b/ownCloudAppFramework/Licensing/Providers/App Store/Parser Support/OCASN1.h @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import #import "OCLicenseAppStoreReceipt.h" @@ -39,3 +41,5 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/Parser Support/OCASN1.m b/ownCloudAppFramework/Licensing/Providers/App Store/Parser Support/OCASN1.m index ec8a2c861..1c09852c4 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/Parser Support/OCASN1.m +++ b/ownCloudAppFramework/Licensing/Providers/App Store/Parser Support/OCASN1.m @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import "OCASN1.h" #import "NSDate+RFC3339.h" @@ -217,3 +219,5 @@ - (OCLicenseAppStoreReceiptParseError)parseSetsOfSequencesWithContainerProvider: } @end + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceipt.h b/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceipt.h index 4fbf33e29..01062bc4a 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceipt.h +++ b/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceipt.h @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import #import "OCLicenseAppStoreItem.h" @@ -105,3 +107,5 @@ typedef NSNumber* OCLicenseAppStoreLineItemID; NS_ASSUME_NONNULL_END #import "OCLicenseAppStoreReceiptInAppPurchase.h" + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceipt.m b/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceipt.m index a99eb4fbd..e9174ef2d 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceipt.m +++ b/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceipt.m @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import #import @@ -243,3 +245,5 @@ - (NSString *)description } @end + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceiptInAppPurchase.h b/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceiptInAppPurchase.h index 29825dbc2..f6a7ac503 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceiptInAppPurchase.h +++ b/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceiptInAppPurchase.h @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import #import "OCLicenseAppStoreReceipt.h" @@ -46,3 +48,5 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceiptInAppPurchase.m b/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceiptInAppPurchase.m index 9197809dd..2414e1360 100644 --- a/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceiptInAppPurchase.m +++ b/ownCloudAppFramework/Licensing/Providers/App Store/Receipt/OCLicenseAppStoreReceiptInAppPurchase.m @@ -16,6 +16,8 @@ * */ +#ifndef DISABLE_APPSTORE_LICENSING + #import "OCLicenseAppStoreReceiptInAppPurchase.h" #import "OCASN1.h" @@ -78,3 +80,5 @@ - (NSString *)description } @end + +#endif /* DISABLE_APPSTORE_LICENSING */ diff --git a/ownCloudAppShared/Intent/OCLicenseManager+Setup.swift b/ownCloudAppShared/Intent/OCLicenseManager+Setup.swift index d1bf29ee6..ba2960158 100644 --- a/ownCloudAppShared/Intent/OCLicenseManager+Setup.swift +++ b/ownCloudAppShared/Intent/OCLicenseManager+Setup.swift @@ -66,6 +66,7 @@ public extension OCLicenseManager { register(OCLicenseProduct(identifier: .bundlePro, name: "Pro Features".localized, description: "Unlock all Pro Features.".localized, contents: [.documentScanner, .shortcuts, .documentMarkup, .photoProFeatures])) // Set up App Store License Provider + #if !DISABLE_APPSTORE_LICENSING if let disableAppStoreLicensing = classSetting(forOCClassSettingsKey: .disableAppStoreLicensing) as? Bool, disableAppStoreLicensing == false, // only add AppStore IAP provider (and IAPs) if IAP licernsing has not been disabled via ClassSettings !OCLicenseEMMProvider.isEMMVersion { // only add AppStore IAP provider (and IAPs) if this is not the EMM version (which is supposed to already include all of them) let appStoreLicenseProvider = OCLicenseAppStoreProvider(items: [ @@ -78,6 +79,7 @@ public extension OCLicenseManager { add(appStoreLicenseProvider) } + #endif // Set up Enterprise Provider if let disableEnterpriseLicensing = classSetting(forOCClassSettingsKey: .disableEnterpriseLicensing) as? Bool, disableEnterpriseLicensing == false { // only add Enterprise provider if not disabled via ClassSettings