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

Commit 7259c6c6 authored by shubang's avatar shubang
Browse files

[TIAF] Add recording callback and cueing message APIs

Bug: 261648703
Test: mmm
Change-Id: Ie9793424c00caa4bcca3e760e85dd01571b87f14
parent bd2d5688
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ oneway interface ITvInputClient {
    void onTimeShiftCurrentPositionChanged(long timeMs, int seq);
    void onAitInfoUpdated(in AitInfo aitInfo, int seq);
    void onSignalStrength(int stength, int seq);
    void onCueingMessageAvailability(boolean available, int seq);
    void onTvMessage(in String type, in Bundle data, int seq);

    void onTuned(in Uri channelUri, int seq);
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ oneway interface ITvInputSessionCallback {
    void onTimeShiftCurrentPositionChanged(long timeMs);
    void onAitInfoUpdated(in AitInfo aitInfo);
    void onSignalStrength(int strength);
    void onCueingMessageAvailability(boolean available);

    // For the recording session
    void onTuned(in Uri channelUri);
+32 −0
Original line number Diff line number Diff line
@@ -56,7 +56,9 @@ import android.view.InputEventSender;
import android.view.KeyEvent;
import android.view.Surface;
import android.view.View;

import com.android.internal.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -718,6 +720,15 @@ public final class TvInputManager {
        public void onSignalStrengthUpdated(Session session, @SignalStrength int strength) {
        }

        /**
         * This is called when cueing message becomes available or unavailable.
         * @param session A {@link TvInputManager.Session} associated with this callback.
         * @param available The current availability of cueing message. {@code true} if cueing
         *                  message is available; {@code false} if it becomes unavailable.
         */
        public void onCueingMessageAvailability(Session session, boolean available) {
        }

        /**
         * This is called when the session has been tuned to the given channel.
         *
@@ -972,6 +983,15 @@ public final class TvInputManager {
            });
        }

        void postCueingMessageAvailability(final boolean available) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mSessionCallback.onCueingMessageAvailability(mSession, available);
                }
            });
        }

        void postTuned(final Uri channelUri) {
            mHandler.post(new Runnable() {
                @Override
@@ -1474,6 +1494,18 @@ public final class TvInputManager {
                }
            }

            @Override
            public void onCueingMessageAvailability(boolean available, int seq) {
                synchronized (mSessionCallbackRecordMap) {
                    SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
                    if (record == null) {
                        Log.e(TAG, "Callback not found for seq " + seq);
                        return;
                    }
                    record.postCueingMessageAvailability(available);
                }
            }

            @Override
            public void onTuned(Uri channelUri, int seq) {
                synchronized (mSessionCallbackRecordMap) {
+29 −0
Original line number Diff line number Diff line
@@ -59,8 +59,10 @@ import android.view.ViewRootImpl;
import android.view.WindowManager;
import android.view.accessibility.CaptioningManager;
import android.widget.FrameLayout;

import com.android.internal.os.SomeArgs;
import com.android.internal.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -1101,6 +1103,33 @@ public abstract class TvInputService extends Service {
            });
        }

        /**
         * Informs the application that cueing message is available or unavailable.
         *
         * <p>The cueing message is used for digital program insertion, based on the standard
         * ANSI/SCTE 35 2019r1.
         *
         * @param available {@code true} if cueing message is available; {@code false} if it becomes
         *                  unavailable.
         * @hide
         */
        public void notifyCueingMessageAvailability(boolean available) {
            executeOrPostRunnableOnMainThread(new Runnable() {
                @MainThread
                @Override
                public void run() {
                    try {
                        if (DEBUG) Log.d(TAG, "notifyCueingMessageAvailability");
                        if (mSessionCallback != null) {
                            mSessionCallback.onCueingMessageAvailability(available);
                        }
                    } catch (RemoteException e) {
                        Log.w(TAG, "error in notifyCueingMessageAvailability", e);
                    }
                }
            });
        }

        /**
         * Assigns a size and position to the surface passed in {@link #onSetSurface}. The position
         * is relative to the overlay view that sits on top of this surface.
+47 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Context;
import android.media.tv.TvInputManager;
import android.media.tv.interactive.TvInteractiveAppView;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -53,6 +54,8 @@ public class TvRecordingClient {
    private boolean mIsPaused;
    private boolean mIsRecordingStopping;
    private final Queue<Pair<String, Bundle>> mPendingAppPrivateCommands = new ArrayDeque<>();
    private TvInteractiveAppView mTvIAppView;
    private String mRecordingId;

    /**
     * Creates a new TvRecordingClient object.
@@ -69,6 +72,26 @@ public class TvRecordingClient {
        mTvInputManager = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE);
    }

    /**
     * Sets the related {@link TvInteractiveAppView} instance so the interactive app service can be
     * notified for recording events.
     *
     * @param view The related {@link TvInteractiveAppView} instance that is linked to this TV
     *             recording client. {@code null} to unlink the view.
     * @param recordingId The ID of the recording which is assigned by applications. {@code null} is
     *                    valid only when the TvInteractiveAppView parameter is null.
     * @hide
     */
    public void setTvInteractiveAppView(
            @Nullable TvInteractiveAppView view, @Nullable String recordingId) {
        if (view != null && recordingId == null) {
            throw new IllegalArgumentException(
                    "null recordingId is allowed only when the view is null");
        }
        mTvIAppView = view;
        mRecordingId = view == null ? null : recordingId;
    }

    /**
     * Tunes to a given channel for TV program recording. The first tune request will create a new
     * recording session for the corresponding TV input and establish a connection between the
@@ -468,6 +491,9 @@ public class TvRecordingClient {
                if (mCallback != null) {
                    mCallback.onConnectionFailed(mInputId);
                }
                if (mTvIAppView != null) {
                    mTvIAppView.notifyRecordingConnectionFailed(mRecordingId, mInputId);
                }
            }
        }

@@ -485,8 +511,13 @@ public class TvRecordingClient {
                return;
            }
            mIsTuned = true;
            if (mCallback != null) {
                mCallback.onTuned(channelUri);
            }
            if (mTvIAppView != null) {
                mTvIAppView.notifyRecordingTuned(mRecordingId, channelUri);
            }
        }

        @Override
        public void onSessionReleased(TvInputManager.Session session) {
@@ -506,6 +537,9 @@ public class TvRecordingClient {
            if (mCallback != null) {
                mCallback.onDisconnected(mInputId);
            }
            if (mTvIAppView != null) {
                mTvIAppView.notifyRecordingDisconnected(mRecordingId, mInputId);
            }
        }

        @Override
@@ -524,8 +558,13 @@ public class TvRecordingClient {
            mIsRecordingStarted = false;
            mIsPaused = false;
            mIsRecordingStopping = false;
            if (mCallback != null) {
                mCallback.onRecordingStopped(recordedProgramUri);
            }
            if (mTvIAppView != null) {
                mTvIAppView.notifyRecordingStopped(mRecordingId);
            }
        }

        @Override
        public void onError(TvInputManager.Session session, int error) {
@@ -536,8 +575,13 @@ public class TvRecordingClient {
                Log.w(TAG, "onError - session not created");
                return;
            }
            if (mCallback == null) {
                mCallback.onError(error);
            }
            if (mTvIAppView != null) {
                mTvIAppView.notifyRecordingError(mRecordingId, error);
            }
        }

        @Override
        public void onSessionEvent(TvInputManager.Session session, String eventType,
Loading