Move "API" constants to API classes
Shell commands are a form of API even if they cannot be accessed from host test code. Put them on the android.app classes accordingly (but hidden). Bug: 172934905 Test: build / treehugger only Change-Id: I083d75f391206273d585c6d1155af70dab25940d
This commit is contained in:
123
core/java/android/app/time/LocationTimeZoneManager.java
Normal file
123
core/java/android/app/time/LocationTimeZoneManager.java
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.app.time;
|
||||
|
||||
/**
|
||||
* Constants related to the LocationTimeZoneManager service that are used by shell commands and
|
||||
* tests.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class LocationTimeZoneManager {
|
||||
|
||||
/**
|
||||
* The name of the primary location time zone provider, used for shell commands.
|
||||
*/
|
||||
public static final String PRIMARY_PROVIDER_NAME = "primary";
|
||||
|
||||
/**
|
||||
* The name of the secondary location time zone provider, used for shell commands.
|
||||
*/
|
||||
public static final String SECONDARY_PROVIDER_NAME = "secondary";
|
||||
|
||||
/**
|
||||
* The name of the service for shell commands
|
||||
*/
|
||||
public static final String SHELL_COMMAND_SERVICE_NAME = "location_time_zone_manager";
|
||||
|
||||
/**
|
||||
* Shell command that starts the service (after stop).
|
||||
*/
|
||||
public static final String SHELL_COMMAND_START = "start";
|
||||
|
||||
/**
|
||||
* Shell command that stops the service.
|
||||
*/
|
||||
public static final String SHELL_COMMAND_STOP = "stop";
|
||||
|
||||
/**
|
||||
* Shell command that sends test commands to a provider
|
||||
*/
|
||||
public static final String SHELL_COMMAND_SEND_PROVIDER_TEST_COMMAND =
|
||||
"send_provider_test_command";
|
||||
|
||||
/**
|
||||
* Simulated provider test command that simulates the bind succeeding.
|
||||
*/
|
||||
public static final String SIMULATED_PROVIDER_TEST_COMMAND_ON_BIND = "on_bind";
|
||||
|
||||
/**
|
||||
* Simulated provider test command that simulates the provider unbinding.
|
||||
*/
|
||||
public static final String SIMULATED_PROVIDER_TEST_COMMAND_ON_UNBIND = "on_unbind";
|
||||
|
||||
/**
|
||||
* Simulated provider test command that simulates the provider entering the "permanent failure"
|
||||
* state.
|
||||
*/
|
||||
public static final String SIMULATED_PROVIDER_TEST_COMMAND_PERM_FAILURE = "perm_fail";
|
||||
|
||||
/**
|
||||
* Simulated provider test command that simulates the provider entering the "success" (time
|
||||
* zone(s) detected) state.
|
||||
*/
|
||||
public static final String SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS = "success";
|
||||
|
||||
/**
|
||||
* Argument for {@link #SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS} to specify TZDB time zone IDs.
|
||||
*/
|
||||
public static final String SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS_ARG_KEY_TZ = "tz";
|
||||
|
||||
/**
|
||||
* Simulated provider test command that simulates the provider entering the "uncertain"
|
||||
* state.
|
||||
*/
|
||||
public static final String SIMULATED_PROVIDER_TEST_COMMAND_UNCERTAIN = "uncertain";
|
||||
|
||||
private static final String SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_PREFIX =
|
||||
"persist.sys.geotz.";
|
||||
|
||||
/**
|
||||
* The name of the system property that can be used to set the primary provider into test mode
|
||||
* (value = {@link #SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_SIMULATED}) or disabled (value = {@link
|
||||
* #SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_DISABLED}).
|
||||
*/
|
||||
public static final String SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_PRIMARY =
|
||||
SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_PREFIX + PRIMARY_PROVIDER_NAME;
|
||||
|
||||
/**
|
||||
* The name of the system property that can be used to set the secondary provider into test mode
|
||||
* (value = {@link #SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_SIMULATED}) or disabled (value = {@link
|
||||
* #SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_DISABLED}).
|
||||
*/
|
||||
public static final String SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_SECONDARY =
|
||||
SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_PREFIX + SECONDARY_PROVIDER_NAME;
|
||||
|
||||
/**
|
||||
* The value of the provider mode system property to put a provider into test mode.
|
||||
*/
|
||||
public static final String SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_SIMULATED = "simulated";
|
||||
|
||||
/**
|
||||
* The value of the provider mode system property to put a provider into disabled mode.
|
||||
*/
|
||||
public static final String SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_DISABLED = "disabled";
|
||||
|
||||
private LocationTimeZoneManager() {
|
||||
// No need to instantiate.
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,13 @@ import android.content.Context;
|
||||
@SystemService(Context.TIME_ZONE_DETECTOR_SERVICE)
|
||||
public interface TimeZoneDetector {
|
||||
|
||||
/** @hide */
|
||||
String SHELL_COMMAND_SUGGEST_GEO_LOCATION_TIME_ZONE = "suggest_geo_location_time_zone";
|
||||
/** @hide */
|
||||
String SHELL_COMMAND_SUGGEST_MANUAL_TIME_ZONE = "suggest_manual_time_zone";
|
||||
/** @hide */
|
||||
String SHELL_COMMAND_SUGGEST_TELEPHONY_TIME_ZONE = "suggest_telephony_time_zone";
|
||||
|
||||
/**
|
||||
* A shared utility method to create a {@link ManualTimeZoneSuggestion}.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
|
||||
package com.android.server.location.timezone;
|
||||
|
||||
import static android.app.time.LocationTimeZoneManager.PRIMARY_PROVIDER_NAME;
|
||||
import static android.app.time.LocationTimeZoneManager.SECONDARY_PROVIDER_NAME;
|
||||
import static android.app.time.LocationTimeZoneManager.SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_PRIMARY;
|
||||
import static android.app.time.LocationTimeZoneManager.SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_SECONDARY;
|
||||
import static android.app.time.LocationTimeZoneManager.SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_DISABLED;
|
||||
import static android.app.time.LocationTimeZoneManager.SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_SIMULATED;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
@@ -119,13 +126,6 @@ public class LocationTimeZoneManagerService extends Binder {
|
||||
|
||||
static final String TAG = "LocationTZDetector";
|
||||
|
||||
static final String PRIMARY_PROVIDER_NAME = "primary";
|
||||
static final String SECONDARY_PROVIDER_NAME = "secondary";
|
||||
|
||||
static final String PROVIDER_MODE_OVERRIDE_SYSTEM_PROPERTY_PREFIX = "persist.sys.geotz.";
|
||||
static final String PROVIDER_MODE_SIMULATED = "simulated";
|
||||
static final String PROVIDER_MODE_DISABLED = "disabled";
|
||||
|
||||
private static final long BLOCKING_OP_WAIT_DURATION_MILLIS = Duration.ofSeconds(20).toMillis();
|
||||
|
||||
private static final String ATTRIBUTION_TAG = "LocationTimeZoneService";
|
||||
@@ -269,13 +269,15 @@ public class LocationTimeZoneManagerService extends Binder {
|
||||
|
||||
/** Used for bug triage and in tests to simulate provider events. */
|
||||
private static boolean isInSimulationMode(String providerName) {
|
||||
return isProviderModeSetInSystemProperties(providerName, PROVIDER_MODE_SIMULATED);
|
||||
return isProviderModeSetInSystemProperties(providerName,
|
||||
SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_SIMULATED);
|
||||
}
|
||||
|
||||
/** Used for bug triage, tests and experiments to remove a provider. */
|
||||
private boolean isDisabled(String providerName) {
|
||||
return !isProviderEnabledInConfig(providerName)
|
||||
|| isProviderModeSetInSystemProperties(providerName, PROVIDER_MODE_DISABLED);
|
||||
|| isProviderModeSetInSystemProperties(
|
||||
providerName, SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_DISABLED);
|
||||
}
|
||||
|
||||
private boolean isProviderEnabledInConfig(String providerName) {
|
||||
@@ -299,8 +301,22 @@ public class LocationTimeZoneManagerService extends Binder {
|
||||
|
||||
private static boolean isProviderModeSetInSystemProperties(
|
||||
@NonNull String providerName, @NonNull String mode) {
|
||||
String systemPropertyProviderMode = SystemProperties.get(
|
||||
PROVIDER_MODE_OVERRIDE_SYSTEM_PROPERTY_PREFIX + providerName, null);
|
||||
String systemPropertyKey;
|
||||
switch (providerName) {
|
||||
case PRIMARY_PROVIDER_NAME: {
|
||||
systemPropertyKey = SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_PRIMARY;
|
||||
break;
|
||||
}
|
||||
case SECONDARY_PROVIDER_NAME: {
|
||||
systemPropertyKey = SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_SECONDARY;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new IllegalArgumentException(providerName);
|
||||
}
|
||||
}
|
||||
|
||||
String systemPropertyProviderMode = SystemProperties.get(systemPropertyKey, null);
|
||||
return Objects.equals(systemPropertyProviderMode, mode);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,15 @@
|
||||
*/
|
||||
package com.android.server.location.timezone;
|
||||
|
||||
import static com.android.server.location.timezone.LocationTimeZoneManagerService.PRIMARY_PROVIDER_NAME;
|
||||
import static com.android.server.location.timezone.LocationTimeZoneManagerService.SECONDARY_PROVIDER_NAME;
|
||||
import static android.app.time.LocationTimeZoneManager.PRIMARY_PROVIDER_NAME;
|
||||
import static android.app.time.LocationTimeZoneManager.SECONDARY_PROVIDER_NAME;
|
||||
import static android.app.time.LocationTimeZoneManager.SHELL_COMMAND_SEND_PROVIDER_TEST_COMMAND;
|
||||
import static android.app.time.LocationTimeZoneManager.SHELL_COMMAND_START;
|
||||
import static android.app.time.LocationTimeZoneManager.SHELL_COMMAND_STOP;
|
||||
import static android.app.time.LocationTimeZoneManager.SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_PRIMARY;
|
||||
import static android.app.time.LocationTimeZoneManager.SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_SECONDARY;
|
||||
import static android.app.time.LocationTimeZoneManager.SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_DISABLED;
|
||||
import static android.app.time.LocationTimeZoneManager.SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_SIMULATED;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.os.Bundle;
|
||||
@@ -32,10 +39,6 @@ class LocationTimeZoneManagerShellCommand extends ShellCommand {
|
||||
private static final List<String> VALID_PROVIDER_NAMES =
|
||||
Arrays.asList(PRIMARY_PROVIDER_NAME, SECONDARY_PROVIDER_NAME);
|
||||
|
||||
private static final String CMD_START = "start";
|
||||
private static final String CMD_STOP = "stop";
|
||||
private static final String CMD_SEND_PROVIDER_TEST_COMMAND = "send_provider_test_command";
|
||||
|
||||
private final LocationTimeZoneManagerService mService;
|
||||
|
||||
LocationTimeZoneManagerShellCommand(LocationTimeZoneManagerService service) {
|
||||
@@ -49,13 +52,13 @@ class LocationTimeZoneManagerShellCommand extends ShellCommand {
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case CMD_START: {
|
||||
case SHELL_COMMAND_START: {
|
||||
return runStart();
|
||||
}
|
||||
case CMD_STOP: {
|
||||
case SHELL_COMMAND_STOP: {
|
||||
return runStop();
|
||||
}
|
||||
case CMD_SEND_PROVIDER_TEST_COMMAND: {
|
||||
case SHELL_COMMAND_SEND_PROVIDER_TEST_COMMAND: {
|
||||
return runSendProviderTestCommand();
|
||||
}
|
||||
default: {
|
||||
@@ -70,15 +73,15 @@ class LocationTimeZoneManagerShellCommand extends ShellCommand {
|
||||
pw.println("Location Time Zone Manager (location_time_zone_manager) commands:");
|
||||
pw.println(" help");
|
||||
pw.println(" Print this help text.");
|
||||
pw.printf(" %s\n", CMD_START);
|
||||
pw.printf(" %s\n", SHELL_COMMAND_START);
|
||||
pw.println(" Starts the location_time_zone_manager, creating time zone providers.");
|
||||
pw.printf(" %s\n", CMD_STOP);
|
||||
pw.printf(" %s\n", SHELL_COMMAND_STOP);
|
||||
pw.println(" Stops the location_time_zone_manager, destroying time zone providers.");
|
||||
pw.printf(" %s <provider name> <test command>\n",
|
||||
CMD_SEND_PROVIDER_TEST_COMMAND);
|
||||
SHELL_COMMAND_SEND_PROVIDER_TEST_COMMAND);
|
||||
pw.println(" Passes a test command to the named provider.");
|
||||
pw.println();
|
||||
pw.printf("%s details:\n", CMD_SEND_PROVIDER_TEST_COMMAND);
|
||||
pw.printf("%s details:\n", SHELL_COMMAND_SEND_PROVIDER_TEST_COMMAND);
|
||||
pw.println();
|
||||
pw.printf("<provider name> = One of %s\n", VALID_PROVIDER_NAMES);
|
||||
pw.println();
|
||||
@@ -86,13 +89,14 @@ class LocationTimeZoneManagerShellCommand extends ShellCommand {
|
||||
pw.println();
|
||||
TestCommand.printShellCommandEncodingHelp(pw);
|
||||
pw.println();
|
||||
pw.printf("Provider modes can be modified by setting the \"%s<provider name>\" system"
|
||||
pw.printf("Provider modes can be modified by setting the \"%s\" or \"%s\"\n system"
|
||||
+ " property and restarting the service or rebooting the device.\n",
|
||||
LocationTimeZoneManagerService.PROVIDER_MODE_OVERRIDE_SYSTEM_PROPERTY_PREFIX);
|
||||
SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_PRIMARY,
|
||||
SYSTEM_PROPERTY_KEY_PROVIDER_MODE_OVERRIDE_SECONDARY);
|
||||
pw.println("Values are:");
|
||||
pw.printf(" %s - simulation mode (see below for commands)\n",
|
||||
LocationTimeZoneManagerService.PROVIDER_MODE_SIMULATED);
|
||||
pw.printf(" %s - disabled mode\n", LocationTimeZoneManagerService.PROVIDER_MODE_DISABLED);
|
||||
SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_SIMULATED);
|
||||
pw.printf(" %s - disabled mode\n", SYSTEM_PROPERTY_VALUE_PROVIDER_MODE_DISABLED);
|
||||
pw.println();
|
||||
pw.println("Simulated providers can be used to test the system server behavior or to"
|
||||
+ " reproduce bugs without the complexity of using real providers.");
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
|
||||
package com.android.server.location.timezone;
|
||||
|
||||
import static android.app.time.LocationTimeZoneManager.SIMULATED_PROVIDER_TEST_COMMAND_ON_BIND;
|
||||
import static android.app.time.LocationTimeZoneManager.SIMULATED_PROVIDER_TEST_COMMAND_ON_UNBIND;
|
||||
import static android.app.time.LocationTimeZoneManager.SIMULATED_PROVIDER_TEST_COMMAND_PERM_FAILURE;
|
||||
import static android.app.time.LocationTimeZoneManager.SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS;
|
||||
import static android.app.time.LocationTimeZoneManager.SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS_ARG_KEY_TZ;
|
||||
import static android.app.time.LocationTimeZoneManager.SIMULATED_PROVIDER_TEST_COMMAND_UNCERTAIN;
|
||||
import static android.service.timezone.TimeZoneProviderService.TEST_COMMAND_RESULT_ERROR_KEY;
|
||||
import static android.service.timezone.TimeZoneProviderService.TEST_COMMAND_RESULT_SUCCESS_KEY;
|
||||
|
||||
@@ -41,17 +47,6 @@ import java.util.Objects;
|
||||
*/
|
||||
class SimulatedLocationTimeZoneProviderProxy extends LocationTimeZoneProviderProxy {
|
||||
|
||||
private static final String TEST_COMMAND_NAME_ON_BIND = "on_bind";
|
||||
private static final String TEST_COMMAND_NAME_ON_UNBIND = "on_unbind";
|
||||
private static final String TEST_COMMAND_NAME_PERM_FAIL = "perm_fail";
|
||||
private static final String TEST_COMMAND_NAME_UNCERTAIN = "uncertain";
|
||||
private static final String TEST_COMMAND_NAME_SUCCESS = "success";
|
||||
|
||||
/**
|
||||
* Used for {@link #TEST_COMMAND_NAME_SUCCESS}.
|
||||
*/
|
||||
private static final String KEY_TIME_ZONE = "tz";
|
||||
|
||||
@GuardedBy("mSharedLock")
|
||||
@NonNull private TimeZoneProviderRequest mRequest;
|
||||
|
||||
@@ -82,21 +77,21 @@ class SimulatedLocationTimeZoneProviderProxy extends LocationTimeZoneProviderPro
|
||||
synchronized (mSharedLock) {
|
||||
Bundle resultBundle = new Bundle();
|
||||
switch (testCommand.getName()) {
|
||||
case TEST_COMMAND_NAME_ON_BIND: {
|
||||
case SIMULATED_PROVIDER_TEST_COMMAND_ON_BIND: {
|
||||
mLastEvent.set("Simulating onProviderBound(), testCommand=" + testCommand);
|
||||
mThreadingDomain.post(this::onBindOnHandlerThread);
|
||||
resultBundle.putBoolean(TEST_COMMAND_RESULT_SUCCESS_KEY, true);
|
||||
break;
|
||||
}
|
||||
case TEST_COMMAND_NAME_ON_UNBIND: {
|
||||
case SIMULATED_PROVIDER_TEST_COMMAND_ON_UNBIND: {
|
||||
mLastEvent.set("Simulating onProviderUnbound(), testCommand=" + testCommand);
|
||||
mThreadingDomain.post(this::onUnbindOnHandlerThread);
|
||||
resultBundle.putBoolean(TEST_COMMAND_RESULT_SUCCESS_KEY, true);
|
||||
break;
|
||||
}
|
||||
case TEST_COMMAND_NAME_PERM_FAIL:
|
||||
case TEST_COMMAND_NAME_UNCERTAIN:
|
||||
case TEST_COMMAND_NAME_SUCCESS: {
|
||||
case SIMULATED_PROVIDER_TEST_COMMAND_PERM_FAILURE:
|
||||
case SIMULATED_PROVIDER_TEST_COMMAND_UNCERTAIN:
|
||||
case SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS: {
|
||||
if (!mRequest.sendUpdates()) {
|
||||
String errorMsg = "testCommand=" + testCommand
|
||||
+ " is testing an invalid case:"
|
||||
@@ -173,12 +168,13 @@ class SimulatedLocationTimeZoneProviderProxy extends LocationTimeZoneProviderPro
|
||||
* {@link #createTimeZoneProviderEventFromTestCommand(TestCommand)}.
|
||||
*/
|
||||
static void printTestCommandShellHelp(@NonNull PrintWriter pw) {
|
||||
pw.printf("%s\n", TEST_COMMAND_NAME_ON_BIND);
|
||||
pw.printf("%s\n", TEST_COMMAND_NAME_ON_UNBIND);
|
||||
pw.printf("%s\n", TEST_COMMAND_NAME_PERM_FAIL);
|
||||
pw.printf("%s\n", TEST_COMMAND_NAME_UNCERTAIN);
|
||||
pw.printf("%s\n", SIMULATED_PROVIDER_TEST_COMMAND_ON_BIND);
|
||||
pw.printf("%s\n", SIMULATED_PROVIDER_TEST_COMMAND_ON_UNBIND);
|
||||
pw.printf("%s\n", SIMULATED_PROVIDER_TEST_COMMAND_PERM_FAILURE);
|
||||
pw.printf("%s\n", SIMULATED_PROVIDER_TEST_COMMAND_UNCERTAIN);
|
||||
pw.printf("%s %s=string_array:<time zone id>[&<time zone id>]+\n",
|
||||
TEST_COMMAND_NAME_SUCCESS, KEY_TIME_ZONE);
|
||||
SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS,
|
||||
SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS_ARG_KEY_TZ);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -186,17 +182,19 @@ class SimulatedLocationTimeZoneProviderProxy extends LocationTimeZoneProviderPro
|
||||
@NonNull TestCommand testCommand) {
|
||||
String name = testCommand.getName();
|
||||
switch (name) {
|
||||
case TEST_COMMAND_NAME_PERM_FAIL: {
|
||||
case SIMULATED_PROVIDER_TEST_COMMAND_PERM_FAILURE: {
|
||||
return TimeZoneProviderEvent.createPermanentFailureEvent("Simulated failure");
|
||||
}
|
||||
case TEST_COMMAND_NAME_UNCERTAIN: {
|
||||
case SIMULATED_PROVIDER_TEST_COMMAND_UNCERTAIN: {
|
||||
return TimeZoneProviderEvent.createUncertainEvent();
|
||||
}
|
||||
case TEST_COMMAND_NAME_SUCCESS: {
|
||||
case SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS: {
|
||||
Bundle args = testCommand.getArgs();
|
||||
String[] timeZoneIds = args.getStringArray(KEY_TIME_ZONE);
|
||||
String[] timeZoneIds = args.getStringArray(
|
||||
SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS_ARG_KEY_TZ);
|
||||
if (timeZoneIds == null) {
|
||||
throw new IllegalArgumentException("No " + KEY_TIME_ZONE + " arg found");
|
||||
throw new IllegalArgumentException("No "
|
||||
+ SIMULATED_PROVIDER_TEST_COMMAND_SUCCESS_ARG_KEY_TZ + " arg found");
|
||||
}
|
||||
TimeZoneProviderSuggestion suggestion = new TimeZoneProviderSuggestion.Builder()
|
||||
.setTimeZoneIds(Arrays.asList(timeZoneIds))
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package com.android.server.timezonedetector;
|
||||
|
||||
import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_SUGGEST_GEO_LOCATION_TIME_ZONE;
|
||||
import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_SUGGEST_MANUAL_TIME_ZONE;
|
||||
import static android.app.timezonedetector.TimeZoneDetector.SHELL_COMMAND_SUGGEST_TELEPHONY_TIME_ZONE;
|
||||
|
||||
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
||||
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
|
||||
import android.os.ShellCommand;
|
||||
@@ -39,11 +43,11 @@ class TimeZoneDetectorShellCommand extends ShellCommand {
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case "suggest_geo_location_time_zone":
|
||||
case SHELL_COMMAND_SUGGEST_GEO_LOCATION_TIME_ZONE:
|
||||
return runSuggestGeolocationTimeZone();
|
||||
case "suggest_manual_time_zone":
|
||||
case SHELL_COMMAND_SUGGEST_MANUAL_TIME_ZONE:
|
||||
return runSuggestManualTimeZone();
|
||||
case "suggest_telephony_time_zone":
|
||||
case SHELL_COMMAND_SUGGEST_TELEPHONY_TIME_ZONE:
|
||||
return runSuggestTelephonyTimeZone();
|
||||
default: {
|
||||
return handleDefaultCommands(cmd);
|
||||
@@ -72,16 +76,7 @@ class TimeZoneDetectorShellCommand extends ShellCommand {
|
||||
private <T> int runSuggestTimeZone(Supplier<T> suggestionParser, Consumer<T> invoker) {
|
||||
final PrintWriter pw = getOutPrintWriter();
|
||||
try {
|
||||
T suggestion = null;
|
||||
String opt;
|
||||
while ((opt = getNextArg()) != null) {
|
||||
if ("--suggestion".equals(opt)) {
|
||||
suggestion = suggestionParser.get();
|
||||
} else {
|
||||
pw.println("Error: Unknown option: " + opt);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
T suggestion = suggestionParser.get();
|
||||
if (suggestion == null) {
|
||||
pw.println("Error: suggestion not specified");
|
||||
return 1;
|
||||
@@ -101,12 +96,12 @@ class TimeZoneDetectorShellCommand extends ShellCommand {
|
||||
pw.println("Time Zone Detector (time_zone_detector) commands:");
|
||||
pw.println(" help");
|
||||
pw.println(" Print this help text.");
|
||||
pw.println(" suggest_geolocation_time_zone");
|
||||
pw.println(" --suggestion <geolocation suggestion opts>");
|
||||
pw.println(" suggest_manual_time_zone");
|
||||
pw.println(" --suggestion <manual suggestion opts>");
|
||||
pw.println(" suggest_telephony_time_zone");
|
||||
pw.println(" --suggestion <telephony suggestion opts>");
|
||||
pw.printf(" %s <geolocation suggestion opts>\n",
|
||||
SHELL_COMMAND_SUGGEST_GEO_LOCATION_TIME_ZONE);
|
||||
pw.printf(" %s <manual suggestion opts>\n",
|
||||
SHELL_COMMAND_SUGGEST_MANUAL_TIME_ZONE);
|
||||
pw.printf(" %s <telephony suggestion opts>\n",
|
||||
SHELL_COMMAND_SUGGEST_TELEPHONY_TIME_ZONE);
|
||||
pw.println();
|
||||
GeolocationTimeZoneSuggestion.printCommandLineOpts(pw);
|
||||
pw.println();
|
||||
|
||||
Reference in New Issue
Block a user