@@ -163,8 +163,6 @@ def upload_handler(end_event: threading.Event) -> None:
163
163
sm = messaging .SubMaster (['deviceState' ])
164
164
tid = threading .get_ident ()
165
165
166
- cellular_unmetered = Params ().get_bool ("CellularUnmetered" )
167
-
168
166
while not end_event .is_set ():
169
167
cur_upload_items [tid ] = None
170
168
@@ -181,46 +179,45 @@ def upload_handler(end_event: threading.Event) -> None:
181
179
cloudlog .event ("athena.upload_handler.expired" , item = cur_upload_items [tid ], error = True )
182
180
continue
183
181
184
- # Check if uploading over cell is allowed
182
+ # Check if uploading over metered connection is allowed
185
183
sm .update (0 )
186
- cell = sm ['deviceState' ].networkType not in [NetworkType .wifi , NetworkType .ethernet ]
187
- if cell and (not cur_upload_items [tid ].allow_cellular ) and (not cellular_unmetered ):
184
+ metered = sm ['deviceState' ].networkMetered
185
+ network_type = sm ['deviceState' ].networkType .raw
186
+ if metered and (not cur_upload_items [tid ].allow_cellular ):
188
187
retry_upload (tid , end_event , False )
189
188
continue
190
189
191
190
try :
192
191
def cb (sz , cur ):
193
- # Abort transfer if connection changed to cell after starting upload
192
+ # Abort transfer if connection changed to metered after starting upload
194
193
sm .update (0 )
195
- cell = sm ['deviceState' ].networkType not in [ NetworkType . wifi , NetworkType . ethernet ]
196
- if cell and (not cur_upload_items [tid ].allow_cellular ) and ( not cellular_unmetered ):
194
+ metered = sm ['deviceState' ].networkMetered
195
+ if metered and (not cur_upload_items [tid ].allow_cellular ):
197
196
raise AbortTransferException
198
197
199
198
cur_upload_items [tid ] = cur_upload_items [tid ]._replace (progress = cur / sz if sz else 1 )
200
199
201
-
202
- network_type = sm ['deviceState' ].networkType .raw
203
200
fn = cur_upload_items [tid ].path
204
201
try :
205
202
sz = os .path .getsize (fn )
206
203
except OSError :
207
204
sz = - 1
208
205
209
- cloudlog .event ("athena.upload_handler.upload_start" , fn = fn , sz = sz , network_type = network_type )
206
+ cloudlog .event ("athena.upload_handler.upload_start" , fn = fn , sz = sz , network_type = network_type , metered = metered )
210
207
response = _do_upload (cur_upload_items [tid ], cb )
211
208
212
209
if response .status_code not in (200 , 201 , 403 , 412 ):
213
- cloudlog .event ("athena.upload_handler.retry" , status_code = response .status_code , fn = fn , sz = sz , network_type = network_type )
210
+ cloudlog .event ("athena.upload_handler.retry" , status_code = response .status_code , fn = fn , sz = sz , network_type = network_type , metered = metered )
214
211
retry_upload (tid , end_event )
215
212
else :
216
- cloudlog .event ("athena.upload_handler.success" , fn = fn , sz = sz , network_type = network_type )
213
+ cloudlog .event ("athena.upload_handler.success" , fn = fn , sz = sz , network_type = network_type , metered = metered )
217
214
218
215
UploadQueueCache .cache (upload_queue )
219
216
except (requests .exceptions .Timeout , requests .exceptions .ConnectionError , requests .exceptions .SSLError ):
220
- cloudlog .event ("athena.upload_handler.timeout" , fn = fn , sz = sz , network_type = network_type )
217
+ cloudlog .event ("athena.upload_handler.timeout" , fn = fn , sz = sz , network_type = network_type , metered = metered )
221
218
retry_upload (tid , end_event )
222
219
except AbortTransferException :
223
- cloudlog .event ("athena.upload_handler.abort" , fn = fn , sz = sz , network_type = network_type )
220
+ cloudlog .event ("athena.upload_handler.abort" , fn = fn , sz = sz , network_type = network_type , metered = metered )
224
221
retry_upload (tid , end_event , False )
225
222
226
223
except queue .Empty :
@@ -459,6 +456,12 @@ def getNetworkType():
459
456
return HARDWARE .get_network_type ()
460
457
461
458
459
+ @dispatcher .add_method
460
+ def getNetworkMetered ():
461
+ network_type = HARDWARE .get_network_type ()
462
+ return HARDWARE .get_network_metered (network_type )
463
+
464
+
462
465
@dispatcher .add_method
463
466
def getNetworks ():
464
467
return HARDWARE .get_networks ()
0 commit comments