-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Migrate from using IID SDK for Remote Config to the new FIS SDK #5096
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
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b514939
Update podspec to replace IID with installations SDK.
dmandar 481bbf4
Update sample app podfile to include installations sdk.
dmandar 52fc81d
Source code changes to support migration to FIS. The FIS SDK now supp…
dmandar da29c32
Update RC test app to use FIS SDK.
dmandar 9f8fdf0
WIP: Unit tests for incorporating FIS with Remote Config.
dmandar 3d137d0
Merge branch 'master' into md-rc-usefissdk
maksymmalyhin 757fbe5
Remote Config: fix Installations tests (#5109)
maksymmalyhin d9ab3bd
Merge branch 'master' into md-rc-usefissdk
maksymmalyhin 977cbb1
Add the installations token as an HTTP header.
dmandar 428cd9f
Add changelog for FIS changes.
dmandar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,10 +16,10 @@ | |
|
|
||
| #import "FirebaseRemoteConfig/Sources/RCNConfigFetch.h" | ||
|
|
||
| #import <FirebaseCore/FIRApp.h> | ||
| #import <FirebaseCore/FIRLogger.h> | ||
| #import <FirebaseCore/FIROptions.h> | ||
| #import <FirebaseInstanceID/FIRInstanceID+Private.h> | ||
| #import <FirebaseInstanceID/FIRInstanceIDCheckinPreferences.h> | ||
| #import <FirebaseInstallations/FirebaseInstallations.h> | ||
| #import <GoogleUtilities/GULNSData+zlib.h> | ||
| #import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h" | ||
| #import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h" | ||
|
|
@@ -40,7 +40,6 @@ | |
| static NSString *const kServerURLQuery = @":fetch?"; | ||
| static NSString *const kServerURLKey = @"key="; | ||
| static NSString *const kRequestJSONKeyAppID = @"app_id"; | ||
| static NSString *const kRequestJSONKeyAppInstanceID = @"app_instance_id"; | ||
|
|
||
| static NSString *const kHTTPMethodPost = @"POST"; ///< HTTP request method config fetch using | ||
| static NSString *const kContentTypeHeaderName = @"Content-Type"; ///< HTTP Header Field Name | ||
|
|
@@ -55,7 +54,6 @@ | |
|
|
||
| /// Config HTTP request content type proto buffer | ||
| static NSString *const kContentTypeValueJSON = @"application/json"; | ||
| static NSString *const kInstanceIDScopeConfig = @"*"; /// InstanceID scope | ||
|
|
||
| /// HTTP status codes. Ref: https://cloud.google.com/apis/design/errors#error_retries | ||
| static NSInteger const kRCNFetchResponseHTTPStatusCodeOK = 200; | ||
|
|
@@ -192,18 +190,24 @@ - (void)fetchConfigWithExpirationDuration:(NSTimeInterval)expirationDuration | |
| withError:error]; | ||
| } | ||
| strongSelf->_settings.isFetchInProgress = YES; | ||
| [strongSelf refreshInstanceIDTokenAndFetchCheckInInfoWithCompletionHandler:completionHandler]; | ||
| [strongSelf refreshInstallationsTokenWithCompletionHandler:completionHandler]; | ||
| }); | ||
| } | ||
|
|
||
| #pragma mark - Fetch helpers | ||
|
|
||
| /// Refresh instance ID token before fetching config. Instance ID is now mandatory for fetch | ||
| - (NSString *)FIRAppNameFromFullyQualifiedNamespace { | ||
| NSString *FIRAppName = | ||
| [_FIRNamespace substringFromIndex:[_FIRNamespace rangeOfString:@":"].location + 1]; | ||
| return FIRAppName; | ||
| } | ||
| /// Refresh installation ID token before fetching config. installation ID is now mandatory for fetch | ||
| /// requests to work.(b/14751422). | ||
| - (void)refreshInstanceIDTokenAndFetchCheckInInfoWithCompletionHandler: | ||
| - (void)refreshInstallationsTokenWithCompletionHandler: | ||
| (FIRRemoteConfigFetchCompletion)completionHandler { | ||
| FIRInstanceID *instanceID = [FIRInstanceID instanceID]; | ||
| if (!_options.GCMSenderID) { | ||
| FIRInstallations *installations = [FIRInstallations | ||
| installationsWithApp:[FIRApp appNamed:[self FIRAppNameFromFullyQualifiedNamespace]]]; | ||
| if (!installations || !_options.GCMSenderID) { | ||
| NSString *errorDescription = @"Failed to get GCMSenderID"; | ||
| FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000074", @"%@", | ||
| [NSString stringWithFormat:@"%@", errorDescription]); | ||
|
|
@@ -217,10 +221,11 @@ - (void)refreshInstanceIDTokenAndFetchCheckInInfoWithCompletionHandler: | |
| NSLocalizedDescriptionKey : errorDescription | ||
| }]]; | ||
| } | ||
| FIRInstanceIDTokenHandler instanceIDHandler = ^(NSString *token, NSError *error) { | ||
| if (!token || error) { | ||
| FIRInstallationsTokenHandler installationsTokenHandler = ^( | ||
| FIRInstallationsAuthTokenResult *tokenResult, NSError *error) { | ||
| if (!tokenResult || !tokenResult.authToken || error) { | ||
| NSString *errorDescription = | ||
| [NSString stringWithFormat:@"Failed to get InstanceID token. Error : %@.", error]; | ||
| [NSString stringWithFormat:@"Failed to get installations token. Error : %@.", error]; | ||
| FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000073", @"%@", | ||
| [NSString stringWithFormat:@"%@", errorDescription]); | ||
| self->_settings.isFetchInProgress = NO; | ||
|
|
@@ -234,20 +239,21 @@ - (void)refreshInstanceIDTokenAndFetchCheckInInfoWithCompletionHandler: | |
| }]]; | ||
| } | ||
|
|
||
| // If the token is available, try to get the instanceID. | ||
| // We have a valid token. Get the backing installationID. | ||
| __weak RCNConfigFetch *weakSelf = self; | ||
| [instanceID getIDWithHandler:^(NSString *_Nullable identity, NSError *_Nullable error) { | ||
| [installations installationIDWithCompletion:^(NSString *_Nullable identifier, | ||
| NSError *_Nullable error) { | ||
| RCNConfigFetch *strongSelf = weakSelf; | ||
|
|
||
| // Dispatch to the RC serial queue to update settings on the queue. | ||
| dispatch_async(strongSelf->_lockQueue, ^{ | ||
| RCNConfigFetch *strongSelfQueue = weakSelf; | ||
|
|
||
| // Update config settings with the IID and token. | ||
| strongSelfQueue->_settings.configInstanceIDToken = [token copy]; | ||
| strongSelfQueue->_settings.configInstanceID = identity; | ||
| strongSelfQueue->_settings.configInstallationsToken = [tokenResult.authToken copy]; | ||
|
||
| strongSelfQueue->_settings.configInstallationsIdentifier = identifier; | ||
|
|
||
| if (!identity || error) { | ||
| if (!identifier || error) { | ||
| NSString *errorDescription = | ||
| [NSString stringWithFormat:@"Error getting iid : %@.", error]; | ||
| FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000055", @"%@", | ||
|
|
@@ -265,56 +271,23 @@ - (void)refreshInstanceIDTokenAndFetchCheckInInfoWithCompletionHandler: | |
| } | ||
|
|
||
| FIRLogInfo(kFIRLoggerRemoteConfig, @"I-RCN000022", @"Success to get iid : %@.", | ||
| strongSelfQueue->_settings.configInstanceID); | ||
|
|
||
| // Continue the fetch regardless of whether fetch of instance ID succeeded. | ||
| [strongSelfQueue fetchCheckinInfoWithCompletionHandler:completionHandler]; | ||
| strongSelfQueue->_settings.configInstallationsIdentifier); | ||
| [strongSelf | ||
| getAnalyticsUserPropertiesWithCompletionHandler:^(NSDictionary *userProperties) { | ||
| dispatch_async(strongSelf->_lockQueue, ^{ | ||
| [strongSelf fetchWithUserProperties:userProperties | ||
| completionHandler:completionHandler]; | ||
| }); | ||
| }]; | ||
| }); | ||
| }]; | ||
| }; | ||
| FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000039", @"Starting requesting token."); | ||
| // Note: We expect the GCMSenderID to always be available by the time this request is made. | ||
| [instanceID tokenWithAuthorizedEntity:_options.GCMSenderID | ||
| scope:kInstanceIDScopeConfig | ||
| options:nil | ||
| handler:instanceIDHandler]; | ||
| } | ||
|
|
||
| /// Fetch checkin info before fetching config. Checkin info including device authentication ID, | ||
| /// secret token and device data version are optional fields in config request. | ||
| - (void)fetchCheckinInfoWithCompletionHandler:(FIRRemoteConfigFetchCompletion)completionHandler { | ||
| FIRInstanceID *instanceID = [FIRInstanceID instanceID]; | ||
| __weak RCNConfigFetch *weakSelf = self; | ||
| [instanceID fetchCheckinInfoWithHandler:^(FIRInstanceIDCheckinPreferences *preferences, | ||
| NSError *error) { | ||
| RCNConfigFetch *fetchCheckinInfoWithHandlerSelf = weakSelf; | ||
| dispatch_async(fetchCheckinInfoWithHandlerSelf->_lockQueue, ^{ | ||
| RCNConfigFetch *strongSelf = fetchCheckinInfoWithHandlerSelf; | ||
| if (error) { | ||
| FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000023", @"Failed to fetch checkin info: %@.", | ||
| error); | ||
| } else { | ||
| strongSelf->_settings.deviceAuthID = preferences.deviceID; | ||
| strongSelf->_settings.secretToken = preferences.secretToken; | ||
| strongSelf->_settings.deviceDataVersion = preferences.deviceDataVersion; | ||
| if (strongSelf->_settings.deviceAuthID.length && strongSelf->_settings.secretToken.length) { | ||
| FIRLogInfo(kFIRLoggerRemoteConfig, @"I-RCN000024", | ||
| @"Success to get device authentication ID: %@, security token: %@.", | ||
| self->_settings.deviceAuthID, self->_settings.secretToken); | ||
| } | ||
| } | ||
| // Checkin info is optional, continue fetch config regardless fetch of checkin info | ||
| // succeeded. | ||
| [strongSelf fetchWithUserPropertiesCompletionHandler:^(NSDictionary *userProperties) { | ||
| dispatch_async(strongSelf->_lockQueue, ^{ | ||
| [strongSelf fetchWithUserProperties:userProperties completionHandler:completionHandler]; | ||
| }); | ||
| }]; | ||
| }); | ||
| }]; | ||
| FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000039", @"Starting requesting token."); | ||
| [installations authTokenWithCompletion:installationsTokenHandler]; | ||
| } | ||
|
|
||
| - (void)fetchWithUserPropertiesCompletionHandler: | ||
| - (void)getAnalyticsUserPropertiesWithCompletionHandler: | ||
| (FIRAInteropUserPropertiesCallback)completionHandler { | ||
| FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000060", @"Fetch with user properties completed."); | ||
| id<FIRAnalyticsInterop> analytics = self->_analytics; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit worried that we compose the string at one place and parse it at another, because it increases probability of errors when the logic needs to be updated. Will it be better to just pass
appNameseparately?If you still would like to parse the string, I would suggest a safer way to do it to avoid crashing if the
_FIRNamespacecontains an unexpected string for some reason, e.g.:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.