From 9d02a125fbc7825a7e47d97fe33e5513d5252427 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Wed, 7 Apr 2021 20:29:50 +0100 Subject: [PATCH] Fix state dumping when service stopped Avoid a NullPointerException. Bug: 178169250 Test: Command line testing Change-Id: If01e31fc72c3284dacef8735fd997a7783faf6e0 --- .../location/LocationTimeZoneManagerService.java | 7 +++++-- .../location/LocationTimeZoneManagerShellCommand.java | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerService.java b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerService.java index ca4a6408cfbb5..6719695bc0e73 100644 --- a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerService.java +++ b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerService.java @@ -437,8 +437,11 @@ public class LocationTimeZoneManagerService extends Binder { }, BLOCKING_OP_WAIT_DURATION_MILLIS); } - /** Returns a snapshot of the current controller state for tests. */ - @NonNull + /** + * Returns a snapshot of the current controller state for tests. Returns {@code null} if the + * service is stopped. + */ + @Nullable LocationTimeZoneManagerServiceState getStateForTests() { enforceManageTimeZoneDetectorPermission(); diff --git a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerShellCommand.java b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerShellCommand.java index bdf4a70a6a2bb..40638080004c5 100644 --- a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerShellCommand.java +++ b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerShellCommand.java @@ -217,6 +217,11 @@ class LocationTimeZoneManagerShellCommand extends ShellCommand { return 1; } + if (state == null) { + // Controller is stopped. + return 0; + } + DualDumpOutputStream outputStream; boolean useProto = Objects.equals(DUMP_STATE_OPTION_PROTO, getNextOption()); if (useProto) {