Skip to content

Commit e215f26

Browse files
author
Jeff Brown
committed
Fix adb am display-size.
There were several problems resulting from the use of mDefaultDisplay before displayReady() was called. As it happens, we don't need mDefaultDisplay becase we can get the information from the default display content. Also modified the Configuration calculations to never choose a SQUARE orientation. The constant is deprecated and documented as no longer used, so we should make that be the case. Change-Id: I326ed7100030a81e24411e898e5243f28895ea22
1 parent 83d616a commit e215f26

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ public void onReceive(Context context, Intent intent) {
434434

435435
final float[] mTmpFloats = new float[9];
436436

437+
boolean mDisplayReady;
437438
boolean mSafeMode;
438439
boolean mDisplayEnabled = false;
439440
boolean mSystemBooted = false;
@@ -503,8 +504,6 @@ public void onReceive(Context context, Intent intent) {
503504
final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
504505
final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
505506

506-
Display mDefaultDisplay;
507-
508507
boolean mIsTouchDevice;
509508

510509
final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
@@ -2085,7 +2084,7 @@ public int addWindow(Session session, IWindow client, int seq,
20852084
long origId;
20862085

20872086
synchronized(mWindowMap) {
2088-
if (mDefaultDisplay == null) {
2087+
if (!mDisplayReady) {
20892088
throw new IllegalStateException("Display has not been initialialized");
20902089
}
20912090

@@ -5604,8 +5603,10 @@ private void showStrictModeViolation(int arg) {
56045603
">>> OPEN TRANSACTION showStrictModeViolation");
56055604
Surface.openTransaction();
56065605
try {
5606+
// TODO(multi-display): support multiple displays
56075607
if (mStrictModeFlash == null) {
5608-
mStrictModeFlash = new StrictModeFlash(mDefaultDisplay, mFxSession);
5608+
mStrictModeFlash = new StrictModeFlash(
5609+
getDefaultDisplayContent().getDisplay(), mFxSession);
56095610
}
56105611
mStrictModeFlash.setVisibility(on);
56115612
} finally {
@@ -5718,7 +5719,7 @@ public Bitmap screenshotApplications(IBinder appToken, int displayId, int width,
57185719
}
57195720

57205721
// The screenshot API does not apply the current screen rotation.
5721-
rot = mDefaultDisplay.getRotation();
5722+
rot = getDefaultDisplayContent().getDisplay().getRotation();
57225723
int fw = frame.width();
57235724
int fh = frame.height();
57245725

@@ -6751,7 +6752,7 @@ private int computeCompatSmallestWidth(boolean rotated, DisplayMetrics dm, int d
67516752
}
67526753

67536754
boolean computeScreenConfigurationLocked(Configuration config) {
6754-
if (mDefaultDisplay == null) {
6755+
if (!mDisplayReady) {
67556756
return false;
67566757
}
67576758

@@ -6785,13 +6786,8 @@ boolean computeScreenConfigurationLocked(Configuration config) {
67856786
}
67866787

67876788
if (config != null) {
6788-
int orientation = Configuration.ORIENTATION_SQUARE;
6789-
if (dw < dh) {
6790-
orientation = Configuration.ORIENTATION_PORTRAIT;
6791-
} else if (dw > dh) {
6792-
orientation = Configuration.ORIENTATION_LANDSCAPE;
6793-
}
6794-
config.orientation = orientation;
6789+
config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT :
6790+
Configuration.ORIENTATION_LANDSCAPE;
67956791
}
67966792

67976793
// Update application display metrics.
@@ -6958,9 +6954,12 @@ IBinder prepareDragSurface(IWindow window, SurfaceSession session,
69586954
synchronized (mWindowMap) {
69596955
try {
69606956
if (mDragState == null) {
6957+
// TODO(multi-display): support other displays
6958+
final DisplayContent displayContent = getDefaultDisplayContent();
6959+
final Display display = displayContent.getDisplay();
69616960
Surface surface = new Surface(session, "drag surface",
69626961
width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN);
6963-
surface.setLayerStack(mDefaultDisplay.getLayerStack());
6962+
surface.setLayerStack(display.getLayerStack());
69646963
if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG "
69656964
+ surface + ": CREATE");
69666965
outSurface.copyFrom(surface);
@@ -7102,26 +7101,28 @@ public boolean detectSafeMode() {
71027101
}
71037102

71047103
public void displayReady() {
7105-
WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
7106-
final Display display = wm.getDefaultDisplay();
7107-
displayReady(display.getDisplayId());
7104+
displayReady(Display.DEFAULT_DISPLAY);
71087105

71097106
synchronized(mWindowMap) {
7110-
readForcedDisplaySizeAndDensityLocked(getDefaultDisplayContent());
7107+
final DisplayContent displayContent = getDefaultDisplayContent();
7108+
final Display display = displayContent.getDisplay();
7109+
readForcedDisplaySizeAndDensityLocked(displayContent);
71117110

7112-
mDefaultDisplay = display;
7111+
mDisplayReady = true;
71137112
mIsTouchDevice = mContext.getPackageManager().hasSystemFeature(
7114-
PackageManager.FEATURE_TOUCHSCREEN);
7113+
PackageManager.FEATURE_TOUCHSCREEN);
71157114

71167115
mAnimator.initializeLocked(display.getLayerStack());
71177116

71187117
final DisplayInfo displayInfo = getDefaultDisplayInfo();
7119-
mAnimator.setDisplayDimensions(displayInfo.logicalWidth, displayInfo.logicalHeight,
7120-
displayInfo.appWidth, displayInfo.appHeight);
7118+
mAnimator.setDisplayDimensions(
7119+
displayInfo.logicalWidth, displayInfo.logicalHeight,
7120+
displayInfo.appWidth, displayInfo.appHeight);
71217121

7122-
final DisplayContent displayContent = getDefaultDisplayContent();
7123-
mPolicy.setInitialDisplaySize(mDefaultDisplay, displayContent.mInitialDisplayWidth,
7124-
displayContent.mInitialDisplayHeight, displayContent.mInitialDisplayDensity);
7122+
mPolicy.setInitialDisplaySize(displayContent.getDisplay(),
7123+
displayContent.mInitialDisplayWidth,
7124+
displayContent.mInitialDisplayHeight,
7125+
displayContent.mInitialDisplayDensity);
71257126
}
71267127

71277128
try {
@@ -7802,6 +7803,7 @@ private void rebuildBlackFrameLocked() {
78027803
}
78037804
// TODO(multidisplay): For now rotations are only main screen.
78047805
final DisplayContent displayContent = getDefaultDisplayContent();
7806+
final Display display = displayContent.getDisplay();
78057807
if (displayContent.mBaseDisplayWidth < displayContent.mInitialDisplayWidth
78067808
|| displayContent.mBaseDisplayHeight < displayContent.mInitialDisplayHeight) {
78077809
int initW, initH, baseW, baseH;
@@ -7829,7 +7831,7 @@ private void rebuildBlackFrameLocked() {
78297831
Rect inner = new Rect(0, 0, baseW, baseH);
78307832
try {
78317833
mBlackFrame = new BlackFrame(mFxSession, outer, inner, MASK_LAYER,
7832-
mDefaultDisplay.getLayerStack());
7834+
display.getLayerStack());
78337835
} catch (Surface.OutOfResourcesException e) {
78347836
}
78357837
}
@@ -7929,8 +7931,10 @@ public void clearForcedDisplayDensity(int displayId) {
79297931

79307932
private void reconfigureDisplayLocked(DisplayContent displayContent) {
79317933
// TODO: Multidisplay: for now only use with default display.
7932-
mPolicy.setInitialDisplaySize(mDefaultDisplay, displayContent.mBaseDisplayWidth,
7933-
displayContent.mBaseDisplayHeight, displayContent.mBaseDisplayDensity);
7934+
mPolicy.setInitialDisplaySize(displayContent.getDisplay(),
7935+
displayContent.mBaseDisplayWidth,
7936+
displayContent.mBaseDisplayHeight,
7937+
displayContent.mBaseDisplayDensity);
79347938

79357939
displayContent.layoutNeeded = true;
79367940

@@ -8154,7 +8158,7 @@ private final void performLayoutAndPlaceSurfacesLocked() {
81548158
return;
81558159
}
81568160

8157-
if (mDefaultDisplay == null) {
8161+
if (!mDisplayReady) {
81588162
// Not yet initialized, nothing to do.
81598163
return;
81608164
}
@@ -8600,11 +8604,14 @@ public int handleAppTransitionReadyLocked(WindowList windows) {
86008604
Rect dirty = new Rect(0, 0, mNextAppTransitionThumbnail.getWidth(),
86018605
mNextAppTransitionThumbnail.getHeight());
86028606
try {
8607+
// TODO(multi-display): support other displays
8608+
final DisplayContent displayContent = getDefaultDisplayContent();
8609+
final Display display = displayContent.getDisplay();
86038610
Surface surface = new Surface(mFxSession,
86048611
"thumbnail anim",
86058612
dirty.width(), dirty.height(),
86068613
PixelFormat.TRANSLUCENT, Surface.HIDDEN);
8607-
surface.setLayerStack(mDefaultDisplay.getLayerStack());
8614+
surface.setLayerStack(display.getLayerStack());
86088615
topOpeningApp.mAppAnimator.thumbnail = surface;
86098616
if (SHOW_TRANSACTIONS) Slog.i(TAG, " THUMBNAIL "
86108617
+ surface + ": CREATE");
@@ -9857,7 +9864,7 @@ private void startFreezingDisplayLocked(boolean inTransaction) {
98579864
return;
98589865
}
98599866

9860-
if (mDefaultDisplay == null || !mPolicy.isScreenOnFully()) {
9867+
if (!mDisplayReady || !mPolicy.isScreenOnFully()) {
98619868
// No need to freeze the screen before the system is ready or if
98629869
// the screen is off.
98639870
return;
@@ -9889,10 +9896,12 @@ private void startFreezingDisplayLocked(boolean inTransaction) {
98899896
}
98909897

98919898
// TODO(multidisplay): rotation on main screen only.
9892-
DisplayInfo displayInfo = getDefaultDisplayContent().getDisplayInfo();
9899+
final DisplayContent displayContent = getDefaultDisplayContent();
9900+
final Display display = displayContent.getDisplay();
9901+
final DisplayInfo displayInfo = displayContent.getDisplayInfo();
98939902
mAnimator.mScreenRotationAnimation = new ScreenRotationAnimation(mContext,
9894-
mDefaultDisplay, mFxSession, inTransaction, displayInfo.logicalWidth,
9895-
displayInfo.logicalHeight, mDefaultDisplay.getRotation());
9903+
display, mFxSession, inTransaction, displayInfo.logicalWidth,
9904+
displayInfo.logicalHeight, display.getRotation());
98969905
}
98979906
}
98989907

@@ -10003,8 +10012,8 @@ void createWatermarkInTransaction() {
1000310012
if (line != null) {
1000410013
String[] toks = line.split("%");
1000510014
if (toks != null && toks.length > 0) {
10006-
mWatermark =
10007-
new Watermark(mDefaultDisplay, mRealDisplayMetrics, mFxSession, toks);
10015+
mWatermark = new Watermark(getDefaultDisplayContent().getDisplay(),
10016+
mRealDisplayMetrics, mFxSession, toks);
1000810017
}
1000910018
}
1001010019
} catch (FileNotFoundException e) {
@@ -10372,7 +10381,7 @@ void dumpWindowsNoHeaderLocked(PrintWriter pw, boolean dumpAll,
1037210381
}
1037310382
}
1037410383
pw.println();
10375-
if (mDefaultDisplay != null) {
10384+
if (mDisplayReady) {
1037610385
DisplayContentsIterator dCIterator = new DisplayContentsIterator();
1037710386
while (dCIterator.hasNext()) {
1037810387
dCIterator.next().dump(pw);
@@ -10804,9 +10813,7 @@ public void remove() {
1080410813
}
1080510814

1080610815
public DisplayContent getDefaultDisplayContent() {
10807-
final int displayId = mDefaultDisplay == null
10808-
? Display.DEFAULT_DISPLAY : mDefaultDisplay.getDisplayId();
10809-
return getDisplayContent(displayId);
10816+
return getDisplayContent(Display.DEFAULT_DISPLAY);
1081010817
}
1081110818

1081210819
public WindowList getDefaultWindowList() {

0 commit comments

Comments
 (0)