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

Commit 215e023b authored by Brian Johnson's avatar Brian Johnson Committed by Huihong Luo
Browse files

Handle display hotplug errors

Display hotplug connection errors propagated from SurfaceFlinger
through IDisplayEventConnection are handled here.

Bug: 241286153
Test: manual
Change-Id: I34583a4dc20a94a9737ff60b0d002e637ecac246
parent 8f9a09b3
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -263,6 +263,16 @@ public abstract class DisplayEventReceiver {
    public void onHotplug(long timestampNanos, long physicalDisplayId, boolean connected) {
    }

    /**
     * Called when a display hotplug event with connection error is received.
     *
     * @param timestampNanos The timestamp of the event, in the {@link System#nanoTime()}
     * timebase.
     * @param connectionError the hotplug connection error code.
     */
    public void onHotplugConnectionError(long timestampNanos, int connectionError) {
    }

    /**
     * Called when a display mode changed event is received.
     *
@@ -345,6 +355,11 @@ public abstract class DisplayEventReceiver {
        onHotplug(timestampNanos, physicalDisplayId, connected);
    }

    @SuppressWarnings("unused")
    private void dispatchHotplugConnectionError(long timestampNanos, int connectionError) {
        onHotplugConnectionError(timestampNanos, connectionError);
    }

    // Called from native code.
    @SuppressWarnings("unused")
    private void dispatchModeChanged(long timestampNanos, long physicalDisplayId, int modeId,
+24 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ static struct {

    jmethodID dispatchVsync;
    jmethodID dispatchHotplug;
    jmethodID dispatchHotplugConnectionError;
    jmethodID dispatchModeChanged;
    jmethodID dispatchFrameRateOverrides;

@@ -89,6 +90,7 @@ private:
    void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count,
                       VsyncEventData vsyncEventData) override;
    void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, bool connected) override;
    void dispatchHotplugConnectionError(nsecs_t timestamp, int errorCode) override;
    void dispatchModeChanged(nsecs_t timestamp, PhysicalDisplayId displayId, int32_t modeId,
                             nsecs_t renderPeriod) override;
    void dispatchFrameRateOverrides(nsecs_t timestamp, PhysicalDisplayId displayId,
@@ -230,6 +232,22 @@ void NativeDisplayEventReceiver::dispatchHotplug(nsecs_t timestamp, PhysicalDisp
    mMessageQueue->raiseAndClearException(env, "dispatchHotplug");
}

void NativeDisplayEventReceiver::dispatchHotplugConnectionError(nsecs_t timestamp,
                                                                int connectionError) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();

    ScopedLocalRef<jobject> receiverObj(env, GetReferent(env, mReceiverWeakGlobal));
    if (receiverObj.get()) {
        ALOGV("receiver %p ~ Invoking hotplug dispatchHotplugConnectionError handler.", this);
        env->CallVoidMethod(receiverObj.get(),
                            gDisplayEventReceiverClassInfo.dispatchHotplugConnectionError,
                            timestamp, connectionError);
        ALOGV("receiver %p ~ Returned from hotplug dispatchHotplugConnectionError handler.", this);
    }

    mMessageQueue->raiseAndClearException(env, "dispatchHotplugConnectionError");
}

void NativeDisplayEventReceiver::dispatchModeChanged(nsecs_t timestamp, PhysicalDisplayId displayId,
                                                     int32_t modeId, nsecs_t renderPeriod) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
@@ -354,8 +372,12 @@ int register_android_view_DisplayEventReceiver(JNIEnv* env) {

    gDisplayEventReceiverClassInfo.dispatchVsync =
            GetMethodIDOrDie(env, gDisplayEventReceiverClassInfo.clazz, "dispatchVsync", "(JJI)V");
    gDisplayEventReceiverClassInfo.dispatchHotplug = GetMethodIDOrDie(env,
            gDisplayEventReceiverClassInfo.clazz, "dispatchHotplug", "(JJZ)V");
    gDisplayEventReceiverClassInfo.dispatchHotplug =
            GetMethodIDOrDie(env, gDisplayEventReceiverClassInfo.clazz, "dispatchHotplug",
                             "(JJZ)V");
    gDisplayEventReceiverClassInfo.dispatchHotplugConnectionError =
            GetMethodIDOrDie(env, gDisplayEventReceiverClassInfo.clazz,
                             "dispatchHotplugConnectionError", "(JI)V");
    gDisplayEventReceiverClassInfo.dispatchModeChanged =
            GetMethodIDOrDie(env, gDisplayEventReceiverClassInfo.clazz, "dispatchModeChanged",
                             "(JJIJ)V");
+15 −0
Original line number Diff line number Diff line
@@ -1344,6 +1344,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {

    public interface DisplayEventListener {
        void onHotplug(long timestampNanos, long physicalDisplayId, boolean connected);
        void onHotplugConnectionError(long timestampNanos, int connectionError);
        void onModeChanged(long timestampNanos, long physicalDisplayId, int modeId,
                long renderPeriod);
        void onFrameRateOverridesChanged(long timestampNanos, long physicalDisplayId,
@@ -1365,6 +1366,11 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            mListener.onHotplug(timestampNanos, physicalDisplayId, connected);
        }

        @Override
        public void onHotplugConnectionError(long timestampNanos, int errorCode) {
            mListener.onHotplugConnectionError(timestampNanos, errorCode);
        }

        @Override
        public void onModeChanged(long timestampNanos, long physicalDisplayId, int modeId,
                long renderPeriod) {
@@ -1390,6 +1396,15 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            }
        }

        @Override
        public void onHotplugConnectionError(long timestampNanos, int connectionError) {
            if (DEBUG) {
                Slog.d(TAG, "onHotplugConnectionError("
                        + "timestampNanos=" + timestampNanos
                        + ", connectionError=" + connectionError + ")");
            }
        }

        @Override
        public void onModeChanged(long timestampNanos, long physicalDisplayId, int modeId,
                long renderPeriod) {