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

Commit 946e8df6 authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Update resource config for default display

When a launched application doesn't occupy the entire screen space,
there is a mismatch between the configuration of the process and the
configuration of activities. This leads to compatibility issues with
apps that don't expect this, read display metrics from Application
resources and try to apply them in activities.

The platform may apply a compatibility mode, in which the process
configuration will match the config of the top running activity. This
means that the process configuration may change and runtime and
result in display adjustments that are different from the default
values. This CL propagates resource configuration updates even for
default display to make sure that the config changes are reflected
for non-activity contexts.

Test: CtsWindowManagerDeviceTestCases:AppConfigurationTests
Change-Id: I91cadc83a82a3be8c8dee810bbd1aa97cbe4e97f
parent fa23a9ee
Loading
Loading
Loading
Loading
+21 −30
Original line number Diff line number Diff line
@@ -1208,8 +1208,7 @@ public class ResourcesManager {
                WeakReference<ResourcesImpl> weakImplRef = mResourceImpls.valueAt(i);
                ResourcesImpl r = weakImplRef != null ? weakImplRef.get() : null;
                if (r != null) {
                    applyConfigurationToResourcesLocked(config, compat, tmpConfig,
                            defaultDisplayMetrics, key, r);
                    applyConfigurationToResourcesLocked(config, compat, tmpConfig, key, r);
                } else {
                    mResourceImpls.removeAt(i);
                }
@@ -1224,8 +1223,7 @@ public class ResourcesManager {
                }

                applyConfigurationToResourcesLocked(config, compat, tmpConfig,
                        defaultDisplayMetrics, resourcesWithLoaders.resourcesKey(),
                        resources.getImpl());
                        resourcesWithLoaders.resourcesKey(), resources.getImpl());
            }

            return changes != 0;
@@ -1236,30 +1234,26 @@ public class ResourcesManager {

    private void applyConfigurationToResourcesLocked(@NonNull Configuration config,
            @Nullable CompatibilityInfo compat, Configuration tmpConfig,
            DisplayMetrics defaultDisplayMetrics, ResourcesKey key, ResourcesImpl resourcesImpl) {
            ResourcesKey key, ResourcesImpl resourcesImpl) {
        if (DEBUG || DEBUG_CONFIGURATION) {
            Slog.v(TAG, "Changing resources "
                    + resourcesImpl + " config to: " + config);
        }
        int displayId = key.mDisplayId;
        boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
        DisplayMetrics dm = defaultDisplayMetrics;
        final boolean hasOverrideConfiguration = key.hasOverrideConfiguration();
        if (!isDefaultDisplay || hasOverrideConfiguration) {
        tmpConfig.setTo(config);

            // Get new DisplayMetrics based on the DisplayAdjustments given
            // to the ResourcesImpl. Update a copy if the CompatibilityInfo
            // changed, because the ResourcesImpl object will handle the
        // Get new DisplayMetrics based on the DisplayAdjustments given to the ResourcesImpl. Update
        // a copy if the CompatibilityInfo changed, because the ResourcesImpl object will handle the
        // update internally.
        DisplayAdjustments daj = resourcesImpl.getDisplayAdjustments();
        if (compat != null) {
            daj = new DisplayAdjustments(daj);
            daj.setCompatibilityInfo(compat);
        }
            dm = getDisplayMetrics(displayId, daj);

            if (!isDefaultDisplay) {
        daj.setConfiguration(config);
        DisplayMetrics dm = getDisplayMetrics(displayId, daj);
        if (displayId != Display.DEFAULT_DISPLAY) {
            applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
        }

@@ -1267,9 +1261,6 @@ public class ResourcesManager {
            tmpConfig.updateFrom(key.mOverrideConfiguration);
        }
        resourcesImpl.updateConfiguration(tmpConfig, dm, compat);
        } else {
            resourcesImpl.updateConfiguration(config, dm, compat);
        }
    }

    /**
+4 −3
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.annotation.TestApi;
import android.app.KeyguardManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Point;
import android.media.projection.MediaProjection;
import android.os.Handler;
@@ -400,10 +401,10 @@ public final class DisplayManager {
        if (display == null) {
            // TODO: We cannot currently provide any override configurations for metrics on displays
            // other than the display the context is associated with.
            final Context context = mContext.getDisplayId() == displayId
                    ? mContext : mContext.getApplicationContext();
            final Resources resources = mContext.getDisplayId() == displayId
                    ? mContext.getResources() : null;

            display = mGlobal.getCompatibleDisplay(displayId, context.getResources());
            display = mGlobal.getCompatibleDisplay(displayId, resources);
            if (display != null) {
                mDisplays.put(displayId, display);
            }
+1 −1
Original line number Diff line number Diff line
@@ -453,7 +453,7 @@ public final class Display {
        mResources = res;
        mDisplayAdjustments = mResources != null
            ? new DisplayAdjustments(mResources.getConfiguration())
            : daj != null ? new DisplayAdjustments(daj) : null;
            : daj != null ? new DisplayAdjustments(daj) : new DisplayAdjustments();
        mIsValid = true;

        // Cache properties that cannot change as long as the display is valid.