From 8b9717c418ad3c2f5e9f069e394719c3b52c9423 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Thu, 14 Jan 2021 15:38:04 +0000 Subject: [PATCH] Introduce a shell command to obtain MLS Introduce a shell command to obtain MLS, and remove the equivalent from TimeZoneDetector. Bug: 172934905 Test: atest CtsLocationTimeZoneManagerHostTest Change-Id: I75f2a12ba435f6c297dcada061fad90915f12c26 --- .../app/timezonedetector/TimeZoneDetector.java | 6 ------ .../server/location/LocationShellCommand.java | 8 ++++++++ .../timezonedetector/TimeZoneDetectorService.java | 15 --------------- .../TimeZoneDetectorShellCommand.java | 14 -------------- 4 files changed, 8 insertions(+), 35 deletions(-) diff --git a/core/java/android/app/timezonedetector/TimeZoneDetector.java b/core/java/android/app/timezonedetector/TimeZoneDetector.java index ee718b35d4c52..b216e913b6ff8 100644 --- a/core/java/android/app/timezonedetector/TimeZoneDetector.java +++ b/core/java/android/app/timezonedetector/TimeZoneDetector.java @@ -54,12 +54,6 @@ public interface TimeZoneDetector { */ String SHELL_COMMAND_IS_GEO_DETECTION_SUPPORTED = "is_geo_detection_supported"; - /** - * A shell command that prints the current user's "location enabled" setting. - * @hide - */ - String SHELL_COMMAND_IS_LOCATION_ENABLED = "is_location_enabled"; - /** * A shell command that prints the current user's "location-based time zone detection enabled" * setting. diff --git a/services/core/java/com/android/server/location/LocationShellCommand.java b/services/core/java/com/android/server/location/LocationShellCommand.java index 0fe66e0b4ea1e..f0dd8b559d649 100644 --- a/services/core/java/com/android/server/location/LocationShellCommand.java +++ b/services/core/java/com/android/server/location/LocationShellCommand.java @@ -49,6 +49,12 @@ class LocationShellCommand extends BasicShellCommandHandler { } switch (cmd) { + case "is-location-enabled": { + int userId = parseUserId(); + boolean enabled = mService.isLocationEnabledForUser(userId); + getOutPrintWriter().println(enabled); + return 0; + } case "set-location-enabled": { int userId = parseUserId(); boolean enabled = Boolean.parseBoolean(getNextArgRequired()); @@ -238,6 +244,8 @@ class LocationShellCommand extends BasicShellCommandHandler { pw.println("Location service commands:"); pw.println(" help or -h"); pw.println(" Print this help text."); + pw.println(" is-location-enabled [--user ]"); + pw.println(" Gets the master location switch enabled state."); pw.println(" set-location-enabled [--user ] true|false"); pw.println(" Sets the master location switch enabled state."); pw.println(" providers"); diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java index d0c632350270c..2ead3bedab0f2 100644 --- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java +++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java @@ -27,7 +27,6 @@ import android.app.timezonedetector.ITimeZoneDetectorService; import android.app.timezonedetector.ManualTimeZoneSuggestion; import android.app.timezonedetector.TelephonyTimeZoneSuggestion; import android.content.Context; -import android.location.LocationManager; import android.os.Binder; import android.os.Handler; import android.os.IBinder; @@ -35,7 +34,6 @@ import android.os.RemoteException; import android.os.ResultReceiver; import android.os.ShellCallback; import android.os.SystemProperties; -import android.os.UserHandle; import android.util.ArrayMap; import android.util.IndentingPrintWriter; import android.util.Slog; @@ -335,19 +333,6 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub return isGeoLocationTimeZoneDetectionEnabled(mContext); } - boolean isLocationEnabled(@UserIdInt int userId) { - enforceManageTimeZoneDetectorPermission(); - - final long token = mCallerIdentityInjector.clearCallingIdentity(); - try { - UserHandle user = UserHandle.of(userId); - LocationManager locationManager = mContext.getSystemService(LocationManager.class); - return locationManager.isLocationEnabledForUser(user); - } finally { - mCallerIdentityInjector.restoreCallingIdentity(token); - } - } - @Override protected void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @Nullable String[] args) { diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorShellCommand.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorShellCommand.java index e965f55e49d76..8c529c42fc8ac 100644 --- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorShellCommand.java +++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorShellCommand.java @@ -18,7 +18,6 @@ package com.android.server.timezonedetector; import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED; import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_IS_GEO_DETECTION_ENABLED; import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_IS_GEO_DETECTION_SUPPORTED; -import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_IS_LOCATION_ENABLED; import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_SET_AUTO_DETECTION_ENABLED; import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_SET_GEO_DETECTION_ENABLED; import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_SUGGEST_GEO_LOCATION_TIME_ZONE; @@ -57,8 +56,6 @@ class TimeZoneDetectorShellCommand extends ShellCommand { return runSetAutoDetectionEnabled(); case SHELL_COMMAND_IS_GEO_DETECTION_SUPPORTED: return runIsGeoDetectionSupported(); - case SHELL_COMMAND_IS_LOCATION_ENABLED: - return runIsLocationEnabled(); case SHELL_COMMAND_IS_GEO_DETECTION_ENABLED: return runIsGeoDetectionEnabled(); case SHELL_COMMAND_SET_GEO_DETECTION_ENABLED: @@ -92,14 +89,6 @@ class TimeZoneDetectorShellCommand extends ShellCommand { return 0; } - private int runIsLocationEnabled() { - final PrintWriter pw = getOutPrintWriter(); - int userId = UserHandle.USER_CURRENT; - boolean enabled = mInterface.isLocationEnabled(userId); - pw.println(enabled); - return 0; - } - private int runIsGeoDetectionEnabled() { final PrintWriter pw = getOutPrintWriter(); int userId = UserHandle.USER_CURRENT; @@ -176,9 +165,6 @@ class TimeZoneDetectorShellCommand extends ShellCommand { pw.printf(" %s\n", SHELL_COMMAND_IS_GEO_DETECTION_SUPPORTED); pw.println(" Prints true/false according to whether geolocation time zone detection is" + " supported on this device"); - pw.printf(" %s\n", SHELL_COMMAND_IS_LOCATION_ENABLED); - pw.println(" Prints true/false according to whether the master location toggle is" - + " enabled for the current user"); pw.printf(" %s\n", SHELL_COMMAND_IS_GEO_DETECTION_ENABLED); pw.println(" Prints true/false according to the geolocation tz detection setting"); pw.printf(" %s true|false\n", SHELL_COMMAND_SET_GEO_DETECTION_ENABLED);