Skip to content

Commit a3909a9

Browse files
author
Jeff Brown
committed
Work around crash when display is removed.
After a display is removed, there may be a brief time when a Context still exists that is bound to it. We need to provide metrics in this case. Bug: 7131637 Change-Id: I11b264a000653adbf0f3da399eaab66c4b40fb2a
1 parent e168edb commit a3909a9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,15 @@ DisplayMetrics getDisplayMetricsLocked(int displayId, CompatibilityInfo ci) {
15861586
CompatibilityInfoHolder cih = new CompatibilityInfoHolder();
15871587
cih.set(ci);
15881588
Display d = displayManager.getCompatibleDisplay(displayId, cih);
1589-
d.getMetrics(dm);
1589+
if (d != null) {
1590+
d.getMetrics(dm);
1591+
} else {
1592+
// Display no longer exists
1593+
// FIXME: This would not be a problem if we kept the Display object around
1594+
// instead of using the raw display id everywhere. The Display object caches
1595+
// its information even after the display has been removed.
1596+
dm.setToDefaults();
1597+
}
15901598
//Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
15911599
// + metrics.heightPixels + " den=" + metrics.density
15921600
// + " xdpi=" + metrics.xdpi + " ydpi=" + metrics.ydpi);

0 commit comments

Comments
 (0)