Skip to content

Commit

Permalink
Implement Prohibited App Blocking
Browse files Browse the repository at this point in the history
Summary:
There are certain 3P apps that are in prohibited categories. For these apps, the server-side currently blocks any incoming signals, but we want to also enforce this blocking on the client-side. In order to do this, we need to use a flag sent from the server-side on the client-side to enable the client to block events from apps that are in prohibited categories (i.e. when this flag is true). This is accomplished by extending the [MobileSdkAppEventsKillSwitchGk](https://www.internalfb.com/code/www/flib/platform/graph/resources/application/mobile_sdk/MobileSdkAppEventsKillSwitchGk.php), which is passed as the ```app_events_killswitch``` flag to the client. More information can be seen [here](https://docs.google.com/document/d/1EYy0vZ-v6q1QDGEDj_N2is6QbX4eDPodI1lYz6W8GEU/), [here](https://docs.google.com/document/d/1MCPIESOxtgTuUJC78DdLeOA8Jv4qiDaWV1NxHzGO34k/), and [here](https://docs.google.com/document/d/1svBR6jklbb6M-lhgh3qj7XyaEchJDn1YXint2ZYU_Fk/).

We already use the ```app_events_killswitch``` flag to block the sending of post-install events. This diff extends the result of the ```app_events_killswitch``` flag to also block install events so that all events are blocked for apps that are in prohibited categories.

Reviewed By: Nathaaaalie

Differential Revision: D51290686

fbshipit-source-id: 573df6453fa705a5290eb9cbef988715ace26034
  • Loading branch information
ryantobinmeta authored and facebook-github-bot committed Dec 14, 2023
1 parent 066eb63 commit 2dc3ba5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ - (void)publishInstall
return;
}
[self fetchServerConfiguration:^{
if ([self.appEventsUtility shouldDropAppEvents]) {
if ([self.appEventsUtility shouldDropAppEvents] || [self.gateKeeperManager boolForKey:FBSDKGateKeeperAppEventsKillSwitch defaultValue:NO]) {
return;
}
NSMutableDictionary<NSString *, NSString *> *params = [self.appEventsUtility activityParametersDictionaryForEvent:@"MOBILE_APP_INSTALL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ final class AppEventsTests: XCTestCase {
}

func testActivateAppWithInitializedSDK() throws {
TestGateKeeperManager.setGateKeeperValue(key: "app_events_killswitch", value: false)
appEvents.activateApp()

XCTAssertTrue(
Expand Down Expand Up @@ -598,6 +599,39 @@ final class AppEventsTests: XCTestCase {
XCTAssertNotNil(capiReporter.capturedEvent)
}

func testActivateAppWithAppEventsKillSwitchEnabled() throws {
TestGateKeeperManager.setGateKeeperValue(key: "app_events_killswitch", value: true)
appEvents.activateApp()

XCTAssertTrue(
timeSpentRecorder.restoreWasCalled,
"Activating App with initialized SDK should restore recording time spent data."
)
XCTAssertTrue(
timeSpentRecorder.capturedCalledFromActivateApp,
"""
Activating App with initialized SDK should indicate its \
calling from activateApp when restoring recording time spent data.
"""
)

// The publish call happens after both configurations are fetched
appEventsConfigurationProvider.firstCapturedBlock?()
appEventsConfigurationProvider.lastCapturedBlock?()
serverConfigurationProvider.capturedCompletionBlock?(nil, nil)
serverConfigurationProvider.secondCapturedCompletionBlock?(nil, nil)

let request = graphRequestFactory.capturedRequests.first
XCTAssertNil(
request,
"No request should be made when the FBSDKGateKeeperAppEventsKillSwitch is enabled"
)
XCTAssertNil(
capiReporter.capturedEvent,
"The capiReporter should not be invoked when the FBSDKGateKeeperAppEventsKillSwitch is enabled"
)
}

func testApplicationBecomingActiveRestoresTimeSpentRecording() {
appEvents.applicationDidBecomeActive()
XCTAssertTrue(
Expand Down

0 comments on commit 2dc3ba5

Please sign in to comment.