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

Commit 3c0078e8 authored by Darryl L Johnson's avatar Darryl L Johnson
Browse files

Don't override config of display contexts with activity display.

This change migrates the previous usages of
ResourcesManager#getResources() from using the display id of expected
resources to an override display ID which will override the display
properties from the parent token resources. This ensures that all
contexts derived from a display context keep the overrides for their
intended display.

This also changes the meaning of ResourcesKey#mOverrideConfiguration and
ResourcesKey#mDisplayId. Previously mDisplayId was used as both the
current display of the ResourcesKey and used to apply overrides
to mOverrideConfiguration. This made it unclear whether a particular key
should keep its display override when an activity changes display or
whether it should inherit the new display from the activity. Now the
display IDs and overrides are managed by the ActivityResources struct and the
ResourcesKey is expected to only contain the final display ID expected
for the resources in 'mDisplayId' and the final configuration that should
be applied to the global configuration in 'mOverrideConfiguration'.

Fixes: 153866583
Fixes: 156758475
Fixes: 163813210
Fixes: 163812902
Fixes: 163813227

Test: ActivityThreadTest
Test: ResourcesManagerTest
Test: AppConfigurationTests#testActivityContextDerivedDisplayContextOrientationWhenRotating

Change-Id: If93f98f93ee15b27d8c7292a2f830c2cc0f49277
parent 60f5ff4f
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -2242,9 +2242,9 @@ public final class ActivityThread extends ClientTransactionHandler {
     * Resources if one has already been created.
     */
    Resources getTopLevelResources(String resDir, String[] splitResDirs, String[] overlayDirs,
            String[] libDirs, int displayId, LoadedApk pkgInfo) {
            String[] libDirs, LoadedApk pkgInfo) {
        return mResourcesManager.getResources(null, resDir, splitResDirs, overlayDirs, libDirs,
                displayId, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader(), null);
                null, null, pkgInfo.getCompatibilityInfo(), pkgInfo.getClassLoader(), null);
    }

    @UnsupportedAppUsage
@@ -5692,8 +5692,7 @@ public final class ActivityThread extends ClientTransactionHandler {
        // many places.
        final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull(
                amOverrideConfig, contextThemeWrapperOverrideConfig);
        mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig,
                displayId, movedToDifferentDisplay);
        mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, displayId);

        activity.mConfigChangeFlags = 0;
        activity.mCurrentConfig = new Configuration(newConfig);
@@ -6014,6 +6013,11 @@ public final class ActivityThread extends ClientTransactionHandler {
            r.mPendingOverrideConfig = null;
        }

        if (displayId == INVALID_DISPLAY) {
            // If INVALID_DISPLAY is passed assume that the activity should keep its current
            // display.
            displayId = r.activity.getDisplayId();
        }
        final boolean movedToDifferentDisplay = isDifferentDisplay(r.activity, displayId);
        if (r.overrideConfig != null && !r.overrideConfig.isOtherSeqNewer(overrideConfig)
                && !movedToDifferentDisplay) {
+1 −2
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ import android.util.ArraySet;
import android.util.DebugUtils;
import android.util.LauncherIcons;
import android.util.Log;
import android.view.Display;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.Immutable;
@@ -1748,7 +1747,7 @@ public class ApplicationPackageManager extends PackageManager {
        final Resources r = mContext.mMainThread.getTopLevelResources(
                    sameUid ? app.sourceDir : app.publicSourceDir,
                    sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
                    app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
                    app.resourceDirs, app.sharedLibraryFiles,
                    mContext.mPackageInfo);
        if (r != null) {
            return r;
+46 −12
Original line number Diff line number Diff line
@@ -227,6 +227,15 @@ class ContextImpl extends Context {
    private @NonNull Resources mResources;
    private @Nullable Display mDisplay; // may be null if invalid display or not initialized yet.

    /**
     * If set to {@code true} the resources for this context will be configured for mDisplay which
     * will override the display configuration inherited from {@link #mToken} (or the global
     * configuration if mToken is null). Typically set for display contexts and contexts derived
     * from display contexts where changes to the activity display and the global configuration
     * display should not impact their resources.
     */
    private boolean mForceDisplayOverrideInResources;

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    private final int mFlags;

@@ -2246,8 +2255,8 @@ class ContextImpl extends Context {
    }

    private static Resources createResources(IBinder activityToken, LoadedApk pi, String splitName,
            int displayId, Configuration overrideConfig, CompatibilityInfo compatInfo,
            List<ResourcesLoader> resourcesLoader) {
            @Nullable Integer overrideDisplayId, Configuration overrideConfig,
            CompatibilityInfo compatInfo, List<ResourcesLoader> resourcesLoader) {
        final String[] splitResDirs;
        final ClassLoader classLoader;
        try {
@@ -2261,7 +2270,7 @@ class ContextImpl extends Context {
                splitResDirs,
                pi.getOverlayDirs(),
                pi.getApplicationInfo().sharedLibraryFiles,
                displayId,
                overrideDisplayId,
                overrideConfig,
                compatInfo,
                classLoader,
@@ -2278,8 +2287,10 @@ class ContextImpl extends Context {
                    new UserHandle(UserHandle.getUserId(application.uid)), flags, null, null);

            final int displayId = getDisplayId();
            final Integer overrideDisplayId = mForceDisplayOverrideInResources
                    ? displayId : null;

            c.setResources(createResources(mToken, pi, null, displayId, null,
            c.setResources(createResources(mToken, pi, null, overrideDisplayId, null,
                    getDisplayAdjustments(displayId).getCompatibilityInfo(), null));
            if (c.mResources != null) {
                return c;
@@ -2313,8 +2324,10 @@ class ContextImpl extends Context {
                    mToken, user, flags, null, null);

            final int displayId = getDisplayId();
            final Integer overrideDisplayId = mForceDisplayOverrideInResources
                    ? displayId : null;

            c.setResources(createResources(mToken, pi, null, displayId, null,
            c.setResources(createResources(mToken, pi, null, overrideDisplayId, null,
                    getDisplayAdjustments(displayId).getCompatibilityInfo(), null));
            if (c.mResources != null) {
                return c;
@@ -2348,15 +2361,13 @@ class ContextImpl extends Context {
        final ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo,
                mAttributionTag, splitName, mToken, mUser, mFlags, classLoader, null);

        final int displayId = getDisplayId();

        context.setResources(ResourcesManager.getInstance().getResources(
                mToken,
                mPackageInfo.getResDir(),
                paths,
                mPackageInfo.getOverlayDirs(),
                mPackageInfo.getApplicationInfo().sharedLibraryFiles,
                displayId,
                mForceDisplayOverrideInResources ? getDisplayId() : null,
                null,
                mPackageInfo.getCompatibilityInfo(),
                classLoader,
@@ -2370,12 +2381,23 @@ class ContextImpl extends Context {
            throw new IllegalArgumentException("overrideConfiguration must not be null");
        }

        if (mForceDisplayOverrideInResources) {
            // Ensure the resources display metrics are adjusted to match the display this context
            // is based on.
            Configuration displayAdjustedConfig = new Configuration();
            displayAdjustedConfig.setTo(mDisplay.getDisplayAdjustments().getConfiguration(),
                    ActivityInfo.CONFIG_WINDOW_CONFIGURATION, 1);
            displayAdjustedConfig.updateFrom(overrideConfiguration);
            overrideConfiguration = displayAdjustedConfig;
        }

        ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mAttributionTag,
                mSplitName, mToken, mUser, mFlags, mClassLoader, null);

        final int displayId = getDisplayId();

        context.setResources(createResources(mToken, mPackageInfo, mSplitName, displayId,
        final Integer overrideDisplayId = mForceDisplayOverrideInResources
                ? displayId : null;
        context.setResources(createResources(mToken, mPackageInfo, mSplitName, overrideDisplayId,
                overrideConfiguration, getDisplayAdjustments(displayId).getCompatibilityInfo(),
                mResources.getLoaders()));
        context.mIsUiContext = isUiContext() || isOuterUiContext();
@@ -2393,11 +2415,20 @@ class ContextImpl extends Context {

        final int displayId = display.getDisplayId();

        // Ensure the resources display metrics are adjusted to match the provided display.
        Configuration overrideConfig = new Configuration();
        overrideConfig.setTo(display.getDisplayAdjustments().getConfiguration(),
                ActivityInfo.CONFIG_WINDOW_CONFIGURATION, 1);

        context.setResources(createResources(mToken, mPackageInfo, mSplitName, displayId,
                null, getDisplayAdjustments(displayId).getCompatibilityInfo(),
                overrideConfig, display.getDisplayAdjustments().getCompatibilityInfo(),
                mResources.getLoaders()));
        context.mDisplay = display;
        context.mIsAssociatedWithDisplay = true;
        // Display contexts and any context derived from a display context should always override
        // the display that would otherwise be inherited from mToken (or the global configuration if
        // mToken is null).
        context.mForceDisplayOverrideInResources = true;
        return context;
    }

@@ -2415,8 +2446,10 @@ class ContextImpl extends Context {
        ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mAttributionTag,
                mSplitName, token, mUser, mFlags, mClassLoader, null);
        context.mIsUiContext = true;

        context.mIsAssociatedWithDisplay = true;
        // Window contexts receive configurations directly from the server and as such do not
        // need to override their display in ResourcesManager.
        context.mForceDisplayOverrideInResources = false;
        return context;
    }

@@ -2759,6 +2792,7 @@ class ContextImpl extends Context {
            mDisplay = container.mDisplay;
            mIsAssociatedWithDisplay = container.mIsAssociatedWithDisplay;
            mIsSystemOrSystemUiContext = container.mIsSystemOrSystemUiContext;
            mForceDisplayOverrideInResources = container.mForceDisplayOverrideInResources;
        } else {
            mBasePackageName = packageInfo.mPackageName;
            ApplicationInfo ainfo = packageInfo.getApplicationInfo();
+2 −3
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.view.Display;
import android.view.DisplayAdjustments;

import com.android.internal.util.ArrayUtils;
@@ -367,7 +366,7 @@ public final class LoadedApk {

                mResources = ResourcesManager.getInstance().getResources(null, mResDir,
                        splitPaths, mOverlayDirs, mApplicationInfo.sharedLibraryFiles,
                        Display.DEFAULT_DISPLAY, null, getCompatibilityInfo(),
                        null, null, getCompatibilityInfo(),
                        getClassLoader(), mApplication == null ? null
                                : mApplication.getResources().getLoaders());
            }
@@ -1231,7 +1230,7 @@ public final class LoadedApk {

            mResources = ResourcesManager.getInstance().getResources(null, mResDir,
                    splitPaths, mOverlayDirs, mApplicationInfo.sharedLibraryFiles,
                    Display.DEFAULT_DISPLAY, null, getCompatibilityInfo(),
                    null, null, getCompatibilityInfo(),
                    getClassLoader(), null);
        }
        return mResources;
+303 −131

File changed.

Preview size limit exceeded, changes collapsed.

Loading