From c406152f5fdcaeae2b2d24ba26663badd92b226b Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Tue, 9 May 2017 10:40:23 -0700 Subject: Use application context getting secondary displays. Activity contexts include override configurations in their resources associated with the primary display. There currently is no way to specify overrides for another display from the same context. As a result, getting metrics for other displays will reflect the metrics of the context's display. This change provides the application context when we create a display if the display id does not match the display associated with the context. Change-Id: I68a7b609ead6d7cc652d36e7e8af432700af8efa Fixes:37923030 Test: cts-tradefed run cts-dev --module CtsDisplayTestCases --test android.display.cts.DisplayTest#testActivityContextGetMetrics --- core/java/android/hardware/display/DisplayManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java index 32671721f58b..244c7a221228 100644 --- a/core/java/android/hardware/display/DisplayManager.java +++ b/core/java/android/hardware/display/DisplayManager.java @@ -340,7 +340,12 @@ public final class DisplayManager { private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid) { Display display = mDisplays.get(displayId); if (display == null) { - display = mGlobal.getCompatibleDisplay(displayId, mContext.getResources()); + // TODO: We cannot currently provide any override configurations for metrics on displays + // other than the display the context is associated with. + final Context context = mContext.getDisplay().getDisplayId() == displayId + ? mContext : mContext.getApplicationContext(); + + display = mGlobal.getCompatibleDisplay(displayId, context.getResources()); if (display != null) { mDisplays.put(displayId, display); } -- cgit v1.2.3-59-g8ed1b