From 5215ac9d41e2593c14f5bd810fbaf3fe3df5d6d9 Mon Sep 17 00:00:00 2001 From: Henry Fang Date: Fri, 1 Feb 2019 19:24:55 +0000 Subject: [PATCH] Revert "Revert "Add public API to use new interfaces from cas@1.1"" This reverts commit cdcaed6acb426f50bd5dfe4e30792ff22219c690. Reason for revert: Change-Id: Id9707692a704c3d4475aee1f6c580208eb6ab744 Test: Manual Bug: 122472761 --- Android.bp | 1 + api/current.txt | 4 +- media/java/android/media/MediaCas.java | 92 ++++++++++++++++++++++++-- 3 files changed, 90 insertions(+), 7 deletions(-) diff --git a/Android.bp b/Android.bp index ecdc0827e8513..8d25704883fdf 100644 --- a/Android.bp +++ b/Android.bp @@ -746,6 +746,7 @@ java_defaults { "game-driver-protos", "mediaplayer2-protos", "android.hidl.base-V1.0-java", + "android.hardware.cas-V1.1-java", "android.hardware.cas-V1.0-java", "android.hardware.contexthub-V1.0-java", "android.hardware.health-V1.0-java-constants", diff --git a/api/current.txt b/api/current.txt index 0652fdd45ae2b..9c0a6aa3d4c59 100644 --- a/api/current.txt +++ b/api/current.txt @@ -24050,7 +24050,8 @@ package android.media { } public static interface MediaCas.EventListener { - method public void onEvent(android.media.MediaCas, int, int, @Nullable byte[]); + method public void onEvent(@NonNull android.media.MediaCas, int, int, @Nullable byte[]); + method public default void onSessionEvent(@NonNull android.media.MediaCas, @NonNull android.media.MediaCas.Session, int, int, @Nullable byte[]); } public static class MediaCas.PluginDescriptor { @@ -24062,6 +24063,7 @@ package android.media { method public void close(); method public void processEcm(@NonNull byte[], int, int) throws android.media.MediaCasException; method public void processEcm(@NonNull byte[]) throws android.media.MediaCasException; + method public void sendSessionEvent(int, int, @Nullable byte[]) throws android.media.MediaCasException; method public void setPrivateData(@NonNull byte[]) throws android.media.MediaCasException; } diff --git a/media/java/android/media/MediaCas.java b/media/java/android/media/MediaCas.java index ce631a43327bc..cf5711d732783 100644 --- a/media/java/android/media/MediaCas.java +++ b/media/java/android/media/MediaCas.java @@ -18,8 +18,12 @@ package android.media; import android.annotation.NonNull; import android.annotation.Nullable; -import android.hardware.cas.V1_0.*; +import android.hardware.cas.V1_0.HidlCasPluginDescriptor; +import android.hardware.cas.V1_1.ICas; +import android.hardware.cas.V1_1.ICasListener; +import android.hardware.cas.V1_1.IMediaCasService; import android.media.MediaCasException.*; +import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; import android.os.IHwBinder; @@ -128,6 +132,9 @@ public final class MediaCas implements AutoCloseable { private class EventHandler extends Handler { private static final int MSG_CAS_EVENT = 0; + private static final int MSG_CAS_SESSION_EVENT = 1; + private static final String SESSION_KEY = "sessionId"; + private static final String DATA_KEY = "data"; public EventHandler(Looper looper) { super(looper); @@ -138,6 +145,12 @@ public final class MediaCas implements AutoCloseable { if (msg.what == MSG_CAS_EVENT) { mListener.onEvent(MediaCas.this, msg.arg1, msg.arg2, toBytes((ArrayList) msg.obj)); + } else if (msg.what == MSG_CAS_SESSION_EVENT) { + Bundle bundle = msg.getData(); + ArrayList sessionId = toByteArray(bundle.getByteArray(SESSION_KEY)); + mListener.onSessionEvent(MediaCas.this, + createFromSessionId(sessionId), msg.arg1, msg.arg2, + bundle.getByteArray(DATA_KEY)); } } } @@ -149,6 +162,20 @@ public final class MediaCas implements AutoCloseable { mEventHandler.sendMessage(mEventHandler.obtainMessage( EventHandler.MSG_CAS_EVENT, event, arg, data)); } + @Override + public void onSessionEvent(@NonNull ArrayList sessionId, + int event, int arg, @Nullable ArrayList data) + throws RemoteException { + Message msg = mEventHandler.obtainMessage(); + msg.what = EventHandler.MSG_CAS_SESSION_EVENT; + msg.arg1 = event; + msg.arg2 = arg; + Bundle bundle = new Bundle(); + bundle.putByteArray(EventHandler.SESSION_KEY, toBytes(sessionId)); + bundle.putByteArray(EventHandler.DATA_KEY, toBytes(data)); + msg.setData(bundle); + mEventHandler.sendMessage(msg); + } }; /** @@ -221,6 +248,20 @@ public final class MediaCas implements AutoCloseable { mSessionId = sessionId; } + /** + * Query if an object equal current Session object. + * + * @param obj an object to compare to current Session object. + * + * @return Whether input object equal current Session object. + */ + public boolean equals(Object obj) { + if (obj instanceof Session) { + return mSessionId.equals(((Session) obj).mSessionId); + } + return false; + } + /** * Set the private data for a session. * @@ -281,6 +322,30 @@ public final class MediaCas implements AutoCloseable { processEcm(data, 0, data.length); } + /** + * Send a session event to a CA system. The format of the event is + * scheme-specific and is opaque to the framework. + * + * @param event an integer denoting a scheme-specific event to be sent. + * @param arg a scheme-specific integer argument for the event. + * @param data a byte array containing scheme-specific data for the event. + * + * @throws IllegalStateException if the MediaCas instance is not valid. + * @throws MediaCasException for CAS-specific errors. + * @throws MediaCasStateException for CAS-specific state exceptions. + */ + public void sendSessionEvent(int event, int arg, @Nullable byte[] data) + throws MediaCasException { + validateInternalStates(); + + try { + MediaCasException.throwExceptionIfNeeded( + mICas.sendSessionEvent(mSessionId, event, arg, toByteArray(data))); + } catch (RemoteException e) { + cleanupAndRethrowIllegalState(); + } + } + /** * Close the session. * @@ -362,7 +427,7 @@ public final class MediaCas implements AutoCloseable { */ public MediaCas(int CA_system_id) throws UnsupportedCasException { try { - mICas = getService().createPlugin(CA_system_id, mBinder); + mICas = getService().createPluginExt(CA_system_id, mBinder); } catch(Exception e) { Log.e(TAG, "Failed to create plugin: " + e); mICas = null; @@ -388,13 +453,28 @@ public final class MediaCas implements AutoCloseable { /** * Notify the listener of a scheme-specific event from the CA system. * - * @param MediaCas the MediaCas object to receive this event. + * @param mediaCas the MediaCas object to receive this event. * @param event an integer whose meaning is scheme-specific. * @param arg an integer whose meaning is scheme-specific. * @param data a byte array of data whose format and meaning are * scheme-specific. */ - void onEvent(MediaCas MediaCas, int event, int arg, @Nullable byte[] data); + void onEvent(@NonNull MediaCas mediaCas, int event, int arg, @Nullable byte[] data); + + /** + * Notify the listener of a scheme-specific session event from CA system. + * + * @param mediaCas the MediaCas object to receive this event. + * @param session session object which the event is for. + * @param event an integer whose meaning is scheme-specific. + * @param arg an integer whose meaning is scheme-specific. + * @param data a byte array of data whose format and meaning are + * scheme-specific. + */ + default void onSessionEvent(@NonNull MediaCas mediaCas, @NonNull Session session, + int event, int arg, @Nullable byte[] data) { + Log.d(TAG, "Received MediaCas Session event"); + } } /** @@ -543,7 +623,7 @@ public final class MediaCas implements AutoCloseable { } } - /** + /** * Initiate a provisioning operation for a CA system. * * @param provisionString string containing information needed for the @@ -603,4 +683,4 @@ public final class MediaCas implements AutoCloseable { protected void finalize() { close(); } -} \ No newline at end of file +}