Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a83c0489 authored by Neil Fuller's avatar Neil Fuller Committed by Android (Google) Code Review
Browse files

Merge "Add command-line support for enabling auto time"

parents 50c0852e 9e9fe686
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,12 @@ public interface TimeDetector {
     */
     */
    String SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED = "is_auto_detection_enabled";
    String SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED = "is_auto_detection_enabled";


    /**
     * A shell command that sets the current "auto time detection" global setting value.
     * @hide
     */
    String SHELL_COMMAND_SET_AUTO_DETECTION_ENABLED = "set_auto_detection_enabled";

    /**
    /**
     * A shell command that injects a manual time suggestion.
     * A shell command that injects a manual time suggestion.
     * @hide
     * @hide
+21 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.server.timedetector;


import static android.app.timedetector.TimeDetector.SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SERVICE_NAME;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SERVICE_NAME;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SET_AUTO_DETECTION_ENABLED;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SUGGEST_EXTERNAL_TIME;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SUGGEST_EXTERNAL_TIME;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SUGGEST_GNSS_TIME;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SUGGEST_GNSS_TIME;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SUGGEST_MANUAL_TIME;
import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SUGGEST_MANUAL_TIME;
@@ -28,11 +29,13 @@ import static com.android.server.timedetector.ServerFlags.KEY_TIME_DETECTOR_LOWE
import static com.android.server.timedetector.ServerFlags.KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE;
import static com.android.server.timedetector.ServerFlags.KEY_TIME_DETECTOR_ORIGIN_PRIORITIES_OVERRIDE;


import android.app.time.ExternalTimeSuggestion;
import android.app.time.ExternalTimeSuggestion;
import android.app.time.TimeConfiguration;
import android.app.timedetector.GnssTimeSuggestion;
import android.app.timedetector.GnssTimeSuggestion;
import android.app.timedetector.ManualTimeSuggestion;
import android.app.timedetector.ManualTimeSuggestion;
import android.app.timedetector.NetworkTimeSuggestion;
import android.app.timedetector.NetworkTimeSuggestion;
import android.app.timedetector.TelephonyTimeSuggestion;
import android.app.timedetector.TelephonyTimeSuggestion;
import android.os.ShellCommand;
import android.os.ShellCommand;
import android.os.UserHandle;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.function.Consumer;
import java.util.function.Consumer;
@@ -56,6 +59,8 @@ class TimeDetectorShellCommand extends ShellCommand {
        switch (cmd) {
        switch (cmd) {
            case SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED:
            case SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED:
                return runIsAutoDetectionEnabled();
                return runIsAutoDetectionEnabled();
            case SHELL_COMMAND_SET_AUTO_DETECTION_ENABLED:
                return runSetAutoDetectionEnabled();
            case SHELL_COMMAND_SUGGEST_MANUAL_TIME:
            case SHELL_COMMAND_SUGGEST_MANUAL_TIME:
                return runSuggestManualTime();
                return runSuggestManualTime();
            case SHELL_COMMAND_SUGGEST_TELEPHONY_TIME:
            case SHELL_COMMAND_SUGGEST_TELEPHONY_TIME:
@@ -81,6 +86,15 @@ class TimeDetectorShellCommand extends ShellCommand {
        return 0;
        return 0;
    }
    }


    private int runSetAutoDetectionEnabled() {
        boolean enabled = Boolean.parseBoolean(getNextArgRequired());
        int userId = UserHandle.USER_CURRENT;
        TimeConfiguration configuration = new TimeConfiguration.Builder()
                .setAutoDetectionEnabled(enabled)
                .build();
        return mInterface.updateConfiguration(userId, configuration) ? 0 : 1;
    }

    private int runSuggestManualTime() {
    private int runSuggestManualTime() {
        return runSuggestTime(
        return runSuggestTime(
                () -> ManualTimeSuggestion.parseCommandLineArg(this),
                () -> ManualTimeSuggestion.parseCommandLineArg(this),
@@ -136,12 +150,19 @@ class TimeDetectorShellCommand extends ShellCommand {
        pw.printf("    Print this help text.\n");
        pw.printf("    Print this help text.\n");
        pw.printf("  %s\n", SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED);
        pw.printf("  %s\n", SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED);
        pw.printf("    Prints true/false according to the automatic time detection setting.\n");
        pw.printf("    Prints true/false according to the automatic time detection setting.\n");
        pw.printf("  %s true|false\n", SHELL_COMMAND_SET_AUTO_DETECTION_ENABLED);
        pw.printf("    Sets the automatic time detection setting.\n");
        pw.println();
        pw.println();
        pw.printf("  %s <manual suggestion opts>\n", SHELL_COMMAND_SUGGEST_MANUAL_TIME);
        pw.printf("  %s <manual suggestion opts>\n", SHELL_COMMAND_SUGGEST_MANUAL_TIME);
        pw.printf("    Suggests a time as if via the \"manual\" origin.\n");
        pw.printf("  %s <telephony suggestion opts>\n", SHELL_COMMAND_SUGGEST_TELEPHONY_TIME);
        pw.printf("  %s <telephony suggestion opts>\n", SHELL_COMMAND_SUGGEST_TELEPHONY_TIME);
        pw.printf("    Suggests a time as if via the \"telephony\" origin.\n");
        pw.printf("  %s <network suggestion opts>\n", SHELL_COMMAND_SUGGEST_NETWORK_TIME);
        pw.printf("  %s <network suggestion opts>\n", SHELL_COMMAND_SUGGEST_NETWORK_TIME);
        pw.printf("    Suggests a time as if via the \"network\" origin.\n");
        pw.printf("  %s <gnss suggestion opts>\n", SHELL_COMMAND_SUGGEST_GNSS_TIME);
        pw.printf("  %s <gnss suggestion opts>\n", SHELL_COMMAND_SUGGEST_GNSS_TIME);
        pw.printf("    Suggests a time as if via the \"gnss\" origin.\n");
        pw.printf("  %s <external suggestion opts>\n", SHELL_COMMAND_SUGGEST_EXTERNAL_TIME);
        pw.printf("  %s <external suggestion opts>\n", SHELL_COMMAND_SUGGEST_EXTERNAL_TIME);
        pw.printf("    Suggests a time as if via the \"external\" origin.\n");
        pw.println();
        pw.println();
        ManualTimeSuggestion.printCommandLineOpts(pw);
        ManualTimeSuggestion.printCommandLineOpts(pw);
        pw.println();
        pw.println();
+3 −0
Original line number Original line Diff line number Diff line
@@ -221,8 +221,11 @@ class TimeZoneDetectorShellCommand extends ShellCommand {
        pw.println();
        pw.println();
        pw.printf("  %s <geolocation suggestion opts>\n",
        pw.printf("  %s <geolocation suggestion opts>\n",
                SHELL_COMMAND_SUGGEST_GEO_LOCATION_TIME_ZONE);
                SHELL_COMMAND_SUGGEST_GEO_LOCATION_TIME_ZONE);
        pw.printf("    Suggests a time zone as if via the \"location\" origin.\n");
        pw.printf("  %s <manual suggestion opts>\n", SHELL_COMMAND_SUGGEST_MANUAL_TIME_ZONE);
        pw.printf("  %s <manual suggestion opts>\n", SHELL_COMMAND_SUGGEST_MANUAL_TIME_ZONE);
        pw.printf("    Suggests a time zone as if via the \"manual\" origin.\n");
        pw.printf("  %s <telephony suggestion opts>\n", SHELL_COMMAND_SUGGEST_TELEPHONY_TIME_ZONE);
        pw.printf("  %s <telephony suggestion opts>\n", SHELL_COMMAND_SUGGEST_TELEPHONY_TIME_ZONE);
        pw.printf("    Suggests a time zone as if via the \"telephony\" origin.\n");
        pw.printf("  %s\n", SHELL_COMMAND_DUMP_METRICS);
        pw.printf("  %s\n", SHELL_COMMAND_DUMP_METRICS);
        pw.printf("    Dumps the service metrics to stdout for inspection.\n");
        pw.printf("    Dumps the service metrics to stdout for inspection.\n");
        pw.println();
        pw.println();