Skip to content

Commit 82f163b

Browse files
authored
Updates to the SDK for Flutter support (#9182)
1 parent 90b117f commit 82f163b

29 files changed

+972
-14
lines changed

Crashlytics/Crashlytics/Components/FIRCLSContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ typedef struct {
4545
volatile bool debuggerAttached;
4646
const char* previouslyCrashedFileFullPath;
4747
const char* logPath;
48+
// Initial report path represents the report path used to initialized the context;
49+
// where non-on-demand exceptions and other crashes will be written.
50+
const char* initialReportPath;
4851
#if CLS_USE_SIGALTSTACK
4952
void* signalStack;
5053
#endif

Crashlytics/Crashlytics/Components/FIRCLSContext.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ bool FIRCLSContextInitialize(FIRCLSInternalReport* report,
100100

101101
// setup our SDK log file synchronously, because other calls may depend on it
102102
_firclsContext.readonly->logPath = FIRCLSContextAppendToRoot(rootPath, @"sdk.log");
103+
_firclsContext.readonly->initialReportPath = FIRCLSDupString([report.path UTF8String]);
103104
if (!FIRCLSUnlinkIfExists(_firclsContext.readonly->logPath)) {
104105
FIRCLSErrorLog(@"Unable to write initialize SDK write paths %s", strerror(errno));
105106
}

Crashlytics/Crashlytics/Components/FIRCLSUserLogging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ extern NSString* const FIRCLSUserNameKey;
3131
extern NSString* const FIRCLSUserEmailKey;
3232
extern NSString* const FIRCLSDevelopmentPlatformNameKey;
3333
extern NSString* const FIRCLSDevelopmentPlatformVersionKey;
34+
extern NSString* const FIRCLSOnDemandRecordedExceptionsKey;
35+
extern NSString* const FIRCLSOnDemandDroppedExceptionsKey;
3436
#endif
3537

3638
extern const uint32_t FIRCLSUserLoggingMaxKVEntries;

Crashlytics/Crashlytics/Components/FIRCLSUserLogging.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
NSString *const FIRCLSDevelopmentPlatformNameKey = @"com.crashlytics.development-platform-name";
3333
NSString *const FIRCLSDevelopmentPlatformVersionKey =
3434
@"com.crashlytics.development-platform-version";
35+
NSString *const FIRCLSOnDemandRecordedExceptionsKey =
36+
@"com.crashlytics.on-demand.recorded-exceptions";
37+
NSString *const FIRCLSOnDemandDroppedExceptionsKey =
38+
@"com.crashlytics.on-demand.dropped-exceptions";
3539

3640
// Empty string object synchronized on to prevent a race condition when accessing AB file path
3741
NSString *const FIRCLSSynchronizedPathKey = @"";

Crashlytics/Crashlytics/Controllers/FIRCLSExistingReportManager.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
2323
#import "Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
2424
#import "Crashlytics/Crashlytics/Models/FIRCLSSettings.h"
25+
#import "Crashlytics/Crashlytics/Private/FIRCLSOnDemandModel_Private.h"
2526
#import "Crashlytics/Crashlytics/Private/FIRCrashlyticsReport_Private.h"
2627
#import "Crashlytics/Crashlytics/Public/FirebaseCrashlytics/FIRCrashlyticsReport.h"
2728

@@ -35,6 +36,7 @@ @interface FIRCLSExistingReportManager ()
3536
@property(nonatomic, strong) NSOperationQueue *operationQueue;
3637
@property(nonatomic, strong) FIRCLSSettings *settings;
3738
@property(nonatomic, strong) FIRCLSDataCollectionArbiter *dataArbiter;
39+
@property(nonatomic, strong) FIRCLSOnDemandModel *onDemandModel;
3840

3941
// This list of active reports excludes the brand new active report that will be created this run of
4042
// the app.
@@ -60,6 +62,7 @@ - (instancetype)initWithManagerData:(FIRCLSManagerData *)managerData
6062
_operationQueue = managerData.operationQueue;
6163
_dataArbiter = managerData.dataArbiter;
6264
_reportUploader = reportUploader;
65+
_onDemandModel = managerData.onDemandModel;
6366

6467
return self;
6568
}
@@ -178,6 +181,13 @@ - (void)sendUnsentReportsWithToken:(FIRCLSDataCollectionToken *)dataCollectionTo
178181
asUrgent:urgent];
179182
}
180183

184+
for (NSString *path in self.onDemandModel.storedActiveReportPaths) {
185+
[self processExistingActiveReportPath:path
186+
dataCollectionToken:dataCollectionToken
187+
asUrgent:urgent];
188+
}
189+
[self.onDemandModel.storedActiveReportPaths removeAllObjects];
190+
181191
// deal with stuff in processing more carefully - do not process again
182192
[self.operationQueue addOperationWithBlock:^{
183193
for (NSString *path in self.processingReportPaths) {
@@ -248,4 +258,14 @@ - (void)deleteUnsentReports {
248258
}];
249259
}
250260

261+
- (void)handleOnDemandReportUpload:(NSString *)path
262+
dataCollectionToken:(FIRCLSDataCollectionToken *)dataCollectionToken
263+
asUrgent:(BOOL)urgent {
264+
dispatch_async(self.operationQueue.underlyingQueue, ^{
265+
[self processExistingActiveReportPath:path
266+
dataCollectionToken:dataCollectionToken
267+
asUrgent:YES];
268+
});
269+
}
270+
251271
@end

Crashlytics/Crashlytics/Controllers/FIRCLSManagerData.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
2222
@class FIRCLSApplicationIdentifierModel;
2323
@class FIRCLSInstallIdentifierModel;
2424
@class FIRCLSExecutionIdentifierModel;
25+
@class FIRCLSOnDemandModel;
2526
@class FIRCLSSettings;
2627
@class FIRCLSLaunchMarkerModel;
2728
@class GDTCORTransport;
@@ -46,7 +47,8 @@ NS_ASSUME_NONNULL_BEGIN
4647
analytics:(nullable id<FIRAnalyticsInterop>)analytics
4748
fileManager:(FIRCLSFileManager *)fileManager
4849
dataArbiter:(FIRCLSDataCollectionArbiter *)dataArbiter
49-
settings:(FIRCLSSettings *)settings NS_DESIGNATED_INITIALIZER;
50+
settings:(FIRCLSSettings *)settings
51+
onDemandModel:(FIRCLSOnDemandModel *)onDemandModel NS_DESIGNATED_INITIALIZER;
5052

5153
- (instancetype)init NS_UNAVAILABLE;
5254
+ (instancetype)new NS_UNAVAILABLE;
@@ -72,6 +74,9 @@ NS_ASSUME_NONNULL_BEGIN
7274
// Uniquely identifies a run of the app
7375
@property(nonatomic, strong) FIRCLSExecutionIdentifierModel *executionIDModel;
7476

77+
// Handles storing and uploading of on-demand events
78+
@property(nonatomic, readonly) FIRCLSOnDemandModel *onDemandModel;
79+
7580
// Settings fetched from the server
7681
@property(nonatomic, strong) FIRCLSSettings *settings;
7782

Crashlytics/Crashlytics/Controllers/FIRCLSManagerData.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#import "Crashlytics/Crashlytics/Components/FIRCLSApplication.h"
1818
#import "Crashlytics/Crashlytics/Models/FIRCLSExecutionIdentifierModel.h"
1919
#import "Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h"
20+
#import "Crashlytics/Crashlytics/Models/FIRCLSSettings.h"
21+
#import "Crashlytics/Crashlytics/Private/FIRCLSOnDemandModel_Private.h"
2022
#import "Crashlytics/Crashlytics/Settings/Models/FIRCLSApplicationIdentifierModel.h"
2123

2224
@implementation FIRCLSManagerData
@@ -27,7 +29,8 @@ - (instancetype)initWithGoogleAppID:(NSString *)googleAppID
2729
analytics:(nullable id<FIRAnalyticsInterop>)analytics
2830
fileManager:(FIRCLSFileManager *)fileManager
2931
dataArbiter:(FIRCLSDataCollectionArbiter *)dataArbiter
30-
settings:(FIRCLSSettings *)settings {
32+
settings:(FIRCLSSettings *)settings
33+
onDemandModel:(FIRCLSOnDemandModel *)onDemandModel {
3134
self = [super init];
3235
if (!self) {
3336
return nil;
@@ -40,6 +43,7 @@ - (instancetype)initWithGoogleAppID:(NSString *)googleAppID
4043
_fileManager = fileManager;
4144
_dataArbiter = dataArbiter;
4245
_settings = settings;
46+
_onDemandModel = onDemandModel;
4347

4448
_appIDModel = [[FIRCLSApplicationIdentifierModel alloc] init];
4549
_installIDModel = [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:installations];

Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
2424
#import "Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h"
2525
#import "Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
26+
#import "Crashlytics/Crashlytics/Models/FIRCLSSettings.h"
2627
#import "Crashlytics/Crashlytics/Models/FIRCLSSymbolResolver.h"
2728
#import "Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.h"
2829
#import "Crashlytics/Crashlytics/Operations/Reports/FIRCLSProcessReportOperation.h"

Crashlytics/Crashlytics/FIRCrashlytics.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#import "Crashlytics/Crashlytics/Components/FIRCLSHost.h"
2626
#include "Crashlytics/Crashlytics/Components/FIRCLSUserLogging.h"
2727
#import "Crashlytics/Crashlytics/DataCollection/FIRCLSDataCollectionArbiter.h"
28+
#import "Crashlytics/Crashlytics/DataCollection/FIRCLSDataCollectionToken.h"
2829
#import "Crashlytics/Crashlytics/FIRCLSUserDefaults/FIRCLSUserDefaults.h"
2930
#include "Crashlytics/Crashlytics/Handlers/FIRCLSException.h"
3031
#import "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
@@ -45,6 +46,9 @@
4546
#import "Crashlytics/Crashlytics/Controllers/FIRCLSNotificationManager.h"
4647
#import "Crashlytics/Crashlytics/Controllers/FIRCLSReportManager.h"
4748
#import "Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.h"
49+
#import "Crashlytics/Crashlytics/Private/FIRCLSExistingReportManager_Private.h"
50+
#import "Crashlytics/Crashlytics/Private/FIRCLSOnDemandModel_Private.h"
51+
#import "Crashlytics/Crashlytics/Private/FIRExceptionModel_Private.h"
4852

4953
#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
5054
#import "FirebaseInstallations/Source/Library/Private/FirebaseInstallationsInternal.h"
@@ -126,13 +130,16 @@ - (instancetype)initWithApp:(FIRApp *)app
126130
FIRCLSSettings *settings = [[FIRCLSSettings alloc] initWithFileManager:_fileManager
127131
appIDModel:appModel];
128132

133+
FIRCLSOnDemandModel *onDemandModel =
134+
[[FIRCLSOnDemandModel alloc] initWithFIRCLSSettings:settings];
129135
_managerData = [[FIRCLSManagerData alloc] initWithGoogleAppID:_googleAppID
130136
googleTransport:googleTransport
131137
installations:installations
132138
analytics:analytics
133139
fileManager:_fileManager
134140
dataArbiter:_dataArbiter
135-
settings:settings];
141+
settings:settings
142+
onDemandModel:onDemandModel];
136143

137144
_reportUploader = [[FIRCLSReportUploader alloc] initWithManagerData:_managerData];
138145

@@ -351,4 +358,11 @@ - (void)recordExceptionModel:(FIRExceptionModel *)exceptionModel {
351358
FIRCLSExceptionRecordModel(exceptionModel);
352359
}
353360

361+
- (void)recordOnDemandExceptionModel:(FIRExceptionModel *)exceptionModel {
362+
[self.managerData.onDemandModel
363+
recordOnDemandExceptionIfQuota:exceptionModel
364+
withDataCollectionEnabled:[self.dataArbiter isCrashlyticsCollectionEnabled]
365+
usingExistingReportManager:self.existingReportManager];
366+
}
367+
354368
@end

Crashlytics/Crashlytics/FIRExceptionModel.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ @interface FIRExceptionModel ()
1818

1919
@property(nonatomic, copy) NSString *name;
2020
@property(nonatomic, copy) NSString *reason;
21+
@property(nonatomic) BOOL isFatal;
22+
@property(nonatomic) BOOL onDemand;
2123

2224
@end
2325

Crashlytics/Crashlytics/Handlers/FIRCLSException.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,21 @@ void FIRCLSExceptionRaiseTestCppException(void) __attribute((noreturn));
6161

6262
#ifdef __OBJC__
6363
void FIRCLSExceptionRecordModel(FIRExceptionModel* exceptionModel);
64+
NSString* FIRCLSExceptionRecordOnDemandModel(FIRExceptionModel* exceptionModel,
65+
int previousRecordedOnDemandExceptions,
66+
int previousDroppedOnDemandExceptions);
6467
void FIRCLSExceptionRecordNSException(NSException* exception);
6568
void FIRCLSExceptionRecord(FIRCLSExceptionType type,
6669
const char* name,
6770
const char* reason,
6871
NSArray<FIRStackFrame*>* frames);
72+
NSString* FIRCLSExceptionRecordOnDemand(FIRCLSExceptionType type,
73+
const char* name,
74+
const char* reason,
75+
NSArray<FIRStackFrame*>* frames,
76+
BOOL fatal,
77+
int previousRecordedOnDemandExceptions,
78+
int previousDroppedOnDemandExceptions);
6979
#endif
7080

7181
__END_DECLS

0 commit comments

Comments
 (0)