修改pods

This commit is contained in:
2025-09-20 17:13:38 +08:00
parent 7787b3ee30
commit 28ff2b0264
5251 changed files with 345029 additions and 285168 deletions

View File

@@ -0,0 +1,28 @@
// Copyright 2024 Google LLC
//
// 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 "GoogleDataTransport/GDTCCTLibrary/Private/GDTCCTURLSessionDataResponse.h"
@implementation GDTCCTURLSessionDataResponse
- (instancetype)initWithResponse:(NSHTTPURLResponse *)response HTTPBody:(NSData *)body {
self = [super init];
if (self) {
_HTTPResponse = response;
_HTTPBody = body;
}
return self;
}
@end

View File

@@ -34,10 +34,9 @@
#import <nanopb/pb_decode.h>
#import <nanopb/pb_encode.h>
#import <GoogleUtilities/GULURLSessionDataResponse.h>
#import <GoogleUtilities/NSURLSession+GULPromises.h>
#import "GoogleDataTransport/GDTCCTLibrary/Private/GDTCCTCompressionHelper.h"
#import "GoogleDataTransport/GDTCCTLibrary/Private/GDTCCTNanopbHelpers.h"
#import "GoogleDataTransport/GDTCCTLibrary/Private/GDTCCTURLSessionDataResponse.h"
#import "GoogleDataTransport/GDTCCTLibrary/Private/GDTCOREvent+GDTMetricsSupport.h"
#import "GoogleDataTransport/GDTCCTLibrary/Protogen/nanopb/cct.nanopb.h"
@@ -227,7 +226,7 @@ typedef void (^GDTCCTUploaderEventBatchBlock)(NSNumber *_Nullable batchID,
// 1. Send URL request.
return [self sendURLRequestWithBatch:batch target:target]
.thenOn(self.uploaderQueue,
^FBLPromise *(GULURLSessionDataResponse *response) {
^FBLPromise *(GDTCCTURLSessionDataResponse *response) {
// 2. Update the next upload time and process response.
[self updateNextUploadTimeWithResponse:response forTarget:target];
@@ -246,7 +245,7 @@ typedef void (^GDTCCTUploaderEventBatchBlock)(NSNumber *_Nullable batchID,
}
/** Processes a URL session response for a given batch from storage. */
- (FBLPromise<NSNull *> *)processResponse:(GULURLSessionDataResponse *)response
- (FBLPromise<NSNull *> *)processResponse:(GDTCCTURLSessionDataResponse *)response
forBatch:(GDTCORUploadBatch *)batch
storage:(id<GDTCORStoragePromiseProtocol>)storage {
// Cleanup batch based on the response's status code.
@@ -286,8 +285,8 @@ typedef void (^GDTCCTUploaderEventBatchBlock)(NSNumber *_Nullable batchID,
}
/** Composes and sends URL request. */
- (FBLPromise<GULURLSessionDataResponse *> *)sendURLRequestWithBatch:(GDTCORUploadBatch *)batch
target:(GDTCORTarget)target {
- (FBLPromise<GDTCCTURLSessionDataResponse *> *)sendURLRequestWithBatch:(GDTCORUploadBatch *)batch
target:(GDTCORTarget)target {
return [FBLPromise
onQueue:self.uploaderQueue
do:^NSURLRequest * {
@@ -307,13 +306,28 @@ typedef void (^GDTCCTUploaderEventBatchBlock)(NSNumber *_Nullable batchID,
return request;
}]
.thenOn(self.uploaderQueue,
^FBLPromise<GULURLSessionDataResponse *> *(NSURLRequest *request) {
^FBLPromise<GDTCCTURLSessionDataResponse *> *(NSURLRequest *request) {
// 2. Send URL request.
return
[[self uploaderSessionCreateIfNeeded] gul_dataTaskPromiseWithRequest:request];
NSURLSession *session = [self uploaderSessionCreateIfNeeded];
return [FBLPromise wrapObjectOrErrorCompletion:^(
FBLPromiseObjectOrErrorCompletion _Nonnull handler) {
[[session dataTaskWithRequest:request
completionHandler:^(NSData *_Nullable data,
NSURLResponse *_Nullable response,
NSError *_Nullable error) {
if (error) {
handler(nil, error);
} else {
handler([[GDTCCTURLSessionDataResponse alloc]
initWithResponse:(NSHTTPURLResponse *)response
HTTPBody:data],
nil);
}
}] resume];
}];
})
.thenOn(self.uploaderQueue,
^GULURLSessionDataResponse *(GULURLSessionDataResponse *response) {
^GDTCCTURLSessionDataResponse *(GDTCCTURLSessionDataResponse *response) {
// Invalidate session to release the delegate (which is `self`) to break the retain
// cycle.
[self.uploaderSession finishTasksAndInvalidate];
@@ -328,7 +342,7 @@ typedef void (^GDTCCTUploaderEventBatchBlock)(NSNumber *_Nullable batchID,
}
/** Parses server response and update next upload time for the specified target based on it. */
- (void)updateNextUploadTimeWithResponse:(GULURLSessionDataResponse *)response
- (void)updateNextUploadTimeWithResponse:(GDTCCTURLSessionDataResponse *)response
forTarget:(GDTCORTarget)target {
GDTCORClock *futureUploadTime;
if (response.HTTPBody) {
@@ -633,6 +647,22 @@ typedef void (^GDTCCTUploaderEventBatchBlock)(NSNumber *_Nullable batchID,
}
}
#pragma mark - Force Category Linking
extern void GDTCCTInclude_GDTCOREvent_GDTCCTSupport_Category(void);
extern void GDTCCTInclude_GDTCOREvent_GDTMetricsSupport_Category(void);
extern void GDTCCTInclude_GDTCORLogSourceMetrics_Internal_Category(void);
/// Does nothing when called, and not meant to be called.
///
/// This method forces the linker to include categories even if
/// users do not include the '-ObjC' linker flag in their project.
+ (void)noop {
GDTCCTInclude_GDTCOREvent_GDTCCTSupport_Category();
GDTCCTInclude_GDTCOREvent_GDTMetricsSupport_Category();
GDTCCTInclude_GDTCORLogSourceMetrics_Internal_Category();
}
@end
NS_ASSUME_NONNULL_END

View File

@@ -238,3 +238,7 @@ NSString *const GDTCCTEventCodeInfo = @"event_code_info";
}
@end
/// Stub used to force the linker to include the categories in this file.
void GDTCCTInclude_GDTCOREvent_GDTCCTSupport_Category(void) {
}

View File

@@ -31,3 +31,7 @@ static NSString *const kMetricEventMappingID = @"1710";
}
@end
/// Stub used to force the linker to include the categories in this file.
void GDTCCTInclude_GDTCOREvent_GDTMetricsSupport_Category(void) {
}

View File

@@ -205,3 +205,7 @@ gdt_client_metrics_LogEventDropped_Reason GDTCCTConvertEventDropReasonToProtoRea
}
@end
/// Stub used to force the linker to include the categories in this file.
void GDTCCTInclude_GDTCORLogSourceMetrics_Internal_Category(void) {
}

View File

@@ -0,0 +1,29 @@
// Copyright 2024 Google LLC
//
// 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>
NS_ASSUME_NONNULL_BEGIN
/** The class represents HTTP response received from `NSURLSession`. */
@interface GDTCCTURLSessionDataResponse : NSObject
@property(nonatomic, readonly) NSHTTPURLResponse *HTTPResponse;
@property(nonatomic, nullable, readonly) NSData *HTTPBody;
- (instancetype)initWithResponse:(NSHTTPURLResponse *)response HTTPBody:(nullable NSData *)body;
@end
NS_ASSUME_NONNULL_END

View File

@@ -36,8 +36,6 @@
// difficult to unit test.
/** Returns the kernel boottime property from sysctl.
*
* Inspired by https://stackoverflow.com/a/40497811
*
* @return The KERN_BOOTTIME property from sysctl, in nanoseconds.
*/
@@ -54,8 +52,6 @@ static int64_t KernelBootTimeInNanoseconds(void) {
}
/** Returns value of gettimeofday, in nanoseconds.
*
* Inspired by https://stackoverflow.com/a/40497811
*
* @return The value of gettimeofday, in nanoseconds.
*/

View File

@@ -155,3 +155,7 @@
}
@end
/// Stub used to force the linker to include the categories in this file.
void GDTCORInclude_GDTCORLogSourceMetrics_Internal_Category(void) {
}

View File

@@ -51,8 +51,8 @@ typedef NSDictionary<NSNumber *, NSNumber *> GDTCORDroppedEventCounter;
// Get the dropped event counter for the event's mapping ID (log source).
// If the dropped event counter for this event's mapping ID is `nil`,
// an empty mutable counter is returned.
NSMutableDictionary<NSNumber *, NSNumber *> *eventCounter =
[NSMutableDictionary dictionaryWithDictionary:eventCounterByLogSource[event.mappingID]];
NSMutableDictionary<NSNumber *, NSNumber *> *eventCounter = [NSMutableDictionary
dictionaryWithDictionary:eventCounterByLogSource[event.mappingID] ?: @{}];
// Increment the log source metrics for the given reason.
NSInteger currentEventCountForReason = [eventCounter[@(reason)] integerValue];

View File

@@ -129,19 +129,13 @@ GDTCORNetworkMobileSubtype GDTCORNetworkMobileSubTypeMessage(void) {
if (networkCurrentRadioAccessTechnologyDict.count) {
networkCurrentRadioAccessTechnology = networkCurrentRadioAccessTechnologyDict.allValues[0];
}
#else // TARGET_OS_MACCATALYST
if (@available(iOS 12.0, *)) {
NSDictionary<NSString *, NSString *> *networkCurrentRadioAccessTechnologyDict =
networkInfo.serviceCurrentRadioAccessTechnology;
if (networkCurrentRadioAccessTechnologyDict.count) {
// In iOS 12, multiple radio technologies can be captured. We prefer not particular radio
// tech to another, so we'll just return the first value in the dictionary.
networkCurrentRadioAccessTechnology = networkCurrentRadioAccessTechnologyDict.allValues[0];
}
} else {
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED < 120000
networkCurrentRadioAccessTechnology = networkInfo.currentRadioAccessTechnology;
#endif // TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED < 120000
#else // TARGET_OS_MACCATALYST
NSDictionary<NSString *, NSString *> *networkCurrentRadioAccessTechnologyDict =
networkInfo.serviceCurrentRadioAccessTechnology;
if (networkCurrentRadioAccessTechnologyDict.count) {
// In iOS 12, multiple radio technologies can be captured. We prefer not particular radio
// tech to another, so we'll just return the first value in the dictionary.
networkCurrentRadioAccessTechnology = networkCurrentRadioAccessTechnologyDict.allValues[0];
}
#endif // TARGET_OS_MACCATALYST
if (networkCurrentRadioAccessTechnology) {
@@ -197,50 +191,23 @@ NSData *_Nullable GDTCOREncodeArchive(id<NSSecureCoding> obj,
}
}
NSData *resultData;
if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4, *)) {
resultData = [NSKeyedArchiver archivedDataWithRootObject:obj
requiringSecureCoding:YES
error:error];
if (resultData == nil || (error != NULL && *error != nil)) {
GDTCORLogDebug(@"Encoding an object failed: %@", *error);
return nil;
}
if (filePath.length > 0) {
result = [resultData writeToFile:filePath options:NSDataWritingAtomic error:error];
if (result == NO || (error != NULL && *error != nil)) {
if (error != NULL && *error != nil) {
GDTCORLogDebug(@"Attempt to write archive failed: path:%@ error:%@", filePath, *error);
} else {
GDTCORLogDebug(@"Attempt to write archive failed: path:%@", filePath);
}
resultData = [NSKeyedArchiver archivedDataWithRootObject:obj
requiringSecureCoding:YES
error:error];
if (resultData == nil || (error != NULL && *error != nil)) {
GDTCORLogDebug(@"Encoding an object failed: %@", *error);
return nil;
}
if (filePath.length > 0) {
result = [resultData writeToFile:filePath options:NSDataWritingAtomic error:error];
if (result == NO || (error != NULL && *error != nil)) {
if (error != NULL && *error != nil) {
GDTCORLogDebug(@"Attempt to write archive failed: path:%@ error:%@", filePath, *error);
} else {
GDTCORLogDebug(@"Writing archive succeeded: %@", filePath);
GDTCORLogDebug(@"Attempt to write archive failed: path:%@", filePath);
}
}
} else {
@try {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
resultData = [NSKeyedArchiver archivedDataWithRootObject:obj];
#pragma clang diagnostic pop
if (filePath.length > 0) {
result = [resultData writeToFile:filePath options:NSDataWritingAtomic error:error];
if (result == NO || *error) {
GDTCORLogDebug(@"Attempt to write archive failed: URL:%@ error:%@", filePath, *error);
} else {
GDTCORLogDebug(@"Writing archive succeeded: %@", filePath);
}
}
} @catch (NSException *exception) {
NSString *errorString =
[NSString stringWithFormat:@"An exception was thrown during encoding: %@", exception];
*error = [NSError errorWithDomain:NSCocoaErrorDomain
code:-1
userInfo:@{NSLocalizedFailureReasonErrorKey : errorString}];
}
if (filePath.length > 0) {
GDTCORLogDebug(@"Attempt to write archive. successful:%@ URL:%@ error:%@",
result ? @"YES" : @"NO", filePath, *error);
} else {
GDTCORLogDebug(@"Writing archive succeeded: %@", filePath);
}
}
return resultData;
@@ -261,26 +228,7 @@ id<NSSecureCoding> _Nullable GDTCORDecodeArchiveAtPath(Class archiveClass,
id<NSSecureCoding> _Nullable GDTCORDecodeArchive(Class archiveClass,
NSData *_Nonnull archiveData,
NSError **_Nonnull error) {
id<NSSecureCoding> unarchivedObject = nil;
if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4, *)) {
unarchivedObject = [NSKeyedUnarchiver unarchivedObjectOfClass:archiveClass
fromData:archiveData
error:error];
} else {
@try {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
unarchivedObject = [NSKeyedUnarchiver unarchiveObjectWithData:archiveData];
#pragma clang diagnostic pop
} @catch (NSException *exception) {
NSString *errorString =
[NSString stringWithFormat:@"An exception was thrown during encoding: %@", exception];
*error = [NSError errorWithDomain:NSCocoaErrorDomain
code:-1
userInfo:@{NSLocalizedFailureReasonErrorKey : errorString}];
}
}
return unarchivedObject;
return [NSKeyedUnarchiver unarchivedObjectOfClass:archiveClass fromData:archiveData error:error];
}
BOOL GDTCORWriteDataToFile(NSData *data, NSString *filePath, NSError *_Nullable *outError) {

View File

@@ -93,4 +93,16 @@
onComplete:completion];
}
#pragma mark - Force Category Linking
extern void GDTCORInclude_GDTCORLogSourceMetrics_Internal_Category(void);
/// Does nothing when called, and not meant to be called.
///
/// This method forces the linker to include categories even if
/// users do not include the '-ObjC' linker flag in their project.
+ (void)noop {
GDTCORInclude_GDTCORLogSourceMetrics_Internal_Category();
}
@end

View File

@@ -36,7 +36,7 @@ After the CI is green:
<summary>Push to <b>SpecsStaging</b></summary>
```console
pod repo push --skip-tests staging GoogleDataTransport.podspec
pod repo push --skip-tests --use-json staging GoogleDataTransport.podspec
```
If the command fails with `Unable to find the 'staging' repo.`, add the staging repo with:
@@ -49,7 +49,7 @@ After the CI is green:
<summary>Push to <b>SpecsDev</b></summary>
```console
pod repo push --skip-tests dev GoogleDataTransport.podspec
pod repo push --skip-tests --use-json dev GoogleDataTransport.podspec
```
If the command fails with `Unable to find the 'dev' repo.`, add the dev repo with:
@@ -94,7 +94,7 @@ The release process is as follows:
> before proceeding.
```console
pod trunk push ~/.cocoapods/repos/staging/GoogleDataTransport/{version}/GoogleDataTransport.podspec --skip-tests
pod trunk push ~/.cocoapods/repos/staging/GoogleDataTransport/{version}/GoogleDataTransport.podspec.json --skip-tests
```
The pod push was successful if the above command logs: `🚀 GoogleDataTransport ({version}) successfully published`.
@@ -214,7 +214,7 @@ GitHub Actions will verify that any code changes are done in a style compliant
way. Install `clang-format` and `mint`:
```console
brew install clang-format@17
brew install clang-format@18
brew install mint
```