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

Commit c15ff84f authored by Henry Fang's avatar Henry Fang
Browse files

Set eventlistener during MediaCas initialization

bug: 171024166
Test: Manual
Change-Id: I4e876e9a0064e79399dbd42ce8465b13cec2a573
parent 79510c2b
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -25275,6 +25275,7 @@ package android.media {
  public final class MediaCas implements java.lang.AutoCloseable {
  public final class MediaCas implements java.lang.AutoCloseable {
    ctor public MediaCas(int) throws android.media.MediaCasException.UnsupportedCasException;
    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) 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 void close();
    method public static android.media.MediaCas.PluginDescriptor[] enumeratePlugins();
    method public static android.media.MediaCas.PluginDescriptor[] enumeratePlugins();
    method protected void finalize();
    method protected void finalize();
+1 −0
Original line number Original line Diff line number Diff line
@@ -25257,6 +25257,7 @@ package android.media {
  public final class MediaCas implements java.lang.AutoCloseable {
  public final class MediaCas implements java.lang.AutoCloseable {
    ctor public MediaCas(int) throws android.media.MediaCasException.UnsupportedCasException;
    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) 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 void close();
    method public static android.media.MediaCas.PluginDescriptor[] enumeratePlugins();
    method public static android.media.MediaCas.PluginDescriptor[] enumeratePlugins();
    method protected void finalize();
    method protected void finalize();
+60 −26
Original line number Original line Diff line number Diff line
@@ -676,17 +676,9 @@ public final class MediaCas implements AutoCloseable {
        return null;
        return null;
    }
    }


    /**
    private void createPlugin(int casSystemId) throws UnsupportedCasException {
     * 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 {
        try {
        try {
            mCasSystemId = CA_system_id;
            mCasSystemId = casSystemId;
            mUserId = ActivityManager.getCurrentUser();
            mUserId = ActivityManager.getCurrentUser();
            IMediaCasService service = getService();
            IMediaCasService service = getService();
            android.hardware.cas.V1_2.IMediaCasService serviceV12 =
            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);
                    android.hardware.cas.V1_1.IMediaCasService.castFrom(service);
                if (serviceV11 == null) {
                if (serviceV11 == null) {
                    Log.d(TAG, "Used cas@1_0 interface to create plugin");
                    Log.d(TAG, "Used cas@1_0 interface to create plugin");
                    mICas = service.createPlugin(CA_system_id, mBinder);
                    mICas = service.createPlugin(casSystemId, mBinder);
                } else {
                } else {
                    Log.d(TAG, "Used cas@1.1 interface to create plugin");
                    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 {
            } else {
                Log.d(TAG, "Used cas@1.2 interface to create plugin");
                Log.d(TAG, "Used cas@1.2 interface to create plugin");
                mICas = mICasV11 = mICasV12 =
                mICas = mICasV11 = mICasV12 =
                    android.hardware.cas.V1_2.ICas
                    android.hardware.cas.V1_2.ICas
                    .castFrom(serviceV12.createPluginExt(CA_system_id, mBinder));
                        .castFrom(serviceV12.createPluginExt(casSystemId, mBinder));
            }
            }
        } catch(Exception e) {
        } catch(Exception e) {
            Log.e(TAG, "Failed to create plugin: " + e);
            Log.e(TAG, "Failed to create plugin: " + e);
@@ -713,9 +705,35 @@ public final class MediaCas implements AutoCloseable {
        } finally {
        } finally {
            if (mICas == null) {
            if (mICas == null) {
                throw new UnsupportedCasException(
                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,
    public MediaCas(@NonNull Context context, int casSystemId,
            @Nullable String tvInputServiceSessionId,
            @Nullable String tvInputServiceSessionId,
            @PriorityHintUseCaseType int priorityHint) throws UnsupportedCasException {
            @PriorityHintUseCaseType int priorityHint) throws UnsupportedCasException {
        this(casSystemId);

        Objects.requireNonNull(context, "context must not be null");
        Objects.requireNonNull(context, "context must not be null");
        mTunerResourceManager = (TunerResourceManager)
        createPlugin(casSystemId);
                context.getSystemService(Context.TV_TUNER_RESOURCE_MGR_SERVICE);
        registerClient(context, tvInputServiceSessionId, priorityHint);
        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 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() {
    IHwBinder getBinder() {