From 140ee33e15766de9687b77adbb0671c4f545228d Mon Sep 17 00:00:00 2001 From: Quang Luong Date: Tue, 10 Mar 2020 00:04:23 -0700 Subject: [WifiTrackerLib] Fix NPE when refreshing link properties Add a null check when referencing link properties due to a race condition where a connected WifiEntry receives a link properties changed callback that is null. Bug: 148752497 Test: atest WifiTrackerLibTests Change-Id: I86d6d1c48b2945e111f66122bd9ace91dd63db12 --- libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libs') diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java index ff230e76c..221829312 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java @@ -304,6 +304,10 @@ public abstract class WifiEntry implements Comparable { * Returns null if getConnectedState() != CONNECTED_STATE_CONNECTED. */ public ConnectedInfo getConnectedInfo() { + if (getConnectedState() != CONNECTED_STATE_CONNECTED) { + return null; + } + return mConnectedInfo; } @@ -585,7 +589,9 @@ public abstract class WifiEntry implements Comparable { // Method for WifiTracker to update the link properties, which is valid for all WifiEntry types. @WorkerThread void updateLinkProperties(@Nullable LinkProperties linkProperties) { - if (getConnectedState() != CONNECTED_STATE_CONNECTED) { + if (linkProperties == null || getConnectedState() != CONNECTED_STATE_CONNECTED) { + mConnectedInfo = null; + notifyOnUpdated(); return; } -- cgit v1.2.3