Skip to content

Commit

Permalink
Merge branch 'fix/arithmetic_overflow_watchos' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nsagnett committed Feb 3, 2021
2 parents 132d5c7 + 0584f77 commit 221490e
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion ATInternet-Apple-SDK-AppExtension.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ATInternet-Apple-SDK-AppExtension"
s.version = '2.22.2'
s.version = '2.22.3'
s.summary = "AT Internet mobile analytics solution for Apple devices"
s.homepage = "https://github.com/at-internet/atinternet-apple-sdk"
s.documentation_url = 'https://developers.atinternet-solutions.com/apple-en/getting-started-apple-en/operating-principle-apple-en/'
Expand Down
2 changes: 1 addition & 1 deletion ATInternet-Apple-SDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ATInternet-Apple-SDK"
s.version = '2.22.2'
s.version = '2.22.3'
s.summary = "AT Internet mobile analytics solution for Apple devices"
s.homepage = "https://github.com/at-internet/atinternet-apple-sdk"
s.documentation_url = 'https://developers.atinternet-solutions.com/apple-en/getting-started-apple-en/operating-principle-apple-en/'
Expand Down
54 changes: 27 additions & 27 deletions ATInternetTracker/Sources/AVMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class AVMedia: RequiredPropertiesDataObject {
fileprivate var currentCursorPositionMillis: Int = 0
fileprivate var eventDurationMillis: Int = 0
fileprivate var sessionDurationMillis: Int = 0
fileprivate var startSessionTimeMillis: Int = 0
fileprivate var bufferTimeMillis: Int = 0
fileprivate var startSessionTimeMillis: Int64 = 0
fileprivate var bufferTimeMillis: Int64 = 0
fileprivate var heartbeatDurations: [Int:Int] = [Int:Int]()
fileprivate var bufferHeartbeatDurations: [Int:Int] = [Int:Int]()

Expand Down Expand Up @@ -82,7 +82,7 @@ public class AVMedia: RequiredPropertiesDataObject {
heartbeat(cursorPosition: -1, extraProps: nil)

if self.autoHeartbeat {
let diffMin = (Int(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis) / 60000
let diffMin = Int((Int64(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis) / 60000)
if let duration = self.heartbeatDurations[diffMin] {
heartbeatTimer = Timer.scheduledTimer(timeInterval: TimeInterval(duration), target: self, selector: #selector(self.processAutoHeartbeat), userInfo: nil, repeats: false)
} else {
Expand Down Expand Up @@ -232,7 +232,7 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc public func heartbeat(cursorPosition: Int, extraProps: [String : Any]?) {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()

Expand All @@ -249,7 +249,7 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc public func bufferHeartbeat(extraProps: [String : Any]?) {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()

Expand All @@ -259,7 +259,7 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc public func rebufferHeartbeat(extraProps: [String : Any]?) {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()

Expand All @@ -271,7 +271,7 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc public func play(cursorPosition: Int, extraProps: [String : Any]?) {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.eventDurationMillis = 0

Expand All @@ -291,7 +291,7 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc public func bufferStart(cursorPosition: Int, extraProps: [String : Any]?) {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()
self.previousCursorPositionMillis = self.currentCursorPositionMillis
Expand All @@ -301,8 +301,8 @@ public class AVMedia: RequiredPropertiesDataObject {

if self.isPlaybackStartAlreadyCalled {
if self.autoBufferHeartbeat {
self.bufferTimeMillis = self.bufferTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.bufferTimeMillis
let diffMin = (Int(Date().timeIntervalSince1970 * 1000) - self.bufferTimeMillis) / 60000
self.bufferTimeMillis = self.bufferTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.bufferTimeMillis
let diffMin = Int((Int64(Date().timeIntervalSince1970 * 1000) - self.bufferTimeMillis) / 60000)
if let duration = self.bufferHeartbeatDurations[diffMin] {
heartbeatTimer = Timer.scheduledTimer(timeInterval: TimeInterval(duration), target: self, selector: #selector(self.processAutoRebufferHeartbeat), userInfo: nil, repeats: false)
} else {
Expand All @@ -312,8 +312,8 @@ public class AVMedia: RequiredPropertiesDataObject {
sendEvents(events: createEvent(name: "av.rebuffer.start", withOptions: true, extraProps: extraProps))
} else {
if self.autoBufferHeartbeat {
self.bufferTimeMillis = self.bufferTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.bufferTimeMillis
let diffMin = (Int(Date().timeIntervalSince1970 * 1000) - self.bufferTimeMillis) / 60000
self.bufferTimeMillis = self.bufferTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.bufferTimeMillis
let diffMin = Int((Int64(Date().timeIntervalSince1970 * 1000) - self.bufferTimeMillis) / 60000)
if let duration = self.bufferHeartbeatDurations[diffMin] {
heartbeatTimer = Timer.scheduledTimer(timeInterval: TimeInterval(duration), target: self, selector: #selector(self.processAutoBufferHeartbeat), userInfo: nil, repeats: false)
} else {
Expand All @@ -327,7 +327,7 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc public func playbackStart(cursorPosition: Int, extraProps: [String : Any]?) {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()

Expand All @@ -341,7 +341,7 @@ public class AVMedia: RequiredPropertiesDataObject {

stopHeartbeatTimer()
if self.autoHeartbeat {
let diffMin = (Int(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis) / 60000
let diffMin = Int((Int64(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis) / 60000)
if let duration = self.heartbeatDurations[diffMin] {
heartbeatTimer = Timer.scheduledTimer(timeInterval: TimeInterval(duration), target: self, selector: #selector(self.processAutoHeartbeat), userInfo: nil, repeats: false)
} else {
Expand All @@ -354,7 +354,7 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc public func playbackResumed(cursorPosition: Int, extraProps: [String : Any]?) {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()
self.previousCursorPositionMillis = self.currentCursorPositionMillis
Expand All @@ -366,7 +366,7 @@ public class AVMedia: RequiredPropertiesDataObject {

stopHeartbeatTimer()
if self.autoHeartbeat {
let diffMin = (Int(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis) / 60000
let diffMin = Int((Int64(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis) / 60000)
if let duration = self.heartbeatDurations[diffMin] {
heartbeatTimer = Timer.scheduledTimer(timeInterval: TimeInterval(duration), target: self, selector: #selector(self.processAutoHeartbeat), userInfo: nil, repeats: false)
} else {
Expand All @@ -379,7 +379,7 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc public func playbackPaused(cursorPosition: Int, extraProps: [String : Any]?) {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()
self.previousCursorPositionMillis = self.currentCursorPositionMillis
Expand All @@ -396,7 +396,7 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc public func playbackStopped(cursorPosition: Int, extraProps: [String : Any]?) {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()
self.previousCursorPositionMillis = self.currentCursorPositionMillis
Expand Down Expand Up @@ -528,14 +528,14 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc func processAutoHeartbeat() {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()

self.previousCursorPositionMillis = self.currentCursorPositionMillis
self.currentCursorPositionMillis += Int(Double(self.eventDurationMillis) * self._playbackSpeed)

let diffMin = (Int(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis) / 60000
let diffMin = Int((Int64(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis) / 60000)
if let duration = self.heartbeatDurations[diffMin] {
heartbeatTimer = Timer.scheduledTimer(timeInterval: TimeInterval(duration), target: self, selector: #selector(self.processAutoHeartbeat), userInfo: nil, repeats: false)
} else {
Expand All @@ -547,12 +547,12 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc func processAutoBufferHeartbeat() {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()

self.bufferTimeMillis = self.bufferTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.bufferTimeMillis
let diffMin = (Int(Date().timeIntervalSince1970 * 1000) - self.bufferTimeMillis) / 60000
self.bufferTimeMillis = self.bufferTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.bufferTimeMillis
let diffMin = Int((Int64(Date().timeIntervalSince1970 * 1000) - self.bufferTimeMillis) / 60000)
if let duration = self.bufferHeartbeatDurations[diffMin] {
heartbeatTimer = Timer.scheduledTimer(timeInterval: TimeInterval(duration), target: self, selector: #selector(self.processAutoBufferHeartbeat), userInfo: nil, repeats: false)
} else {
Expand All @@ -564,14 +564,14 @@ public class AVMedia: RequiredPropertiesDataObject {

@objc func processAutoRebufferHeartbeat() {
self.avSynchronizer.sync {
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis
self.startSessionTimeMillis = self.startSessionTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.startSessionTimeMillis

self.updateDuration()

self.previousCursorPositionMillis = self.currentCursorPositionMillis

self.bufferTimeMillis = self.bufferTimeMillis == 0 ? Int(Date().timeIntervalSince1970 * 1000) : self.bufferTimeMillis
let diffMin = (Int(Date().timeIntervalSince1970 * 1000) - self.bufferTimeMillis) / 60000
self.bufferTimeMillis = self.bufferTimeMillis == 0 ? Int64(Date().timeIntervalSince1970 * 1000) : self.bufferTimeMillis
let diffMin = Int((Int64(Date().timeIntervalSince1970 * 1000) - self.bufferTimeMillis) / 60000)
if let duration = self.bufferHeartbeatDurations[diffMin] {
heartbeatTimer = Timer.scheduledTimer(timeInterval: TimeInterval(duration), target: self, selector: #selector(self.processAutoRebufferHeartbeat), userInfo: nil, repeats: false)
} else {
Expand Down Expand Up @@ -604,7 +604,7 @@ public class AVMedia: RequiredPropertiesDataObject {
}

private func updateDuration() {
self.eventDurationMillis = Int(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis - self.sessionDurationMillis
self.eventDurationMillis = Int(Int64(Date().timeIntervalSince1970 * 1000) - self.startSessionTimeMillis) - self.sessionDurationMillis
self.sessionDurationMillis += self.eventDurationMillis
}

Expand Down
2 changes: 1 addition & 1 deletion ATInternetTracker/Sources/Info-iOS-Extension.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.22.2</string>
<string>2.22.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion ATInternetTracker/Sources/Info-iOS.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.22.2</string>
<string>2.22.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion ATInternetTracker/Sources/Info-tvOS.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.19.2</string>
<string>1.19.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion ATInternetTracker/Sources/Info-watchOS.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.19.2</string>
<string>1.19.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
13 changes: 7 additions & 6 deletions ATInternetTracker/Sources/Privacy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class Privacy: NSObject {
userDefaults.removeObject(forKey: IdentifiedVisitorHelperKey.category.rawValue)
}
userDefaults.setValue(visitorMode.rawValue, forKey: PrivacyModeKey)
userDefaults.setValue((Int(Date().timeIntervalSince1970) * 1000) + (duration * 86400000), forKey: PrivacyModeExpirationTimestampKey)
userDefaults.setValue(Int64(Date().timeIntervalSince1970 * 1000) + Int64(duration * 86400000), forKey: PrivacyModeExpirationTimestampKey)
userDefaults.synchronize()
}

Expand All @@ -105,11 +105,12 @@ public class Privacy: NSObject {
*/
public class func getVisitorMode() -> VisitorMode {
let userDefaults = UserDefaults.standard
let privacyModeExpirationTs = userDefaults.integer(forKey: PrivacyModeExpirationTimestampKey)
if ((Int(Date().timeIntervalSince1970) * 1000) >= privacyModeExpirationTs) {
userDefaults.setValue(VisitorMode.none.rawValue, forKey: PrivacyModeKey)
userDefaults.setValue(-1, forKey: PrivacyModeExpirationTimestampKey)
userDefaults.synchronize()
if let privacyModeExpirationTs = userDefaults.object(forKey: PrivacyModeExpirationTimestampKey) as? Int64 {
if (Int64(Date().timeIntervalSince1970 * 1000) >= privacyModeExpirationTs) {
userDefaults.setValue(VisitorMode.none.rawValue, forKey: PrivacyModeKey)
userDefaults.setValue(-1, forKey: PrivacyModeExpirationTimestampKey)
userDefaults.synchronize()
}
}
return VisitorMode.init(rawValue: userDefaults.string(forKey: PrivacyModeKey) ?? VisitorMode.none.rawValue) ?? VisitorMode.none
}
Expand Down
2 changes: 1 addition & 1 deletion ATInternetTracker/Sources/Sender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Sender: Operation {
// Si le hit provient du stockage et que l'envoi a réussi, on le supprime de la base
if(self.hit.isOffline) {
OfflineHit.sentWithSuccess = true
_ = db.delete(self.hit.url)
_ = db.delete(self.hit.id)
}

self.tracker.delegate?.sendDidEnd?(HitStatus.success, message: self.hit.url)
Expand Down
4 changes: 2 additions & 2 deletions ATInternetTracker/Sources/TechnicalContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class TechnicalContext: NSObject {
class var sdkVersion: String {
get {
#if os(watchOS) || os(tvOS)
return "1.19.2"
return "1.19.3"
#else
return "2.22.2"
return "2.22.3"
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion ATInternetTracker/Tests/Info-iOS.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>2.22.2</string>
<string>2.22.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit 221490e

Please sign in to comment.