Skip to content

Commit d820aad

Browse files
Crashlytics SDK: use Firebase Installations instead of Instance ID (#4954)
* WIP * Replace Instance ID by FIS * Crashlytics podspec: replace FirebaseInstanceID by FirebaseInstallations * Run ./scripts/style.sh * Cleanup and copyright update.
1 parent 2f5a980 commit d820aad

13 files changed

+121
-119
lines changed

Crashlytics/Crashlytics/Controllers/FIRCLSReportManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ NS_ASSUME_NONNULL_BEGIN
2525
@class FIRCLSFileManager;
2626
@class FIRCLSInternalReport;
2727
@class FIRCLSSettings;
28-
@class FIRInstanceID;
28+
@class FIRInstallations;
2929
@protocol FIRAnalyticsInterop;
3030

3131
@interface FIRCLSReportManager : NSObject
3232

3333
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
34-
instanceID:(FIRInstanceID *)instanceID
34+
installations:(FIRInstallations *)installations
3535
analytics:(nullable id<FIRAnalyticsInterop>)analytics
3636
googleAppID:(NSString *)googleAppID
3737
dataArbiter:(FIRCLSDataCollectionArbiter *)dataArbiter

Crashlytics/Crashlytics/Controllers/FIRCLSReportManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ @implementation FIRCLSReportManager
164164
static void (^reportSentCallback)(void);
165165

166166
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
167-
instanceID:(FIRInstanceID *)instanceID
167+
installations:(FIRInstallations *)installations
168168
analytics:(id<FIRAnalyticsInterop>)analytics
169169
googleAppID:(NSString *)googleAppID
170170
dataArbiter:(FIRCLSDataCollectionArbiter *)dataArbiter {
@@ -196,7 +196,7 @@ - (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
196196
_checkForUnsentReportsCalled = NO;
197197

198198
_appIDModel = [[FIRCLSApplicationIdentifierModel alloc] init];
199-
_installIDModel = [[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:instanceID];
199+
_installIDModel = [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:installations];
200200
_executionIDModel = [[FIRCLSExecutionIdentifierModel alloc] init];
201201

202202
_settings = [[FIRCLSSettings alloc] initWithFileManager:_fileManager appIDModel:_appIDModel];

Crashlytics/Crashlytics/FIRCrashlytics.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#import <FirebaseCore/FIRDependency.h>
4747
#import <FirebaseCore/FIRLibrary.h>
4848
#import <FirebaseCore/FIROptionsInternal.h>
49-
#import <FirebaseInstanceID/FirebaseInstanceID.h>
49+
#import <FirebaseInstallations/FirebaseInstallations.h>
5050

5151
#if TARGET_OS_IPHONE
5252
#import <UIKit/UIKit.h>
@@ -79,7 +79,7 @@ @implementation FIRCrashlytics
7979

8080
- (instancetype)initWithApp:(FIRApp *)app
8181
appInfo:(NSDictionary *)appInfo
82-
instanceID:(FIRInstanceID *)instanceID
82+
installations:(FIRInstallations *)installations
8383
analytics:(id<FIRAnalyticsInterop>)analytics {
8484
self = [super init];
8585

@@ -101,7 +101,7 @@ - (instancetype)initWithApp:(FIRApp *)app
101101
_googleAppID = app.options.googleAppID;
102102
_dataArbiter = [[FIRCLSDataCollectionArbiter alloc] initWithApp:app withAppInfo:appInfo];
103103
_reportManager = [[FIRCLSReportManager alloc] initWithFileManager:_fileManager
104-
instanceID:instanceID
104+
installations:installations
105105
analytics:analytics
106106
googleAppID:_googleAppID
107107
dataArbiter:_dataArbiter];
@@ -151,13 +151,13 @@ + (void)load {
151151

152152
id<FIRAnalyticsInterop> analytics = FIR_COMPONENT(FIRAnalyticsInterop, container);
153153

154-
FIRInstanceID *instanceID = FIRInstanceID.instanceID;
154+
FIRInstallations *installations = [FIRInstallations installationsWithApp:container.app];
155155

156156
*isCacheable = YES;
157157

158158
return [[FIRCrashlytics alloc] initWithApp:container.app
159159
appInfo:NSBundle.mainBundle.infoDictionary
160-
instanceID:instanceID
160+
installations:installations
161161
analytics:analytics];
162162
};
163163

Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#import <Foundation/Foundation.h>
1616

17-
@class FIRInstanceID;
17+
@class FIRInstallations;
1818

1919
NS_ASSUME_NONNULL_BEGIN
2020

@@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
2525

2626
- (instancetype)init NS_UNAVAILABLE;
2727

28-
- (instancetype)initWithInstanceID:(FIRInstanceID *)instanceID NS_DESIGNATED_INITIALIZER;
28+
- (instancetype)initWithInstallations:(FIRInstallations *)instanceID NS_DESIGNATED_INITIALIZER;
2929

3030
/**
3131
* Returns the backwards compatible Crashlytics Installation UUID

Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.m

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#import "FIRCLSInstallIdentifierModel.h"
1616

17-
#import <FirebaseInstanceID/FIRInstanceID.h>
17+
#import <FirebaseInstallations/FirebaseInstallations.h>
1818

1919
#import "FIRCLSByteUtility.h"
2020
#import "FIRCLSLogger.h"
@@ -31,7 +31,7 @@ @interface FIRCLSInstallIdentifierModel ()
3131

3232
@property(nonatomic, copy) NSString *installID;
3333

34-
@property(nonatomic, readonly) FIRInstanceID *instanceID;
34+
@property(nonatomic, readonly) FIRInstallations *installations;
3535

3636
@end
3737

@@ -41,15 +41,15 @@ @implementation FIRCLSInstallIdentifierModel
4141
// overridden setters and getters
4242
@synthesize installID = _installID;
4343

44-
- (instancetype)initWithInstanceID:(FIRInstanceID *)instanceID {
44+
- (instancetype)initWithInstallations:(FIRInstallations *)installations {
4545
self = [super init];
4646
if (!self) {
4747
return nil;
4848
}
4949

5050
// capture the install ID information
5151
_installID = [self readInstallationUUID].copy;
52-
_instanceID = instanceID;
52+
_installations = installations;
5353

5454
if (!_installID) {
5555
FIRCLSDebugLog(@"Generating Install ID");
@@ -103,12 +103,13 @@ - (NSString *)generateInstallationUUID {
103103
*/
104104
- (void)regenerateInstallIDIfNeededWithBlock:(void (^)(BOOL didRotate))callback {
105105
// This callback is on the main thread
106-
[self.instanceID getIDWithHandler:^(NSString *_Nullable currentIID, NSError *_Nullable error) {
107-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
108-
BOOL didRotate = [self rotateCrashlyticsInstallUUIDWithIID:currentIID error:error];
109-
callback(didRotate);
110-
});
111-
}];
106+
[self.installations
107+
installationIDWithCompletion:^(NSString *_Nullable currentIID, NSError *_Nullable error) {
108+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
109+
BOOL didRotate = [self rotateCrashlyticsInstallUUIDWithIID:currentIID error:error];
110+
callback(didRotate);
111+
});
112+
}];
112113
}
113114

114115
- (BOOL)rotateCrashlyticsInstallUUIDWithIID:(NSString *_Nullable)currentIID

Crashlytics/UnitTests/FIRCLSInstallIdentifierModelTests.m

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#import <XCTest/XCTest.h>
1818

1919
#import "FIRCLSUserDefaults.h"
20-
#import "FIRMockInstanceID.h"
20+
#import "FIRMockInstallations.h"
2121

2222
static NSString *const FABInstallationUUIDKey = @"com.crashlytics.iuuid";
2323
static NSString *const FABInstallationADIDKey = @"com.crashlytics.install.adid";
@@ -66,21 +66,21 @@ - (BOOL)blockOnRegeneration:(FIRCLSInstallIdentifierModel *)model {
6666
}
6767

6868
- (void)testCreateUUID {
69-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"test_instance_id"];
69+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:@"test_instance_id"];
7070

7171
FIRCLSInstallIdentifierModel *model =
72-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
72+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
7373
XCTAssertNotNil(model.installID);
7474

7575
XCTAssertEqualObjects([_defaults objectForKey:FABInstallationUUIDKey], model.installID);
7676
XCTAssertNil([_defaults objectForKey:FABInstallationADIDKey]);
7777
}
7878

7979
- (void)testCreateUUIDAndRotate {
80-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"test_instance_id"];
80+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:@"test_instance_id"];
8181

8282
FIRCLSInstallIdentifierModel *model =
83-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
83+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
8484
XCTAssertNotNil(model.installID);
8585

8686
BOOL didRotate = [self blockOnRegeneration:model];
@@ -94,10 +94,10 @@ - (void)testCreateUUIDAndRotate {
9494

9595
- (void)testCreateUUIDAndErrorGettingInstanceID {
9696
NSError *fakeError = [NSError errorWithDomain:NSCocoaErrorDomain code:-1 userInfo:@{}];
97-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithError:fakeError];
97+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithError:fakeError];
9898

9999
FIRCLSInstallIdentifierModel *model =
100-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
100+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
101101
XCTAssertNotNil(model.installID);
102102

103103
BOOL didRotate = [self blockOnRegeneration:model];
@@ -109,10 +109,10 @@ - (void)testCreateUUIDAndErrorGettingInstanceID {
109109
}
110110

111111
- (void)testCreateUUIDNoIID {
112-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:nil];
112+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:nil];
113113

114114
FIRCLSInstallIdentifierModel *model =
115-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
115+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
116116
XCTAssertNotNil(model.installID);
117117

118118
XCTAssertEqualObjects([_defaults objectForKey:FABInstallationUUIDKey], model.installID);
@@ -126,9 +126,9 @@ - (void)testIIDBecomesNil {
126126
[_defaults setObject:@"old_instance_id" forKey:FIRCLSInstallationIIDHashKey];
127127

128128
// Initialize the model with the a nil IID.
129-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:nil];
129+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:nil];
130130
FIRCLSInstallIdentifierModel *model =
131-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
131+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
132132
XCTAssertNotNil(model.installID);
133133

134134
// Test that the UUID did not change. The FIID can be nil if
@@ -144,9 +144,9 @@ - (void)testIIDChanges {
144144
[_defaults setObject:@"old_instance_id" forKey:FIRCLSInstallationIIDHashKey];
145145

146146
// Initialize the model with the a new IID.
147-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"new_instance_id"];
147+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:@"new_instance_id"];
148148
FIRCLSInstallIdentifierModel *model =
149-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
149+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
150150
XCTAssertNotNil(model.installID);
151151

152152
BOOL didRotate = [self blockOnRegeneration:model];
@@ -166,9 +166,9 @@ - (void)testIIDDoesntChange {
166166
[_defaults setObject:FIRCLSTestHashOfTestInstanceID forKey:FIRCLSInstallationIIDHashKey];
167167

168168
// Initialize the model with the a new IID.
169-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"test_instance_id"];
169+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:@"test_instance_id"];
170170
FIRCLSInstallIdentifierModel *model =
171-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
171+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
172172
XCTAssertNotNil(model.installID);
173173

174174
BOOL didRotate = [self blockOnRegeneration:model];
@@ -187,9 +187,9 @@ - (void)testUUIDSetButNeverIIDNilIID {
187187
[_defaults setObject:@"old_uuid" forKey:FABInstallationUUIDKey];
188188

189189
// Initialize the model with the a nil IID.
190-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:nil];
190+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:nil];
191191
FIRCLSInstallIdentifierModel *model =
192-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
192+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
193193
XCTAssertNotNil(model.installID);
194194

195195
BOOL didRotate = [self blockOnRegeneration:model];
@@ -208,9 +208,9 @@ - (void)testUUIDSetButNeverIIDWithIID {
208208
[_defaults setObject:@"old_uuid" forKey:FABInstallationUUIDKey];
209209

210210
// Initialize the model with the a nil IID.
211-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"test_instance_id"];
211+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:@"test_instance_id"];
212212
FIRCLSInstallIdentifierModel *model =
213-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
213+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
214214
XCTAssertNotNil(model.installID);
215215

216216
BOOL didRotate = [self blockOnRegeneration:model];
@@ -231,9 +231,9 @@ - (void)testADIDWasSetButNeverIID {
231231
[_defaults setObject:@"test_adid" forKey:FABInstallationADIDKey];
232232

233233
// Initialize the model with the a new IID.
234-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:nil];
234+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:nil];
235235
FIRCLSInstallIdentifierModel *model =
236-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
236+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
237237
XCTAssertNotNil(model.installID);
238238

239239
BOOL didRotate = [self blockOnRegeneration:model];
@@ -252,9 +252,9 @@ - (void)testADIDWasSetAndIIDBecomesSet {
252252
[_defaults setObject:@"test_adid" forKey:FABInstallationADIDKey];
253253

254254
// Initialize the model with the a new IID.
255-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"test_instance_id"];
255+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:@"test_instance_id"];
256256
FIRCLSInstallIdentifierModel *model =
257-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
257+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
258258
XCTAssertNotNil(model.installID);
259259

260260
BOOL didRotate = [self blockOnRegeneration:model];
@@ -275,9 +275,9 @@ - (void)testADIDAndIIDWereSet {
275275
[_defaults setObject:FIRCLSTestHashOfTestInstanceID forKey:FIRCLSInstallationIIDHashKey];
276276

277277
// Initialize the model with the a new IID.
278-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"test_instance_id"];
278+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:@"test_instance_id"];
279279
FIRCLSInstallIdentifierModel *model =
280-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
280+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
281281
XCTAssertNotNil(model.installID);
282282

283283
BOOL didRotate = [self blockOnRegeneration:model];
@@ -298,9 +298,10 @@ - (void)testADIDAndIIDWereSet2 {
298298
[_defaults setObject:FIRCLSTestHashOfTestInstanceID forKey:FIRCLSInstallationIIDHashKey];
299299

300300
// Initialize the model with the a new IID.
301-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"test_changed_instance_id"];
301+
FIRMockInstallations *iid =
302+
[[FIRMockInstallations alloc] initWithFID:@"test_changed_instance_id"];
302303
FIRCLSInstallIdentifierModel *model =
303-
[[FIRCLSInstallIdentifierModel alloc] initWithInstanceID:iid];
304+
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
304305
XCTAssertNotNil(model.installID);
305306

306307
BOOL didRotate = [self blockOnRegeneration:model];

Crashlytics/UnitTests/FIRCLSReportManagerTests.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#import "FIRCLSMockFileManager.h"
3636
#import "FIRCLSMockReportManager.h"
3737
#import "FIRCLSMockReportUploader.h"
38-
#import "FIRMockInstanceID.h"
38+
#import "FIRMockInstallations.h"
3939

4040
#define TEST_API_KEY (@"DB5C8FA65C0D43419120FB96CFDBDE0C")
4141
#define TEST_GOOGLE_APP_ID (@"1:632950151350:ios:d5b0d08d4f00f4b1")
@@ -71,13 +71,13 @@ - (void)setUp {
7171
// Delete cached settings
7272
[self.fileManager removeItemAtPath:_fileManager.settingsFilePath];
7373

74-
FIRMockInstanceID *iid = [[FIRMockInstanceID alloc] initWithIID:@"test_token"];
74+
FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:@"test_token"];
7575

7676
FABMockApplicationIdentifierModel *appIDModel = [[FABMockApplicationIdentifierModel alloc] init];
7777
appIDModel.bundleID = TEST_BUNDLE_ID;
7878

7979
self.reportManager = [[FIRCLSMockReportManager alloc] initWithFileManager:self.fileManager
80-
instanceID:iid
80+
installations:iid
8181
analytics:nil
8282
googleAppID:TEST_GOOGLE_APP_ID
8383
dataArbiter:self.dataArbiter

Crashlytics/UnitTests/Mocks/FIRCLSMockReportManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ NS_ASSUME_NONNULL_BEGIN
2323
@interface FIRCLSMockReportManager : FIRCLSReportManager
2424

2525
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
26-
instanceID:(FIRInstanceID *)instanceID
26+
installations:(FIRInstallations *)installations
2727
analytics:(nullable id<FIRAnalyticsInterop>)analytics
2828
googleAppID:(NSString *)googleAppID
2929
dataArbiter:(FIRCLSDataCollectionArbiter *)dataArbiter
3030
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
3131
NS_DESIGNATED_INITIALIZER;
3232

3333
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
34-
instanceID:(FIRInstanceID *)instanceID
34+
installations:(FIRInstallations *)instanceID
3535
analytics:(nullable id<FIRAnalyticsInterop>)analytics
3636
googleAppID:(NSString *)googleAppID
3737
dataArbiter:(FIRCLSDataCollectionArbiter *)dataArbiter NS_UNAVAILABLE;

Crashlytics/UnitTests/Mocks/FIRCLSMockReportManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ @implementation FIRCLSMockReportManager
3434
@synthesize bundleIdentifier;
3535

3636
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager
37-
instanceID:(FIRInstanceID *)instanceID
37+
installations:(FIRInstallations *)installations
3838
analytics:(id<FIRAnalyticsInterop>)analytics
3939
googleAppID:(nonnull NSString *)googleAppID
4040
dataArbiter:(FIRCLSDataCollectionArbiter *)dataArbiter
4141
appIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel {
4242
self = [super initWithFileManager:fileManager
43-
instanceID:instanceID
43+
installations:installations
4444
analytics:analytics
4545
googleAppID:googleAppID
4646
dataArbiter:dataArbiter];

0 commit comments

Comments
 (0)