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

Commit e7dfae24 authored by Ananya's avatar Ananya
Browse files

Add new shell command for listing device locales.

adb shell cmd locale list-device-locales

Test: Manual Testing
Bug: b/394760079
Flag: NONE not needed for the new adb command
Change-Id: I239aace8260568be4cb7efb4fdd4feaf36ba8d91
parent 7e4f7217
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) {