diff options
3 files changed, 61 insertions, 38 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index c92c36052e72..f3ecfeb40498 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -20180,6 +20180,11 @@ public class ActivityManagerService extends IActivityManager.Stub mTempConfig.setTo(getGlobalConfiguration()); final int changes = mTempConfig.updateFrom(values); if (changes == 0) { + // Since calling to Activity.setRequestedOrientation leads to freezing the window with + // setting WindowManagerService.mWaitingForConfig to true, it is important that we call + // performDisplayOverrideConfigUpdate in order to send the new display configuration + // (even if there are no actual changes) to unfreeze the window. + performDisplayOverrideConfigUpdate(values, deferResume, DEFAULT_DISPLAY); return 0; } @@ -20368,20 +20373,19 @@ public class ActivityManagerService extends IActivityManager.Stub int displayId) { mTempConfig.setTo(mStackSupervisor.getDisplayOverrideConfiguration(displayId)); final int changes = mTempConfig.updateFrom(values); - if (changes == 0) { - return 0; - } - - Slog.i(TAG, "Override config changes=" + Integer.toHexString(changes) + " " + mTempConfig - + " for displayId=" + displayId); - mStackSupervisor.setDisplayOverrideConfiguration(mTempConfig, displayId); + if (changes != 0) { + Slog.i(TAG, "Override config changes=" + Integer.toHexString(changes) + " " + + mTempConfig + " for displayId=" + displayId); + mStackSupervisor.setDisplayOverrideConfiguration(mTempConfig, displayId); - final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0; - if (isDensityChange && displayId == DEFAULT_DISPLAY) { - // Reset the unsupported display size dialog. - mUiHandler.sendEmptyMessage(SHOW_UNSUPPORTED_DISPLAY_SIZE_DIALOG_MSG); + final boolean isDensityChange = (changes & ActivityInfo.CONFIG_DENSITY) != 0; + if (isDensityChange && displayId == DEFAULT_DISPLAY) { + // Reset the unsupported display size dialog. + mUiHandler.sendEmptyMessage(SHOW_UNSUPPORTED_DISPLAY_SIZE_DIALOG_MSG); - killAllBackgroundProcessesExcept(N, ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE); + killAllBackgroundProcessesExcept(N, + ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE); + } } // Update the configuration with WM first and check if any of the stacks need to be resized diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index e828d38ef249..b55bae91da8d 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -470,7 +470,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } Configuration getDisplayOverrideConfiguration(int displayId) { - final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); + final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); if (activityDisplay == null) { throw new IllegalArgumentException("No display found with id: " + displayId); } @@ -479,7 +479,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } void setDisplayOverrideConfiguration(Configuration overrideConfiguration, int displayId) { - final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); + final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); if (activityDisplay == null) { throw new IllegalArgumentException("No display found with id: " + displayId); } @@ -507,7 +507,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D if (displayId == INVALID_DISPLAY) { return false; } - final ActivityDisplay targetDisplay = mActivityDisplays.get(displayId); + final ActivityDisplay targetDisplay = getActivityDisplayOrCreateLocked(displayId); if (targetDisplay == null) { throw new IllegalArgumentException("No display found with id: " + displayId); } @@ -1672,7 +1672,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: displayId=" + launchDisplayId + " callingPid=" + callingPid + " callingUid=" + callingUid); - final ActivityDisplay activityDisplay = mActivityDisplays.get(launchDisplayId); + final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(launchDisplayId); if (activityDisplay == null) { Slog.w(TAG, "Launch on display check: display not found"); return false; @@ -2191,7 +2191,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. */ ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r) { - final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); + final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); if (activityDisplay == null) { throw new IllegalArgumentException( "Display with displayId=" + displayId + " not found."); @@ -2242,10 +2242,9 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { final int displayId = mTmpOrderedDisplayIds.get(i); - final List<ActivityStack> stacks = mActivityDisplays.get(displayId).mStacks; - if (stacks == null) { - continue; - } + // If a display is registered in WM, it must also be available in AM. + @SuppressWarnings("ConstantConditions") + final List<ActivityStack> stacks = getActivityDisplayOrCreateLocked(displayId).mStacks; for (int j = stacks.size() - 1; j >= 0; --j) { final ActivityStack stack = stacks.get(j); if (stack != currentFocus && stack.isFocusable() @@ -2576,7 +2575,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } ActivityStack createStackOnDisplay(int stackId, int displayId, boolean onTop) { - final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); + final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); if (activityDisplay == null) { return null; } @@ -2808,7 +2807,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D * @param onTop Indicates whether container should be place on top or on bottom. */ void moveStackToDisplayLocked(int stackId, int displayId, boolean onTop) { - final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); + final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); if (activityDisplay == null) { throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown displayId=" + displayId); @@ -3915,25 +3914,44 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } private void handleDisplayAdded(int displayId) { - boolean newDisplay; synchronized (mService) { - newDisplay = mActivityDisplays.get(displayId) == null; - if (newDisplay) { - ActivityDisplay activityDisplay = new ActivityDisplay(displayId); - if (activityDisplay.mDisplay == null) { - Slog.w(TAG, "Display " + displayId + " gone before initialization complete"); - return; - } - mActivityDisplays.put(displayId, activityDisplay); - calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); - mWindowManager.onDisplayAdded(displayId); - } + getActivityDisplayOrCreateLocked(displayId); } } /** Check if display with specified id is added to the list. */ boolean isDisplayAdded(int displayId) { - return mActivityDisplays.get(displayId) != null; + return getActivityDisplayOrCreateLocked(displayId) != null; + } + + /** + * Get an existing instance of {@link ActivityDisplay} or create new if there is a + * corresponding record in display manager. + */ + private ActivityDisplay getActivityDisplayOrCreateLocked(int displayId) { + ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); + if (activityDisplay != null) { + return activityDisplay; + } + if (mDisplayManager == null) { + // The system isn't fully initialized yet. + return null; + } + final Display display = mDisplayManager.getDisplay(displayId); + if (display == null) { + // The display is not registered in DisplayManager. + return null; + } + // The display hasn't been added to ActivityManager yet, create a new record now. + activityDisplay = new ActivityDisplay(displayId); + if (activityDisplay.mDisplay == null) { + Slog.w(TAG, "Display " + displayId + " gone before initialization complete"); + return null; + } + mActivityDisplays.put(displayId, activityDisplay); + calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); + mWindowManager.onDisplayAdded(displayId); + return activityDisplay; } private void calculateDefaultMinimalSizeOfResizeableTasks(ActivityDisplay display) { @@ -3991,6 +4009,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D info.stackId = stack.mStackId; info.userId = stack.mCurrentUser; info.visible = stack.shouldBeVisible(null) == STACK_VISIBLE; + // A stack might be not attached to a display. info.position = display != null ? display.mStacks.indexOf(stack) : 0; @@ -4618,7 +4637,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D @Override public void addToDisplay(int displayId) { synchronized (mService) { - ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); + final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); if (activityDisplay == null) { return; } diff --git a/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java b/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java index c080f344c186..4da9c060fc4d 100644 --- a/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java +++ b/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java @@ -52,7 +52,7 @@ public class WindowManagerDebugConfig { static final boolean DEBUG_CONFIGURATION = false; static final boolean DEBUG_APP_TRANSITIONS = false; static final boolean DEBUG_STARTING_WINDOW_VERBOSE = false; - static final boolean DEBUG_STARTING_WINDOW = DEBUG_STARTING_WINDOW_VERBOSE || true; + static final boolean DEBUG_STARTING_WINDOW = DEBUG_STARTING_WINDOW_VERBOSE || false; static final boolean DEBUG_WALLPAPER = false; static final boolean DEBUG_WALLPAPER_LIGHT = false || DEBUG_WALLPAPER; static final boolean DEBUG_DRAG = false; |