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

Commit a474039b authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Override application display adjustments while launching activity

A launching activity with fixed rotation may get information from
a Display object which is associated with application resources.
In order to let the display size and rotation are consistent with
the activity configuration, the override configuration of activity
will update to the display adjustments of application resources.

Fixes: 157558894
Test: AppConfigurationTests#testRotatedInfoWithFixedRotationTransform

Change-Id: I7f72d838170a5f588bb8dd279ae081d1a3ddba95
parent 75f35b04
Loading
Loading
Loading
Loading
+48 −9
Original line number Diff line number Diff line
@@ -3252,19 +3252,57 @@ public final class ActivityThread extends ClientTransactionHandler {
    @Override
    public void handleFixedRotationAdjustments(@NonNull IBinder token,
            @Nullable FixedRotationAdjustments fixedRotationAdjustments) {
        final Consumer<DisplayAdjustments> override = fixedRotationAdjustments != null
                ? displayAdjustments -> displayAdjustments.setFixedRotationAdjustments(
                        fixedRotationAdjustments)
                : null;
        handleFixedRotationAdjustments(token, fixedRotationAdjustments, null /* overrideConfig */);
    }

    /**
     * Applies the rotation adjustments to override display information in resources belong to the
     * provided token. If the token is activity token, the adjustments also apply to application
     * because the appearance of activity is usually more sensitive to the application resources.
     *
     * @param token The token to apply the adjustments.
     * @param fixedRotationAdjustments The information to override the display adjustments of
     *                                 corresponding resources. If it is null, the exiting override
     *                                 will be cleared.
     * @param overrideConfig The override configuration of activity. It is used to override
     *                       application configuration. If it is non-null, it means the token is
     *                       confirmed as activity token. Especially when launching new activity,
     *                       {@link #mActivities} hasn't put the new token.
     */
    private void handleFixedRotationAdjustments(@NonNull IBinder token,
            @Nullable FixedRotationAdjustments fixedRotationAdjustments,
            @Nullable Configuration overrideConfig) {
        // The element of application configuration override is set only if the application
        // adjustments are needed, because activity already has its own override configuration.
        final Configuration[] appConfigOverride;
        final Consumer<DisplayAdjustments> override;
        if (fixedRotationAdjustments != null) {
            appConfigOverride = new Configuration[1];
            override = displayAdjustments -> {
                displayAdjustments.setFixedRotationAdjustments(fixedRotationAdjustments);
                if (appConfigOverride[0] != null) {
                    displayAdjustments.getConfiguration().updateFrom(appConfigOverride[0]);
                }
            };
        } else {
            appConfigOverride = null;
            override = null;
        }
        if (!mResourcesManager.overrideTokenDisplayAdjustments(token, override)) {
            // No resources are associated with the token.
            return;
        }
        if (mActivities.get(token) == null) {
            // Only apply the override to application for activity token because the appearance of
            // activity is usually more sensitive to the application resources.
        if (overrideConfig == null) {
            final ActivityClientRecord r = mActivities.get(token);
            if (r == null) {
                // It is not an activity token. Nothing to do for application.
                return;
            }
            overrideConfig = r.overrideConfig;
        }
        if (appConfigOverride != null) {
            appConfigOverride[0] = overrideConfig;
        }

        // Apply the last override to application resources for compatibility. Because the Resources
        // of Display can be from application, e.g.
@@ -3503,7 +3541,8 @@ public final class ActivityThread extends ClientTransactionHandler {
        // The rotation adjustments must be applied before creating the activity, so the activity
        // can get the adjusted display info during creation.
        if (r.mPendingFixedRotationAdjustments != null) {
            handleFixedRotationAdjustments(r.token, r.mPendingFixedRotationAdjustments);
            handleFixedRotationAdjustments(r.token, r.mPendingFixedRotationAdjustments,
                    r.overrideConfig);
            r.mPendingFixedRotationAdjustments = null;
        }