-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: - The SDK decision tree can be found at https://docs.google.com/document/d/10Gftcn5wqtegaEPh0LgOkarb4T0jvE_iZKEiUpVu4nU/edit - Unit tests will be added in the next diff Reviewed By: dreamolight Differential Revision: D51140801 fbshipit-source-id: 0883ac19b5a35efb1a97f34cdc7cc7fb38487749
- Loading branch information
1 parent
d18a1db
commit 324571d
Showing
5 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
extension Settings { | ||
enum AutoLogAppEventServerFlags: String { | ||
case DEFAUT = "auto_log_app_events_default" | ||
case ENABLE = "auto_log_app_events_enabled" | ||
} | ||
|
||
func checkAutoLogAppEventsEnabled() -> Bool { | ||
guard let dependencies = try? getDependencies() else { | ||
return true | ||
} | ||
guard let migratedAutoLogValues = dependencies | ||
.serverConfigurationProvider.cachedServerConfiguration().migratedAutoLogValues else { | ||
return isAutoLogAppEventsEnabledLocally | ||
} | ||
if let migratedAutoLogEnabled = migratedAutoLogValues[AutoLogAppEventServerFlags.ENABLE.rawValue] as? NSNumber { | ||
return migratedAutoLogEnabled.boolValue | ||
} | ||
if let locallyEnabled = checkClientSideConfiguration(dependencies) { | ||
return locallyEnabled | ||
} | ||
if let migratedDefault = migratedAutoLogValues[AutoLogAppEventServerFlags.DEFAUT.rawValue] as? NSNumber { | ||
return migratedDefault.boolValue | ||
} | ||
return true | ||
} | ||
|
||
// swiftlint:disable:next discouraged_optional_boolean | ||
private func checkClientSideConfiguration(_ dependencies: ObjectDependencies) -> Bool? { | ||
if let isAutoLogAppEventsEnabledInUserDefault = checkUserDefault() { | ||
return isAutoLogAppEventsEnabledInUserDefault | ||
} | ||
if let isAutoLogAppEventsEnabledInPlist = checkInfoPlist(dependencies) { | ||
return isAutoLogAppEventsEnabledInPlist | ||
} | ||
return nil | ||
} | ||
|
||
// swiftlint:disable:next discouraged_optional_boolean | ||
private func checkInfoPlist(_ dependencies: ObjectDependencies) -> Bool? { | ||
if let infoPlistValue = dependencies.infoDictionaryProvider | ||
.fb_object(forInfoDictionaryKey: PersistenceKey.isAutoLogAppEventsEnabledLocally.rawValue) as? NSNumber { | ||
return infoPlistValue.boolValue | ||
} | ||
return nil | ||
} | ||
|
||
// swiftlint:disable:next discouraged_optional_boolean | ||
private func checkUserDefault() -> Bool? { | ||
// swiftformat:disable:this redundantSelf | ||
if let userDefaultValue = self.dataStore? | ||
.fb_object(forKey: Settings.PersistenceKey.isAutoLogAppEventsEnabledLocally.rawValue) as? NSNumber { | ||
return userDefaultValue.boolValue | ||
} | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...CoreKit/FBSDKCoreKitTests/Internal/Helpers/TestAppEventsServerConfigurationProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import Foundation | ||
|
||
final class TestAppEventsServerConfigurationProvider: NSObject, _ServerConfigurationProviding { | ||
var configs: [String: Any]? | ||
|
||
func cachedServerConfiguration() -> _ServerConfiguration { | ||
if let configs = configs { | ||
return ServerConfigurationFixtures.configuration(withDictionary: configs) | ||
} else { | ||
return ServerConfigurationFixtures.defaultConfiguration | ||
} | ||
} | ||
|
||
func loadServerConfiguration(completionBlock: _ServerConfigurationBlock? = nil) { | ||
// no-op | ||
} | ||
|
||
func processLoadRequestResponse(_ result: Any, error: Error?, appID: String) { | ||
// no-op | ||
} | ||
|
||
func request(toLoadServerConfiguration appID: String) -> GraphRequest? { | ||
// no-op | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters