diff options
author | Youngsang Cho <youngsang@google.com> | 2014-05-21 20:54:03 +0900 |
---|---|---|
committer | Dongwon Kang <dwkang@google.com> | 2014-05-29 21:04:52 -0700 |
commit | 832860fb9f6b3a7188a6af2d5d67806593595800 (patch) | |
tree | 1e4c22742eb689b0f0cc151dda761fd21581808c /core | |
parent | 2070252f988e4daac08acf88ea6865138d899f75 (diff) | |
download | frameworks_base-832860fb9f6b3a7188a6af2d5d67806593595800.zip frameworks_base-832860fb9f6b3a7188a6af2d5d67806593595800.tar.gz frameworks_base-832860fb9f6b3a7188a6af2d5d67806593595800.tar.bz2 |
Add a path for generic event from a session to an application in Tv Input Framework.
Plus, Video size changed event is also added.
Bug: 14126559
Change-Id: I04c553481fbaf8d92adbcc34f3c9d26acc87b361
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/tv/ITvInputClient.aidl | 3 | ||||
-rw-r--r-- | core/java/android/tv/ITvInputSessionCallback.aidl | 3 | ||||
-rw-r--r-- | core/java/android/tv/TvInputManager.java | 66 | ||||
-rw-r--r-- | core/java/android/tv/TvInputService.java | 65 | ||||
-rw-r--r-- | core/java/android/tv/TvView.java | 19 |
5 files changed, 147 insertions, 9 deletions
diff --git a/core/java/android/tv/ITvInputClient.aidl b/core/java/android/tv/ITvInputClient.aidl index ac83356..ef89c68 100644 --- a/core/java/android/tv/ITvInputClient.aidl +++ b/core/java/android/tv/ITvInputClient.aidl @@ -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); } diff --git a/core/java/android/tv/ITvInputSessionCallback.aidl b/core/java/android/tv/ITvInputSessionCallback.aidl index a2bd0d7..e27b8bf 100644 --- a/core/java/android/tv/ITvInputSessionCallback.aidl +++ b/core/java/android/tv/ITvInputSessionCallback.aidl @@ -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); } diff --git a/core/java/android/tv/TvInputManager.java b/core/java/android/tv/TvInputManager.java index dfa84f8..d0c2ca6 100644 --- a/core/java/android/tv/TvInputManager.java +++ b/core/java/android/tv/TvInputManager.java @@ -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); + } + }); + } } /** @@ -196,6 +238,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) { List<TvInputListenerRecord> records = mTvInputListenerRecordsMap.get(inputId); diff --git a/core/java/android/tv/TvInputService.java b/core/java/android/tv/TvInputService.java index cb0142f..03d24db 100644 --- a/core/java/android/tv/TvInputService.java +++ b/core/java/android/tv/TvInputService.java @@ -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); @@ -188,6 +190,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. */ public abstract void onRelease(); @@ -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); diff --git a/core/java/android/tv/TvView.java b/core/java/android/tv/TvView.java index 59b6386..2d31701 100644 --- a/core/java/android/tv/TvView.java +++ b/core/java/android/tv/TvView.java @@ -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); + } + } } } |