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

Commit 9a00cb4b authored by Ananya Latchupatula's avatar Ananya Latchupatula Committed by Android (Google) Code Review
Browse files

Merge "Add new shell command for listing device locales." into main

parents 95295f7a e7dfae24
Loading
Loading
Loading
Loading
+45 −19
Original line number Diff line number Diff line
@@ -26,19 +26,25 @@ import android.os.RemoteException;
import android.os.ShellCommand;
import android.os.UserHandle;

import com.android.internal.app.LocalePicker;

import java.io.PrintWriter;

/**
 * Shell commands for {@link LocaleManagerService}
 */
public class LocaleManagerShellCommand extends ShellCommand {

    private final ILocaleManager mBinderService;
    private final Context mContext;
    private String[] mSupportedLocales;

    LocaleManagerShellCommand(ILocaleManager localeManager, Context context) {
        mBinderService = localeManager;
        mContext = context;
        mSupportedLocales = LocalePicker.getSupportedLocales(mContext);
    }

    @Override
    public int onCommand(String cmd) {
        if (cmd == null) {
@@ -55,6 +61,8 @@ public class LocaleManagerShellCommand extends ShellCommand {
                return runGetAppOverrideLocaleConfig();
            case "get-app-localeconfig-ignore-override":
                return runGetAppLocaleConfigIgnoreOverride();
            case "list-device-locales":
                return runListDeviceLocales();
            default: {
                return handleDefaultCommands(cmd);
            }
@@ -97,6 +105,10 @@ public class LocaleManagerShellCommand extends ShellCommand {
        pw.println("    Get the locales within the override LocaleConfig for the specified app.");
        pw.println("    --user <USER_ID>: get for the given user, "
                + "the current user is used when unspecified.");
        pw.println("  list-device-locales");
        pw.println("    List the locales of the device.");
        pw.println("    Outputs a list of all BCP 47 language tags for locales supported by the "
                + "device.");
    }

    private int runSetAppLocales() {
@@ -316,6 +328,20 @@ public class LocaleManagerShellCommand extends ShellCommand {
        return 0;
    }

    private int runListDeviceLocales() {
        final PrintWriter err = getErrPrintWriter();

        if (mSupportedLocales == null || mSupportedLocales.length == 0) {
            err.println("Error: No supported locales found.");
            return -1;
        }

        for (String locale : mSupportedLocales) {
            getOutPrintWriter().println(locale);
        }
        return 0;
    }

    private LocaleList parseOverrideLocales() {
        String locales = getNextArg();
        if (locales == null) {