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

Commit cac2f8a0 authored by Charles Chen's avatar Charles Chen
Browse files

Fix WindowMetrics not get updated when moving a freeform activity

Previously, we only applied the config changes to Resources if a public
fields are updated. After WM#getCurrent(Maximum)WindowMetrics were
released, we should also update WindowConfiguration changes to the
Resources because WindowMetrics#getBounds is provided by
WindowConfiguration fields.

This CL updates the window configuration to Resources if there are
differences between current & updated window configuration.

Bug: 169687278
Test: atest WindowMetricsOnActivityTests

Change-Id: I822204dab226d0acae2a0966b8ea05cf8f578b49
parent 8edab97f
Loading
Loading
Loading
Loading
+31 −7
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ import android.database.sqlite.SQLiteDebug.DbStats;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.HardwareRenderer;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.hardware.display.DisplayManagerGlobal;
import android.inputmethodservice.InputMethodService;
@@ -5623,10 +5624,13 @@ public final class ActivityThread extends ClientTransactionHandler {
            // If the new config is the same as the config this Activity is already running with and
            // the override config also didn't change, then don't bother calling
            // onConfigurationChanged.
            // TODO(b/173090263): Use diff instead after the improvement of AssetManager and
            // ResourcesImpl constructions.
            final int diff = activity.mCurrentConfig.diffPublicOnly(newConfig);
            if (diff == 0 && !movedToDifferentDisplay
                    && mResourcesManager.isSameResourcesOverrideConfig(activityToken,
                    amOverrideConfig)) {

            if (diff == 0 && !shouldUpdateWindowMetricsBounds(activity.mCurrentConfig, newConfig)
                    && !movedToDifferentDisplay && mResourcesManager.isSameResourcesOverrideConfig(
                            activityToken, amOverrideConfig)) {
                // Nothing significant, don't proceed with updating and reporting.
                return null;
            } else if ((~activity.mActivityInfo.getRealConfigChanged() & diff) == 0) {
@@ -5678,6 +5682,26 @@ public final class ActivityThread extends ClientTransactionHandler {
        return configToReport;
    }

    // TODO(b/173090263): Remove this method after the improvement of AssetManager and ResourcesImpl
    // constructions.
    /**
     * Returns {@code true} if the metrics reported by {@link android.view.WindowMetrics} APIs
     * should be updated.
     *
     * @see WindowManager#getCurrentWindowMetrics()
     * @see WindowManager#getMaximumWindowMetrics()
     */
    private static boolean shouldUpdateWindowMetricsBounds(@NonNull Configuration currentConfig,
            @NonNull Configuration newConfig) {
        final Rect currentBounds = currentConfig.windowConfiguration.getBounds();
        final Rect newBounds = newConfig.windowConfiguration.getBounds();

        final Rect currentMaxBounds = currentConfig.windowConfiguration.getMaxBounds();
        final Rect newMaxBounds = newConfig.windowConfiguration.getMaxBounds();

        return !currentBounds.equals(newBounds) || !currentMaxBounds.equals(newMaxBounds);
    }

    public final void applyConfigurationToResources(Configuration config) {
        synchronized (mResourcesManager) {
            mResourcesManager.applyConfigurationToResourcesLocked(config, null);
@@ -5912,7 +5936,7 @@ public final class ActivityThread extends ClientTransactionHandler {
    /**
     * Sets the supplied {@code overrideConfig} as pending for the {@code activityToken}. Calling
     * this method prevents any calls to
     * {@link #handleActivityConfigurationChanged(IBinder, Configuration, int, boolean)} from
     * {@link #handleActivityConfigurationChanged(ActivityClientRecord, Configuration, int)} from
     * processing any configurations older than {@code overrideConfig}.
     */
    @Override
@@ -5934,8 +5958,8 @@ public final class ActivityThread extends ClientTransactionHandler {

    /**
     * Handle new activity configuration and/or move to a different display. This method is a noop
     * if {@link #updatePendingActivityConfiguration(IBinder, Configuration)} has been called with
     * a newer config than {@code overrideConfig}.
     * if {@link #updatePendingActivityConfiguration(ActivityClientRecord, Configuration)} has been
     * called with a newer config than {@code overrideConfig}.
     *
     * @param r Target activity record.
     * @param overrideConfig Activity override config.
@@ -6000,7 +6024,7 @@ public final class ActivityThread extends ClientTransactionHandler {

    /**
     * Checks if the display id of activity is different from the given one. Note that
     * {@link #INVALID_DISPLAY} means no difference.
     * {@link Display#INVALID_DISPLAY} means no difference.
     */
    private static boolean isDifferentDisplay(@NonNull Activity activity, int displayId) {
        return displayId != INVALID_DISPLAY && displayId != activity.getDisplayId();
+2 −0
Original line number Diff line number Diff line
@@ -1178,6 +1178,8 @@ public class ResourcesManager {
                        continue;
                    }

                    // TODO(b/173090263): Improve the performance of AssetManager & ResourcesImpl
                    // constructions.
                    final ResourcesImpl resourcesImpl =
                            findOrCreateResourcesImplForKeyLocked(newKey);
                    if (resourcesImpl != null && resourcesImpl != resources.getImpl()) {