From 07c129cb1a0c1032c2db4f6ddf9c6e10d86781fb Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Tue, 5 May 2020 13:17:01 -0700 Subject: [PATCH] DO NOT MERGE Don't crash if already unregistered Bug: 155284432 Test: manual Change-Id: Id04ab9093b9cd4c837058442a8d0e04ff4dde051 --- .../android/location/LocationManager.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index 412b43e6a5820..a112bdd0ce03c 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -2954,10 +2954,10 @@ public class LocationManager { @Override protected void unregisterService() throws RemoteException { - Preconditions.checkState(mListenerTransport != null); - - mService.unregisterGnssStatusCallback(mListenerTransport); - mListenerTransport = null; + if (mListenerTransport != null) { + mService.unregisterGnssStatusCallback(mListenerTransport); + mListenerTransport = null; + } } private class GnssStatusListener extends IGnssStatusListener.Stub { @@ -3020,10 +3020,10 @@ public class LocationManager { @Override protected void unregisterService() throws RemoteException { - Preconditions.checkState(mListenerTransport != null); - - mService.removeGnssMeasurementsListener(mListenerTransport); - mListenerTransport = null; + if (mListenerTransport != null) { + mService.removeGnssMeasurementsListener(mListenerTransport); + mListenerTransport = null; + } } @Override @@ -3073,10 +3073,10 @@ public class LocationManager { @Override protected void unregisterService() throws RemoteException { - Preconditions.checkState(mListenerTransport != null); - - mService.removeGnssNavigationMessageListener(mListenerTransport); - mListenerTransport = null; + if (mListenerTransport != null) { + mService.removeGnssNavigationMessageListener(mListenerTransport); + mListenerTransport = null; + } } private class GnssNavigationMessageListener extends IGnssNavigationMessageListener.Stub { @@ -3114,10 +3114,10 @@ public class LocationManager { @Override protected void unregisterService() throws RemoteException { - Preconditions.checkState(mListenerTransport != null); - - mService.removeGnssAntennaInfoListener(mListenerTransport); - mListenerTransport = null; + if (mListenerTransport != null) { + mService.removeGnssAntennaInfoListener(mListenerTransport); + mListenerTransport = null; + } } private class GnssAntennaInfoListener extends IGnssAntennaInfoListener.Stub { @@ -3151,10 +3151,10 @@ public class LocationManager { @Override protected void unregisterService() throws RemoteException { - Preconditions.checkState(mListenerTransport != null); - - mService.removeGnssBatchingCallback(); - mListenerTransport = null; + if (mListenerTransport != null) { + mService.removeGnssBatchingCallback(); + mListenerTransport = null; + } } private class BatchedLocationCallback extends IBatchedLocationCallback.Stub {