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

Commit 286845eb authored by Charles Chen's avatar Charles Chen
Browse files

Report Activity config changes only if it handles the change

In S, we don't dispatch #onConfigurationChanged callback if the screen
size changes doesn't corss size buckets. However,user may still want
to know the change even if it's very small.
This CL changes to dispatch the callback if the Activity handles
the config changes.
Also clean-up the unused code.

Bug: 202468254
Test: atest AppConfigurationTests
Change-Id: Ief68922ed80a0fcfc05c7ccb5e3692334352a2c3
parent 490be11e
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import static android.content.ContentResolver.DEPRECATE_DATA_COLUMNS;
import static android.content.ContentResolver.DEPRECATE_DATA_PREFIX;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.window.ConfigurationHelper.diffPublicWithSizeBuckets;
import static android.window.ConfigurationHelper.freeTextLayoutCachesIfNeeded;
import static android.window.ConfigurationHelper.isDifferentDisplay;
import static android.window.ConfigurationHelper.shouldUpdateResources;
@@ -5940,15 +5939,15 @@ public final class ActivityThread extends ClientTransactionHandler

        final boolean movedToDifferentDisplay = isDifferentDisplay(activity.getDisplayId(),
                displayId);
        final ActivityClientRecord r = mActivities.get(activityToken);
        final int diff = diffPublicWithSizeBuckets(activity.mCurrentConfig,
                newConfig, r != null ? r.mSizeConfigurations : null);
        final Configuration currentConfig = activity.mCurrentConfig;
        final int diff = (currentConfig == null) ? 0xffffffff
                : currentConfig.diffPublicOnly(newConfig);
        final boolean hasPublicConfigChange = diff != 0;
        // TODO(b/173090263): Use diff instead after the improvement of AssetManager and
        // ResourcesImpl constructions.
        final boolean shouldUpdateResources = hasPublicConfigChange
                || shouldUpdateResources(activityToken, activity.mCurrentConfig, newConfig,
                amOverrideConfig, movedToDifferentDisplay, hasPublicConfigChange);
                || shouldUpdateResources(activityToken, currentConfig, newConfig, amOverrideConfig,
                movedToDifferentDisplay, hasPublicConfigChange);
        final boolean shouldReportChange = hasPublicConfigChange
                // If this activity doesn't handle any of the config changes, then don't bother
                // calling onConfigurationChanged. Otherwise, report to the activity for the
+0 −18
Original line number Diff line number Diff line
@@ -46,24 +46,6 @@ public class ConfigurationHelper {
        }
    }

    /**
     * A helper method to filter out {@link ActivityInfo#CONFIG_SCREEN_SIZE} if the
     * {@link Configuration#diffPublicOnly(Configuration) diff} of two {@link Configuration}
     * doesn't cross the boundary.
     *
     * @see SizeConfigurationBuckets#filterDiff(int, Configuration, Configuration,
     * SizeConfigurationBuckets)
     */
    public static int diffPublicWithSizeBuckets(@Nullable Configuration currentConfig,
            @NonNull Configuration newConfig, @Nullable SizeConfigurationBuckets buckets) {
        // If current configuration is null, it is definitely different from updated Configuration.
        if (currentConfig == null) {
            return 0xffffffff;
        }
        int publicDiff = currentConfig.diffPublicOnly(newConfig);
        return SizeConfigurationBuckets.filterDiff(publicDiff, currentConfig, newConfig, buckets);
    }

    /**
     * Returns {@code true} if the {@link android.content.res.Resources} associated with
     * a {@code token} needs to be updated.