firebase log level

This commit is contained in:
oscarz
2024-08-29 18:25:13 +08:00
parent 8500300d18
commit 27c160beaf
1165 changed files with 122916 additions and 1 deletions

View File

@ -0,0 +1,57 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
#if __has_include(<FBLPromises/FBLPromises.h>)
#import <FBLPromises/FBLPromises.h>
#else
#import "FBLPromises.h"
#endif
@class FIRCLSApplicationIdentifierModel;
@class FIRCLSDataCollectionToken;
@class FIRCLSFileManager;
@class FIRCLSInstallIdentifierModel;
@class FIRCLSSettings;
NS_ASSUME_NONNULL_BEGIN
/**
* Use this class to retrieve remote settings for the application from crashlytics backend.
*/
@interface FIRCLSSettingsManager : NSObject
/**
* Designated Initializer.
*/
- (instancetype)initWithAppIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel
settings:(FIRCLSSettings *)settings
fileManager:(FIRCLSFileManager *)fileManager
googleAppID:(NSString *)googleAppID NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
/**
* This method kicks off downloading settings for the app.
* @param googleAppID (required) GMP id for the app.
* @param token (required) Data collection token signifying we can make network calls
*/
- (void)beginSettingsWithGoogleAppId:(NSString *)googleAppID
token:(FIRCLSDataCollectionToken *)token;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,157 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "Crashlytics/Crashlytics/Settings/FIRCLSSettingsManager.h"
#import "Crashlytics/Crashlytics/DataCollection/FIRCLSDataCollectionToken.h"
#import "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
#import "Crashlytics/Crashlytics/Helpers/FIRCLSLogger.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSSettings.h"
#import "Crashlytics/Crashlytics/Settings/Models/FIRCLSApplicationIdentifierModel.h"
#import "Crashlytics/Crashlytics/Settings/Operations/FIRCLSDownloadAndSaveSettingsOperation.h"
#import "Crashlytics/Shared/FIRCLSConstants.h"
#import "Crashlytics/Shared/FIRCLSNetworking/FIRCLSFABNetworkClient.h"
#import "Crashlytics/Shared/FIRCLSNetworking/FIRCLSURLBuilder.h"
@interface FIRCLSSettingsManager () <FIRCLSDownloadAndSaveSettingsOperationDelegate>
@property(nonatomic, strong) FIRCLSApplicationIdentifierModel *appIDModel;
@property(nonatomic, strong) FIRCLSInstallIdentifierModel *installIDModel;
@property(nonatomic, strong) FIRCLSSettings *settings;
@property(nonatomic, strong) FIRCLSFileManager *fileManager;
@property(nonatomic) NSDictionary *configuration;
@property(nonatomic) NSDictionary *defaultConfiguration;
@property(nonatomic, copy) NSString *googleAppID;
@property(nonatomic, copy) NSDictionary *kitVersionsByKitBundleIdentifier;
@property(nonatomic, readonly) FIRCLSFABNetworkClient *networkClient;
@end
@implementation FIRCLSSettingsManager
- (instancetype)initWithAppIDModel:(FIRCLSApplicationIdentifierModel *)appIDModel
installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel
settings:(FIRCLSSettings *)settings
fileManager:(FIRCLSFileManager *)fileManager
googleAppID:(NSString *)googleAppID {
self = [super init];
if (!self) {
return nil;
}
_appIDModel = appIDModel;
_installIDModel = installIDModel;
_settings = settings;
_fileManager = fileManager;
_googleAppID = googleAppID;
_networkClient = [[FIRCLSFABNetworkClient alloc] initWithQueue:nil];
return self;
}
- (void)beginSettingsWithGoogleAppId:(NSString *)googleAppID
token:(FIRCLSDataCollectionToken *)token {
NSParameterAssert(googleAppID);
self.googleAppID = googleAppID;
// This map helps us determine what versions of the SDK
// are out there. We're keeping the Fabric value in there for
// backwards compatibility
// TODO(b/141747635)
self.kitVersionsByKitBundleIdentifier = @{
FIRCLSApplicationGetSDKBundleID() : FIRCLSSDKVersion(),
};
[self beginSettingsDownload:token];
}
#pragma mark Helper methods
/**
* Makes a settings download request. If the request fails, the error is handled silently (with a
* log statement).
*/
- (void)beginSettingsDownload:(FIRCLSDataCollectionToken *)token {
FIRCLSDownloadAndSaveSettingsOperation *operation = nil;
operation = [[FIRCLSDownloadAndSaveSettingsOperation alloc]
initWithGoogleAppID:self.googleAppID
delegate:self
settingsURL:self.settingsURL
settingsDirectoryPath:self.fileManager.settingsDirectoryPath
settingsFilePath:self.fileManager.settingsFilePath
installIDModel:self.installIDModel
networkClient:self.networkClient
token:token];
[operation startWithToken:token];
}
- (void)finishNetworkingSession {
[self.networkClient invalidateAndCancel];
}
#pragma mark FIRCLSDownloadAndSaveSettingsOperationDelegate methods
- (void)operation:(FIRCLSDownloadAndSaveSettingsOperation *)operation
didDownloadAndSaveSettingsWithError:(nullable NSError *)error {
if (error) {
NSString *message = @"Failed to download settings.";
if (error.userInfo && [error.userInfo objectForKey:@"status_code"] &&
[[error.userInfo objectForKey:@"status_code"]
isEqualToNumber:[NSNumber numberWithInt:404]]) {
NSString *debugHint = @"If this is your first time launching the app, make sure you have "
@"enabled Crashlytics in the Firebase Console.";
message = [NSString stringWithFormat:@"%@ %@", message, debugHint];
}
FIRCLSErrorLog(@"%@ %@", message, error);
[self finishNetworkingSession];
return;
}
FIRCLSDebugLog(@"Settings downloaded successfully");
NSTimeInterval currentTimestamp = [NSDate timeIntervalSinceReferenceDate];
[self.settings cacheSettingsWithGoogleAppID:self.googleAppID currentTimestamp:currentTimestamp];
// we're all set!
[self finishNetworkingSession];
}
- (NSURL *)settingsURL {
// GET
// /spi/v2/platforms/:platform/apps/:identifier/settings?build_version=1234&display_version=abc&instance=xyz&source=1
FIRCLSURLBuilder *url = [FIRCLSURLBuilder URLWithBase:FIRCLSSettingsEndpoint];
[url appendComponent:@"/spi/v2/platforms/"];
[url escapeAndAppendComponent:self.appIDModel.platform];
[url appendComponent:@"/gmp/"];
[url escapeAndAppendComponent:self.googleAppID];
[url appendComponent:@"/settings"];
[url appendValue:self.appIDModel.buildVersion forQueryParam:@"build_version"];
[url appendValue:self.appIDModel.displayVersion forQueryParam:@"display_version"];
[url appendValue:self.appIDModel.buildInstanceID forQueryParam:@"instance"];
[url appendValue:@(self.appIDModel.installSource) forQueryParam:@"source"];
// TODO: find the right param name for KitVersions and add them here
return url.URL;
}
@end

View File

@ -0,0 +1,71 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
#import "Crashlytics/Crashlytics/Components/FIRCLSApplication.h"
NS_ASSUME_NONNULL_BEGIN
/**
* This class is a model for identifiers related to the application binary.
* It is thread-safe.
*/
@interface FIRCLSApplicationIdentifierModel : NSObject
@property(nonatomic, readonly, nullable) NSString* bundleID;
/**
* Returns the user-facing app name
*/
@property(nonatomic, readonly, nullable) NSString* displayName;
@property(nonatomic, readonly, nullable) NSString* platform;
@property(nonatomic, readonly, nullable) NSString* buildVersion;
@property(nonatomic, readonly, nullable) NSString* displayVersion;
/**
* Returns the synthesized app version, similar to how the backend does it
* <displayVersion> (<buildVersion>)
*/
@property(nonatomic, readonly, nullable) NSString* synthesizedVersion;
@property(nonatomic, readonly) FIRCLSApplicationInstallationSourceType installSource;
/**
* A mapping between all supported architectures and their UUIDs
*/
@property(nonatomic, readonly) NSDictionary* architectureUUIDMap;
/**
* Returns the linked OS SDK
*/
@property(nonatomic, readonly) NSString* builtSDKString;
/**
* Returns the min supported OS
*/
@property(nonatomic, readonly) NSString* minimumSDKString;
/**
* The unique identifier for this instance of the version of app running Crashlytics. This is
* computed by hashing the app itself.
*
* On Android, this is called the Build ID
*/
@property(nonatomic, readonly) NSString* buildInstanceID;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,138 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "Crashlytics/Crashlytics/Settings/Models/FIRCLSApplicationIdentifierModel.h"
#import "Crashlytics/Crashlytics/Components/FIRCLSApplication.h"
#import "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
#import "Crashlytics/Shared/FIRCLSByteUtility.h"
#import "Crashlytics/Shared/FIRCLSMachO/FIRCLSMachO.h"
#import "Crashlytics/Shared/FIRCLSUUID.h"
@interface FIRCLSApplicationIdentifierModel ()
@property(nonatomic, copy, readwrite) NSDictionary *architectureUUIDMap;
@property(nonatomic, copy, readwrite) NSString *buildInstanceID;
@property(nonatomic, readonly) FIRCLSMachOVersion builtSDK;
@property(nonatomic, readonly) FIRCLSMachOVersion minimumSDK;
@end
@implementation FIRCLSApplicationIdentifierModel
- (nullable instancetype)init {
self = [super init];
if (!self) {
return nil;
}
if (![self computeExecutableInfo]) {
return nil;
}
[self computeInstanceIdentifier];
return self;
}
- (NSString *)bundleID {
return FIRCLSApplicationGetBundleIdentifier();
}
- (NSString *)displayName {
return FIRCLSApplicationGetName();
}
- (NSString *)platform {
return FIRCLSApplicationGetPlatform();
}
- (NSString *)buildVersion {
return FIRCLSApplicationGetBundleVersion();
}
- (NSString *)displayVersion {
return FIRCLSApplicationGetShortBundleVersion();
}
- (NSString *)synthesizedVersion {
return [NSString stringWithFormat:@"%@ (%@)", self.displayVersion, self.buildVersion];
}
- (FIRCLSApplicationInstallationSourceType)installSource {
return FIRCLSApplicationInstallationSource();
}
- (NSString *)builtSDKString {
return FIRCLSMachOFormatVersion(&_builtSDK);
}
- (NSString *)minimumSDKString {
return FIRCLSMachOFormatVersion(&_minimumSDK);
}
- (BOOL)computeExecutableInfo {
struct FIRCLSMachOFile file;
if (!FIRCLSMachOFileInitWithCurrent(&file)) {
return NO;
}
NSMutableDictionary *executables = [NSMutableDictionary dictionary];
FIRCLSMachOFileEnumerateSlices(&file, ^(FIRCLSMachOSliceRef fileSlice) {
NSString *arch;
arch = [NSString stringWithUTF8String:FIRCLSMachOSliceGetArchitectureName(fileSlice)];
FIRCLSMachOSliceEnumerateLoadCommands(
fileSlice, ^(uint32_t type, uint32_t size, const struct load_command *cmd) {
if (type == LC_UUID) {
const uint8_t *uuid;
uuid = FIRCLSMachOGetUUID(cmd);
[executables setObject:FIRCLSUUIDToNSString(uuid) forKey:arch];
} else if (type == LC_VERSION_MIN_MACOSX || type == LC_VERSION_MIN_IPHONEOS) {
self->_minimumSDK = FIRCLSMachOGetMinimumOSVersion(cmd);
self->_builtSDK = FIRCLSMachOGetLinkedSDKVersion(cmd);
}
});
});
FIRCLSMachOFileDestroy(&file);
_architectureUUIDMap = executables;
return YES;
}
- (void)computeInstanceIdentifier {
// build up the components of the instance identifier
NSMutableString *string = [NSMutableString string];
// first, the uuids, sorted by architecture name
for (NSString *key in
[[_architectureUUIDMap allKeys] sortedArrayUsingSelector:@selector(compare:)]) {
[string appendString:[self.architectureUUIDMap objectForKey:key]];
}
// TODO: the instance identifier calculation needs to match Beta's expectation. So, we have to
// continue generating a less-correct value for now. One day, we should incorporate a hash of the
// Info.plist and icon data.
_buildInstanceID = FIRCLSHashNSData([string dataUsingEncoding:NSUTF8StringEncoding]);
}
@end

View File

@ -0,0 +1,80 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
#import "Crashlytics/Crashlytics/Settings/Operations/FIRCLSNetworkOperation.h"
@class FIRCLSDownloadAndSaveSettingsOperation;
@class FIRCLSFABNetworkClient;
@class FIRCLSInstallIdentifierModel;
NS_ASSUME_NONNULL_BEGIN
/**
* This is the protocol that a delegate of FIRCLSDownloadAndSaveSettingsOperation needs to follow.
*/
@protocol FIRCLSDownloadAndSaveSettingsOperationDelegate <NSObject>
@required
/**
* Method that is called when settings have been downloaded and saved, or an error has occurred
* during the operation. This method may be called on an arbitrary background thread.
*/
- (void)operation:(FIRCLSDownloadAndSaveSettingsOperation *)operation
didDownloadAndSaveSettingsWithError:(nullable NSError *)error;
@end
/**
* This operation downloads settings from the backend servers, and saves them in file on disk.
*/
@interface FIRCLSDownloadAndSaveSettingsOperation : FIRCLSNetworkOperation
- (instancetype)initWithGoogleAppID:(NSString *)googleAppID
token:(FIRCLSDataCollectionToken *)token NS_UNAVAILABLE;
/**
* @param googleAppID must NOT be nil
* @param delegate gets a callback after settings have been downloaded or an error occurs.
* @param settingsURL must NOT be nil. This is the URL to which a download request is made.
* @param settingsDirectoryPath must NOT be nil. This is the directory on disk where the settings
* are persisted.
* @param settingsFilePath must NOT be nil. It is the full file path (including file name) in which
* settings will be persisted on disk.
* @param installIDModel must NOT be nil. This value is sent back to the backend to uniquely
* identify the app install.
*/
- (instancetype)initWithGoogleAppID:(NSString *)googleAppID
delegate:(id<FIRCLSDownloadAndSaveSettingsOperationDelegate>)delegate
settingsURL:(NSURL *)settingsURL
settingsDirectoryPath:(NSString *)settingsDirectoryPath
settingsFilePath:(NSString *)settingsFilePath
installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel
networkClient:(FIRCLSFABNetworkClient *)networkClient
token:(FIRCLSDataCollectionToken *)token NS_DESIGNATED_INITIALIZER;
/**
* Delegate of this operation.
*/
@property(nonatomic, readonly, weak) id<FIRCLSDownloadAndSaveSettingsOperationDelegate> delegate;
/**
* When an error occurs during this operation, it is made available in this property.
*/
@property(nonatomic, readonly) NSError *error;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,132 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "Crashlytics/Crashlytics/Settings/Operations/FIRCLSDownloadAndSaveSettingsOperation.h"
#import "Crashlytics/Crashlytics/Helpers/FIRCLSLogger.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h"
#import "Crashlytics/Shared/FIRCLSConstants.h"
#import "Crashlytics/Shared/FIRCLSFABHost.h"
#import "Crashlytics/Shared/FIRCLSNetworking/FIRCLSFABNetworkClient.h"
@interface FIRCLSDownloadAndSaveSettingsOperation ()
/**
* Method called to fetch the URL from where settings have to be downloaded.
*/
@property(readonly, nonatomic) NSURL *settingsURL;
/**
* File manager which will be used to save settings on disk.
*/
@property(readonly, nonatomic) NSFileManager *fileManager;
/**
* Directory path on which settings file will be saved
*/
@property(readonly, nonatomic) NSString *settingsDirectoryPath;
/**
* Complete file path on which settings file will be saved
*/
@property(readonly, nonatomic) NSString *settingsFilePath;
/**
* App install identifier.
*/
@property(strong, readonly, nonatomic) FIRCLSInstallIdentifierModel *installIDModel;
@property(weak, readonly, nonatomic) FIRCLSFABNetworkClient *networkClient;
@end
@implementation FIRCLSDownloadAndSaveSettingsOperation
- (instancetype)initWithGoogleAppID:(NSString *)googleAppID
delegate:(id<FIRCLSDownloadAndSaveSettingsOperationDelegate>)delegate
settingsURL:(NSURL *)settingsURL
settingsDirectoryPath:(NSString *)settingsDirectoryPath
settingsFilePath:(NSString *)settingsFilePath
installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel
networkClient:(FIRCLSFABNetworkClient *)networkClient
token:(FIRCLSDataCollectionToken *)token {
NSParameterAssert(settingsURL);
NSParameterAssert(settingsDirectoryPath);
NSParameterAssert(settingsFilePath);
NSParameterAssert(installIDModel);
self = [super initWithGoogleAppID:googleAppID token:token];
if (self) {
_delegate = delegate;
_settingsURL = settingsURL.copy;
_settingsDirectoryPath = settingsDirectoryPath.copy;
_settingsFilePath = settingsFilePath.copy;
_fileManager = [[NSFileManager alloc] init];
_installIDModel = installIDModel;
_networkClient = networkClient;
}
return self;
}
- (NSMutableURLRequest *)mutableRequestWithDefaultHTTPHeaderFieldsAndTimeoutForURL:(NSURL *)url {
NSMutableURLRequest *request =
[super mutableRequestWithDefaultHTTPHeaderFieldsAndTimeoutForURL:url];
request.HTTPMethod = @"GET";
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:self.installIDModel.installID
forHTTPHeaderField:@"X-Crashlytics-Installation-ID"];
[request setValue:FIRCLSHostModelInfo() forHTTPHeaderField:@"X-Crashlytics-Device-Model"];
[request setValue:FIRCLSHostOSBuildVersion()
forHTTPHeaderField:@"X-Crashlytics-OS-Build-Version"];
[request setValue:FIRCLSHostOSDisplayVersion()
forHTTPHeaderField:@"X-Crashlytics-OS-Display-Version"];
[request setValue:FIRCLSSDKVersion() forHTTPHeaderField:@"X-Crashlytics-API-Client-Version"];
return request;
}
- (void)main {
NSMutableURLRequest *request =
[self mutableRequestWithDefaultHTTPHeaderFieldsAndTimeoutForURL:self.settingsURL];
[self.networkClient
startDownloadTaskWithRequest:request
retryLimit:1
completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
if (error) {
self->_error = error;
[self.delegate operation:self didDownloadAndSaveSettingsWithError:self.error];
[self finishWithError:error];
return;
}
// This move needs to happen synchronously, because after this method completes,
// the file will not be available.
NSError *moveError = nil;
// this removal will frequently fail, and we don't want the warning
[self.fileManager removeItemAtPath:self.settingsDirectoryPath error:nil];
[self.fileManager createDirectoryAtPath:self.settingsDirectoryPath
withIntermediateDirectories:YES
attributes:nil
error:nil];
if (![self.fileManager moveItemAtPath:location.path
toPath:self.settingsFilePath
error:&moveError]) {
FIRCLSErrorLog(@"Unable to complete settings download %@", moveError);
self->_error = moveError;
}
[self.delegate operation:self didDownloadAndSaveSettingsWithError:self.error];
[self finishWithError:self.error];
}];
}
@end

View File

@ -0,0 +1,55 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
#import "Crashlytics/Shared/FIRCLSOperation/FIRCLSOperation.h"
NS_ASSUME_NONNULL_BEGIN
@class FIRCLSDataCollectionToken;
@class FIRCLSSettings;
/**
* This is a base class for network based operations.
*/
@interface FIRCLSNetworkOperation : FIRCLSFABAsyncOperation
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
/**
* Designated initializer. All parameters are mandatory and must not be nil.
*/
- (instancetype)initWithGoogleAppID:(NSString *)googleAppID
token:(FIRCLSDataCollectionToken *)token NS_DESIGNATED_INITIALIZER;
- (void)start NS_UNAVAILABLE;
- (void)startWithToken:(FIRCLSDataCollectionToken *)token;
/**
* Creates a mutable request for posting to Crashlytics backend with a default timeout.
*/
- (NSMutableURLRequest *)mutableRequestWithDefaultHTTPHeaderFieldsAndTimeoutForURL:(NSURL *)url;
/**
* Creates a mutable request for posting to Crashlytics backend with given timeout.
*/
- (NSMutableURLRequest *)mutableRequestWithDefaultHTTPHeadersForURL:(NSURL *)url
timeout:(NSTimeInterval)timeout;
@property(nonatomic, strong, readonly) FIRCLSDataCollectionToken *token;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,93 @@
// Copyright 2019 Google
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "Crashlytics/Crashlytics/Settings/Operations/FIRCLSNetworkOperation.h"
#import "Crashlytics/Crashlytics/Components/FIRCLSApplication.h"
#import "Crashlytics/Crashlytics/DataCollection/FIRCLSDataCollectionToken.h"
#import "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
#import "Crashlytics/Crashlytics/Helpers/FIRCLSLogger.h"
#import "Crashlytics/Shared/FIRCLSConstants.h"
@interface FIRCLSNetworkOperation ()
@property(nonatomic, strong, readonly) NSString *googleAppID;
@end
@implementation FIRCLSNetworkOperation
- (instancetype)initWithGoogleAppID:(NSString *)googleAppID
token:(FIRCLSDataCollectionToken *)token {
NSParameterAssert(googleAppID);
if (!googleAppID) {
return nil;
}
self = [super init];
if (self) {
_googleAppID = googleAppID;
_token = token;
}
return self;
}
- (void)startWithToken:(FIRCLSDataCollectionToken *)token {
// Settings is considered data collection, so we must only
// call this with a valid token
if (![token isValid]) {
FIRCLSErrorLog(@"Skipping network operation with invalid data collection token");
return;
}
[super start];
}
- (NSMutableURLRequest *)mutableRequestWithDefaultHTTPHeaderFieldsAndTimeoutForURL:(NSURL *)url {
return [self mutableRequestWithDefaultHTTPHeadersForURL:url timeout:10.0];
}
- (NSMutableURLRequest *)mutableRequestWithDefaultHTTPHeadersForURL:(NSURL *)url
timeout:(NSTimeInterval)timeout {
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:timeout];
NSString *localeId = self.localeIdentifier;
[request setValue:self.userAgentString forHTTPHeaderField:FIRCLSNetworkUserAgent];
[request setValue:FIRCLSNetworkUTF8 forHTTPHeaderField:FIRCLSNetworkAcceptCharset];
[request setValue:localeId forHTTPHeaderField:FIRCLSNetworkAcceptLanguage];
[request setValue:localeId forHTTPHeaderField:FIRCLSNetworkContentLanguage];
[request setValue:FIRCLSDeveloperToken forHTTPHeaderField:FIRCLSNetworkCrashlyticsDeveloperToken];
[request setValue:FIRCLSApplicationGetSDKBundleID()
forHTTPHeaderField:FIRCLSNetworkCrashlyticsAPIClientId];
[request setValue:FIRCLSSDKVersion()
forHTTPHeaderField:FIRCLSNetworkCrashlyticsAPIClientDisplayVersion];
[request setValue:self.googleAppID forHTTPHeaderField:FIRCLSNetworkCrashlyticsGoogleAppId];
return request;
}
- (NSString *)userAgentString {
return
[NSString stringWithFormat:@"%@/%@", FIRCLSApplicationGetSDKBundleID(), FIRCLSSDKVersion()];
}
- (NSString *)localeIdentifier {
return NSLocale.currentLocale.localeIdentifier;
}
@end