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

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

Merge "Set eventlistener during MediaCas initialization"

parents b35e5bc9 c15ff84f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25278,6 +25278,7 @@ package android.media {
  public final class MediaCas implements java.lang.AutoCloseable {
    ctor public MediaCas(int) throws android.media.MediaCasException.UnsupportedCasException;
    ctor public MediaCas(@NonNull android.content.Context, int, @Nullable String, int) throws android.media.MediaCasException.UnsupportedCasException;
    ctor public MediaCas(@NonNull android.content.Context, int, @Nullable String, int, @Nullable android.os.Handler, @Nullable android.media.MediaCas.EventListener) throws android.media.MediaCasException.UnsupportedCasException;
    method public void close();
    method public static android.media.MediaCas.PluginDescriptor[] enumeratePlugins();
    method protected void finalize();
+1 −0
Original line number Diff line number Diff line
@@ -25260,6 +25260,7 @@ package android.media {
  public final class MediaCas implements java.lang.AutoCloseable {
    ctor public MediaCas(int) throws android.media.MediaCasException.UnsupportedCasException;
    ctor public MediaCas(@NonNull android.content.Context, int, @Nullable String, int) throws android.media.MediaCasException.UnsupportedCasException;
    ctor public MediaCas(@NonNull android.content.Context, int, @Nullable String, int, @Nullable android.os.Handler, @Nullable android.media.MediaCas.EventListener) throws android.media.MediaCasException.UnsupportedCasException;
    method public void close();
    method public static android.media.MediaCas.PluginDescriptor[] enumeratePlugins();
    method protected void finalize();
+60 −26
Original line number Diff line number Diff line
@@ -676,17 +676,9 @@ public final class MediaCas implements AutoCloseable {
        return null;
    }

    /**
     * Instantiate a CA system of the specified system id.
     *
     * @param CA_system_id The system id of the CA system.
     *
     * @throws UnsupportedCasException if the device does not support the
     * specified CA system.
     */
    public MediaCas(int CA_system_id) throws UnsupportedCasException {
    private void createPlugin(int casSystemId) throws UnsupportedCasException {
        try {
            mCasSystemId = CA_system_id;
            mCasSystemId = casSystemId;
            mUserId = ActivityManager.getCurrentUser();
            IMediaCasService service = getService();
            android.hardware.cas.V1_2.IMediaCasService serviceV12 =
@@ -696,16 +688,16 @@ public final class MediaCas implements AutoCloseable {
                    android.hardware.cas.V1_1.IMediaCasService.castFrom(service);
                if (serviceV11 == null) {
                    Log.d(TAG, "Used cas@1_0 interface to create plugin");
                    mICas = service.createPlugin(CA_system_id, mBinder);
                    mICas = service.createPlugin(casSystemId, mBinder);
                } else {
                    Log.d(TAG, "Used cas@1.1 interface to create plugin");
                    mICas = mICasV11 = serviceV11.createPluginExt(CA_system_id, mBinder);
                    mICas = mICasV11 = serviceV11.createPluginExt(casSystemId, mBinder);
                }
            } else {
                Log.d(TAG, "Used cas@1.2 interface to create plugin");
                mICas = mICasV11 = mICasV12 =
                    android.hardware.cas.V1_2.ICas
                    .castFrom(serviceV12.createPluginExt(CA_system_id, mBinder));
                        .castFrom(serviceV12.createPluginExt(casSystemId, mBinder));
            }
        } catch(Exception e) {
            Log.e(TAG, "Failed to create plugin: " + e);
@@ -713,9 +705,35 @@ public final class MediaCas implements AutoCloseable {
        } finally {
            if (mICas == null) {
                throw new UnsupportedCasException(
                        "Unsupported CA_system_id " + CA_system_id);
                    "Unsupported casSystemId " + casSystemId);
            }
        }
    }

    private void registerClient(@NonNull Context context,
            @Nullable String tvInputServiceSessionId,  @PriorityHintUseCaseType int priorityHint)  {

        mTunerResourceManager = (TunerResourceManager)
            context.getSystemService(Context.TV_TUNER_RESOURCE_MGR_SERVICE);
        if (mTunerResourceManager != null) {
            int[] clientId = new int[1];
            ResourceClientProfile profile =
                    new ResourceClientProfile(tvInputServiceSessionId, priorityHint);
            mTunerResourceManager.registerClientProfile(
                    profile, context.getMainExecutor(), mResourceListener, clientId);
            mClientId = clientId[0];
        }
    }
    /**
     * Instantiate a CA system of the specified system id.
     *
     * @param casSystemId The system id of the CA system.
     *
     * @throws UnsupportedCasException if the device does not support the
     * specified CA system.
     */
    public MediaCas(int casSystemId) throws UnsupportedCasException {
        createPlugin(casSystemId);
    }

    /**
@@ -733,19 +751,35 @@ public final class MediaCas implements AutoCloseable {
    public MediaCas(@NonNull Context context, int casSystemId,
            @Nullable String tvInputServiceSessionId,
            @PriorityHintUseCaseType int priorityHint) throws UnsupportedCasException {
        this(casSystemId);

        Objects.requireNonNull(context, "context must not be null");
        mTunerResourceManager = (TunerResourceManager)
                context.getSystemService(Context.TV_TUNER_RESOURCE_MGR_SERVICE);
        if (mTunerResourceManager != null) {
            int[] clientId = new int[1];
            ResourceClientProfile profile =
                    new ResourceClientProfile(tvInputServiceSessionId, priorityHint);
            mTunerResourceManager.registerClientProfile(
                    profile, context.getMainExecutor(), mResourceListener, clientId);
            mClientId = clientId[0];
        createPlugin(casSystemId);
        registerClient(context, tvInputServiceSessionId, priorityHint);
    }
    /**
     * Instantiate a CA system of the specified system id with EvenListener.
     *
     * @param context the context of the caller.
     * @param casSystemId The system id of the CA system.
     * @param tvInputServiceSessionId The Id of the session opened in TV Input Service (TIS)
     *        {@link android.media.tv.TvInputService#onCreateSession(String, String)}
     * @param priorityHint priority hint from the use case type for new created CAS system.
     * @param listener the event listener to be set.
     * @param handler the handler whose looper the event listener will be called on.
     * If handler is null, we'll try to use current thread's looper, or the main
     * looper. If neither are available, an internal thread will be created instead.
     *
     * @throws UnsupportedCasException if the device does not support the
     * specified CA system.
     */
    public MediaCas(@NonNull Context context, int casSystemId,
            @Nullable String tvInputServiceSessionId,
            @PriorityHintUseCaseType int priorityHint,
            @Nullable Handler handler, @Nullable EventListener listener)
            throws UnsupportedCasException {
        Objects.requireNonNull(context, "context must not be null");
        setEventListener(listener, handler);
        createPlugin(casSystemId);
        registerClient(context, tvInputServiceSessionId, priorityHint);
    }

    IHwBinder getBinder() {