diff options
author | Howard Hao <hhhao@google.com> | 2022-11-23 00:18:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-11-23 00:18:15 +0000 |
commit | faa1731256a5bfd1bec3f850719cf144415f00f6 (patch) | |
tree | 72822f9845468ce3e32e3df9845437135e6e0460 /service/src/com/android/car/telemetry/publisher/ConnectivityPublisher.java | |
parent | cc430eb764b722669020e2fdc4756b289d4d3ec4 (diff) | |
parent | 3da83556dc8db0d703db8e2d7227c11c0b4c7842 (diff) | |
download | Car-faa1731256a5bfd1bec3f850719cf144415f00f6.tar.gz |
Merge "Handle NPE for query in ConnectivityPublisher." into tm-qpr-dev
Diffstat (limited to 'service/src/com/android/car/telemetry/publisher/ConnectivityPublisher.java')
-rw-r--r-- | service/src/com/android/car/telemetry/publisher/ConnectivityPublisher.java | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/service/src/com/android/car/telemetry/publisher/ConnectivityPublisher.java b/service/src/com/android/car/telemetry/publisher/ConnectivityPublisher.java index ca4ef84280..2bc7a8c3ee 100644 --- a/service/src/com/android/car/telemetry/publisher/ConnectivityPublisher.java +++ b/service/src/com/android/car/telemetry/publisher/ConnectivityPublisher.java @@ -173,7 +173,11 @@ public class ConnectivityPublisher extends AbstractPublisher { } try { for (QueryParam param : mSubscribers.keySet()) { - mTransportPreviousNetstats.put(param, getSummaryForAllUid(param)); + RefinedStats summary = getSummaryForAllUid(param); + if (summary == null) { + continue; + } + mTransportPreviousNetstats.put(param, summary); } } catch (RemoteException e) { // Can't do much if the NetworkStatsService is not available. Next netstats pull @@ -233,13 +237,17 @@ public class ConnectivityPublisher extends AbstractPublisher { RefinedStats current; try { current = getSummaryForAllUid(param); - } catch (RemoteException | NullPointerException e) { + } catch (RemoteException e) { // If the NetworkStatsService is not available, it retries in the next pull. Slogf.w(CarLog.TAG_TELEMETRY, e); mTraceLog.traceEnd(); return null; } + if (current == null) { + mTraceLog.traceEnd(); + return null; + } // By subtracting, it calculates network usage since the last pull. RefinedStats diff = RefinedStats.subtract(current, previous); @@ -260,7 +268,7 @@ public class ConnectivityPublisher extends AbstractPublisher { * * <p>TODO(b/218529196): run this method on a separate thread for better performance. */ - @NonNull + @Nullable private RefinedStats getSummaryForAllUid(@NonNull QueryParam param) throws RemoteException { if (DEBUG) { Slogf.d(CarLog.TAG_TELEMETRY, "getSummaryForAllUid " + param); @@ -273,12 +281,22 @@ public class ConnectivityPublisher extends AbstractPublisher { - elapsedMillisSinceBoot - NETSTATS_UID_DEFAULT_BUCKET_DURATION_MILLIS; - NetworkStatsWrapper nonTaggedStats = - mNetworkStatsManager.querySummary( - param.buildNetworkTemplate(), startMillis, currentTimeInMillis); - NetworkStatsWrapper taggedStats = - mNetworkStatsManager.queryTaggedSummary( - param.buildNetworkTemplate(), startMillis, currentTimeInMillis); + NetworkStatsWrapper nonTaggedStats; + NetworkStatsWrapper taggedStats; + // querySummary and queryTaggedSummary may throw NPE propagated from NetworkStatsService + // when its NetworkStatsRecorder failed to initialize and + // NetworkStatsRecorder.getOrLoadCompleteLocked() is called. + try { + nonTaggedStats = + mNetworkStatsManager.querySummary( + param.buildNetworkTemplate(), startMillis, currentTimeInMillis); + taggedStats = + mNetworkStatsManager.queryTaggedSummary( + param.buildNetworkTemplate(), startMillis, currentTimeInMillis); + } catch (NullPointerException e) { + Slogf.w(CarLog.TAG_TELEMETRY, e); + return null; + } RefinedStats result = new RefinedStats(startMillis, currentTimeInMillis); result.addNetworkStats(nonTaggedStats); |