Skip to content

Wrap diagnostics notification in collection flag check. #1979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Example/Core/Tests/FIRAppTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,6 @@ - (void)testGlobalDataCollectionClearedAfterDelete {
}

- (void)testGlobalDataCollectionNoDiagnosticsSent {
[FIRApp configure];

// Add an observer for the diagnostics notification - both with and without an object to ensure it
// catches it either way. Currently no object is sent, but in the future that could change.
[self.notificationCenter addMockObserver:self.observerMock
Expand All @@ -707,6 +705,9 @@ - (void)testGlobalDataCollectionNoDiagnosticsSent {
OCMStub([self.appClassMock readDataCollectionSwitchFromUserDefaultsForApp:OCMOCK_ANY])
.andReturn(@NO);

// Ensure configure doesn't fire a notification.
[FIRApp configure];

NSError *error = [NSError errorWithDomain:@"com.firebase" code:42 userInfo:nil];
[[FIRApp defaultApp] sendLogsWithServiceName:@"Service" version:@"Version" error:error];

Expand Down
39 changes: 24 additions & 15 deletions Firebase/Core/FIRApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,19 @@ @implementation FIRApp
+ (void)configure {
FIROptions *options = [FIROptions defaultOptions];
if (!options) {
[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
userInfo:@{
kFIRAppDiagnosticsConfigurationTypeKey : @(FIRConfigTypeCore),
kFIRAppDiagnosticsErrorKey : [FIRApp errorForMissingOptions]
}];
// Read the Info.plist to see if the flag is set. At this point we can't check any user defaults
// since the app isn't configured at all, so only rely on the Info.plist value.
NSNumber *collectionEnabledPlistValue = [[self class] readDataCollectionSwitchFromPlist];
if (!collectionEnabledPlistValue || [collectionEnabledPlistValue boolValue]) {
[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
userInfo:@{
kFIRAppDiagnosticsConfigurationTypeKey : @(FIRConfigTypeCore),
kFIRAppDiagnosticsErrorKey : [FIRApp errorForMissingOptions]
}];
}

[NSException raise:kFirebaseCoreErrorDomain
format:
@"`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find "
Expand Down Expand Up @@ -274,13 +280,6 @@ + (void)addAppToAppDictionary:(FIRApp *)app {
}
if ([app configureCore]) {
sAllApps[app.name] = app;
[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
userInfo:@{
kFIRAppDiagnosticsConfigurationTypeKey : @(FIRConfigTypeCore),
kFIRAppDiagnosticsFIRAppKey : app
}];
} else {
[NSException raise:kFirebaseCoreErrorDomain
format:
Expand Down Expand Up @@ -317,7 +316,7 @@ - (void)getTokenForcingRefresh:(BOOL)forceRefresh withCallback:(FIRTokenCallback
- (BOOL)configureCore {
[self checkExpectedBundleID];
if (![self isAppIDValid]) {
if (_options.usingOptionsFromDefaultPlist) {
if (_options.usingOptionsFromDefaultPlist && [self isDataCollectionDefaultEnabled]) {
[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
Expand All @@ -329,6 +328,16 @@ - (BOOL)configureCore {
return NO;
}

if ([self isDataCollectionDefaultEnabled]) {
[[NSNotificationCenter defaultCenter]
postNotificationName:kFIRAppDiagnosticsNotification
object:nil
userInfo:@{
kFIRAppDiagnosticsConfigurationTypeKey : @(FIRConfigTypeCore),
kFIRAppDiagnosticsFIRAppKey : self
}];
}

#if TARGET_OS_IOS
// Initialize the Analytics once there is a valid options under default app. Analytics should
// always initialize first by itself before the other SDKs.
Expand Down