Skip to content

Commit

Permalink
Merge pull request microsoft#1262 from Microsoft/develop
Browse files Browse the repository at this point in the history
PR to merge develop to master for SDK December release
  • Loading branch information
guperrot authored Dec 11, 2018
2 parents 1509924 + 7c9627b commit 97ea791
Show file tree
Hide file tree
Showing 136 changed files with 3,148 additions and 1,068 deletions.
2 changes: 1 addition & 1 deletion AppCenter.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AppCenter'
s.version = '1.11.0'
s.version = '1.12.0'

s.summary = 'Visual Studio App Center is your continuous integration, delivery and learning solution for iOS and macOS apps.'
s.description = <<-DESC
Expand Down
88 changes: 84 additions & 4 deletions AppCenter/AppCenter.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
* @discussion The default maximum database size is 10485760 bytes (10 MiB).
*
* @param sizeInBytes Maximum size of the internal storage in bytes. This will be rounded up to the nearest multiple of a SQLite page size
* (default is 4096 bytes). Values below 20480 bytes (20 KiB) will be ignored.
* (default is 4096 bytes). Values below 24576 bytes (24 KiB) will be ignored.
* @param completionHandler Callback that is invoked when the database size has been set. The `BOOL` parameter is `YES` if changing the size
* is successful, and `NO` otherwise.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import "MSDeviceTracker.h"
#import "MSIngestionProtocol.h"
#import "MSStorage.h"
#import "MSUserIdContext.h"
#import "MSUtility+StringFormatting.h"

@implementation MSChannelUnitDefault
Expand Down
22 changes: 0 additions & 22 deletions AppCenter/AppCenter/Internals/Device/MSDeviceHistoryInfo.h

This file was deleted.

23 changes: 23 additions & 0 deletions AppCenter/AppCenter/Internals/History/Device/MSDeviceHistoryInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#import "MSHistoryInfo.h"

@class MSDevice;

/**
* Model class that correlates MSDevice to a crash at app relaunch.
*/
@interface MSDeviceHistoryInfo : MSHistoryInfo

/**
* Instance of MSDevice.
*/
@property(nonatomic) MSDevice *device;

/**
* Initializes a new `MSDeviceHistoryInfo` instance.
*
* @param timestamp Timestamp.
* @param device Device instance.
*/
- (instancetype)initWithTimestamp:(NSDate *)timestamp andDevice:(MSDevice *)device;

@end
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#import "MSDeviceHistoryInfo.h"

static NSString *const kMSDeviceKey = @"deviceKey";
static NSString *const kMSTimestampKey = @"timestampKey";

/**
* This class is used to associate device properties with the timestamp that it was created with.
*/
@implementation MSDeviceHistoryInfo

- (instancetype)initWithTimestamp:(NSDate *)timestamp andDevice:(MSDevice *)device {
if ((self = [super init])) {
_timestamp = timestamp;
self = [super initWithTimestamp:timestamp];
if (self) {
_device = device;
}
return self;
Expand All @@ -16,17 +18,15 @@ - (instancetype)initWithTimestamp:(NSDate *)timestamp andDevice:(MSDevice *)devi
#pragma mark - NSCoding

- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super init];
self = [super initWithCoder:coder];
if (self) {
self.timestamp = [coder decodeObjectForKey:kMSTimestampKey];
self.device = [coder decodeObjectForKey:kMSDeviceKey];
}

return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:self.timestamp forKey:kMSTimestampKey];
[super encodeWithCoder:coder];
[coder encodeObject:self.device forKey:kMSDeviceKey];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
*/
+ (instancetype)sharedInstance;

/**
* Clears the device history in memory and in NSUserDefaults as well as the current device.
*/
- (void)clearDevices;

@end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "MSDeviceTracker.h"
#import "MSConstants+Internal.h"
#import "MSDeviceHistoryInfo.h"
#import "MSDeviceTracker.h"
#import "MSDeviceTrackerPrivate.h"
#import "MSUserDefaults.h"
#import "MSUtility+Application.h"
Expand All @@ -22,17 +22,26 @@ @implementation MSDeviceTracker : NSObject
static BOOL needRefresh = YES;
static MSWrapperSdk *wrapperSdkInformation = nil;

/**
* Singleton.
*/
static dispatch_once_t onceToken;
static MSDeviceTracker *sharedInstance = nil;

#pragma mark - Initialisation

+ (instancetype)sharedInstance {
static MSDeviceTracker *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[MSDeviceTracker alloc] init];
});
return sharedInstance;
}

+ (void)resetSharedInstance {
onceToken = 0;
sharedInstance = nil;
}

- (instancetype)init {
if ((self = [super init])) {

Expand Down Expand Up @@ -87,11 +96,11 @@ - (MSDevice *)device {

// Insert new MSDeviceHistoryInfo at the proper index to keep self.deviceHistory sorted.
NSUInteger newIndex = [self.deviceHistory indexOfObject:deviceHistoryInfo
inSortedRange:(NSRange) { 0, [self.deviceHistory count] }
options:NSBinarySearchingInsertionIndex
usingComparator:^(MSDeviceHistoryInfo *a, MSDeviceHistoryInfo *b) {
return [a.timestamp compare:b.timestamp];
}];
inSortedRange:(NSRange){0, [self.deviceHistory count]}
options:NSBinarySearchingInsertionIndex
usingComparator:^(MSDeviceHistoryInfo *a, MSDeviceHistoryInfo *b) {
return [a.timestamp compare:b.timestamp];
}];
[self.deviceHistory insertObject:deviceHistoryInfo atIndex:newIndex];

// Remove first (the oldest) item if reached max limit.
Expand All @@ -111,9 +120,37 @@ - (MSDevice *)device {
*/
- (MSDevice *)updatedDevice {
@synchronized(self) {
MSDevice *newDevice = [[MSDevice alloc] init];
MSDevice *newDevice = [MSDevice new];
#if TARGET_OS_IOS
CTCarrier *carrier = [[[CTTelephonyNetworkInfo alloc] init] subscriberCellularProvider];
CTTelephonyNetworkInfo *telephonyNetworkInfo = [CTTelephonyNetworkInfo new];
CTCarrier *carrier;

// TODO Use @available API and availability attribute when deprecating Xcode 8.
SEL serviceSubscriberCellularProviders = NSSelectorFromString(@"serviceSubscriberCellularProviders");
if ([telephonyNetworkInfo respondsToSelector:serviceSubscriberCellularProviders]) {

// Call serviceSubscriberCellularProviders.
NSInvocation *invocation =
[NSInvocation invocationWithMethodSignature:[telephonyNetworkInfo methodSignatureForSelector:serviceSubscriberCellularProviders]];
[invocation setSelector:serviceSubscriberCellularProviders];
[invocation setTarget:telephonyNetworkInfo];
[invocation invoke];
void *returnValue;
[invocation getReturnValue:&returnValue];
NSDictionary<NSString *, CTCarrier *> *carriers = (__bridge NSDictionary<NSString *, CTCarrier *> *)returnValue;
for (NSString *key in carriers) {
carrier = carriers[key];
break;
}
}

// Use the old API as fallback if new one doesn't work.
if (carrier == nil) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
carrier = [telephonyNetworkInfo subscriberCellularProvider];
#pragma clang diagnostic pop
}
#endif

// Collect device properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ static NSString *const kMSPastDevicesKey = @"pastDevicesKey";
@property(nonatomic) NSMutableArray<MSDeviceHistoryInfo *> *deviceHistory;

/**
* Sets a flag that will cause MSDeviceTracker to update it's device info the next time the device property is accessed. Mostly intended for
* Unit Testing.
* Reset singleton instance.
*/
+ (void)refreshDeviceNextTime;
+ (void)resetSharedInstance;

/**
* Clears the device history in memory and in NSUserDefaults as well as the current device.
* Sets a flag that will cause MSDeviceTracker to update it's device info the next time the device property is accessed. Mostly intended for
* Unit Testing.
*/
- (void)clearDevices;
+ (void)refreshDeviceNextTime;

/**
* Get device model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Get session Id at specific time.
*
* @param date The timestamp for the ssession.
* @param date The timestamp for the session.
*
* @return The session Id at the given time.
*/
- (nullable NSString *)sessionIdAt:(NSDate *)date;

/**
* Clear all session Id history.
*
* @param keepCurrentSession YES to keep current session, NO to delete every entry.
*/
- (void)clearSessionHistory;
- (void)clearSessionHistoryAndKeepCurrentSession:(BOOL)keepCurrentSession;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#import "MSUtility.h"

/**
* Base URL for HTTP Ingestion backend API calls.
* Storage key for history data.
*/
static NSString *const kMSSessionIdHistoryKey = @"SessionIdHistory";

Expand Down Expand Up @@ -75,10 +75,12 @@ - (nullable NSString *)sessionIdAt:(NSDate *)date {
}
}

- (void)clearSessionHistory {
- (void)clearSessionHistoryAndKeepCurrentSession:(BOOL)keepCurrentSession {
@synchronized(self) {
[self.sessionHistory removeAllObjects];
[self.sessionHistory addObject:self.currentSessionInfo];
if (keepCurrentSession) {
[self.sessionHistory addObject:self.currentSessionInfo];
}
[MS_USER_DEFAULTS setObject:[NSKeyedArchiver archivedDataWithRootObject:self.sessionHistory] forKey:kMSSessionIdHistoryKey];
MSLogVerbose([MSAppCenter logTag], @"Cleared old sessions.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#import <Foundation/Foundation.h>

@interface MSSessionHistoryInfo : NSObject <NSCoding>
#import "MSHistoryInfo.h"

/**
* Initializes a new `MSSessionHistoryInfo` instance.
*
* @param timestamp Timestamp
* @param sessionId Session Id
* Model class that is intended to be used to correlate sessionId to a crash at app relaunch.
*/
- (instancetype)initWithTimestamp:(NSDate *)timestamp andSessionId:(NSString *)sessionId;
@interface MSSessionHistoryInfo : MSHistoryInfo

/**
* Session Id.
*/
@property(nonatomic, copy) NSString *sessionId;

/**
* Timestamp.
* Initializes a new `MSSessionHistoryInfo` instance.
*
* @param timestamp Timestamp.
* @param sessionId Session Id.
*/
@property(nonatomic) NSDate *timestamp;
- (instancetype)initWithTimestamp:(NSDate *)timestamp andSessionId:(NSString *)sessionId;

@end
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
#import "MSSessionHistoryInfo.h"

static NSString *const kMSSessionIdKey = @"sessionIdKey";
static NSString *const kMSTimestampKey = @"timestampKey";

/**
* This class is used to associate session id with the timestamp that it was created.
*/
@implementation MSSessionHistoryInfo

- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super init];
- (instancetype)initWithTimestamp:(NSDate *)timestamp andSessionId:(NSString *)sessionId {
self = [super initWithTimestamp:timestamp];
if (self) {
_sessionId = [coder decodeObjectForKey:kMSSessionIdKey];
_timestamp = [coder decodeObjectForKey:kMSTimestampKey];
_sessionId = sessionId;
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:self.sessionId forKey:kMSSessionIdKey];
[coder encodeObject:self.timestamp forKey:kMSTimestampKey];
}
#pragma mark - NSCoding

- (instancetype)initWithTimestamp:(NSDate *)timestamp andSessionId:(NSString *)sessionId {
self = [super init];
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
_sessionId = sessionId;
_timestamp = timestamp;
_sessionId = [coder decodeObjectForKey:kMSSessionIdKey];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder:coder];
[coder encodeObject:self.sessionId forKey:kMSSessionIdKey];
}

@end
Loading

0 comments on commit 97ea791

Please sign in to comment.