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

Commit 887ad97e authored by Youngsang Cho's avatar Youngsang Cho Committed by Android (Google) Code Review
Browse files

Merge "Add a method in TIS to relayout SurfaceView" into lmp-dev

parents 9551e925 ff04ae75
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -39,4 +39,5 @@ oneway interface ITvInputClient {
    void onVideoUnavailable(int reason, int seq);
    void onContentAllowed(int seq);
    void onContentBlocked(in String rating, int seq);
    void onLayoutSurface(int left, int top, int right, int bottom, int seq);
}
+1 −0
Original line number Diff line number Diff line
@@ -36,4 +36,5 @@ oneway interface ITvInputSessionCallback {
    void onVideoUnavailable(int reason);
    void onContentAllowed();
    void onContentBlocked(in String rating);
    void onLayoutSurface(int left, int top, int right, int bottom);
}
+37 −0
Original line number Diff line number Diff line
@@ -234,6 +234,21 @@ public final class TvInputManager {
        public void onContentBlocked(Session session, TvContentRating rating) {
        }

        /**
         * This is called when {@link TvInputService.Session#layoutSurface} is called to
         * change the layout of surface.
         *
         * @param session A {@link TvInputManager.Session} associated with this callback
         * @param l Left position.
         * @param t Top position.
         * @param r Right position.
         * @param b Bottom position.
         * @hide
         */
        @SystemApi
        public void onLayoutSurface(Session session, int left, int top, int right, int bottom) {
        }

        /**
         * This is called when a custom event has been sent from this session.
         *
@@ -364,6 +379,16 @@ public final class TvInputManager {
            });
        }

        public void postLayoutSurface(final int left, final int top, final int right,
                final int bottom) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mSessionCallback.onLayoutSurface(mSession, left, top, right, bottom);
                }
            });
        }

        public void postSessionEvent(final String eventType, final Bundle eventArgs) {
            mHandler.post(new Runnable() {
                @Override
@@ -573,6 +598,18 @@ public final class TvInputManager {
                }
            }

            @Override
            public void onLayoutSurface(int left, int top, int right, int bottom, int seq) {
                synchronized (mSessionCallbackRecordMap) {
                    SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
                    if (record == null) {
                        Log.e(TAG, "Callback not found for seq " + seq);
                        return;
                    }
                    record.postLayoutSurface(left, top, right, bottom);
                }
            }

            @Override
            public void onSessionEvent(String eventType, Bundle eventArgs, int seq) {
                synchronized (mSessionCallbackRecordMap) {
+52 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.view.InputEventReceiver;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.view.accessibility.CaptioningManager;
@@ -503,6 +504,35 @@ public abstract class TvInputService extends Service {
            });
        }

        /**
         * Assigns a position of the {@link Surface} passed by {@link #onSetSurface}. The position
         * is relative to an overlay view. {@see #onOverlayViewSizeChanged}.
         *
         * @param left Left position in pixels, relative to the overlay view.
         * @param top Top position in pixels, relative to the overlay view.
         * @param right Right position in pixels, relative to the overlay view.
         * @param bottm Bottom position in pixels, relative to the overlay view.
         * @hide
         */
        @SystemApi
        public void layoutSurface(final int left, final int top, final int right, final int bottm) {
            if (left > right || top > bottm) {
                throw new IllegalArgumentException("Invalid parameter");
            }
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (DEBUG) Log.d(TAG, "layoutSurface (l=" + left + ", t=" + top + ", r="
                                + right + ", b=" + bottm + ",)");
                        mSessionCallback.onLayoutSurface(left, top, right, bottm);
                    } catch (RemoteException e) {
                        Log.w(TAG, "error in layoutSurface");
                    }
                }
            });
        }

        /**
         * Called when the session is released.
         */
@@ -555,6 +585,20 @@ public abstract class TvInputService extends Service {
        public void onSurfaceChanged(int format, int width, int height) {
        }

        /**
         * Called when a size of an overlay view is changed by an application. Even when the overlay
         * view is disabled by {@link #setOverlayViewEnabled}, this is called. The size is same as
         * the size of {@link Surface} in general. Once {@link #layoutSurface} is called, the sizes
         * of {@link Surface} and the overlay view can be different.
         *
         * @param width The width of the overlay view.
         * @param height The height of the overlay view.
         * @hide
         */
        @SystemApi
        public void onOverlayViewSizeChanged(int width, int height) {
        }

        /**
         * Sets the relative stream volume of the current TV input session to handle the change of
         * audio focus by setting.
@@ -873,6 +917,7 @@ public abstract class TvInputService extends Service {
            if (DEBUG) Log.d(TAG, "create overlay view(" + frame + ")");
            mWindowToken = windowToken;
            mOverlayFrame = frame;
            onOverlayViewSizeChanged(frame.right - frame.left, frame.bottom - frame.top);
            if (!mOverlayViewEnabled) {
                return;
            }
@@ -887,7 +932,7 @@ public abstract class TvInputService extends Service {
            // the application that owns the window token can decide whether to consume or
            // dispatch the input events.
            int flag = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
            mWindowParams = new WindowManager.LayoutParams(
                    frame.right - frame.left, frame.bottom - frame.top,
@@ -906,6 +951,12 @@ public abstract class TvInputService extends Service {
         */
        void relayoutOverlayView(Rect frame) {
            if (DEBUG) Log.d(TAG, "relayoutOverlayView(" + frame + ")");
            if (mOverlayFrame == null || mOverlayFrame.width() != frame.width()
                    || mOverlayFrame.height() != frame.height()) {
                // Note: relayoutOverlayView is called whenever TvView's layout is changed
                // regardless of setOverlayViewEnabled.
                onOverlayViewSizeChanged(frame.right - frame.left, frame.bottom - frame.top);
            }
            mOverlayFrame = frame;
            if (!mOverlayViewEnabled || mOverlayView == null) {
                return;
+30 −1
Original line number Diff line number Diff line
@@ -102,6 +102,11 @@ public class TvView extends ViewGroup {
    private final AttributeSet mAttrs;
    private final int mDefStyleAttr;
    private int mWindowZOrder;
    private boolean mUseRequestedSurfaceLayout;
    private int mSurfaceViewLeft;
    private int mSurfaceViewRight;
    private int mSurfaceViewTop;
    private int mSurfaceViewBottom;

    private final SurfaceHolder.Callback mSurfaceHolderCallback = new SurfaceHolder.Callback() {
        @Override
@@ -546,8 +551,17 @@ public class TvView extends ViewGroup {

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        if (DEBUG) {
            Log.d(TAG, "onLayout (left=" + left + ", top=" + top + ", right=" + right
                    + ", bottom=" + bottom + ",)");
        }
        if (mUseRequestedSurfaceLayout) {
            mSurfaceView.layout(mSurfaceViewLeft, mSurfaceViewTop, mSurfaceViewRight,
                    mSurfaceViewBottom);
        } else {
            mSurfaceView.layout(0, 0, right - left, bottom - top);
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@@ -594,6 +608,7 @@ public class TvView extends ViewGroup {
    private void release() {
        setSessionSurface(null);
        removeSessionOverlayView();
        mUseRequestedSurfaceLayout = false;
        mSession.release();
        mSession = null;
        mSessionCallback = null;
@@ -929,6 +944,20 @@ public class TvView extends ViewGroup {
            }
        }

        @Override
        public void onLayoutSurface(Session session, int left, int top, int right, int bottom) {
            if (DEBUG) {
                Log.d(TAG, "onLayoutSurface (left=" + left + ", top=" + top + ", right="
                        + right + ", bottom=" + bottom + ",)");
            }
            mSurfaceViewLeft = left;
            mSurfaceViewTop = top;
            mSurfaceViewRight = right;
            mSurfaceViewBottom = bottom;
            mUseRequestedSurfaceLayout = true;
            requestLayout();
        }

        @Override
        public void onSessionEvent(Session session, String eventType, Bundle eventArgs) {
            if (this != mSessionCallback) {
Loading