16
16
17
17
#import " Crashlytics/Crashlytics/Controllers/FIRCLSManagerData.h"
18
18
#import " Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.h"
19
+ #import " Crashlytics/Crashlytics/DataCollection/FIRCLSDataCollectionArbiter.h"
19
20
#import " Crashlytics/Crashlytics/DataCollection/FIRCLSDataCollectionToken.h"
20
21
#import " Crashlytics/Crashlytics/Helpers/FIRCLSLogger.h"
21
22
#import " Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
22
23
#import " Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
24
+ #import " Crashlytics/Crashlytics/Models/FIRCLSSettings.h"
23
25
#import " Crashlytics/Crashlytics/Private/FIRCrashlyticsReport_Private.h"
24
26
#import " Crashlytics/Crashlytics/Public/FirebaseCrashlytics/FIRCrashlyticsReport.h"
25
27
@@ -31,6 +33,8 @@ @interface FIRCLSExistingReportManager ()
31
33
@property (nonatomic , strong ) FIRCLSFileManager *fileManager;
32
34
@property (nonatomic , strong ) FIRCLSReportUploader *reportUploader;
33
35
@property (nonatomic , strong ) NSOperationQueue *operationQueue;
36
+ @property (nonatomic , strong ) FIRCLSSettings *settings;
37
+ @property (nonatomic , strong ) FIRCLSDataCollectionArbiter *dataArbiter;
34
38
35
39
// This list of active reports excludes the brand new active report that will be created this run of
36
40
// the app.
@@ -52,7 +56,9 @@ - (instancetype)initWithManagerData:(FIRCLSManagerData *)managerData
52
56
}
53
57
54
58
_fileManager = managerData.fileManager ;
59
+ _settings = managerData.settings ;
55
60
_operationQueue = managerData.operationQueue ;
61
+ _dataArbiter = managerData.dataArbiter ;
56
62
_reportUploader = reportUploader;
57
63
58
64
return self;
@@ -91,16 +97,36 @@ - (NSUInteger)unsentReportsCount {
91
97
*/
92
98
- (NSArray <NSString *> *)getUnsentActiveReportsAndDeleteEmptyOrOld : (NSArray *)reportPaths {
93
99
NSMutableArray <FIRCLSInternalReport *> *validReports = [NSMutableArray array ];
100
+ NSMutableArray <FIRCLSInternalReport *> *reports = [NSMutableArray array ];
101
+
94
102
for (NSString *path in reportPaths) {
95
103
FIRCLSInternalReport *_Nullable report = [FIRCLSInternalReport reportWithPath: path];
96
104
if (!report) {
97
105
continue ;
98
106
}
99
107
108
+ [reports addObject: report];
109
+ }
110
+
111
+ if (reports.count == 0 ) {
112
+ return @[];
113
+ }
114
+
115
+ [reports sortUsingFunction: compareNewer context: nil ];
116
+ NSString *newestReportPath = [reports firstObject ].path ;
117
+
118
+ // If there was a MetricKit event recorded on the last run of the app, add it to the newest
119
+ // report.
120
+ if (self.settings .metricKitCollectionEnabled &&
121
+ [self .fileManager metricKitDiagnosticFileExists ]) {
122
+ [self .fileManager createEmptyMetricKitFile: newestReportPath];
123
+ }
124
+
125
+ for (FIRCLSInternalReport *report in reports) {
100
126
// Delete reports without any crashes or non-fatals
101
127
if (![report hasAnyEvents ]) {
102
128
[self .operationQueue addOperationWithBlock: ^{
103
- [self .fileManager removeItemAtPath: path];
129
+ [self .fileManager removeItemAtPath: report. path];
104
130
}];
105
131
continue ;
106
132
}
0 commit comments