Skip to content
Commit d5c5a1b4 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Make process level rotated config and display metrics consistent

The application may get Resources instance from Resources.getSystem()
and context.getApplicationContext().getResources(). Since fixed
rotation is introduced that allows an activity to start in a different
rotation than the current display, when using getConfiguration() and
getDisplayMetrics() of these Resources instances, the orientation
and metrics need to be the same as current display is rotated.
Otherwise the app may show unexpected UI layout.

Although it is not recommended to use global resources/config for
activity. One of the goal of fixed rotation transform is to simulate
the app is started in a rotated environment, so this CL makes the
configuration and display metrics of system resources are consistent
with application and activity for compatibility.

About WindowProcessController and ActivityStackSupervisor:
 The process configuration passed to LaunchActivityItem may be
 associated from activity. if the sequence number of configuration
 is overridden by activity, the configuration may be ignored when
 launching the activity because the sequence number isn't larger
 than the previous process configuration. Although there will be a
 ConfigurationChangeItem later to update correct state, the app may
 get the intermediate state with old configuration and metrics.

About ResourcesManager and DisplayAdjustments:
 There are 2 new fields appWidth and appHeight added to
 DisplayAdjustments#FixedRotationAdjustments because the display
 metrics from Resources.getSystem() is independent from activity
 configuration. Only window manager knows the rotated size, so
 the values need to send to client and then ResourcesManager takes
 the adjustment to change the global display metrics.

About WindowToken:
 When fixed rotation is applied on the token, send the
 FixedRotationAdjustmentsItem first so the later configuration
 change can pick the adjustment at ActivityThread. And because the
 registration of activity configuration only occurs on add/remove
 activity, if it is only switching to another existing activity in
 different orientation, the process configuration still needs to
 be updated.

About ActivityThread:
 The code flow for a rotated activity (DA = display adjustments):
 - Launch new activity
    handleLaunchActivity: override app DA
     handleConfigurationChanged: adjust global display metrics by DA
     performLaunchActivity
      createBaseContextForActivity: override activity DA
 - Resume existing activity
    handleFixedRotationAdjustments: override app and activity DA
    handleConfigurationChanged: adjust global display metrics by DA
    handleResumeActivity

Also some minor corrections:
- Set missing rotated max bounds.
- Fix wrong display metrics adjustment that xdpi and ydpi should
  not be swapped because they are physical attributes.

Bug: 167564038
Test: atest DisplayAdjustmentsTests
      AppConfigurationTests#testRotatedInfoWithFixedRotationTransform
      WindowProcessControllerTests#testProcessLevelConfiguration
      DisplayContenTests#testApplyTopFixedRotationTransform

Change-Id: I60bedc7e09f54683d5e857ccc51402d5d144cd9e
parent a67c5344
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment