aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2021-05-20 12:02:50 +0100
committerNeil Fuller <nfuller@google.com>2021-05-20 12:22:43 +0100
commitf4fd8221d759328f78ed483a6909a0ca712d3ec0 (patch)
treed142aad4a31b290ddf6f98c5abb0cf5d84bbd7ee
parentcd940eb49421b45d32b582daa8a23472185dbf75 (diff)
downloadGeoTZ-f4fd8221d759328f78ed483a6909a0ca712d3ec0.tar.gz
Stop an IllegalStateException in rare conditions
Bug fixed by inspection after a single report in production. Because there are multiple threads involved, but the OfflineLocationTimeZoneDelegate is single threaded, there's probably a race after location listening is stopped when the delivery of a location can still occur (i.e. one that has been blocked while the delegate was transitioning into the stopped state). This removes the IllegalStateException throw. All callers to the method have a return statement immediately afterwards, so this won't significantly alter behavior, just prevent the exception being thrown. Test: atest OfflineLocationTimeZoneProviderTests Test: build / boot Bug: 188743586 Change-Id: I75ebe7a1847fd30fe6defa73b50fa1e25b9c1f24
-rw-r--r--locationtzprovider/src/main/java/com/android/timezone/location/provider/core/OfflineLocationTimeZoneDelegate.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/locationtzprovider/src/main/java/com/android/timezone/location/provider/core/OfflineLocationTimeZoneDelegate.java b/locationtzprovider/src/main/java/com/android/timezone/location/provider/core/OfflineLocationTimeZoneDelegate.java
index 56d6c39..1bfb202 100644
--- a/locationtzprovider/src/main/java/com/android/timezone/location/provider/core/OfflineLocationTimeZoneDelegate.java
+++ b/locationtzprovider/src/main/java/com/android/timezone/location/provider/core/OfflineLocationTimeZoneDelegate.java
@@ -301,7 +301,7 @@ public final class OfflineLocationTimeZoneDelegate {
String unexpectedStateDebugInfo = "Unexpected call to onActiveListeningResult(),"
+ " activeListeningResult=" + activeListeningResult
+ ", currentMode=" + currentMode;
- handleUnexpectedCallback(unexpectedStateDebugInfo);
+ handleUnexpectedLocationCallback(unexpectedStateDebugInfo);
return;
}
@@ -343,7 +343,7 @@ public final class OfflineLocationTimeZoneDelegate {
String unexpectedStateDebugInfo = "Unexpected call to onPassiveListeningResult(),"
+ " passiveListeningResult=" + passiveListeningResult
+ ", currentMode=" + currentMode;
- handleUnexpectedCallback(unexpectedStateDebugInfo);
+ handleUnexpectedLocationCallback(unexpectedStateDebugInfo);
return;
}
logDebug("onPassiveListeningResult()"
@@ -416,7 +416,7 @@ public final class OfflineLocationTimeZoneDelegate {
Mode currentMode = mCurrentMode.get();
if (currentMode.mModeEnum != MODE_STARTED
|| currentMode.mListenMode != LOCATION_LISTEN_MODE_PASSIVE) {
- handleUnexpectedCallback("Unexpected call to onPassiveListeningEnded()"
+ handleUnexpectedLocationCallback("Unexpected call to onPassiveListeningEnded()"
+ ", currentMode=" + currentMode);
return;
}
@@ -555,10 +555,11 @@ public final class OfflineLocationTimeZoneDelegate {
}
@GuardedBy("mLock")
- private void handleUnexpectedCallback(@NonNull String debugInfo) {
- // To help track down unexpected behavior, this fails hard.
- logWarn(debugInfo);
- throw new IllegalStateException(debugInfo);
+ private void handleUnexpectedLocationCallback(@NonNull String debugInfo) {
+ // Unexpected location callbacks can occur when location listening is cancelled, but a
+ // location is already available (e.g. the callback is already invoked but blocked or
+ // sitting in a handler queue). This is logged but generally ignored.
+ logDebug(debugInfo);
}
@GuardedBy("mLock")