Skip to content
Browse files

Fix up expanded desktop behaviour.

The expanded desktop mode had a number of issues:
- It didn't handle multi-user scenarios correctly
- In the keyguard, the status bar was shown while the navigation bar was
  hidden, which was inconsistent to the !keyguard case
- Live wallpaper sizing was incorrect when expanded desktop mode was
  enabled due wallpaper windows not being recalculated correctly after
  enabling expanded desktop

This patch should fix all of those items.

Change-Id: I976ffae3a56d411b00026f86b16efa9743a23293
  • Loading branch information...
1 parent 4baf37a commit 667cdc82096a82d44c59914cdcd5652549b5fce1 @maniac103 maniac103 committed Mar 21, 2013
View
5 core/java/android/view/IWindowManager.aidl
@@ -265,4 +265,9 @@ interface IWindowManager
* credentials.
*/
void showAssistant();
+
+ /**
+ * Update the application display metrics
+ */
+ void updateDisplayMetrics();
}
View
86 policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -475,6 +475,8 @@ public void onInputEvent(InputEvent event) {
boolean mForcingShowNavBar;
int mForcingShowNavBarLayer;
+ int mExpandedDesktopStyle = -1;
+
// States of keyguard dismiss.
private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
@@ -1334,7 +1336,7 @@ public void setInitialDisplaySize(Display display, int width, int height, int de
public void updateSettings() {
ContentResolver resolver = mContext.getContentResolver();
- boolean updateRotation = false;
+ boolean updateRotation = false, updateDisplayMetrics = false;
synchronized (mLock) {
mEndcallBehavior = Settings.System.getIntForUser(resolver,
Settings.System.END_BUTTON_BEHAVIOR,
@@ -1415,6 +1417,18 @@ public void updateSettings() {
}
}
+ int expandedDesktopStyle = Settings.System.getIntForUser(resolver,
+ Settings.System.EXPANDED_DESKTOP_STYLE, 0, UserHandle.USER_CURRENT);
+ if (Settings.System.getIntForUser(resolver,
+ Settings.System.EXPANDED_DESKTOP_STATE, 0, UserHandle.USER_CURRENT) == 0) {
+ expandedDesktopStyle = 0;
+ }
+
+ if (expandedDesktopStyle != mExpandedDesktopStyle) {
+ mExpandedDesktopStyle = expandedDesktopStyle;
+ updateDisplayMetrics = true;
+ }
+
// Configure rotation lock.
int userRotation = Settings.System.getIntForUser(resolver,
Settings.System.USER_ROTATION, Surface.ROTATION_0,
@@ -1459,9 +1473,7 @@ public void updateSettings() {
}
// Update navigation bar dimensions
- boolean desktopExpanded = Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.EXPANDED_DESKTOP_STATE, 0) == 1;
- if (desktopExpanded) {
+ if (expandedDesktopHidesNavigationBar()) {
// Set the navigation bar's dimensions to 0 in expanded desktop mode
mNavigationBarWidthForRotation[mPortraitRotation]
= mNavigationBarWidthForRotation[mUpsideDownRotation]
@@ -1494,6 +1506,8 @@ public void updateSettings() {
if (updateRotation) {
updateRotation(true);
+ } else if (updateDisplayMetrics) {
+ updateDisplayMetrics();
}
}
@@ -2833,8 +2847,7 @@ public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect content
if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
== (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
int availRight, availBottom;
- if (mCanHideNavigationBar &&
- (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
+ if (shouldHideNavigationBarLw(systemUiVisibility)) {
availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
} else {
@@ -2919,8 +2932,11 @@ public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displa
// For purposes of positioning and showing the nav bar, if we have
// decided that it can't be hidden (because of the screen aspect ratio),
// then take that into account.
- navVisible |= !mCanHideNavigationBar;
- navVisible &= (Settings.System.getInt(mContext.getContentResolver(), Settings.System.EXPANDED_DESKTOP_STATE, 0) == 0);
+ if (expandedDesktopHidesNavigationBar()) {
+ navVisible = false;
+ } else if (!mCanHideNavigationBar) {
+ navVisible = true;
+ }
if (mNavigationBar != null) {
// Force the navigation bar to its appropriate place and
@@ -2999,8 +3015,12 @@ public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displa
// Let the status bar determine its size.
mStatusBar.computeFrameLw(pf, df, vf, vf);
- // For layout, the status bar is always at the top with our fixed height.
- mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
+ // For layout, the status bar is always at the top with our fixed height
+ // (except if it's hidden by expanded desktop, in which case we know it's
+ // never shown)
+ if (!expandedDesktopHidesStatusBar()) {
+ mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
+ }
// If the status bar is hidden, we don't want to cause
// windows behind it to scroll.
@@ -3202,8 +3222,7 @@ public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
"Laying out status bar window: (%d,%d - %d,%d)",
pf.left, pf.top, pf.right, pf.bottom));
}
- } else if (mCanHideNavigationBar
- && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
+ } else if (shouldHideNavigationBarLw(sysUiFl)
&& attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
&& attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
// Asking for layout as if the nav bar is hidden, lets the
@@ -3293,8 +3312,7 @@ public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
pf.right = df.right = cf.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
pf.bottom = df.bottom = cf.bottom
= mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
- } else if (mCanHideNavigationBar
- && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
+ } else if (shouldHideNavigationBarLw(sysUiFl)
&& attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
&& attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
// Asking for layout as if the nav bar is hidden, lets the
@@ -3399,6 +3417,28 @@ public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
}
}
+ private boolean expandedDesktopHidesStatusBar() {
+ return mExpandedDesktopStyle == 2;
+ }
+
+ private boolean expandedDesktopHidesNavigationBar() {
+ return mExpandedDesktopStyle != 0;
+ }
+
+ private boolean shouldHideNavigationBarLw(int systemUiVisibility) {
+ if (expandedDesktopHidesNavigationBar()) {
+ return true;
+ }
+
+ if (mCanHideNavigationBar) {
+ if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private void offsetInputMethodWindowLw(WindowState win) {
int top = win.getContentFrameLw().top;
top += win.getGivenContentInsetsLw().top;
@@ -3521,7 +3561,10 @@ public int finishPostLayoutPolicyLw() {
if (DEBUG_LAYOUT) Log.i(TAG, "force=" + mForceStatusBar
+ " forcefkg=" + mForceStatusBarFromKeyguard
+ " top=" + mTopFullscreenOpaqueWindowState);
- if (mForceStatusBar || mForceStatusBarFromKeyguard) {
+ if (expandedDesktopHidesStatusBar()) {
+ if (DEBUG_LAYOUT) Log.v(TAG, "Hiding status bar: expanded desktop enabled");
+ if (mStatusBar.hideLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
+ } else if (mForceStatusBar || mForceStatusBarFromKeyguard) {
if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar: forced");
if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
} else if (mTopFullscreenOpaqueWindowState != null) {
@@ -3537,10 +3580,7 @@ public int finishPostLayoutPolicyLw() {
// and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
// has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
// case though.
- if (topIsFullscreen || (Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.EXPANDED_DESKTOP_STATE, 0) == 1 &&
- Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.EXPANDED_DESKTOP_STYLE, 0) == 2)) {
+ if (topIsFullscreen) {
if (DEBUG_LAYOUT) Log.v(TAG, "** HIDING status bar");
if (mStatusBar.hideLw(true)) {
changes |= FINISH_LAYOUT_REDO_LAYOUT;
@@ -4931,6 +4971,14 @@ void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
}
}
+ void updateDisplayMetrics() {
+ try {
+ mWindowManager.updateDisplayMetrics();
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ }
+
/**
* Return an Intent to launch the currently active dock app as home. Returns
* null if the standard home should be launched, which is the case if any of the following is
View
87 services/java/com/android/server/wm/WindowManagerService.java
@@ -6925,53 +6925,54 @@ private int computeCompatSmallestWidth(boolean rotated, DisplayMetrics dm, int d
return sw;
}
- boolean computeScreenConfigurationLocked(Configuration config) {
- if (!mDisplayReady) {
- return false;
- }
+ private static class ApplicationDisplayMetrics {
+ boolean rotated;
+ int dh;
+ int dw;
+ }
- // TODO(multidisplay): For now, apply Configuration to main screen only.
- final DisplayContent displayContent = getDefaultDisplayContentLocked();
+ private ApplicationDisplayMetrics calculateDisplayMetrics(DisplayContent displayContent) {
+ ApplicationDisplayMetrics dm = new ApplicationDisplayMetrics();
- // Use the effective "visual" dimensions based on current rotation
- final boolean rotated = (mRotation == Surface.ROTATION_90
- || mRotation == Surface.ROTATION_270);
- final int realdw = rotated ?
+ dm.rotated = (mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270);
+ final int realdw = dm.rotated ?
displayContent.mBaseDisplayHeight : displayContent.mBaseDisplayWidth;
- final int realdh = rotated ?
+ final int realdh = dm.rotated ?
displayContent.mBaseDisplayWidth : displayContent.mBaseDisplayHeight;
- int dw = realdw;
- int dh = realdh;
+
+ dm.dw = realdw;
+ dm.dh = realdh;
if (mAltOrientation) {
if (realdw > realdh) {
// Turn landscape into portrait.
int maxw = (int)(realdh/1.3f);
if (maxw < realdw) {
- dw = maxw;
+ dm.dw = maxw;
}
} else {
// Turn portrait into landscape.
int maxh = (int)(realdw/1.3f);
if (maxh < realdh) {
- dh = maxh;
+ dm.dh = maxh;
}
}
}
- if (config != null) {
- config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT :
- Configuration.ORIENTATION_LANDSCAPE;
- }
+ return dm;
+ }
- // Update application display metrics.
- final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation);
- final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation);
+ private ApplicationDisplayMetrics updateApplicationDisplayMetricsLocked(
+ DisplayContent displayContent) {
+ final ApplicationDisplayMetrics m = calculateDisplayMetrics(displayContent);
+ final int appWidth = mPolicy.getNonDecorDisplayWidth(m.dw, m.dh, mRotation);
+ final int appHeight = mPolicy.getNonDecorDisplayHeight(m.dw, m.dh, mRotation);
final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+
synchronized(displayContent.mDisplaySizeLock) {
displayInfo.rotation = mRotation;
- displayInfo.logicalWidth = dw;
- displayInfo.logicalHeight = dh;
+ displayInfo.logicalWidth = m.dw;
+ displayInfo.logicalHeight = m.dh;
displayInfo.logicalDensityDpi = displayContent.mBaseDisplayDensity;
displayInfo.appWidth = appWidth;
displayInfo.appHeight = appHeight;
@@ -6980,12 +6981,37 @@ boolean computeScreenConfigurationLocked(Configuration config) {
mDisplayManagerService.setDisplayInfoOverrideFromWindowManager(
displayContent.getDisplayId(), displayInfo);
- mAnimator.setDisplayDimensions(dw, dh, appWidth, appHeight);
+ mAnimator.setDisplayDimensions(m.dw, m.dh, appWidth, appHeight);
}
+
if (false) {
Slog.i(TAG, "Set app display size: " + appWidth + " x " + appHeight);
}
+ return m;
+ }
+
+ boolean computeScreenConfigurationLocked(Configuration config) {
+ if (!mDisplayReady) {
+ return false;
+ }
+
+ // TODO(multidisplay): For now, apply Configuration to main screen only.
+ final DisplayContent displayContent = getDefaultDisplayContentLocked();
+
+ // Update application display metrics.
+ final ApplicationDisplayMetrics appDm = updateApplicationDisplayMetricsLocked(
+ displayContent);
+ final boolean rotated = appDm.rotated;
+ final int dw = appDm.dw;
+ final int dh = appDm.dh;
+
+ if (config != null) {
+ config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT :
+ Configuration.ORIENTATION_LANDSCAPE;
+ }
+
+ final DisplayInfo displayInfo = displayContent.getDisplayInfo();
final DisplayMetrics dm = mDisplayMetrics;
mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm,
mCompatDisplayMetrics);
@@ -10445,6 +10471,17 @@ public void showAssistant() {
mPolicy.showAssistant();
}
+ public void updateDisplayMetrics() {
+ long origId = Binder.clearCallingIdentity();
+
+ synchronized (mWindowMap) {
+ final DisplayContent displayContent = getDefaultDisplayContentLocked();
+ updateApplicationDisplayMetricsLocked(displayContent);
+ }
+
+ Binder.restoreCallingIdentity(origId);
+ }
+
void dumpPolicyLocked(PrintWriter pw, String[] args, boolean dumpAll) {
pw.println("WINDOW MANAGER POLICY STATE (dumpsys window policy)");
mPolicy.dump(" ", pw, args);
View
2 services/java/com/android/server/wm/WindowState.java
@@ -498,7 +498,7 @@ public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) {
mCompatFrame.scale(mInvGlobalScale);
}
- if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) {
+ if (mIsWallpaper) {
final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
mService.updateWallpaperOffsetLocked(this, displayInfo.appWidth, displayInfo.appHeight,
false);
View
5 tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java
@@ -458,6 +458,11 @@ public void showAssistant() {
}
@Override
+ public void updateDisplayMetrics() {
+
+ }
+
+ @Override
public IBinder getFocusedWindowToken() {
// TODO Auto-generated method stub
return null;

0 comments on commit 667cdc8

Please sign in to comment.
Something went wrong with that request. Please try again.