From 6358423729a1ac95a41adffead457419e85a7fa5 Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Thu, 7 Nov 2019 17:12:55 -0800 Subject: [PATCH] fetch GK from server to enable the feature Summary: - fetch feature GK from server to control enabling suggested events Reviewed By: KylinChang Differential Revision: D18383293 fbshipit-source-id: 67d40381d8e351da1764540e1e7bd5ef52037713 --- FBSDKCoreKit.podspec | 1 + .../FBSDKCoreKit.xcodeproj/project.pbxproj | 16 +++++ .../FBSDKCoreKit/AppEvents/FBSDKAppEvents.m | 6 ++ .../FBSDKSuggestedEventsIndexer.h | 29 +++++++++ .../FBSDKSuggestedEventsIndexer.m | 65 +++++++++++++++++++ .../Internal/FBSDKCoreKit+Internal.h | 2 + .../Internal/FBSDKFeatureManager.h | 1 + .../Internal/FBSDKFeatureManager.m | 2 + 8 files changed, 122 insertions(+) create mode 100644 FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/SuggestedEvents/FBSDKSuggestedEventsIndexer.h create mode 100644 FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/SuggestedEvents/FBSDKSuggestedEventsIndexer.m diff --git a/FBSDKCoreKit.podspec b/FBSDKCoreKit.podspec index bbd4bce31..e193dfec4 100644 --- a/FBSDKCoreKit.podspec +++ b/FBSDKCoreKit.podspec @@ -67,6 +67,7 @@ Pod::Spec.new do |s| 'FBSDKCoreKit/FBSDKCoreKit/Internal/Device/**/*', 'FBSDKCoreKit/FBSDKCoreKit/Swift/**/*' ss.tvos.exclude_files = 'FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/AAM/*', + 'FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/SuggestedEvents/*', 'FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/Codeless/*', 'FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/FBSDKHybridAppEventsScriptMessageHandler.{h,m}', 'FBSDKCoreKit/FBSDKCoreKit/AppLink/**/*', diff --git a/FBSDKCoreKit/FBSDKCoreKit.xcodeproj/project.pbxproj b/FBSDKCoreKit/FBSDKCoreKit.xcodeproj/project.pbxproj index 66abc3e2b..479e80330 100644 --- a/FBSDKCoreKit/FBSDKCoreKit.xcodeproj/project.pbxproj +++ b/FBSDKCoreKit/FBSDKCoreKit.xcodeproj/project.pbxproj @@ -722,6 +722,8 @@ 9DF2A4001A70572B00DFB2FD /* FBSDKGraphRequestMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF2A3FE1A70572B00DFB2FD /* FBSDKGraphRequestMetadata.m */; }; ADEA17731B7ECA1A0070EDC0 /* FBSDKMonotonicTime.h in Headers */ = {isa = PBXBuildFile; fileRef = ADEA17711B7ECA1A0070EDC0 /* FBSDKMonotonicTime.h */; }; ADEA17741B7ECA1A0070EDC0 /* FBSDKMonotonicTime.m in Sources */ = {isa = PBXBuildFile; fileRef = ADEA17721B7ECA1A0070EDC0 /* FBSDKMonotonicTime.m */; }; + BF247C822374E1B200A522C0 /* FBSDKSuggestedEventsIndexer.h in Headers */ = {isa = PBXBuildFile; fileRef = BF247C802374E1B100A522C0 /* FBSDKSuggestedEventsIndexer.h */; }; + BF247C832374E1B200A522C0 /* FBSDKSuggestedEventsIndexer.m in Sources */ = {isa = PBXBuildFile; fileRef = BF247C812374E1B200A522C0 /* FBSDKSuggestedEventsIndexer.m */; }; C4513901202CBF1F0063275D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C4513900202CBF1F0063275D /* WebKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; C4FC99D9202CD5590038C5ED /* FBSDKHybridAppEventsScriptMessageHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = C4FC99D7202CD5590038C5ED /* FBSDKHybridAppEventsScriptMessageHandler.h */; }; C4FC99DA202CD5590038C5ED /* FBSDKHybridAppEventsScriptMessageHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = C4FC99D8202CD5590038C5ED /* FBSDKHybridAppEventsScriptMessageHandler.m */; }; @@ -1708,6 +1710,8 @@ 9DF2A3FE1A70572B00DFB2FD /* FBSDKGraphRequestMetadata.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBSDKGraphRequestMetadata.m; sourceTree = ""; }; ADEA17711B7ECA1A0070EDC0 /* FBSDKMonotonicTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBSDKMonotonicTime.h; sourceTree = ""; }; ADEA17721B7ECA1A0070EDC0 /* FBSDKMonotonicTime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBSDKMonotonicTime.m; sourceTree = ""; }; + BF247C802374E1B100A522C0 /* FBSDKSuggestedEventsIndexer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBSDKSuggestedEventsIndexer.h; sourceTree = ""; }; + BF247C812374E1B200A522C0 /* FBSDKSuggestedEventsIndexer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBSDKSuggestedEventsIndexer.m; sourceTree = ""; }; C4513900202CBF1F0063275D /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; }; C4FC99D7202CD5590038C5ED /* FBSDKHybridAppEventsScriptMessageHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBSDKHybridAppEventsScriptMessageHandler.h; sourceTree = ""; }; C4FC99D8202CD5590038C5ED /* FBSDKHybridAppEventsScriptMessageHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBSDKHybridAppEventsScriptMessageHandler.m; sourceTree = ""; }; @@ -2470,6 +2474,15 @@ name = Products; sourceTree = ""; }; + BF247C642374C73F00A522C0 /* SuggestedEvents */ = { + isa = PBXGroup; + children = ( + BF247C802374E1B100A522C0 /* FBSDKSuggestedEventsIndexer.h */, + BF247C812374E1B200A522C0 /* FBSDKSuggestedEventsIndexer.m */, + ); + path = SuggestedEvents; + sourceTree = ""; + }; C51121C720A27EF50041DC94 /* Codeless */ = { isa = PBXGroup; children = ( @@ -2495,6 +2508,7 @@ children = ( 5D9031C0233AAC5D0001450C /* RestrictiveDataFilter */, F952EA442339403900B20652 /* AAM */, + BF247C642374C73F00A522C0 /* SuggestedEvents */, C5696F1D209BBC35009C931F /* Codeless */, 9D0BC1531A8D23DB00BE8BA4 /* FBSDKAppEvents+Internal.h */, 5F7063FA1AF733F300E42ED7 /* FBSDKAppEventsDeviceInfo.h */, @@ -2947,6 +2961,7 @@ 894C0AF61A6F2278009137EF /* FBSDKBridgeAPIProtocolNativeV1.h in Headers */, 9D432FFB1C1649B000A6C377 /* FBSDKURLOpening.h in Headers */, 893F44AC1A644744001DB0B6 /* FBSDKMath.h in Headers */, + BF247C822374E1B200A522C0 /* FBSDKSuggestedEventsIndexer.h in Headers */, C5D25D3621795B790037B13D /* FBSDKCodelessIndexer.h in Headers */, 52963A88215992F400C7B252 /* FBSDKAppLinkReturnToRefererController.h in Headers */, C5696F77209BBC35009C931F /* FBSDKCodelessPathComponent.h in Headers */, @@ -4157,6 +4172,7 @@ 9D0BC1581A8D23E200BE8BA4 /* FBSDKAppEvents.m in Sources */, F9FD9A7D21659F320068DEAF /* FBSDKGateKeeperManager.m in Sources */, F9169B842155A03C00FA1789 /* FBSDKUserDataStore.m in Sources */, + BF247C832374E1B200A522C0 /* FBSDKSuggestedEventsIndexer.m in Sources */, F9098FCB22BC332C00857C2D /* FBSDKURLSession.m in Sources */, 9DF18BBA1A9F1A05000F6748 /* _FBSDKTemporaryErrorRecoveryAttempter.m in Sources */, 52963AAE2159A16E00C7B252 /* FBSDKMeasurementEvent.m in Sources */, diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m index 631896b1e..7e25535ae 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m @@ -1077,6 +1077,12 @@ static NSString *g_overrideAppID = nil; [FBSDKMetadataIndexer enable]; } }]; + [FBSDKFeatureManager checkFeature:FBSDKFeatureSuggestedEvents completionBlock:^(BOOL enabled) { + if (enabled) { + // Enable Suggested Events + [FBSDKSuggestedEventsIndexer enable]; + } + }]; #endif if (callback) { callback(); diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/SuggestedEvents/FBSDKSuggestedEventsIndexer.h b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/SuggestedEvents/FBSDKSuggestedEventsIndexer.h new file mode 100644 index 000000000..c38cf5626 --- /dev/null +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/SuggestedEvents/FBSDKSuggestedEventsIndexer.h @@ -0,0 +1,29 @@ +// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. +// +// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, +// copy, modify, and distribute this software in source code or binary form for use +// in connection with the web services and APIs provided by Facebook. +// +// As with any software that integrates with the Facebook platform, your use of +// this software is subject to the Facebook Developer Principles and Policies +// [http://developers.facebook.com/policy/]. This copyright notice shall be +// included in all copies or substantial portions of the software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface FBSDKSuggestedEventsIndexer : NSObject + ++ (void)enable; + +@end + +NS_ASSUME_NONNULL_END diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/SuggestedEvents/FBSDKSuggestedEventsIndexer.m b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/SuggestedEvents/FBSDKSuggestedEventsIndexer.m new file mode 100644 index 000000000..7c4c48ccb --- /dev/null +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/SuggestedEvents/FBSDKSuggestedEventsIndexer.m @@ -0,0 +1,65 @@ +// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. +// +// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, +// copy, modify, and distribute this software in source code or binary form for use +// in connection with the web services and APIs provided by Facebook. +// +// As with any software that integrates with the Facebook platform, your use of +// this software is subject to the Facebook Developer Principles and Policies +// [http://developers.facebook.com/policy/]. This copyright notice shall be +// included in all copies or substantial portions of the software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#import "FBSDKSuggestedEventsIndexer.h" + +#import +#import +#import + +#import + +#import "FBSDKCoreKit+Internal.h" + +#define ViewHierarchyKeyIsInteracted @"is_interacted" +#define ViewHierarchyKeyChildViews @"childviews" +#define ViewHierarchyKeyScreenName @"screenname" +#define ViewHierarchyKeyView @"view" + +static NSMutableArray *> *_viewTrees; +static NSMutableSet *_optInEvents; +static NSMutableSet *_unconfirmedEvents; + +@interface FBSDKViewHierarchy () ++ (NSMutableDictionary *)getDetailAttributesOf:(NSObject *)obj withHash:(BOOL)hash; +@end + +@implementation FBSDKSuggestedEventsIndexer + ++ (void)initialize +{ + [self retrieveOptInAndUnconfirmedEvents]; + _viewTrees = [NSMutableArray array]; +} + ++ (void)enable +{ +} + +// TODO: T54222097 will get the opt-in events and unconfimed events from server ++ (void)retrieveOptInAndUnconfirmedEvents +{ + _optInEvents = [NSMutableSet set]; + [_optInEvents addObject:FBSDKAppEventNameAddedToCart]; + [_optInEvents addObject:FBSDKAppEventNamePurchased]; + + _unconfirmedEvents = [NSMutableSet set]; + [_unconfirmedEvents addObject:FBSDKAppEventNameCompletedRegistration]; +} + +@end diff --git a/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKCoreKit+Internal.h b/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKCoreKit+Internal.h index aa7712148..e7c312fea 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKCoreKit+Internal.h +++ b/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKCoreKit+Internal.h @@ -31,6 +31,7 @@ #import "FBSDKCodelessMacros.h" #import "FBSDKCodelessIndexer.h" #import "FBSDKMetadataIndexer.h" +#import "FBSDKSuggestedEventsIndexer.h" #import "FBSDKCrypto.h" #import "FBSDKAudioResourceLoader.h" #import "FBSDKContainerViewController.h" @@ -102,6 +103,7 @@ #import "../AppEvents/Internal/Codeless/FBSDKCodelessMacros.h" #import "../AppEvents/Internal/Codeless/FBSDKCodelessIndexer.h" #import "../AppEvents/Internal/AAM/FBSDKMetadataIndexer.h" +#import "../AppEvents/Internal/SuggestedEvents/FBSDKSuggestedEventsIndexer.h" #import "Cryptography/FBSDKCrypto.h" #import "FBSDKAudioResourceLoader.h" #import "FBSDKContainerViewController.h" diff --git a/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKFeatureManager.h b/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKFeatureManager.h index 451914ec7..523e0e488 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKFeatureManager.h +++ b/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKFeatureManager.h @@ -47,6 +47,7 @@ typedef NS_ENUM(NSUInteger, FBSDKFeature) FBSDKFeatureCodelessEvents = 0x00010100, FBSDKFeatureRestrictiveDataFiltering = 0x00010200, FBSDKFeatureAAM = 0x00010300, + FBSDKFeatureSuggestedEvents = 0x00010400, FBSDKFeatureInstrument = 0x00020000, FBSDKFeatureCrashReport = 0x00020100, FBSDKFeatureCrashShield = 0x00020101, diff --git a/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKFeatureManager.m b/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKFeatureManager.m index 25bbc809b..b78cd4dd6 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKFeatureManager.m +++ b/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKFeatureManager.m @@ -90,6 +90,7 @@ static NSString *const FBSDKFeatureManagerPrefix = @"com.facebook.sdk:FBSDKFeatu case FBSDKFeatureCodelessEvents: featureName = @"CodelessEvents"; break; case FBSDKFeatureRestrictiveDataFiltering: featureName = @"RestrictiveDataFiltering"; break; case FBSDKFeatureAAM: featureName = @"AAM"; break; + case FBSDKFeatureSuggestedEvents: featureName = @"SuggestedEvents"; break; case FBSDKFeatureInstrument: featureName = @"Instrument"; break; case FBSDKFeatureCrashReport: featureName = @"CrashReport"; break; case FBSDKFeatureCrashShield: featureName = @"CrashShield"; break; @@ -114,6 +115,7 @@ static NSString *const FBSDKFeatureManagerPrefix = @"com.facebook.sdk:FBSDKFeatu case FBSDKFeatureCrashShield: case FBSDKFeatureErrorReport: case FBSDKFeatureAAM: + case FBSDKFeatureSuggestedEvents: return NO; default: return YES; }