Loading core/java/android/hardware/display/DisplayManager.java +55 −64 Original line number Diff line number Diff line Loading @@ -53,12 +53,16 @@ import android.view.Surface; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import libcore.util.EmptyArray; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.concurrent.Executor; import java.util.function.Predicate; /** Loading Loading @@ -86,9 +90,6 @@ public final class DisplayManager { @GuardedBy("mLock") private final WeakDisplayCache mDisplayCache = new WeakDisplayCache(); @GuardedBy("mLock") private final ArrayList<Display> mTempDisplays = new ArrayList<Display>(); /** * Broadcast receiver that indicates when the Wifi display status changes. * <p> Loading Loading @@ -627,9 +628,7 @@ public final class DisplayManager { * @return The display object, or null if there is no valid display with the given id. */ public Display getDisplay(int displayId) { synchronized (mLock) { return getOrCreateDisplayLocked(displayId, false /*assumeValid*/); } return getOrCreateDisplay(displayId, false /*assumeValid*/); } /** Loading Loading @@ -661,66 +660,57 @@ public final class DisplayManager { boolean includeDisabled = (category != null && category.equals(DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED)); final int[] displayIds = mGlobal.getDisplayIds(includeDisabled); synchronized (mLock) { try { if (DISPLAY_CATEGORY_PRESENTATION.equals(category)) { addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_WIFI, Display.FLAG_PRESENTATION); addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_EXTERNAL, Display.FLAG_PRESENTATION); addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_OVERLAY, Display.FLAG_PRESENTATION); addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_VIRTUAL, Display.FLAG_PRESENTATION); addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_INTERNAL, Display.FLAG_PRESENTATION); return getDisplays(displayIds, DisplayManager::isPresentationDisplay); } else if (DISPLAY_CATEGORY_REAR.equals(category)) { addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_INTERNAL, Display.FLAG_REAR); } else if (category == null || DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED.equals(category)) { addAllDisplaysLocked(mTempDisplays, displayIds); } return mTempDisplays.toArray(new Display[mTempDisplays.size()]); } finally { mTempDisplays.clear(); } return getDisplays(displayIds, DisplayManager::isRearDisplay); } else if (category == null || DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED.equals(category)) { return getDisplays(displayIds, Objects::nonNull); } return (Display[]) EmptyArray.OBJECT; } @GuardedBy("mLock") private void addAllDisplaysLocked(ArrayList<Display> displays, int[] displayIds) { for (int i = 0; i < displayIds.length; i++) { Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/); if (display != null) { displays.add(display); private Display[] getDisplays(int[] displayIds, Predicate<Display> predicate) { ArrayList<Display> tmpDisplays = new ArrayList<>(); for (int displayId : displayIds) { Display display = getOrCreateDisplay(displayId, /*assumeValid=*/true); if (predicate.test(display)) { tmpDisplays.add(display); } } return tmpDisplays.toArray(new Display[tmpDisplays.size()]); } @GuardedBy("mLock") private void addDisplaysLocked( ArrayList<Display> displays, int[] displayIds, int matchType, int flagMask) { for (int displayId : displayIds) { if (displayId == DEFAULT_DISPLAY) { continue; private static boolean isPresentationDisplay(@Nullable Display display) { if (display == null || (display.getDisplayId() == DEFAULT_DISPLAY) || (display.getFlags() & Display.FLAG_PRESENTATION) == 0) { return false; } Display display = getOrCreateDisplayLocked(displayId, /* assumeValid= */ true); if (display != null && (display.getFlags() & flagMask) == flagMask && display.getType() == matchType) { displays.add(display); switch (display.getType()) { case Display.TYPE_INTERNAL: case Display.TYPE_EXTERNAL: case Display.TYPE_WIFI: case Display.TYPE_OVERLAY: case Display.TYPE_VIRTUAL: return true; default: return false; } } private static boolean isRearDisplay(@Nullable Display display) { return display != null && display.getDisplayId() != DEFAULT_DISPLAY && display.getType() == Display.TYPE_INTERNAL && (display.getFlags() & Display.FLAG_REAR) != 0; } @GuardedBy("mLock") private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid) { Display display = mDisplayCache.get(displayId); private Display getOrCreateDisplay(int displayId, boolean assumeValid) { Display display; synchronized (mLock) { display = mDisplayCache.get(displayId); if (display == null) { // TODO: We cannot currently provide any override configurations for metrics on displays // other than the display the context is associated with. // TODO: We cannot currently provide any override configurations for metrics on // displays other than the display the context is associated with. final Resources resources = mContext.getDisplayId() == displayId ? mContext.getResources() : null; Loading @@ -731,6 +721,7 @@ public final class DisplayManager { } else if (!assumeValid && !display.isValid()) { display = null; } } return display; } Loading Loading
core/java/android/hardware/display/DisplayManager.java +55 −64 Original line number Diff line number Diff line Loading @@ -53,12 +53,16 @@ import android.view.Surface; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import libcore.util.EmptyArray; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.concurrent.Executor; import java.util.function.Predicate; /** Loading Loading @@ -86,9 +90,6 @@ public final class DisplayManager { @GuardedBy("mLock") private final WeakDisplayCache mDisplayCache = new WeakDisplayCache(); @GuardedBy("mLock") private final ArrayList<Display> mTempDisplays = new ArrayList<Display>(); /** * Broadcast receiver that indicates when the Wifi display status changes. * <p> Loading Loading @@ -627,9 +628,7 @@ public final class DisplayManager { * @return The display object, or null if there is no valid display with the given id. */ public Display getDisplay(int displayId) { synchronized (mLock) { return getOrCreateDisplayLocked(displayId, false /*assumeValid*/); } return getOrCreateDisplay(displayId, false /*assumeValid*/); } /** Loading Loading @@ -661,66 +660,57 @@ public final class DisplayManager { boolean includeDisabled = (category != null && category.equals(DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED)); final int[] displayIds = mGlobal.getDisplayIds(includeDisabled); synchronized (mLock) { try { if (DISPLAY_CATEGORY_PRESENTATION.equals(category)) { addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_WIFI, Display.FLAG_PRESENTATION); addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_EXTERNAL, Display.FLAG_PRESENTATION); addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_OVERLAY, Display.FLAG_PRESENTATION); addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_VIRTUAL, Display.FLAG_PRESENTATION); addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_INTERNAL, Display.FLAG_PRESENTATION); return getDisplays(displayIds, DisplayManager::isPresentationDisplay); } else if (DISPLAY_CATEGORY_REAR.equals(category)) { addDisplaysLocked(mTempDisplays, displayIds, Display.TYPE_INTERNAL, Display.FLAG_REAR); } else if (category == null || DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED.equals(category)) { addAllDisplaysLocked(mTempDisplays, displayIds); } return mTempDisplays.toArray(new Display[mTempDisplays.size()]); } finally { mTempDisplays.clear(); } return getDisplays(displayIds, DisplayManager::isRearDisplay); } else if (category == null || DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED.equals(category)) { return getDisplays(displayIds, Objects::nonNull); } return (Display[]) EmptyArray.OBJECT; } @GuardedBy("mLock") private void addAllDisplaysLocked(ArrayList<Display> displays, int[] displayIds) { for (int i = 0; i < displayIds.length; i++) { Display display = getOrCreateDisplayLocked(displayIds[i], true /*assumeValid*/); if (display != null) { displays.add(display); private Display[] getDisplays(int[] displayIds, Predicate<Display> predicate) { ArrayList<Display> tmpDisplays = new ArrayList<>(); for (int displayId : displayIds) { Display display = getOrCreateDisplay(displayId, /*assumeValid=*/true); if (predicate.test(display)) { tmpDisplays.add(display); } } return tmpDisplays.toArray(new Display[tmpDisplays.size()]); } @GuardedBy("mLock") private void addDisplaysLocked( ArrayList<Display> displays, int[] displayIds, int matchType, int flagMask) { for (int displayId : displayIds) { if (displayId == DEFAULT_DISPLAY) { continue; private static boolean isPresentationDisplay(@Nullable Display display) { if (display == null || (display.getDisplayId() == DEFAULT_DISPLAY) || (display.getFlags() & Display.FLAG_PRESENTATION) == 0) { return false; } Display display = getOrCreateDisplayLocked(displayId, /* assumeValid= */ true); if (display != null && (display.getFlags() & flagMask) == flagMask && display.getType() == matchType) { displays.add(display); switch (display.getType()) { case Display.TYPE_INTERNAL: case Display.TYPE_EXTERNAL: case Display.TYPE_WIFI: case Display.TYPE_OVERLAY: case Display.TYPE_VIRTUAL: return true; default: return false; } } private static boolean isRearDisplay(@Nullable Display display) { return display != null && display.getDisplayId() != DEFAULT_DISPLAY && display.getType() == Display.TYPE_INTERNAL && (display.getFlags() & Display.FLAG_REAR) != 0; } @GuardedBy("mLock") private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid) { Display display = mDisplayCache.get(displayId); private Display getOrCreateDisplay(int displayId, boolean assumeValid) { Display display; synchronized (mLock) { display = mDisplayCache.get(displayId); if (display == null) { // TODO: We cannot currently provide any override configurations for metrics on displays // other than the display the context is associated with. // TODO: We cannot currently provide any override configurations for metrics on // displays other than the display the context is associated with. final Resources resources = mContext.getDisplayId() == displayId ? mContext.getResources() : null; Loading @@ -731,6 +721,7 @@ public final class DisplayManager { } else if (!assumeValid && !display.isValid()) { display = null; } } return display; } Loading