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

Commit 06fee9d5 authored by Mark Punzalan's avatar Mark Punzalan
Browse files

Pass full SDK version (w/ minor) to AssetManager

Bug: 383177182
Test: atest FrameworksCoreTests
Test: Build + boot on Pixel 6 Pro
Flag: android.content.res.resources_minor_version_support
Change-Id: Ie1210c0b570e1547b14af0393986432ae1bb008c
parent eff5f94a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1457,7 +1457,7 @@ 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);
                0, 0, 0, Build.VERSION.RESOURCES_SDK_INT_FULL);
        return assetManager;
    }

@@ -9017,7 +9017,7 @@ 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);
                    0, 0, 0, Build.VERSION.RESOURCES_SDK_INT_FULL);
            assets.setApkAssets(apkAssets, false /*invalidateCaches*/);

            mCachedAssetManager = assets;
@@ -9092,7 +9092,7 @@ 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);
                    0, 0, 0, Build.VERSION.RESOURCES_SDK_INT_FULL);
            assets.setApkAssets(apkAssets, false /*invalidateCaches*/);
            return assets;
        }
+10 −28
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.content.res;

import static android.app.ResourcesManager.ApkKey;
import static android.content.res.Flags.resourcesMinorVersionSupport;
import static android.content.res.Resources.ID_NULL;

import android.annotation.AnyRes;
@@ -33,6 +34,7 @@ import android.content.pm.ActivityInfo;
import android.content.res.Configuration.NativeConfig;
import android.content.res.loader.ResourcesLoader;
import android.os.Build;
import android.os.Build.SdkIntFull;
import android.os.ParcelFileDescriptor;
import android.ravenwood.annotation.RavenwoodKeepWholeClass;
import android.ravenwood.annotation.RavenwoodReplace;
@@ -1573,38 +1575,15 @@ public final class AssetManager implements AutoCloseable {
     * @hide
     */
    @UnsupportedAppUsage
    public void setConfiguration(int mcc, int mnc, @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) {
        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,
                    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) {
            int grammaticalGender, @SdkIntFull int sdkVersionFull) {
        setConfigurationInternal(mcc, mnc, defaultLocale, locales, orientation,
                touchscreen, density, keyboard, keyboardHidden, navigation, screenWidth,
                screenHeight, smallestScreenWidthDp, screenWidthDp, screenHeightDp,
                screenLayout, uiMode, colorMode, grammaticalGender, majorVersion, false);
                screenLayout, uiMode, colorMode, grammaticalGender, sdkVersionFull, false);
    }

    /**
@@ -1616,13 +1595,16 @@ public final class AssetManager implements AutoCloseable {
            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, boolean forceRefresh) {
            int grammaticalGender, @SdkIntFull int sdkVersionFull, boolean forceRefresh) {
        synchronized (this) {
            ensureValidLocked();
            final int majorVersion = Build.getMajorSdkVersion(sdkVersionFull);
            final int minorVersion = resourcesMinorVersionSupport()
                    ? Build.getMinorSdkVersion(sdkVersionFull) : 0;
            nativeSetConfiguration(mObject, mcc, mnc, defaultLocale, locales, orientation,
                    touchscreen, density, keyboard, keyboardHidden, navigation, screenWidth,
                    screenHeight, smallestScreenWidthDp, screenWidthDp, screenHeightDp,
                    screenLayout, uiMode, colorMode, grammaticalGender, majorVersion,
                    screenLayout, uiMode, colorMode, grammaticalGender, majorVersion, minorVersion,
                    forceRefresh);
        }
    }
@@ -1736,7 +1718,7 @@ public final class AssetManager implements AutoCloseable {
            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, boolean forceRefresh);
            int majorVersion, int minorVersion, boolean forceRefresh);
    private static native void nativeSetOverlayConstraints(long ptr, int displayId, int deviceId);
    private static native @NonNull SparseArray<String> nativeGetAssignedPackageIdentifiers(
            long ptr, boolean includeOverlays, boolean includeLoaders);
+19 −4
Original line number Diff line number Diff line
@@ -229,7 +229,8 @@ public class ResourcesImpl {
        mMetrics.setToDefaults();
        mDisplayAdjustments = displayAdjustments;
        mConfiguration.setToDefaults();
        updateConfigurationImpl(config, metrics, displayAdjustments.getCompatibilityInfo(), true);
        updateConfigurationImpl(config, metrics, displayAdjustments.getCompatibilityInfo(), true,
                Build.VERSION.RESOURCES_SDK_INT_FULL);
    }

    /**
@@ -451,13 +452,27 @@ public class ResourcesImpl {
        return mStateListAnimatorCache;
    }

    /**
     * Set the SDK version used for resource lookup. Not for use outside of tests.
     *
     * @param sdkVersionFull The SDK version, with minor version encoded
     */
    @VisibleForTesting
    public void updateResourcesSdkVersion(int sdkVersionFull) {
        Configuration config = new Configuration();
        config.setTo(mConfiguration);
        updateConfigurationImpl(config, null, null, true, sdkVersionFull);
    }

    public void updateConfiguration(Configuration config, DisplayMetrics metrics,
            CompatibilityInfo compat) {
        updateConfigurationImpl(config, metrics, compat, false);
        updateConfigurationImpl(config, metrics, compat, false,
                Build.VERSION.RESOURCES_SDK_INT_FULL);
    }

    private void updateConfigurationImpl(Configuration config, DisplayMetrics metrics,
                                    CompatibilityInfo compat, boolean forceAssetsRefresh) {
                                         CompatibilityInfo compat, boolean forceAssetsRefresh,
                                         int sdkVersionFull) {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesImpl#updateConfiguration");
        try {
            synchronized (mAccessLock) {
@@ -598,7 +613,7 @@ public class ResourcesImpl {
                        mConfiguration.screenWidthDp, mConfiguration.screenHeightDp,
                        mConfiguration.screenLayout, mConfiguration.uiMode,
                        mConfiguration.colorMode, mConfiguration.getGrammaticalGender(),
                        Build.VERSION.RESOURCES_SDK_INT, forceAssetsRefresh);
                        sdkVersionFull, forceAssetsRefresh);

                if (DEBUG_CONFIG) {
                    Slog.i(TAG, "**** Updating config of " + this + ": final config is "
+9 −0
Original line number Diff line number Diff line
@@ -533,6 +533,15 @@ public class Build {
        @TestApi
        public static final int RESOURCES_SDK_INT = SDK_INT + ACTIVE_CODENAMES.length;

        /**
         * The SDK version to use when accessing resources, with minor version encoded.
         * Use the current SDK version code.  For every active development codename
         * we are operating under, we bump the assumed resource platform major version by 1.
         * @hide
         */
        public static final int RESOURCES_SDK_INT_FULL = SDK_INT_FULL
                + (ACTIVE_CODENAMES.length * VERSION_CODES_FULL.SDK_INT_MULTIPLIER);

        /**
         * The current lowest supported value of app target SDK. Applications targeting
         * lower values may not function on devices running this SDK version. Its possible
+1 −1
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ public class DefaultSplitAssetLoader implements SplitAssetLoader {

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

        mCachedAssetManager = assets;
Loading