From a163b76570d15e0bbfd318b2962c4966a8a538e5 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Tue, 24 Jan 2017 11:05:01 -0800 Subject: [PATCH] Allow opening activity to specify orientation. An activity's window is initially not visible. This means it is not accounted for until it becomes visible, which means requested orientations will not be honored until after onCreate. This changelist removes the visibility check previously used determining the orientation. This changelist also addresses an issue where an ActivityRecord member variable tracking the last configuration sent was not being initially updated. Fixes: 33844887 Fixes: 33814250 Fixes: 34165818 Fixes: 34177026 Fixes: 33809086 Fixes: 34111451 Fixes: 33844423 Test: Verified reported issues fixed in apps mentioned in bugs Test: bit FrameworksServicesTests:com.android.server.wm.WindowContainerTests Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test android.server.cts.ActivityManagerAppConfigurationTests Change-Id: If9243792b9f2d137dc5addbf6fb735a0048fa192 --- .../com/android/server/am/ActivityRecord.java | 15 ++++- .../server/am/ActivityStackSupervisor.java | 14 ++++- .../com/android/server/wm/AppWindowToken.java | 7 ++- .../android/server/wm/WindowContainer.java | 9 ++- .../server/wm/WindowContainerTests.java | 58 ++++++++++++++++--- 5 files changed, 81 insertions(+), 22 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index baf7772206919..020e75f9fec42 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -1899,11 +1899,22 @@ final class ActivityRecord implements AppWindowContainerListener { task.taskId, requestedOrientation); } - // TODO: now used only in one place to address race-condition. Remove when that will be fixed. - void setLastReportedConfiguration(@NonNull Configuration config) { + /** + * Set the last reported global configuration to the client. Should be called whenever a new + * global configuration is sent to the client for this activity. + */ + void setLastReportedGlobalConfiguration(@NonNull Configuration config) { mLastReportedConfiguration.setTo(config); } + /** + * Set the last reported merged override configuration to the client. Should be called whenever + * a new merged configuration is sent to the client for this activity. + */ + void setLastReportedMergedOverrideConfiguration(@NonNull Configuration config) { + mLastReportedOverrideConfiguration.setTo(config); + } + /** Call when override config was sent to the Window Manager to update internal records. */ void onOverrideConfigurationSent() { mLastReportedOverrideConfiguration.setTo(task.getMergedOverrideConfiguration()); diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index b2b3e61ca534f..ef06fc581ebb4 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -1333,10 +1333,18 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D // Because we could be starting an Activity in the system process this may not go across // a Binder interface which would create a new Configuration. Consequently we have to // always create a new Configuration here. + + final Configuration globalConfiguration = + new Configuration(mService.getGlobalConfiguration()); + r.setLastReportedGlobalConfiguration(globalConfiguration); + final Configuration mergedOverrideConfiguration = + new Configuration(task.getMergedOverrideConfiguration()); + r.setLastReportedMergedOverrideConfiguration(mergedOverrideConfiguration); + app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken, System.identityHashCode(r), r.info, - new Configuration(mService.getGlobalConfiguration()), - new Configuration(task.getMergedOverrideConfiguration()), r.compat, + globalConfiguration, + mergedOverrideConfiguration, r.compat, r.launchedFromPackage, task.voiceInteractor, app.repProcState, r.icicle, r.persistentState, results, newIntents, !andResume, mService.isNextTransitionForward(), profilerInfo); @@ -1731,7 +1739,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D // We'll update with whatever configuration it now says // it used to launch. if (config != null) { - r.setLastReportedConfiguration(config); + r.setLastReportedGlobalConfiguration(config); } // We are now idle. If someone is waiting for a thumbnail from diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java index bcc720d05424e..d643769736163 100644 --- a/services/core/java/com/android/server/wm/AppWindowToken.java +++ b/services/core/java/com/android/server/wm/AppWindowToken.java @@ -1151,10 +1151,11 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree */ @Override int getOrientation() { - if (hidden || hiddenRequested) { - return SCREEN_ORIENTATION_UNSET; + if (fillsParent() && (isVisible() || mService.mOpeningApps.contains(this))) { + return mOrientation; } - return mOrientation; + + return SCREEN_ORIENTATION_UNSET; } /** Returns the app's preferred orientation regardless of its currently visibility state. */ diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index 5b96263b18172..6973c3c95d49d 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -510,14 +510,13 @@ class WindowContainer implements Comparable