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

Commit 15c56aac authored by Ji-Hwan Lee's avatar Ji-Hwan Lee
Browse files

TIF: Call setMain(false) when session is released.

Also, rename setMainTvView() and setMainSession() to setMain(), except
ITvInputManager.

Change-Id: I586e3fd42720f07a75d6f31b1ee955ce5c29dd68
parent 8809f1e5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ import android.view.Surface;
oneway interface ITvInputSession {
    void release();

    void setMainSession(boolean isMainSession);
    void setMain(boolean isMain);
    void setSurface(in Surface surface);
    void dispatchSurfaceChanged(int format, int width, int height);
    // TODO: Remove this once it becomes irrelevant for applications to handle audio focus. The plan
+5 −5
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand
    private static final String TAG = "TvInputSessionWrapper";

    private static final int DO_RELEASE = 1;
    private static final int DO_SET_MAIN_SESSION = 2;
    private static final int DO_SET_MAIN = 2;
    private static final int DO_SET_SURFACE = 3;
    private static final int DO_DISPATCH_SURFACE_CHANGED = 4;
    private static final int DO_SET_STREAM_VOLUME = 5;
@@ -91,8 +91,8 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand
                }
                return;
            }
            case DO_SET_MAIN_SESSION: {
                mTvInputSessionImpl.setMainSession((Boolean) msg.obj);
            case DO_SET_MAIN: {
                mTvInputSessionImpl.setMain((Boolean) msg.obj);
                return;
            }
            case DO_SET_SURFACE: {
@@ -162,8 +162,8 @@ public class ITvInputSessionWrapper extends ITvInputSession.Stub implements Hand
    }

    @Override
    public void setMainSession(boolean isMain) {
        mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_MAIN_SESSION, isMain));
    public void setMain(boolean isMain) {
        mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_MAIN, isMain));
    }

    @Override
+5 −3
Original line number Diff line number Diff line
@@ -1023,10 +1023,12 @@ public final class TvInputManager {
        }

        /**
         * Sets this as main session. See {@link TvView#setMainTvView} for about meaning of "main".
         * @hide
         * Sets this as the main session. The main session is a session whose corresponding TV
         * input determines the HDMI-CEC active source device.
         *
         * @see TvView#setMain
         */
        public void setMainSession() {
        void setMain() {
            if (mToken == null) {
                Log.w(TAG, "The session has been already released");
                return;
+20 −19
Original line number Diff line number Diff line
@@ -551,29 +551,30 @@ public abstract class TvInputService extends Service {
        public abstract void onRelease();

        /**
         * Set the current session as the "main" session. See {@link TvView#setMainTvView} for the
         * meaning of "main".
         * Sets the current session as the main session. The main session is a session whose
         * corresponding TV input determines the HDMI-CEC active source device.
         * <p>
         * This is primarily for HDMI-CEC active source management. TV input service that manages
         * HDMI-CEC logical device should make sure not only to select the corresponding HDMI
         * logical device as source device on {@code onSetMainSession(true)}, but also to select
         * internal device on {@code onSetMainSession(false)}. Also, if surface is set to non-main
         * session, it needs to select internal device after temporarily selecting corresponding
         * HDMI logical device for set up.
         * TV input service that manages HDMI-CEC logical device should implement {@link
         * #onSetMain} to (1) select the corresponding HDMI logical device as the source device
         * when {@code isMain} is {@code true}, and to (2) select the internal device (= TV itself)
         * as the source device when {@code isMain} is {@code false} and the session is still main.
         * Also, if a surface is passed to a non-main session and active source is changed to
         * initiate the surface, the active source should be returned to the main session.
         * </p><p>
         * It is guaranteed that {@code onSetMainSession(true)} for new session is called first,
         * and {@code onSetMainSession(false)} for old session is called afterwards. This allows
         * {@code onSetMainSession(false)} to be no-op when TV input service knows that the next
         * main session corresponds to another HDMI logical device. Practically, this implies that
         * one TV input service should handle all HDMI port and HDMI-CEC logical devices for smooth
         * active source transition.
         * {@link TvView} guarantees that, when tuning involves a session transition, {@code
         * onSetMain(true)} for new session is called first, {@code onSetMain(false)} for old
         * session is called afterwards. This allows {@code onSetMain(false)} to be no-op when TV
         * input service knows that the next main session corresponds to another HDMI logical
         * device. Practically, this implies that one TV input service should handle all HDMI port
         * and HDMI-CEC logical devices for smooth active source transition.
         * </p>
         *
         * @param isMainSession If true, session is main.
         * @param isMain If true, session should become main.
         * @see TvView#setMain
         * @hide
         */
        @SystemApi
        public void onSetMainSession(boolean isMainSession) {
        public void onSetMain(boolean isMain) {
        }

        /**
@@ -841,10 +842,10 @@ public abstract class TvInputService extends Service {
        }

        /**
         * Calls {@link #onSetMainSession}.
         * Calls {@link #onSetMain}.
         */
        void setMainSession(boolean isMainSession) {
            onSetMainSession(isMainSession);
        void setMain(boolean isMain) {
            onSetMain(isMain);
        }

        /**
+23 −13
Original line number Diff line number Diff line
@@ -116,8 +116,10 @@ public class TvView extends ViewGroup {
    private final SurfaceHolder.Callback mSurfaceHolderCallback = new SurfaceHolder.Callback() {
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            Log.d(TAG, "surfaceChanged(holder=" + holder + ", format=" + format + ", width=" + width
                    + ", height=" + height + ")");
            if (DEBUG) {
                Log.d(TAG, "surfaceChanged(holder=" + holder + ", format=" + format + ", width="
                    + width + ", height=" + height + ")");
            }
            mSurfaceFormat = format;
            mSurfaceWidth = width;
            mSurfaceHeight = height;
@@ -188,24 +190,27 @@ public class TvView extends ViewGroup {
    }

    /**
     * Sets this as main TvView.
     * Sets this as the main {@link TvView}.
     * <p>
     * Main TvView is the TvView which user is watching and interacting mainly.  It is used for
     * determining internal behavior of hardware TV input devices. For example, this influences
     * how HDMI-CEC active source will be managed.
     * The main {@link TvView} is a {@link TvView} whose corresponding TV input determines the
     * HDMI-CEC active source device. For an HDMI port input, one of source devices that is
     * connected to that HDMI port becomes the active source. For an HDMI-CEC logical device input,
     * the corresponding HDMI-CEC logical device becomes the active source. For any non-HDMI input
     * (including the tuner, composite, S-Video, etc.), the internal device (= TV itself) becomes
     * the active source.
     * </p><p>
     * First tuned TvView becomes main automatically, and keeps to be main until setMainTvView() is
     * called for other TvView. Note that main TvView won't be reset even when current main TvView
     * is removed from view hierarchy.
     * First tuned {@link TvView} becomes main automatically, and keeps to be main until {@link
     * #setMain} is called for other {@link TvView}. Note that main {@link TvView} won't be reset
     * even when current main {@link TvView} is removed from view hierarchy.
     * </p>
     * @hide
     */
    @SystemApi
    public void setMainTvView() {
    public void setMain() {
        synchronized (sMainTvViewLock) {
            sMainTvView = this;
            if (hasWindowFocus() && mSession != null) {
                mSession.setMainSession();
                mSession.setMain();
            }
        }
    }
@@ -327,6 +332,7 @@ public class TvView extends ViewGroup {
     * This method is primarily used to un-tune the current TvView.
     */
    public void reset() {
        if (DEBUG) Log.d(TAG, "reset()");
        if (mSession != null) {
            release();
            resetSurfaceView();
@@ -538,7 +544,7 @@ public class TvView extends ViewGroup {
        // Set main again to regain main session.
        synchronized (sMainTvViewLock) {
            if (hasFocus && this == sMainTvView && mSession != null) {
                mSession.setMainSession();
                mSession.setMain();
            }
        }
    }
@@ -596,6 +602,7 @@ public class TvView extends ViewGroup {
            mSurfaceView.getHolder().removeCallback(mSurfaceHolderCallback);
            removeView(mSurfaceView);
        }
        mSurface = null;
        mSurfaceView = new SurfaceView(getContext(), mAttrs, mDefStyleAttr) {
            @Override
            protected void updateWindow(boolean force, boolean redrawNeeded) {
@@ -821,11 +828,14 @@ public class TvView extends ViewGroup {
                }
                return;
            }
            if (DEBUG) {
                Log.d(TAG, "onSessionCreated()");
            }
            mSession = session;
            if (session != null) {
                synchronized (sMainTvViewLock) {
                    if (hasWindowFocus() && TvView.this == sMainTvView) {
                        mSession.setMainSession();
                        mSession.setMain();
                    }
                }
                // mSurface may not be ready yet as soon as starting an application.
Loading