Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f83ec838 authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "More improvements to the display manager." into jb-mr1-dev

parents 3b9a4160 4ed8fe75
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23473,6 +23473,7 @@ package android.view {
    method public int getDisplayId();
    method public deprecated int getHeight();
    method public void getMetrics(android.util.DisplayMetrics);
    method public java.lang.String getName();
    method public deprecated int getOrientation();
    method public deprecated int getPixelFormat();
    method public void getRealMetrics(android.util.DisplayMetrics);
+38 −13
Original line number Diff line number Diff line
@@ -42,6 +42,16 @@ public final class DisplayManagerGlobal {
    private static final String TAG = "DisplayManager";
    private static final boolean DEBUG = false;

    // True if display info and display ids should be cached.
    //
    // FIXME: The cache is currently disabled because it's unclear whether we have the
    // necessary guarantees that the caches will always be flushed before clients
    // attempt to observe their new state.  For example, depending on the order
    // in which the binder transactions take place, we might have a problem where
    // an application could start processing a configuration change due to a display
    // orientation change before the display info cache has actually been invalidated.
    private static final boolean USE_CACHE = false;

    public static final int EVENT_DISPLAY_ADDED = 1;
    public static final int EVENT_DISPLAY_CHANGED = 2;
    public static final int EVENT_DISPLAY_REMOVED = 3;
@@ -91,21 +101,27 @@ public final class DisplayManagerGlobal {
    public DisplayInfo getDisplayInfo(int displayId) {
        try {
            synchronized (mLock) {
                DisplayInfo info = mDisplayInfoCache.get(displayId);
                DisplayInfo info;
                if (USE_CACHE) {
                    info = mDisplayInfoCache.get(displayId);
                    if (info != null) {
                        return info;
                    }
                }

                info = mDm.getDisplayInfo(displayId);
                if (info == null) {
                    return null;
                }
                if (DEBUG) {
                    Log.d(TAG, "getDisplayInfo: displayId=" + displayId + ", info=" + info);
                }

                if (USE_CACHE) {
                    mDisplayInfoCache.put(displayId, info);
                }
                registerCallbackIfNeededLocked();

                if (DEBUG) {
                    Log.d(TAG, "getDisplayInfo: displayId=" + displayId + ", info=" + info);
                }
                return info;
            }
        } catch (RemoteException ex) {
@@ -122,12 +138,19 @@ public final class DisplayManagerGlobal {
    public int[] getDisplayIds() {
        try {
            synchronized (mLock) {
                if (mDisplayIdCache == null) {
                    mDisplayIdCache = mDm.getDisplayIds();
                    registerCallbackIfNeededLocked();
                }
                if (USE_CACHE) {
                    if (mDisplayIdCache != null) {
                        return mDisplayIdCache;
                    }
                }

                int[] displayIds = mDm.getDisplayIds();
                if (USE_CACHE) {
                    mDisplayIdCache = displayIds;
                }
                registerCallbackIfNeededLocked();
                return displayIds;
            }
        } catch (RemoteException ex) {
            Log.e(TAG, "Could not get display ids from display manager.", ex);
            return new int[] { Display.DEFAULT_DISPLAY };
@@ -215,11 +238,13 @@ public final class DisplayManagerGlobal {

    private void handleDisplayEvent(int displayId, int event) {
        synchronized (mLock) {
            if (USE_CACHE) {
                mDisplayInfoCache.remove(displayId);

                if (event == EVENT_DISPLAY_ADDED || event == EVENT_DISPLAY_REMOVED) {
                    mDisplayIdCache = null;
                }
            }

            final int numListeners = mDisplayListeners.size();
            for (int i = 0; i < numListeners; i++) {
+29 −7
Original line number Diff line number Diff line
@@ -431,7 +431,12 @@ public class Handler {
     * set up a Handler thread and need to perform some initialization steps on
     * it before continuing execution.
     *
     * If timeout occurs then this method returns <code>false</code> but the runnable
     * will remain posted on the handler and may already be in progress or
     * complete at a later time.
     *
     * @param r The Runnable that will be executed synchronously.
     * @param timeout The timeout in milliseconds, or 0 to wait indefinitely.
     *
     * @return Returns true if the Runnable was successfully executed.
     *         Returns false on failure, usually because the
@@ -441,10 +446,13 @@ public class Handler {
     * If we ever do make it part of the API, we might want to rename it to something
     * less funny like runUnsafe().
     */
    public final boolean runWithScissors(final Runnable r) {
    public final boolean runWithScissors(final Runnable r, long timeout) {
        if (r == null) {
            throw new IllegalArgumentException("runnable must not be null");
        }
        if (timeout < 0) {
            throw new IllegalArgumentException("timeout must be non-negative");
        }

        if (Looper.myLooper() == mLooper) {
            r.run();
@@ -452,7 +460,7 @@ public class Handler {
        }

        BlockingRunnable br = new BlockingRunnable(r);
        return br.postAndWait(this);
        return br.postAndWait(this, timeout);
    }

    /**
@@ -743,12 +751,25 @@ public class Handler {
            }
        }

        public boolean postAndWait(Handler handler) {
        public boolean postAndWait(Handler handler, long timeout) {
            if (!handler.post(this)) {
                return false;
            }

            synchronized (this) {
                if (timeout > 0) {
                    final long expirationTime = SystemClock.uptimeMillis() + timeout;
                    while (!mDone) {
                        long delay = expirationTime - SystemClock.uptimeMillis();
                        if (delay <= 0) {
                            return false; // timeout
                        }
                        try {
                            wait(delay);
                        } catch (InterruptedException ex) {
                        }
                    }
                } else {
                    while (!mDone) {
                        try {
                            wait();
@@ -756,6 +777,7 @@ public class Handler {
                        }
                    }
                }
            }
            return true;
        }
    }
+14 −4
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public final class Display {

    private final DisplayManagerGlobal mGlobal;
    private final int mDisplayId;
    private final int mLayerStack;
    private final String mName;
    private final CompatibilityInfoHolder mCompatibilityInfo;

    private DisplayInfo mDisplayInfo; // never null
@@ -90,6 +92,8 @@ public final class Display {
        mGlobal = global;
        mDisplayId = displayId;
        mDisplayInfo = displayInfo;
        mLayerStack = displayInfo.layerStack; // can never change as long as the display is valid
        mName = displayInfo.name; // cannot change as long as the display is valid
        mCompatibilityInfo = compatibilityInfo;
        mIsValid = true;
    }
@@ -146,13 +150,11 @@ public final class Display {
     * Each display has its own independent layer stack upon which surfaces
     * are placed to be managed by surface flinger.
     *
     * @return The layer stack number.
     * @return The display's layer stack number.
     * @hide
     */
    public int getLayerStack() {
        // Note: This is the current convention but there is no requirement that
        // the display id and layer stack id be the same.
        return mDisplayId;
        return mLayerStack;
    }

    /**
@@ -165,6 +167,14 @@ public final class Display {
        return mCompatibilityInfo;
    }

    /**
     * Gets the name of the display.
     * @return The display's name.
     */
    public String getName() {
        return mName;
    }

    /**
     * Gets the size of the display, in pixels.
     * <p>
+52 −4
Original line number Diff line number Diff line
@@ -21,11 +21,23 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.DisplayMetrics;

import libcore.util.Objects;

/**
 * Describes the characteristics of a particular logical display.
 * @hide
 */
public final class DisplayInfo implements Parcelable {
    /**
     * The surface flinger layer stack associated with this logical display.
     */
    public int layerStack;

    /**
     * The human-readable name of the display.
     */
    public String name;

    /**
     * The width of the portion of the display that is available to applications, in pixels.
     * Represents the size of the display minus any system decorations.
@@ -147,11 +159,37 @@ public final class DisplayInfo implements Parcelable {
    }

    @Override
    public int describeContents() {
        return 0;
    public boolean equals(Object o) {
        return o instanceof DisplayInfo && equals((DisplayInfo)o);
    }

    public boolean equals(DisplayInfo other) {
        return other != null
                && layerStack == other.layerStack
                && Objects.equal(name, other.name)
                && appWidth == other.appWidth
                && appHeight == other.appHeight
                && smallestNominalAppWidth == other.smallestNominalAppWidth
                && smallestNominalAppHeight == other.smallestNominalAppHeight
                && largestNominalAppWidth == other.largestNominalAppWidth
                && largestNominalAppHeight == other.largestNominalAppHeight
                && logicalWidth == other.logicalWidth
                && logicalHeight == other.logicalHeight
                && rotation == other.rotation
                && refreshRate == other.refreshRate
                && logicalDensityDpi == other.logicalDensityDpi
                && physicalXDpi == other.physicalXDpi
                && physicalYDpi == other.physicalYDpi;
    }

    @Override
    public int hashCode() {
        return 0; // don't care
    }

    public void copyFrom(DisplayInfo other) {
        layerStack = other.layerStack;
        name = other.name;
        appWidth = other.appWidth;
        appHeight = other.appHeight;
        smallestNominalAppWidth = other.smallestNominalAppWidth;
@@ -168,6 +206,8 @@ public final class DisplayInfo implements Parcelable {
    }

    public void readFromParcel(Parcel source) {
        layerStack = source.readInt();
        name = source.readString();
        appWidth = source.readInt();
        appHeight = source.readInt();
        smallestNominalAppWidth = source.readInt();
@@ -185,6 +225,8 @@ public final class DisplayInfo implements Parcelable {

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(layerStack);
        dest.writeString(name);
        dest.writeInt(appWidth);
        dest.writeInt(appHeight);
        dest.writeInt(smallestNominalAppWidth);
@@ -200,6 +242,11 @@ public final class DisplayInfo implements Parcelable {
        dest.writeFloat(physicalYDpi);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public void getAppMetrics(DisplayMetrics outMetrics, CompatibilityInfoHolder cih) {
        getMetricsWithSize(outMetrics, cih, appWidth, appHeight);
    }
@@ -231,13 +278,14 @@ public final class DisplayInfo implements Parcelable {
    // For debugging purposes
    @Override
    public String toString() {
        return "app " + appWidth + " x " + appHeight
        return "DisplayInfo{\"" + name + "\", app " + appWidth + " x " + appHeight
                + ", real " + logicalWidth + " x " + logicalHeight
                + ", largest app " + largestNominalAppWidth + " x " + largestNominalAppHeight
                + ", smallest app " + smallestNominalAppWidth + " x " + smallestNominalAppHeight
                + ", " + refreshRate + " fps"
                + ", rotation " + rotation
                + ", density " + logicalDensityDpi
                + ", " + physicalXDpi + " x " + physicalYDpi + " dpi";
                + ", " + physicalXDpi + " x " + physicalYDpi + " dpi"
                + ", layerStack " + layerStack + "}";
    }
}
Loading