@@ -210,6 +210,39 @@ extension DownloadManager: URLSessionDelegate, URLSessionDownloadDelegate {
210210 return
211211 }
212212
213+ // Track cellular data usage
214+ let bytesReceived = task. countOfBytesReceived
215+ let isCellular = metrics. transactionMetrics. last? . isCellular ?? false
216+
217+ if bytesReceived > 0 {
218+ let autoDownloadStatus = AutoDownloadStatus ( rawValue: episode. autoDownloadStatus)
219+ let operationType : CellularDataUsageManager . OperationType
220+ switch autoDownloadStatus {
221+ case . playerDownloadedForStreaming:
222+ operationType = . stream
223+ default :
224+ operationType = . download
225+ }
226+
227+ let sessionType : CellularDataUsageManager . SessionType =
228+ session === wifiOnlyBackgroundSession ? . background :
229+ ( session === cellularBackgroundSession ? . background : . foreground)
230+
231+ let bytesDownloaded = operationType != . stream ? bytesReceived : 0
232+ let bytesStreamed = operationType == . stream ? bytesReceived : 0
233+ let connectionType : CellularDataUsageManager . ConnectionType = isCellular ? . cellular : . wifi
234+
235+ dataManager. cellularDataUsageManager. add (
236+ episodeUuid: episode. uuid,
237+ podcastUuid: episode. parentIdentifier ( ) ,
238+ bytesDownloaded: bytesDownloaded,
239+ bytesStreamed: bytesStreamed,
240+ operationType: operationType,
241+ connectionType: connectionType,
242+ sessionType: sessionType
243+ )
244+ }
245+
213246 if let failure = taskFailure [ episode. uuid] {
214247 logDownload ( episode, failure: failure, metrics: metrics, session: session)
215248 taskFailure. removeValue ( forKey: episode. uuid)
0 commit comments