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

Commit 3796e79f authored by Henry Fang's avatar Henry Fang Committed by Android (Google) Code Review
Browse files

Merge "Revert "Revert "Add public API to use new interfaces from cas@1.1"""

parents 8fa03704 5215ac9d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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",
+3 −1
Original line number Diff line number Diff line
@@ -24051,7 +24051,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 {
@@ -24063,6 +24064,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;
  }
+86 −6
Original line number Diff line number Diff line
@@ -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(@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.
         */
        void onEvent(MediaCas MediaCas, int event, int arg, @Nullable byte[] data);
        default void onSessionEvent(@NonNull MediaCas mediaCas, @NonNull Session session,
                int event, int arg, @Nullable byte[] data) {
            Log.d(TAG, "Received MediaCas Session event");
        }
    }

    /**