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

Commit cc6ff387 authored by Jeremy Meyer's avatar Jeremy Meyer Committed by Android (Google) Code Review
Browse files

Revert "Pass all preferred locales to AssetManager"

This reverts commit 09158c69.

Reason for revert: causes test failures
Fixes: 290377322
Fixes: 290377794
Fixes: 290377713

Change-Id: I69b6fe1e1ce597656ff80ccd4446f12c76ffc19b
parent 09158c69
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
@@ -195,8 +195,7 @@ public class LocaleConfig implements Parcelable {
        XmlUtils.beginDocument(parser, TAG_LOCALE_CONFIG);
        int outerDepth = parser.getDepth();
        AttributeSet attrs = Xml.asAttributeSet(parser);
        // LinkedHashSet to preserve insertion order
        Set<String> localeNames = new LinkedHashSet<>();
        Set<String> localeNames = new HashSet<String>();
        while (XmlUtils.nextElementWithin(parser, outerDepth)) {
            if (TAG_LOCALE.equals(parser.getName())) {
                final TypedArray attributes = res.obtainAttributes(
+6 −6
Original line number Diff line number Diff line
@@ -1456,8 +1456,8 @@ public class PackageParser {

    private static AssetManager newConfiguredAssetManager() {
        AssetManager assetManager = new AssetManager();
        assetManager.setConfiguration(0, 0, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, Build.VERSION.RESOURCES_SDK_INT);
        assetManager.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                Build.VERSION.RESOURCES_SDK_INT);
        return assetManager;
    }

@@ -9011,8 +9011,8 @@ public class PackageParser {
            }

            AssetManager assets = new AssetManager();
            assets.setConfiguration(0, 0, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, Build.VERSION.RESOURCES_SDK_INT);
            assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    Build.VERSION.RESOURCES_SDK_INT);
            assets.setApkAssets(apkAssets, false /*invalidateCaches*/);

            mCachedAssetManager = assets;
@@ -9086,8 +9086,8 @@ public class PackageParser {

        private static AssetManager createAssetManagerWithAssets(ApkAssets[] apkAssets) {
            final AssetManager assets = new AssetManager();
            assets.setConfiguration(0, 0, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, Build.VERSION.RESOURCES_SDK_INT);
            assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    Build.VERSION.RESOURCES_SDK_INT);
            assets.setApkAssets(apkAssets, false /*invalidateCaches*/);
            return assets;
        }
+7 −31
Original line number Diff line number Diff line
@@ -1478,38 +1478,15 @@ public final class AssetManager implements AutoCloseable {
            int screenWidth, int screenHeight, int smallestScreenWidthDp, int screenWidthDp,
            int screenHeightDp, int screenLayout, int uiMode, int colorMode, int grammaticalGender,
            int majorVersion) {
        if (locale != null) {
            setConfiguration(mcc, mnc, null, new String[]{locale}, orientation, touchscreen,
                    density, keyboard, keyboardHidden, navigation, screenWidth, screenHeight,
                    smallestScreenWidthDp, screenWidthDp, screenHeightDp, screenLayout, uiMode,
                    colorMode, grammaticalGender, majorVersion);
        } else {
            setConfiguration(mcc, mnc, null, null, orientation, touchscreen, density,
        synchronized (this) {
            ensureValidLocked();
            nativeSetConfiguration(mObject, mcc, mnc, locale, orientation, touchscreen, density,
                    keyboard, keyboardHidden, navigation, screenWidth, screenHeight,
                    smallestScreenWidthDp, screenWidthDp, screenHeightDp, screenLayout, uiMode,
                    colorMode, grammaticalGender, majorVersion);
        }
    }

    /**
     * Change the configuration used when retrieving resources.  Not for use by
     * applications.
     * @hide
     */
    public void setConfiguration(int mcc, int mnc, String defaultLocale, String[] locales,
            int orientation, int touchscreen, int density, int keyboard, int keyboardHidden,
            int navigation, int screenWidth, int screenHeight, int smallestScreenWidthDp,
            int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode, int colorMode,
            int grammaticalGender, int majorVersion) {
        synchronized (this) {
            ensureValidLocked();
            nativeSetConfiguration(mObject, mcc, mnc, defaultLocale, locales, orientation,
                    touchscreen, density, keyboard, keyboardHidden, navigation, screenWidth,
                    screenHeight, smallestScreenWidthDp, screenWidthDp, screenHeightDp,
                    screenLayout, uiMode, colorMode, grammaticalGender, majorVersion);
        }
    }

    /**
     * @hide
     */
@@ -1593,11 +1570,10 @@ public final class AssetManager implements AutoCloseable {
    private static native void nativeSetApkAssets(long ptr, @NonNull ApkAssets[] apkAssets,
            boolean invalidateCaches);
    private static native void nativeSetConfiguration(long ptr, int mcc, int mnc,
            @Nullable String defaultLocale, @NonNull String[] locales, int orientation,
            int touchscreen, int density, int keyboard, int keyboardHidden, int navigation,
            int screenWidth, int screenHeight, int smallestScreenWidthDp, int screenWidthDp,
            int screenHeightDp, int screenLayout, int uiMode, int colorMode, int grammaticalGender,
            int majorVersion);
            @Nullable String locale, int orientation, int touchscreen, int density, int keyboard,
            int keyboardHidden, int navigation, int screenWidth, int screenHeight,
            int smallestScreenWidthDp, int screenWidthDp, int screenHeightDp, int screenLayout,
            int uiMode, int colorMode, int grammaticalGender, int majorVersion);
    private static native @NonNull SparseArray<String> nativeGetAssignedPackageIdentifiers(
            long ptr, boolean includeOverlays, boolean includeLoaders);

+12 −27
Original line number Diff line number Diff line
@@ -407,12 +407,14 @@ public class ResourcesImpl {
                    mConfiguration.setLocales(locales);
                }

                String[] selectedLocales = null;
                String defaultLocale = null;
                if ((configChanges & ActivityInfo.CONFIG_LOCALE) != 0) {
                    if (locales.size() > 1) {
                        String[] availableLocales;
                        if (ResourcesManager.getInstance().getLocaleList().isEmpty()) {

                        LocaleList localeList = ResourcesManager.getInstance().getLocaleList();
                        if (!localeList.isEmpty()) {
                            availableLocales = localeList.toLanguageTags().split(",");
                        } else {
                            // The LocaleList has changed. We must query the AssetManager's
                            // available Locales and figure out the best matching Locale in the new
                            // LocaleList.
@@ -424,30 +426,14 @@ public class ResourcesImpl {
                                    availableLocales = null;
                                }
                            }
                        }
                        if (availableLocales != null) {
                            final Locale bestLocale = locales.getFirstMatchWithEnglishSupported(
                                    availableLocales);
                                if (bestLocale != null) {
                                    selectedLocales = new String[]{
                                            adjustLanguageTag(bestLocale.toLanguageTag())};
                                    if (!bestLocale.equals(locales.get(0))) {
                                        mConfiguration.setLocales(
                                                new LocaleList(bestLocale, locales));
                                    }
                                }
                            }
                        } else {
                            selectedLocales = locales.getIntersection(
                                    ResourcesManager.getInstance().getLocaleList());
                            defaultLocale = ResourcesManager.getInstance()
                                    .getLocaleList().get(0).toLanguageTag();
                        }
                            if (bestLocale != null && bestLocale != locales.get(0)) {
                                mConfiguration.setLocales(new LocaleList(bestLocale, locales));
                            }
                        }
                if (selectedLocales == null) {
                    selectedLocales = new String[locales.size()];
                    for (int i = 0; i < locales.size(); i++) {
                        selectedLocales[i] = adjustLanguageTag(locales.get(i).toLanguageTag());
                    }
                }

@@ -484,8 +470,7 @@ public class ResourcesImpl {
                }

                mAssets.setConfiguration(mConfiguration.mcc, mConfiguration.mnc,
                        defaultLocale,
                        selectedLocales,
                        adjustLanguageTag(mConfiguration.getLocales().get(0).toLanguageTag()),
                        mConfiguration.orientation,
                        mConfiguration.touchscreen,
                        mConfiguration.densityDpi, mConfiguration.keyboard,
+0 −20
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;

/**
@@ -151,25 +150,6 @@ public final class LocaleList implements Parcelable {
        return mStringRepresentation;
    }

    /**
     * Find the intersection between this LocaleList and another
     * @return a String array of the Locales in both LocaleLists
     * {@hide}
     */
    @NonNull
    public String[] getIntersection(@NonNull LocaleList other) {
        List<String> intersection = new ArrayList<>();
        for (Locale l1 : mList) {
            for (Locale l2 : other.mList) {
                if (matchesLanguageAndScript(l2, l1)) {
                    intersection.add(l1.toLanguageTag());
                    break;
                }
            }
        }
        return intersection.toArray(new String[0]);
    }

    /**
     * Creates a new {@link LocaleList}.
     *
Loading