22
22
import android .net .wifi .WifiManager ;
23
23
import android .os .BatteryStats ;
24
24
import android .os .Bundle ;
25
+ import android .os .OutcomeReceiver ;
25
26
import android .os .Parcelable ;
26
27
import android .os .Process ;
27
28
import android .os .ServiceManager ;
40
41
import com .android .internal .util .FrameworkStatsLog ;
41
42
import com .android .internal .util .function .pooled .PooledLambda ;
42
43
44
+ import java .util .concurrent .ExecutionException ;
43
45
import libcore .util .EmptyArray ;
44
46
45
47
import java .util .concurrent .CompletableFuture ;
@@ -405,7 +407,7 @@ private void updateExternalStatsLocked(final String reason, int updateFlags,
405
407
// We will request data from external processes asynchronously, and wait on a timeout.
406
408
SynchronousResultReceiver wifiReceiver = null ;
407
409
SynchronousResultReceiver bluetoothReceiver = null ;
408
- SynchronousResultReceiver modemReceiver = null ;
410
+ CompletableFuture < ModemActivityInfo > modemFuture = CompletableFuture . completedFuture ( null ) ;
409
411
boolean railUpdated = false ;
410
412
411
413
if ((updateFlags & BatteryStatsImpl .ExternalStatsSync .UPDATE_WIFI ) != 0 ) {
@@ -460,8 +462,22 @@ public void execute(Runnable runnable) {
460
462
}
461
463
462
464
if (mTelephony != null ) {
463
- modemReceiver = new SynchronousResultReceiver ("telephony" );
464
- mTelephony .requestModemActivityInfo (modemReceiver );
465
+ CompletableFuture <ModemActivityInfo > temp = new CompletableFuture <>();
466
+ mTelephony .requestModemActivityInfo (Runnable ::run ,
467
+ new OutcomeReceiver <ModemActivityInfo ,
468
+ TelephonyManager .ModemActivityInfoException >() {
469
+ @ Override
470
+ public void onResult (ModemActivityInfo result ) {
471
+ temp .complete (result );
472
+ }
473
+
474
+ @ Override
475
+ public void onError (TelephonyManager .ModemActivityInfoException e ) {
476
+ Slog .w (TAG , "error reading modem stats:" + e );
477
+ temp .complete (null );
478
+ }
479
+ });
480
+ modemFuture = temp ;
465
481
}
466
482
if (!railUpdated ) {
467
483
synchronized (mStats ) {
@@ -472,7 +488,17 @@ public void execute(Runnable runnable) {
472
488
473
489
final WifiActivityEnergyInfo wifiInfo = awaitControllerInfo (wifiReceiver );
474
490
final BluetoothActivityEnergyInfo bluetoothInfo = awaitControllerInfo (bluetoothReceiver );
475
- final ModemActivityInfo modemInfo = awaitControllerInfo (modemReceiver );
491
+ ModemActivityInfo modemInfo = null ;
492
+ try {
493
+ modemInfo = modemFuture .get (EXTERNAL_STATS_SYNC_TIMEOUT_MILLIS ,
494
+ TimeUnit .MILLISECONDS );
495
+ } catch (TimeoutException | InterruptedException e ) {
496
+ Slog .w (TAG , "timeout or interrupt reading modem stats: " + e );
497
+ } catch (ExecutionException e ) {
498
+ Slog .w (TAG , "exception reading modem stats: " + e .getCause ());
499
+ }
500
+ final long elapsedRealtime = SystemClock .elapsedRealtime ();
501
+ final long uptime = SystemClock .uptimeMillis ();
476
502
477
503
synchronized (mStats ) {
478
504
mStats .addHistoryEventLocked (
@@ -519,11 +545,7 @@ public void execute(Runnable runnable) {
519
545
}
520
546
521
547
if (modemInfo != null ) {
522
- if (modemInfo .isValid ()) {
523
- mStats .updateMobileRadioState (modemInfo );
524
- } else {
525
- Slog .w (TAG , "modem info is invalid: " + modemInfo );
526
- }
548
+ mStats .updateMobileRadioState (modemInfo );
527
549
}
528
550
}
529
551
0 commit comments