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

Commit e4988b45 authored by Huihong Luo's avatar Huihong Luo Committed by Android (Google) Code Review
Browse files

Merge "Handle display hotplug errors" into main

parents ee20263f 215e023b
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
@@ -1345,6 +1345,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,
@@ -1366,6 +1367,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) {
@@ -1391,6 +1397,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) {