Merge "Add TIAF watermarking APIs"

This commit is contained in:
David Zhao
2023-01-09 22:45:39 +00:00
committed by Android (Google) Code Review
12 changed files with 199 additions and 2 deletions

View File

@@ -49,6 +49,7 @@ oneway interface ITvInputClient {
void onTimeShiftCurrentPositionChanged(long timeMs, int seq);
void onAitInfoUpdated(in AitInfo aitInfo, int seq);
void onSignalStrength(int stength, int seq);
void onTvMessage(in String type, in Bundle data, int seq);
void onTuned(in Uri channelUri, int seq);
// For the recording session

View File

@@ -58,4 +58,7 @@ oneway interface ITvInputSessionCallback {
// For ad response
void onAdResponse(in AdResponse response);
void onAdBufferConsumed(in AdBuffer buffer);
// For messages sent from the TV input
void onTvMessage(in String type, in Bundle data);
}

View File

@@ -22,6 +22,7 @@ import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.StringDef;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
@@ -130,6 +131,20 @@ public final class TvInputManager {
VIDEO_UNAVAILABLE_REASON_CAS_REBOOTING, VIDEO_UNAVAILABLE_REASON_CAS_UNKNOWN})
public @interface VideoUnavailableReason {}
/**
* @hide
*/
public static final String TV_MESSAGE_TYPE_WATERMARK = "Watermark";
/**
* @hide
*/
public static final String TV_MESSAGE_TYPE_ATSC_CC = "ATSC_CC";
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@StringDef({TV_MESSAGE_TYPE_WATERMARK, TV_MESSAGE_TYPE_ATSC_CC})
public @interface TvMessageType {}
static final int VIDEO_UNAVAILABLE_REASON_START = 0;
static final int VIDEO_UNAVAILABLE_REASON_END = 18;
@@ -690,6 +705,17 @@ public final class TvInputManager {
public void onTuned(Session session, Uri channelUri) {
}
/**
* This is called when the session receives a new Tv Message
*
* @param type the type of {@link TvMessageType}
* @param data the raw data of the message
* @hide
*/
public void onTvMessage(Session session, @TvInputManager.TvMessageType String type,
Bundle data) {
}
// For the recording session only
/**
* This is called when the current recording session has stopped recording and created a
@@ -919,6 +945,19 @@ public final class TvInputManager {
});
}
void postTvMessage(String type, Bundle data) {
mHandler.post(new Runnable() {
@Override
public void run() {
mSessionCallback.onTvMessage(mSession, type, data);
if (mSession.mIAppNotificationEnabled
&& mSession.getInteractiveAppSession() != null) {
mSession.getInteractiveAppSession().notifyTvMessage(type, data);
}
}
});
}
// For the recording session only
void postRecordingStopped(final Uri recordedProgramUri) {
mHandler.post(new Runnable() {
@@ -1378,6 +1417,18 @@ public final class TvInputManager {
}
}
@Override
public void onTvMessage(String type, Bundle data, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postTvMessage(type, data);
}
}
@Override
public void onRecordingStopped(Uri recordedProgramUri, int seq) {
synchronized (mSessionCallbackRecordMap) {

View File

@@ -2062,6 +2062,27 @@ public abstract class TvInputService extends Service {
});
}
/**
* Informs the application of the raw data from the TV message.
* @param type The {@link TvInputManager.TvMessageType} of message that was sent.
* @param data The data sent with the message.
* @hide
*/
public void notifyTvMessage(@TvInputManager.TvMessageType String type, Bundle data) {
}
/**
* Called when the application enables or disables the detection of the specified message
* type.
* @param type The {@link TvInputManager.TvMessageType} of message that was sent.
* @param enabled {@code true} if you want to enable TV message detecting
* {@code false} otherwise.
* @hide
*/
public void onSetTvMessageEnabled(@TvInputManager.TvMessageType String type,
boolean enabled) {
}
/**
* Called when the application requests to tune to a given channel for TV program recording.
*

View File

@@ -653,6 +653,17 @@ public class TvView extends ViewGroup {
mOnUnhandledInputEventListener = listener;
}
/**
* Enables or disables TV message detecting in the streams of bound TV input.
*
* @param type The type of {@link android.media.tv.TvInputManager.TvMessageType}
* @param enabled {@code true} if you want to enable TV message detecting
* {@code false} otherwise.
* @hide
*/
public void setTvMessageEnabled(@TvInputManager.TvMessageType String type, boolean enabled) {
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (super.dispatchKeyEvent(event)) {
@@ -1094,6 +1105,17 @@ public class TvView extends ViewGroup {
*/
public void onTuned(@NonNull String inputId, @NonNull Uri channelUri) {
}
/**
* This is called when the session has been tuned to the given channel.
*
* @param type The type of {@link android.media.tv.TvInputManager.TvMessageType}
* @param data The raw data of the message
* @hide
*/
public void onTvMessage(@NonNull String inputId, @TvInputManager.TvMessageType String type,
Bundle data) {
}
}
/**
@@ -1432,5 +1454,19 @@ public class TvView extends ViewGroup {
mCallback.onTuned(mInputId, channelUri);
}
}
@Override
public void onTvMessage(Session session, String type, Bundle data) {
if (DEBUG) {
Log.d(TAG, "onTvMessage(type=" + type + ", data=" + data + ")");
}
if (this != mSessionCallback) {
Log.w(TAG, "onTvMessage - session not created");
return;
}
if (mCallback != null) {
mCallback.onTvMessage(mInputId, type, data);
}
}
}
}

View File

@@ -70,6 +70,7 @@ interface ITvInteractiveAppManager {
void notifySignalStrength(in IBinder sessionToken, int stength, int userId);
void notifyRecordingStarted(in IBinder sessionToken, in String recordingId, int userId);
void notifyRecordingStopped(in IBinder sessionToken, in String recordingId, int userId);
void notifyTvMessage(in IBinder sessionToken, in String type, in Bundle data, int userId);
void setSurface(in IBinder sessionToken, in Surface surface, int userId);
void dispatchSurfaceChanged(in IBinder sessionToken, int format, int width, int height,
int userId);

View File

@@ -59,6 +59,7 @@ oneway interface ITvInteractiveAppSession {
void notifySignalStrength(int strength);
void notifyRecordingStarted(in String recordingId);
void notifyRecordingStopped(in String recordingId);
void notifyTvMessage(in String type, in Bundle data);
void setSurface(in Surface surface);
void dispatchSurfaceChanged(int format, int width, int height);
void notifyBroadcastInfoResponse(in BroadcastInfoResponse response);

View File

@@ -86,8 +86,9 @@ public class ITvInteractiveAppSessionWrapper
private static final int DO_NOTIFY_RECORDING_STARTED = 30;
private static final int DO_NOTIFY_RECORDING_STOPPED = 31;
private static final int DO_NOTIFY_AD_BUFFER_CONSUMED = 32;
private static final int DO_SEND_RECORDING_INFO = 33;
private static final int DO_SEND_RECORDING_INFO_LIST = 34;
private static final int DO_NOTIFY_TV_MESSAGE = 33;
private static final int DO_SEND_RECORDING_INFO = 34;
private static final int DO_SEND_RECORDING_INFO_LIST = 35;
private final HandlerCaller mCaller;
private Session mSessionImpl;
@@ -213,6 +214,12 @@ public class ITvInteractiveAppSessionWrapper
mSessionImpl.notifyTracksChanged((List<TvTrackInfo>) msg.obj);
break;
}
case DO_NOTIFY_TV_MESSAGE: {
SomeArgs args = (SomeArgs) msg.obj;
mSessionImpl.notifyTvMessage((String) args.arg1, (Bundle) args.arg2);
args.recycle();
break;
}
case DO_NOTIFY_VIDEO_AVAILABLE: {
mSessionImpl.notifyVideoAvailable();
break;
@@ -389,6 +396,12 @@ public class ITvInteractiveAppSessionWrapper
mCaller.obtainMessageOO(DO_NOTIFY_TRACK_SELECTED, type, trackId));
}
@Override
public void notifyTvMessage(String type, Bundle data) {
mCaller.executeOrSendMessage(
mCaller.obtainMessageOO(DO_NOTIFY_TRACK_SELECTED, type, data));
}
@Override
public void notifyTracksChanged(List<TvTrackInfo> tracks) {
mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_NOTIFY_TRACKS_CHANGED, tracks));

View File

@@ -1504,6 +1504,21 @@ public final class TvInteractiveAppManager {
}
}
/**
* Notifies Interactive APP session when a new TV message is received.
*/
public void notifyTvMessage(String type, Bundle data) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.notifyTvMessage(mToken, type, data, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
private void flushPendingEventsLocked() {
mHandler.removeMessages(InputEventHandler.MSG_FLUSH_INPUT_EVENT);

View File

@@ -641,6 +641,14 @@ public abstract class TvInteractiveAppService extends Service {
* @hide
*/
public void onAdBufferConsumed(AdBuffer buffer) {
}
/**
* Called when a tv message is received
* @hide
*/
public void onTvMessage(@NonNull String type, @NonNull Bundle data) {
}
@Override
@@ -1289,6 +1297,13 @@ public abstract class TvInteractiveAppService extends Service {
onAdResponse(response);
}
void notifyTvMessage(String type, Bundle data) {
if (DEBUG) {
Log.d(TAG, "notifyTvMessage (type=" + type + ", data= " + data + ")");
}
onTvMessage(type, data);
}
/**
* Calls {@link #onAdBufferConsumed}.
*/

View File

@@ -3610,6 +3610,23 @@ public final class TvInputManagerService extends SystemService {
}
}
@Override
public void onTvMessage(String type, Bundle data) {
synchronized (mLock) {
if (DEBUG) {
Slog.d(TAG, "onTvMessage(type=" + type + ", data=" + data + ")");
}
if (mSessionState.session == null || mSessionState.client == null) {
return;
}
try {
mSessionState.client.onTvMessage(type, data, mSessionState.seq);
} catch (RemoteException e) {
Slog.e(TAG, "error in onTvMessage", e);
}
}
}
// For the recording session only
@Override
public void onRecordingStopped(Uri recordedProgramUri) {

View File

@@ -1048,6 +1048,29 @@ public class TvInteractiveAppManagerService extends SystemService {
}
}
@Override
public void notifyTvMessage(IBinder sessionToken, String type, Bundle data, int userId) {
final int callingUid = Binder.getCallingUid();
final int callingPid = Binder.getCallingPid();
final int resolvedUserId = resolveCallingUserId(callingPid, callingUid, userId,
"notifyTvMessage");
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
try {
SessionState sessionState = getSessionStateLocked(sessionToken, callingUid,
resolvedUserId);
getSessionLocked(sessionState).notifyTvMessage(type, data);
} catch (RemoteException | SessionNotFoundException e) {
Slogf.e(TAG, "error in notifyTvMessage", e);
}
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
@Override
public void notifyRecordingStarted(IBinder sessionToken, String recordingId, int userId) {
final int callingUid = Binder.getCallingUid();