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

Commit eb2c8c25 authored by Josh Hou's avatar Josh Hou Committed by Android (Google) Code Review
Browse files

Merge "[Panlingual] Get the LocaleConfig without overrides" into main

parents ffda9a50 65762a0d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ public class LocaleManagerService extends SystemService {
        public void onShellCommand(FileDescriptor in, FileDescriptor out,
                FileDescriptor err, String[] args, ShellCallback callback,
                ResultReceiver resultReceiver) {
            (new LocaleManagerShellCommand(mBinderService))
            (new LocaleManagerShellCommand(mBinderService, mContext))
                    .exec(this, in, out, err, args, callback, resultReceiver);
        }

+56 −1
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.server.locales;
import android.app.ActivityManager;
import android.app.ILocaleManager;
import android.app.LocaleConfig;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.LocaleList;
import android.os.RemoteException;
import android.os.ShellCommand;
@@ -31,9 +33,11 @@ import java.io.PrintWriter;
 */
public class LocaleManagerShellCommand extends ShellCommand {
    private final ILocaleManager mBinderService;
    private final Context mContext;

    LocaleManagerShellCommand(ILocaleManager localeManager) {
    LocaleManagerShellCommand(ILocaleManager localeManager, Context context) {
        mBinderService = localeManager;
        mContext = context;
    }
    @Override
    public int onCommand(String cmd) {
@@ -49,6 +53,8 @@ public class LocaleManagerShellCommand extends ShellCommand {
                return runSetAppOverrideLocaleConfig();
            case "get-app-localeconfig":
                return runGetAppOverrideLocaleConfig();
            case "get-app-localeconfig-ignore-override":
                return runGetAppLocaleConfigIgnoreOverride();
            default: {
                return handleDefaultCommands(cmd);
            }
@@ -261,6 +267,55 @@ public class LocaleManagerShellCommand extends ShellCommand {
        return 0;
    }

    private int runGetAppLocaleConfigIgnoreOverride() {
        String packageName = getNextArg();
        final PrintWriter err = getErrPrintWriter();

        if (packageName != null) {
            int userId = ActivityManager.getCurrentUser();
            do {
                String option = getNextOption();
                if (option == null) {
                    break;
                }
                if ("--user".equals(option)) {
                    userId = UserHandle.parseUserArg(getNextArgRequired());
                    break;
                } else {
                    throw new IllegalArgumentException("Unknown option: " + option);
                }
            } while (true);
            LocaleConfig resLocaleConfig = null;
            try {
                resLocaleConfig = LocaleConfig.fromContextIgnoringOverride(
                    mContext.createPackageContextAsUser(packageName, /* flags= */ 0,
                        UserHandle.of(userId)));
            } catch (PackageManager.NameNotFoundException e) {
                err.println("Unknown package name " + packageName + " for user " + userId);
                return -1;
            }
            if (resLocaleConfig == null) {
                getOutPrintWriter().println(
                        "LocaleConfig for " + packageName + " for user " + userId + " is null");
            } else {
                LocaleList locales = resLocaleConfig.getSupportedLocales();
                if (locales == null) {
                    getOutPrintWriter().println(
                            "Locales within the LocaleConfig for " + packageName + " for user "
                                    + userId + " are null");
                } else {
                    getOutPrintWriter().println(
                            "Locales within the LocaleConfig for " + packageName + " for user "
                                    + userId + " are [" + locales.toLanguageTags() + "]");
                }
            }
        } else {
            err.println("Error: no package specified");
            return -1;
        }
        return 0;
    }

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