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

Commit 240b8368 authored by Dongwon Kang's avatar Dongwon Kang Committed by Android Git Automerger
Browse files

am 41e5f190: Merge "Add a path for generic event from a session to an...

am 41e5f190: Merge "Add a path for generic event from a session to an application in Tv Input Framework." into lmp-preview-dev

* commit '41e5f1907dc029ab5117b9f8bcbc69c7a0abaa11':
  Add a path for generic event from a session to an application in Tv Input Framework.
parents 1462ddcb 0bf8a214
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.tv;

import android.content.ComponentName;
import android.os.Bundle;
import android.tv.ITvInputSession;
import android.view.InputChannel;

@@ -29,4 +30,6 @@ oneway interface ITvInputClient {
    void onSessionCreated(in String inputId, IBinder token, in InputChannel channel, int seq);
    void onAvailabilityChanged(in String inputId, boolean isAvailable);
    void onSessionReleased(int seq);
    void onSessionEvent(in String name, in Bundle args, int seq);
    void onVideoSizeChanged(int width, int height, int seq);
}
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.tv;

import android.os.Bundle;
import android.tv.ITvInputSession;

/**
@@ -25,4 +26,6 @@ import android.tv.ITvInputSession;
 */
oneway interface ITvInputSessionCallback {
    void onSessionCreated(ITvInputSession session);
    void onSessionEvent(in String name, in Bundle args);
    void onVideoSizeChanged(int width, int height);
}
+66 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.tv;

import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -85,6 +86,29 @@ public final class TvInputManager {
         */
        public void onSessionReleased(Session session) {
        }

        /**
         * This is called at the beginning of the playback of a channel and later when the size of
         * the video has been changed.
         *
         * @param session A {@link TvInputManager.Session} associated with this callback
         * @param width the width of the video
         * @param height the height of the video
         * @hide
         */
        public void onVideoSizeChanged(Session session, int width, int height) {
        }

        /**
         * This is called when a custom event has been sent from this session.
         *
         * @param session A {@link TvInputManager.Session} associated with this callback
         * @param eventType The type of the event.
         * @param eventArgs Optional arguments of the event.
         * @hide
         */
        public void onSessionEvent(Session session, String eventType, Bundle eventArgs) {
        }
    }

    private static final class SessionCallbackRecord {
@@ -116,6 +140,24 @@ public final class TvInputManager {
                }
            });
        }

        public void postVideoSizeChanged(final int width, final int height) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mSessionCallback.onVideoSizeChanged(mSession, width, height);
                }
            });
        }

        public void postSessionEvent(final String eventType, final Bundle eventArgs) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mSessionCallback.onSessionEvent(mSession, eventType, eventArgs);
                }
            });
        }
    }

    /**
@@ -195,6 +237,30 @@ public final class TvInputManager {
                }
            }

            @Override
            public void onVideoSizeChanged(int width, int height, int seq) {
                synchronized (mSessionCallbackRecordMap) {
                    SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
                    if (record == null) {
                        Log.e(TAG, "Callback not found for seq " + seq);
                        return;
                    }
                    record.postVideoSizeChanged(width, height);
                }
            }

            @Override
            public void onSessionEvent(String eventType, Bundle eventArgs, int seq) {
                synchronized (mSessionCallbackRecordMap) {
                    SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
                    if (record == null) {
                        Log.e(TAG, "Callback not found for seq " + seq);
                        return;
                    }
                    record.postSessionEvent(eventType, eventArgs);
                }
            }

            @Override
            public void onAvailabilityChanged(String inputId, boolean isAvailable) {
                synchronized (mTvInputListenerRecordsMap) {
+56 −9
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
@@ -156,6 +157,7 @@ public abstract class TvInputService extends Service {
        private boolean mOverlayViewEnabled;
        private IBinder mWindowToken;
        private Rect mOverlayFrame;
        private ITvInputSessionCallback mSessionCallback;

        public TvInputSessionImpl() {
            mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
@@ -187,6 +189,52 @@ public abstract class TvInputService extends Service {
            });
        }

        /**
         * Dispatches an event to the application using this session.
         *
         * @param eventType The type of the event.
         * @param eventArgs Optional arguments of the event.
         * @hide
         */
        public void dispatchSessionEvent(final String eventType, final Bundle eventArgs) {
            if (eventType == null) {
                throw new IllegalArgumentException("eventType should not be null.");
            }
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (DEBUG) Log.d(TAG, "dispatchSessionEvent(" + eventType + ")");
                        mSessionCallback.onSessionEvent(eventType, eventArgs);
                    } catch (RemoteException e) {
                        Log.w(TAG, "error in sending event (event=" + eventType + ")");
                    }
                }
            });
        }

        /**
         * Sends the change on the size of the video. This is expected to be called at the
         * beginning of the playback and later when the size has been changed.
         *
         * @param width The width of the video.
         * @param height The height of the video.
         * @hide
         */
        public void dispatchVideoSizeChanged(final int width, final int height) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (DEBUG) Log.d(TAG, "dispatchVideoSizeChanged");
                        mSessionCallback.onVideoSizeChanged(width, height);
                    } catch (RemoteException e) {
                        Log.w(TAG, "error in dispatchVideoSizeChanged");
                    }
                }
            });
        }

        /**
         * Called when the session is released.
         */
@@ -394,9 +442,7 @@ public abstract class TvInputService extends Service {
                mWindowManager.removeView(mOverlayView);
                mOverlayView = null;
            }
            if (DEBUG) {
                Log.d(TAG, "create overlay view(" + frame + ")");
            }
            if (DEBUG) Log.d(TAG, "create overlay view(" + frame + ")");
            mWindowToken = windowToken;
            mOverlayFrame = frame;
            if (!mOverlayViewEnabled) {
@@ -431,9 +477,7 @@ public abstract class TvInputService extends Service {
         * @param frame A new position of the overlay view.
         */
        void relayoutOverlayView(Rect frame) {
            if (DEBUG) {
                Log.d(TAG, "relayout overlay view(" + frame + ")");
            }
            if (DEBUG) Log.d(TAG, "relayoutOverlayView(" + frame + ")");
            mOverlayFrame = frame;
            if (!mOverlayViewEnabled || mOverlayView == null) {
                return;
@@ -449,9 +493,7 @@ public abstract class TvInputService extends Service {
         * Removes the current overlay view.
         */
        void removeOverlayView(boolean clearWindowToken) {
            if (DEBUG) {
                Log.d(TAG, "remove overlay view(" + mOverlayView + ")");
            }
            if (DEBUG) Log.d(TAG, "removeOverlayView(" + mOverlayView + ")");
            if (clearWindowToken) {
                mWindowToken = null;
                mOverlayFrame = null;
@@ -498,6 +540,10 @@ public abstract class TvInputService extends Service {
            mOverlayView.getViewRootImpl().dispatchInputEvent(event, receiver);
            return Session.DISPATCH_IN_PROGRESS;
        }

        private void setSessionCallback(ITvInputSessionCallback callback) {
            mSessionCallback = callback;
        }
    }

    private final class ServiceHandler extends Handler {
@@ -517,6 +563,7 @@ public abstract class TvInputService extends Service {
                            // Failed to create a session.
                            cb.onSessionCreated(null);
                        } else {
                            sessionImpl.setSessionCallback(cb);
                            ITvInputSession stub = new ITvInputSessionWrapper(TvInputService.this,
                                    sessionImpl, channel);
                            cb.onSessionCreated(stub);
+19 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.tv;

import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.tv.TvInputManager.Session;
@@ -379,5 +380,23 @@ public class TvView extends SurfaceView {
                mExternalCallback.onSessionReleased(session);
            }
        }

        @Override
        public void onVideoSizeChanged(Session session, int width, int height) {
            if (DEBUG) {
                Log.d(TAG, "onVideoSizeChanged(" + width + ", " + height + ")");
            }
            if (mExternalCallback != null) {
                mExternalCallback.onVideoSizeChanged(session, width, height);
            }
        }

        @Override
        public void onSessionEvent(TvInputManager.Session session, String eventType,
                Bundle eventArgs) {
            if (mExternalCallback != null) {
                mExternalCallback.onSessionEvent(session, eventType, eventArgs);
            }
        }
    }
}
Loading