Prevent NPE on race condition
There could be a race condition where there is a dispatch to mCallback after it's been nulled, due to the dispatch happening not on the same thread. Check if the callback has been nulled. Fixes: 287421329 Test: build Change-Id: Idaa0c106ff034ea55b08bf4230565aa3cae6f6a8
This commit is contained in:
@@ -173,6 +173,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
||||
private AccessPointController mAccessPointController;
|
||||
private IntentFilter mConnectionStateFilter;
|
||||
@VisibleForTesting
|
||||
@Nullable
|
||||
InternetDialogCallback mCallback;
|
||||
private UiEventLogger mUiEventLogger;
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
@@ -730,7 +731,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
||||
ActivityLaunchAnimator.Controller controller =
|
||||
mDialogLaunchAnimator.createActivityLaunchController(view);
|
||||
|
||||
if (controller == null) {
|
||||
if (controller == null && mCallback != null) {
|
||||
mCallback.dismissDialog();
|
||||
}
|
||||
|
||||
@@ -1101,7 +1102,9 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
||||
mHasWifiEntries = false;
|
||||
}
|
||||
|
||||
mCallback.onAccessPointsChanged(wifiEntries, connectedEntry, hasMoreWifiEntries);
|
||||
if (mCallback != null) {
|
||||
mCallback.onAccessPointsChanged(wifiEntries, connectedEntry, hasMoreWifiEntries);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1123,34 +1126,46 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
||||
|
||||
@Override
|
||||
public void onServiceStateChanged(@NonNull ServiceState serviceState) {
|
||||
mCallback.onServiceStateChanged(serviceState);
|
||||
if (mCallback != null) {
|
||||
mCallback.onServiceStateChanged(serviceState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataConnectionStateChanged(int state, int networkType) {
|
||||
mCallback.onDataConnectionStateChanged(state, networkType);
|
||||
if (mCallback != null) {
|
||||
mCallback.onDataConnectionStateChanged(state, networkType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSignalStrengthsChanged(@NonNull SignalStrength signalStrength) {
|
||||
mCallback.onSignalStrengthsChanged(signalStrength);
|
||||
if (mCallback != null) {
|
||||
mCallback.onSignalStrengthsChanged(signalStrength);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayInfoChanged(@NonNull TelephonyDisplayInfo telephonyDisplayInfo) {
|
||||
mSubIdTelephonyDisplayInfoMap.put(mSubId, telephonyDisplayInfo);
|
||||
mCallback.onDisplayInfoChanged(telephonyDisplayInfo);
|
||||
if (mCallback != null) {
|
||||
mCallback.onDisplayInfoChanged(telephonyDisplayInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserMobileDataStateChanged(boolean enabled) {
|
||||
mCallback.onUserMobileDataStateChanged(enabled);
|
||||
if (mCallback != null) {
|
||||
mCallback.onUserMobileDataStateChanged(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCarrierNetworkChange(boolean active) {
|
||||
mCarrierNetworkChangeMode = active;
|
||||
mCallback.onCarrierNetworkChange(active);
|
||||
if (mCallback != null) {
|
||||
mCallback.onCarrierNetworkChange(active);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1177,14 +1192,18 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
||||
scanWifiAccessPoints();
|
||||
}
|
||||
// update UI
|
||||
mCallback.onCapabilitiesChanged(network, capabilities);
|
||||
if (mCallback != null) {
|
||||
mCallback.onCapabilitiesChanged(network, capabilities);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@WorkerThread
|
||||
public void onLost(@NonNull Network network) {
|
||||
mHasEthernet = false;
|
||||
mCallback.onLost(network);
|
||||
if (mCallback != null) {
|
||||
mCallback.onLost(network);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user