Revert "Revert "Add public API to use new interfaces from cas@1.1""
This reverts commit cdcaed6acb.
Reason for revert: <Verified build locally, CL is fine. original issue may be caused by conflict between merges>
Change-Id: Id9707692a704c3d4475aee1f6c580208eb6ab744
Test: Manual
Bug: 122472761
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Byte>) msg.obj));
|
||||
} else if (msg.what == MSG_CAS_SESSION_EVENT) {
|
||||
Bundle bundle = msg.getData();
|
||||
ArrayList<Byte> 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<Byte> sessionId,
|
||||
int event, int arg, @Nullable ArrayList<Byte> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user