diff options
| author | Riddle Hsu <riddlehsu@google.com> | 2020-06-03 14:50:46 +0800 |
|---|---|---|
| committer | Riddle Hsu <riddlehsu@google.com> | 2020-06-03 22:34:01 +0800 |
| commit | a474039bdc60fd75075c4ff5a7fdeab05e799788 (patch) | |
| tree | c3aa668d675c99f44165124de4f77738c8c805e5 /core/java/android | |
| parent | 75f35b0494fd200ce2d4bd58187654da5bc99fe6 (diff) | |
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
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index cffa59c06a53..7bd477be1563 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -3252,18 +3252,56 @@ 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. - return; + 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 @@ -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; } |
