Skip to content

Commit 88f10c6

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix issue #5679504: Device stuck and sudden reboot - Watchdog reset?" into ics-mr1
2 parents f8d20bd + 1fbee79 commit 88f10c6

File tree

2 files changed

+63
-40
lines changed

2 files changed

+63
-40
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ public final class ActivityThread {
175175
// These can be accessed by multiple threads; mPackages is the lock.
176176
// XXX For now we keep around information about all packages we have
177177
// seen, not removing entries from this map.
178-
// NOTE: The activity manager in its process needs to call in to
178+
// NOTE: The activity and window managers need to call in to
179179
// ActivityThread to do things like update resource configurations,
180-
// which means this lock gets held while the activity manager holds its
181-
// own lock. Thus you MUST NEVER call back into the activity manager
182-
// or anything that depends on it while holding this lock.
180+
// which means this lock gets held while the activity and window managers
181+
// holds their own lock. Thus you MUST NEVER call back into the activity manager
182+
// or window manager or anything that depends on them while holding this lock.
183183
final HashMap<String, WeakReference<LoadedApk>> mPackages
184184
= new HashMap<String, WeakReference<LoadedApk>>();
185185
final HashMap<String, WeakReference<LoadedApk>> mResourcePackages

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

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,18 @@ public void onReceive(Context context, Intent intent) {
429429
boolean mSystemBooted = false;
430430
boolean mForceDisplayEnabled = false;
431431
boolean mShowingBootMessages = false;
432+
433+
// This protects the following display size properties, so that
434+
// getDisplaySize() doesn't need to acquire the global lock. This is
435+
// needed because the window manager sometimes needs to use ActivityThread
436+
// while it has its global state locked (for example to load animation
437+
// resources), but the ActivityThread also needs get the current display
438+
// size sometimes when it has its package lock held.
439+
//
440+
// These will only be modified with both mWindowMap and mDisplaySizeLock
441+
// held (in that order) so the window manager doesn't need to acquire this
442+
// lock when needing these values in its normal operation.
443+
final Object mDisplaySizeLock = new Object();
432444
int mInitialDisplayWidth = 0;
433445
int mInitialDisplayHeight = 0;
434446
int mBaseDisplayWidth = 0;
@@ -437,6 +449,7 @@ public void onReceive(Context context, Intent intent) {
437449
int mCurDisplayHeight = 0;
438450
int mAppDisplayWidth = 0;
439451
int mAppDisplayHeight = 0;
452+
440453
int mRotation = 0;
441454
int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
442455
boolean mAltOrientation = false;
@@ -6006,25 +6019,27 @@ boolean computeNewConfigurationLocked(Configuration config) {
60066019
final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
60076020
final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
60086021

6009-
if (mAltOrientation) {
6010-
mCurDisplayWidth = realdw;
6011-
mCurDisplayHeight = realdh;
6012-
if (realdw > realdh) {
6013-
// Turn landscape into portrait.
6014-
int maxw = (int)(realdh/1.3f);
6015-
if (maxw < realdw) {
6016-
mCurDisplayWidth = maxw;
6022+
synchronized(mDisplaySizeLock) {
6023+
if (mAltOrientation) {
6024+
mCurDisplayWidth = realdw;
6025+
mCurDisplayHeight = realdh;
6026+
if (realdw > realdh) {
6027+
// Turn landscape into portrait.
6028+
int maxw = (int)(realdh/1.3f);
6029+
if (maxw < realdw) {
6030+
mCurDisplayWidth = maxw;
6031+
}
6032+
} else {
6033+
// Turn portrait into landscape.
6034+
int maxh = (int)(realdw/1.3f);
6035+
if (maxh < realdh) {
6036+
mCurDisplayHeight = maxh;
6037+
}
60176038
}
60186039
} else {
6019-
// Turn portrait into landscape.
6020-
int maxh = (int)(realdw/1.3f);
6021-
if (maxh < realdh) {
6022-
mCurDisplayHeight = maxh;
6023-
}
6040+
mCurDisplayWidth = realdw;
6041+
mCurDisplayHeight = realdh;
60246042
}
6025-
} else {
6026-
mCurDisplayWidth = realdw;
6027-
mCurDisplayHeight = realdh;
60286043
}
60296044

60306045
final int dw = mCurDisplayWidth;
@@ -6043,8 +6058,12 @@ boolean computeNewConfigurationLocked(Configuration config) {
60436058

60446059
// Update application display metrics.
60456060
final DisplayMetrics dm = mDisplayMetrics;
6046-
mAppDisplayWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation);
6047-
mAppDisplayHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation);
6061+
final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation);
6062+
final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation);
6063+
synchronized(mDisplaySizeLock) {
6064+
mAppDisplayWidth = appWidth;
6065+
mAppDisplayHeight = appHeight;
6066+
}
60486067
if (false) {
60496068
Slog.i(TAG, "Set app display size: " + mAppDisplayWidth
60506069
+ " x " + mAppDisplayHeight);
@@ -6414,18 +6433,20 @@ public void displayReady() {
64146433
}
64156434
WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
64166435
mDisplay = wm.getDefaultDisplay();
6417-
mInitialDisplayWidth = mDisplay.getRawWidth();
6418-
mInitialDisplayHeight = mDisplay.getRawHeight();
6419-
int rot = mDisplay.getRotation();
6420-
if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
6421-
// If the screen is currently rotated, we need to swap the
6422-
// initial width and height to get the true natural values.
6423-
int tmp = mInitialDisplayWidth;
6424-
mInitialDisplayWidth = mInitialDisplayHeight;
6425-
mInitialDisplayHeight = tmp;
6426-
}
6427-
mBaseDisplayWidth = mCurDisplayWidth = mAppDisplayWidth = mInitialDisplayWidth;
6428-
mBaseDisplayHeight = mCurDisplayHeight = mAppDisplayHeight = mInitialDisplayHeight;
6436+
synchronized(mDisplaySizeLock) {
6437+
mInitialDisplayWidth = mDisplay.getRawWidth();
6438+
mInitialDisplayHeight = mDisplay.getRawHeight();
6439+
int rot = mDisplay.getRotation();
6440+
if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
6441+
// If the screen is currently rotated, we need to swap the
6442+
// initial width and height to get the true natural values.
6443+
int tmp = mInitialDisplayWidth;
6444+
mInitialDisplayWidth = mInitialDisplayHeight;
6445+
mInitialDisplayHeight = tmp;
6446+
}
6447+
mBaseDisplayWidth = mCurDisplayWidth = mAppDisplayWidth = mInitialDisplayWidth;
6448+
mBaseDisplayHeight = mCurDisplayHeight = mAppDisplayHeight = mInitialDisplayHeight;
6449+
}
64296450
mInputManager.setDisplaySize(Display.DEFAULT_DISPLAY,
64306451
mDisplay.getRawWidth(), mDisplay.getRawHeight(),
64316452
mDisplay.getRawExternalWidth(), mDisplay.getRawExternalHeight());
@@ -6963,28 +6984,28 @@ public boolean inputMethodClientHasFocus(IInputMethodClient client) {
69636984
}
69646985

69656986
public void getDisplaySize(Point size) {
6966-
synchronized(mWindowMap) {
6987+
synchronized(mDisplaySizeLock) {
69676988
size.x = mAppDisplayWidth;
69686989
size.y = mAppDisplayHeight;
69696990
}
69706991
}
69716992

69726993
public void getRealDisplaySize(Point size) {
6973-
synchronized(mWindowMap) {
6994+
synchronized(mDisplaySizeLock) {
69746995
size.x = mCurDisplayWidth;
69756996
size.y = mCurDisplayHeight;
69766997
}
69776998
}
69786999

69797000
public void getInitialDisplaySize(Point size) {
6980-
synchronized(mWindowMap) {
7001+
synchronized(mDisplaySizeLock) {
69817002
size.x = mInitialDisplayWidth;
69827003
size.y = mInitialDisplayHeight;
69837004
}
69847005
}
69857006

69867007
public int getMaximumSizeDimension() {
6987-
synchronized(mWindowMap) {
7008+
synchronized(mDisplaySizeLock) {
69887009
// Do this based on the raw screen size, until we are smarter.
69897010
return mBaseDisplayWidth > mBaseDisplayHeight
69907011
? mBaseDisplayWidth : mBaseDisplayHeight;
@@ -7077,8 +7098,10 @@ private void readForcedDisplaySizeLocked() {
70777098
private void setForcedDisplaySizeLocked(int width, int height) {
70787099
Slog.i(TAG, "Using new display size: " + width + "x" + height);
70797100

7080-
mBaseDisplayWidth = width;
7081-
mBaseDisplayHeight = height;
7101+
synchronized(mDisplaySizeLock) {
7102+
mBaseDisplayWidth = width;
7103+
mBaseDisplayHeight = height;
7104+
}
70827105
mPolicy.setInitialDisplaySize(mBaseDisplayWidth, mBaseDisplayHeight);
70837106

70847107
mLayoutNeeded = true;

0 commit comments

Comments
 (0)