Skip to content

Commit

Permalink
Merge pull request #852 from bugsnag/release-v6.2.2
Browse files Browse the repository at this point in the history
Release v6.2.2
  • Loading branch information
kstenerud authored Oct 21, 2020
2 parents 63accee + 0b07ef2 commit a6596e5
Show file tree
Hide file tree
Showing 31 changed files with 447 additions and 502 deletions.
4 changes: 2 additions & 2 deletions Bugsnag.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Bugsnag",
"version": "6.2.1",
"version": "6.2.2",
"summary": "The Bugsnag crash reporting framework for Apple platforms.",
"homepage": "https://bugsnag.com",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
},
"source": {
"git": "https://github.com/bugsnag/bugsnag-cocoa.git",
"tag": "v6.2.1"
"tag": "v6.2.2"
},
"frameworks": [
"Foundation",
Expand Down
27 changes: 24 additions & 3 deletions Bugsnag/BugsnagSystemState.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

#import <TargetConditionals.h>
#if !TARGET_OS_OSX
#if TARGET_OS_OSX
#import <AppKit/AppKit.h>
#else
#import <UIKit/UIKit.h>
#endif

Expand Down Expand Up @@ -71,7 +73,10 @@ id blankIfNil(id value) {
bool isBeingDebugged = bsg_ksmachisBeingTraced();
bool isInForeground = true;
bool isActive = true;
#if !TARGET_OS_OSX
#if TARGET_OS_OSX
// MacOS "active" serves the same purpose as "foreground" in iOS
isInForeground = [NSApplication sharedApplication].active;
#else
UIApplicationState appState = [BSG_KSSystemInfo currentAppState];
isInForeground = [BSG_KSSystemInfo isInForeground:appState];
isActive = appState == UIApplicationStateActive;
Expand All @@ -95,6 +100,8 @@ id blankIfNil(id value) {
app[BSGKeyType] = @"tvOS";
#elif BSG_PLATFORM_IOS
app[BSGKeyType] = @"iOS";
#elif BSG_PLATFORM_OSX
app[BSGKeyType] = @"macOS";
#endif
app[SYSTEMSTATE_APP_DEBUGGER_IS_ACTIVE] = @(isBeingDebugged);

Expand Down Expand Up @@ -149,9 +156,23 @@ - (instancetype)initWithConfiguration:(BugsnagConfiguration *)config {
_currentLaunchState = [_currentLaunchStateRW copy];
[self sync];

#if !TARGET_OS_OSX
__weak __typeof__(self) weakSelf = self;
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
#if TARGET_OS_OSX
[center addObserverForName:NSApplicationWillTerminateNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
[weakSelf.kvStore setBoolean:YES forKey:SYSTEMSTATE_APP_WAS_TERMINATED];
// No need to update since we are shutting down.
}];
// MacOS "active" serves the same purpose as "foreground" in iOS
[center addObserverForName:NSApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
[weakSelf.kvStore setBoolean:YES forKey:SYSTEMSTATE_APP_IS_IN_FOREGROUND];
[weakSelf bgSetAppValue:@YES forKey:SYSTEMSTATE_APP_IS_IN_FOREGROUND];
}];
[center addObserverForName:NSApplicationDidResignActiveNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
[weakSelf.kvStore setBoolean:NO forKey:SYSTEMSTATE_APP_IS_IN_FOREGROUND];
[weakSelf bgSetAppValue:@NO forKey:SYSTEMSTATE_APP_IS_IN_FOREGROUND];
}];
#else
[center addObserverForName:UIApplicationWillTerminateNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
[weakSelf.kvStore setBoolean:YES forKey:SYSTEMSTATE_APP_WAS_TERMINATED];
// No need to update since we are shutting down.
Expand Down
30 changes: 22 additions & 8 deletions Bugsnag/Helpers/BSG_RFC3339DateTool.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@

#import "BSG_RFC3339DateTool.h"

// New formatter: Everything is UTC
// New formatter: Everything is UTC with milliseconds
static NSDateFormatter *g_currentDateFormatter;

// Old formatter: Everything is UTC, no milliseconds
static NSDateFormatter *g_utcDateFormatter;

// Old formatter: Time zones can be specified
// Oldx2 formatter: Time zones can be specified
static NSDateFormatter *g_timezoneAllowedDateFormatter;

@implementation BSG_RFC3339DateTool
Expand All @@ -36,6 +39,11 @@ + (void)initialize {
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
NSTimeZone *zone = [NSTimeZone timeZoneForSecondsFromGMT:0];

g_currentDateFormatter = [NSDateFormatter new];
[g_currentDateFormatter setLocale:locale];
[g_currentDateFormatter setTimeZone:zone];
[g_currentDateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'"];

g_utcDateFormatter = [NSDateFormatter new];
[g_utcDateFormatter setLocale:locale];
[g_utcDateFormatter setTimeZone:zone];
Expand All @@ -52,19 +60,25 @@ + (NSString *)stringFromDate:(NSDate *)date {
if (![date isKindOfClass:[NSDate class]]) {
return nil;
}
return [g_utcDateFormatter stringFromDate:date];
return [g_currentDateFormatter stringFromDate:date];
}

+ (NSDate *)dateFromString:(NSString *)string {
if (![string isKindOfClass:[NSString class]]) {
return nil;
}
NSDate *date = [g_utcDateFormatter dateFromString:string];
if (!date) {
// Fallback to older date format that included time zones
date = [g_timezoneAllowedDateFormatter dateFromString:string];
NSDate *date = nil;

if((date = [g_currentDateFormatter dateFromString:string]) != nil) {
return date;
}

// Fallback to older date formats
if((date = [g_utcDateFormatter dateFromString:string]) != nil) {
return date;
}
return date;

return [g_timezoneAllowedDateFormatter dateFromString:string];
}

+ (NSString *)stringFromUNIXTimestamp:(unsigned long long)timestamp {
Expand Down
29 changes: 23 additions & 6 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#if BSG_HAS_UIKIT
#import <UIKit/UIKit.h>
#endif
#if TARGET_OS_OSX
#import <AppKit/AppKit.h>
#endif

// ============================================================================
#pragma mark - Default Constants -
Expand Down Expand Up @@ -235,8 +238,8 @@ - (BOOL)install {
return false;
}

#if BSG_HAS_UIKIT
NSNotificationCenter *nCenter = [NSNotificationCenter defaultCenter];
#if BSG_HAS_UIKIT
[nCenter addObserver:self
selector:@selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
Expand All @@ -257,6 +260,20 @@ - (BOOL)install {
selector:@selector(applicationWillTerminate)
name:UIApplicationWillTerminateNotification
object:nil];
#elif TARGET_OS_OSX
// MacOS "active" serves the same purpose as "foreground" in iOS
[nCenter addObserver:self
selector:@selector(applicationDidEnterBackground)
name:NSApplicationDidResignActiveNotification
object:nil];
[nCenter addObserver:self
selector:@selector(applicationWillEnterForeground)
name:NSApplicationDidBecomeActiveNotification
object:nil];
[nCenter addObserver:self
selector:@selector(applicationWillTerminate)
name:NSApplicationWillTerminateNotification
object:nil];
#endif

return true;
Expand Down Expand Up @@ -339,7 +356,7 @@ - (NSDictionary *)captureAppStats {
BSG_KSCrash_State state = crashContext()->state;
bsg_kscrashstate_updateDurationStats(&state);
NSMutableDictionary *dict = [NSMutableDictionary new];
BSGDictSetSafeObject(dict, @(state.activeDurationSinceLaunch), @BSG_KSCrashField_ActiveTimeSinceLaunch);
BSGDictSetSafeObject(dict, @(state.foregroundDurationSinceLaunch), @BSG_KSCrashField_ActiveTimeSinceLaunch);
BSGDictSetSafeObject(dict, @(state.backgroundDurationSinceLaunch), @BSG_KSCrashField_BGTimeSinceLaunch);
BSGDictSetSafeObject(dict, @(state.applicationIsInForeground), @BSG_KSCrashField_AppInFG);
return dict;
Expand Down Expand Up @@ -376,12 +393,12 @@ -(TYPE)NAME { \
}

BSG_SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval,
activeDurationSinceLastCrash)
foregroundDurationSinceLastCrash)
BSG_SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval,
backgroundDurationSinceLastCrash)
BSG_SYNTHESIZE_CRASH_STATE_PROPERTY(int, launchesSinceLastCrash)
BSG_SYNTHESIZE_CRASH_STATE_PROPERTY(int, sessionsSinceLastCrash)
BSG_SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, activeDurationSinceLaunch)
BSG_SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval, foregroundDurationSinceLaunch)
BSG_SYNTHESIZE_CRASH_STATE_PROPERTY(NSTimeInterval,
backgroundDurationSinceLaunch)
BSG_SYNTHESIZE_CRASH_STATE_PROPERTY(int, sessionsSinceLaunch)
Expand Down Expand Up @@ -476,11 +493,11 @@ - (const char *)encodeAsJSONString:(id)object {
// ============================================================================

- (void)applicationDidBecomeActive {
bsg_kscrashstate_notifyAppActive(true);
bsg_kscrashstate_notifyAppInForeground(true);
}

- (void)applicationWillResignActive {
bsg_kscrashstate_notifyAppActive(false);
bsg_kscrashstate_notifyAppInForeground(true);
}

- (void)applicationDidEnterBackground {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

/** Total active time elapsed since the last crash. */
@property(nonatomic, readonly, assign)
NSTimeInterval activeDurationSinceLastCrash;
NSTimeInterval foregroundDurationSinceLastCrash;

/** Total time backgrounded elapsed since the last crash. */
@property(nonatomic, readonly, assign)
Expand All @@ -51,7 +51,7 @@
@property(nonatomic, readonly, assign) int sessionsSinceLastCrash;

/** Total active time elapsed since launch. */
@property(nonatomic, readonly, assign) NSTimeInterval activeDurationSinceLaunch;
@property(nonatomic, readonly, assign) NSTimeInterval foregroundDurationSinceLaunch;

/** Total time backgrounded elapsed since launch. */
@property(nonatomic, readonly, assign)
Expand Down
1 change: 1 addition & 0 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashC.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void bsg_kscrash_reinstall(const char *const crashReportFilePath,
BSG_KSLOG_ERROR("Failed to initialize persistent crash state");
}
context->state.appLaunchTime = mach_absolute_time();
context->state.appStateTransitionTime = mach_absolute_time();
}

BSG_KSCrashType bsg_kscrash_setHandlingCrashTypes(BSG_KSCrashType crashTypes) {
Expand Down
6 changes: 2 additions & 4 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashReport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,6 @@ void bsg_kscrw_i_writeAppStats(const BSG_KSCrashReportWriter *const writer,
BSG_KSCrash_State *state) {
writer->beginObject(writer, key);
{
writer->addBooleanElement(writer, BSG_KSCrashField_AppActive,
state->applicationIsActive);
writer->addBooleanElement(writer, BSG_KSCrashField_AppInFG,
state->applicationIsInForeground);

Expand All @@ -1362,7 +1360,7 @@ void bsg_kscrw_i_writeAppStats(const BSG_KSCrashReportWriter *const writer,
state->sessionsSinceLastCrash);
writer->addFloatingPointElement(writer,
BSG_KSCrashField_ActiveTimeSinceCrash,
state->activeDurationSinceLastCrash);
state->foregroundDurationSinceLastCrash);
writer->addFloatingPointElement(
writer, BSG_KSCrashField_BGTimeSinceCrash,
state->backgroundDurationSinceLastCrash);
Expand All @@ -1371,7 +1369,7 @@ void bsg_kscrw_i_writeAppStats(const BSG_KSCrashReportWriter *const writer,
state->sessionsSinceLaunch);
writer->addFloatingPointElement(writer,
BSG_KSCrashField_ActiveTimeSinceLaunch,
state->activeDurationSinceLaunch);
state->foregroundDurationSinceLaunch);
writer->addFloatingPointElement(writer,
BSG_KSCrashField_BGTimeSinceLaunch,
state->backgroundDurationSinceLaunch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@

#define BSG_KSCrashField_ActiveTimeSinceCrash "active_time_since_last_crash"
#define BSG_KSCrashField_ActiveTimeSinceLaunch "active_time_since_launch"
#define BSG_KSCrashField_AppActive "application_active"
#define BSG_KSCrashField_AppInFG "application_in_foreground"
#define BSG_KSCrashField_BGTimeSinceCrash "background_time_since_last_crash"
#define BSG_KSCrashField_BGTimeSinceLaunch "background_time_since_launch"
Expand Down
22 changes: 7 additions & 15 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashState.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ extern "C" {
#include "BSG_KSCrashType.h"

typedef struct {

// Saved data

/** Total active time elapsed since the last crash. */
double activeDurationSinceLastCrash;
/** Total time elapsed in the foreground since the last crash. */
double foregroundDurationSinceLastCrash;

/** Total time backgrounded elapsed since the last crash. */
double backgroundDurationSinceLastCrash;
Expand All @@ -54,8 +55,8 @@ typedef struct {
/** Number of sessions (launch, resume from suspend) since last crash. */
int sessionsSinceLastCrash;

/** Total active time elapsed since launch. */
double activeDurationSinceLaunch;
/** Total time elapsed in the foreground since launch. */
double foregroundDurationSinceLaunch;

/** Total time backgrounded elapsed since launch. */
double backgroundDurationSinceLaunch;
Expand All @@ -74,13 +75,10 @@ typedef struct {
/** Timestamp for when the app was launched (mach_absolute_time()) */
uint64_t appLaunchTime;

/** Timestamp for when the app state was last changed (active<-> inactive,
* background<->foreground) (mach_absolute_time()) */
/** Timestamp for when the app state was last changed
* (background<->foreground) (mach_absolute_time()) */
uint64_t appStateTransitionTime;

/** If true, the application is currently active. */
bool applicationIsActive;

/** If true, the application is currently in the foreground. */
bool applicationIsInForeground;

Expand All @@ -96,12 +94,6 @@ typedef struct {
*/
bool bsg_kscrashstate_init(const char *stateFilePath, BSG_KSCrash_State *state);

/** Notify the crash reporter of the application active state.
*
* @param isActive true if the application is active, otherwise false.
*/
void bsg_kscrashstate_notifyAppActive(bool isActive);

/** Notify the crash reporter of the application foreground/background state.
*
* @param isInForeground true if the application is in the foreground, false if
Expand Down
Loading

0 comments on commit a6596e5

Please sign in to comment.