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

Commit f2d5ccf6 authored by Shubang Lu's avatar Shubang Lu Committed by David Zhao
Browse files

[CSAI API] Unhide TvAdCallback APIs

Error scheme consistent with existing API in TvInteractiveAppView

Bug: 321108085
Test: CtsTvTestCases
API-Coverage-Bug: 320723228
Change-Id: I43dc3db0a0edebbd4e649702255f5c1bd1b23706
parent f5d37c93
Loading
Loading
Loading
Loading
+46 −1
Original line number Diff line number Diff line
@@ -27671,7 +27671,7 @@ package android.media.tv {
package android.media.tv.ad {
  @FlaggedApi("android.media.tv.flags.enable_ad_service_fw") public class TvAdManager {
  @FlaggedApi("android.media.tv.flags.enable_ad_service_fw") public final class TvAdManager {
    method @NonNull public java.util.List<android.media.tv.ad.TvAdServiceInfo> getTvAdServiceList();
    method public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.media.tv.ad.TvAdManager.TvAdServiceCallback);
    method public void sendAppLinkCommand(@NonNull String, @NonNull android.os.Bundle);
@@ -27682,6 +27682,14 @@ package android.media.tv.ad {
    field public static final String APP_LINK_KEY_COMMAND_TYPE = "command_type";
    field public static final String APP_LINK_KEY_PACKAGE_NAME = "package_name";
    field public static final String APP_LINK_KEY_SERVICE_ID = "service_id";
    field public static final int ERROR_BLOCKED = 5; // 0x5
    field public static final int ERROR_ENCRYPTED = 6; // 0x6
    field public static final int ERROR_NONE = 0; // 0x0
    field public static final int ERROR_NOT_SUPPORTED = 2; // 0x2
    field public static final int ERROR_RESOURCE_UNAVAILABLE = 4; // 0x4
    field public static final int ERROR_UNKNOWN = 1; // 0x1
    field public static final int ERROR_UNKNOWN_CHANNEL = 7; // 0x7
    field public static final int ERROR_WEAK_SIGNAL = 3; // 0x3
    field public static final String INTENT_KEY_AD_SERVICE_ID = "ad_service_id";
    field public static final String INTENT_KEY_CHANNEL_URI = "channel_uri";
    field public static final String INTENT_KEY_COMMAND_TYPE = "command_type";
@@ -27694,6 +27702,9 @@ package android.media.tv.ad {
    field public static final String SESSION_DATA_TYPE_AD_REQUEST = "ad_request";
    field public static final String SESSION_DATA_TYPE_BROADCAST_INFO_REQUEST = "broadcast_info_request";
    field public static final String SESSION_DATA_TYPE_REMOVE_BROADCAST_INFO_REQUEST = "remove_broadcast_info_request";
    field public static final int SESSION_STATE_ERROR = 3; // 0x3
    field public static final int SESSION_STATE_RUNNING = 2; // 0x2
    field public static final int SESSION_STATE_STOPPED = 1; // 0x1
  }
  public abstract static class TvAdManager.TvAdServiceCallback {
@@ -27716,7 +27727,12 @@ package android.media.tv.ad {
    ctor public TvAdService.Session(@NonNull android.content.Context);
    method public boolean isMediaViewEnabled();
    method @CallSuper public void layoutSurface(int, int, int, int);
    method @CallSuper public void notifySessionStateChanged(int, int);
    method @Nullable public android.view.View onCreateMediaView();
    method public void onCurrentChannelUri(@Nullable android.net.Uri);
    method public void onCurrentTvInputId(@Nullable String);
    method public void onCurrentVideoBounds(@NonNull android.graphics.Rect);
    method public void onError(@NonNull String, @NonNull android.os.Bundle);
    method public boolean onGenericMotionEvent(@NonNull android.view.MotionEvent);
    method public boolean onKeyDown(int, @Nullable android.view.KeyEvent);
    method public boolean onKeyLongPress(int, @Nullable android.view.KeyEvent);
@@ -27726,12 +27742,20 @@ package android.media.tv.ad {
    method public abstract void onRelease();
    method public void onResetAdService();
    method public abstract boolean onSetSurface(@Nullable android.view.Surface);
    method public void onSigningResult(@NonNull String, @NonNull byte[]);
    method public void onStartAdService();
    method public void onStopAdService();
    method public void onSurfaceChanged(int, int, int);
    method public boolean onTouchEvent(@NonNull android.view.MotionEvent);
    method public void onTrackInfoList(@NonNull java.util.List<android.media.tv.TvTrackInfo>);
    method public boolean onTrackballEvent(@NonNull android.view.MotionEvent);
    method public void onTvInputSessionData(@NonNull String, @NonNull android.os.Bundle);
    method public void onTvMessage(int, @NonNull android.os.Bundle);
    method @CallSuper public void requestCurrentChannelUri();
    method @CallSuper public void requestCurrentTvInputId();
    method @CallSuper public void requestCurrentVideoBounds();
    method @CallSuper public void requestSigning(@NonNull String, @NonNull String, @NonNull String, @NonNull byte[]);
    method @CallSuper public void requestTrackInfoList();
    method public void sendTvAdSessionData(@NonNull String, @NonNull android.os.Bundle);
    method @CallSuper public void setMediaViewEnabled(boolean);
  }
@@ -27750,9 +27774,12 @@ package android.media.tv.ad {
    ctor public TvAdView(@NonNull android.content.Context);
    ctor public TvAdView(@NonNull android.content.Context, @Nullable android.util.AttributeSet);
    ctor public TvAdView(@NonNull android.content.Context, @Nullable android.util.AttributeSet, int);
    method public void clearCallback();
    method public void clearOnUnhandledInputEventListener();
    method public boolean dispatchUnhandledInputEvent(@NonNull android.view.InputEvent);
    method @Nullable public android.media.tv.ad.TvAdView.OnUnhandledInputEventListener getOnUnhandledInputEventListener();
    method public void notifyError(@NonNull String, @NonNull android.os.Bundle);
    method public void notifyTvMessage(@NonNull int, @NonNull android.os.Bundle);
    method public void onAttachedToWindow();
    method public void onDetachedFromWindow();
    method public void onLayout(boolean, int, int, int, int);
@@ -27762,16 +27789,34 @@ package android.media.tv.ad {
    method public void prepareAdService(@NonNull String, @NonNull String);
    method public void reset();
    method public void resetAdService();
    method public void sendCurrentChannelUri(@Nullable android.net.Uri);
    method public void sendCurrentTvInputId(@Nullable String);
    method public void sendCurrentVideoBounds(@NonNull android.graphics.Rect);
    method public void sendSigningResult(@NonNull String, @NonNull byte[]);
    method public void sendTrackInfoList(@Nullable java.util.List<android.media.tv.TvTrackInfo>);
    method public void setCallback(@NonNull java.util.concurrent.Executor, @NonNull android.media.tv.ad.TvAdView.TvAdCallback);
    method public void setOnUnhandledInputEventListener(@NonNull java.util.concurrent.Executor, @NonNull android.media.tv.ad.TvAdView.OnUnhandledInputEventListener);
    method public boolean setTvView(@Nullable android.media.tv.TvView);
    method public void startAdService();
    method public void stopAdService();
    field public static final String ERROR_KEY_ERROR_CODE = "error_code";
    field public static final String ERROR_KEY_METHOD_NAME = "method_name";
  }
  public static interface TvAdView.OnUnhandledInputEventListener {
    method public boolean onUnhandledInputEvent(@NonNull android.view.InputEvent);
  }
  public abstract static class TvAdView.TvAdCallback {
    ctor public TvAdView.TvAdCallback();
    method public void onRequestCurrentChannelUri(@NonNull String);
    method public void onRequestCurrentTvInputId(@NonNull String);
    method public void onRequestCurrentVideoBounds(@NonNull String);
    method public void onRequestSigning(@NonNull String, @NonNull String, @NonNull String, @NonNull String, @NonNull byte[]);
    method public void onRequestTrackInfoList(@NonNull String);
    method public void onStateChanged(@NonNull String, int, int);
  }
}
package android.media.tv.interactive {
+72 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.media.tv.ad;

import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
@@ -59,7 +60,7 @@ import java.util.concurrent.Executor;
 */
@FlaggedApi(Flags.FLAG_ENABLE_AD_SERVICE_FW)
@SystemService(Context.TV_AD_SERVICE)
public class TvAdManager {
public final class TvAdManager {
    // TODO: implement more methods and unhide APIs.
    private static final String TAG = "TvAdManager";

@@ -237,6 +238,76 @@ public class TvAdManager {
     */
    public static final String SESSION_DATA_KEY_REQUEST_ID = "request_id";


    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = false, prefix = "SESSION_STATE_", value = {
            SESSION_STATE_STOPPED,
            SESSION_STATE_RUNNING,
            SESSION_STATE_ERROR})
    public @interface SessionState {}

    /**
     * Stopped (or not started) state of AD service session.
     */
    public static final int SESSION_STATE_STOPPED = 1;
    /**
     * Running state of AD service session.
     */
    public static final int SESSION_STATE_RUNNING = 2;
    /**
     * Error state of AD service session.
     */
    public static final int SESSION_STATE_ERROR = 3;


    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = false, prefix = "ERROR_", value = {
            ERROR_NONE,
            ERROR_UNKNOWN,
            ERROR_NOT_SUPPORTED,
            ERROR_WEAK_SIGNAL,
            ERROR_RESOURCE_UNAVAILABLE,
            ERROR_BLOCKED,
            ERROR_ENCRYPTED,
            ERROR_UNKNOWN_CHANNEL,
    })
    public @interface ErrorCode {}

    /**
     * No error.
     */
    public static final int ERROR_NONE = 0;
    /**
     * Unknown error code.
     */
    public static final int ERROR_UNKNOWN = 1;
    /**
     * Error code for an unsupported channel.
     */
    public static final int ERROR_NOT_SUPPORTED = 2;
    /**
     * Error code for weak signal.
     */
    public static final int ERROR_WEAK_SIGNAL = 3;
    /**
     * Error code when resource (e.g. tuner) is unavailable.
     */
    public static final int ERROR_RESOURCE_UNAVAILABLE = 4;
    /**
     * Error code for blocked contents.
     */
    public static final int ERROR_BLOCKED = 5;
    /**
     * Error code when the key or module is missing for the encrypted channel.
     */
    public static final int ERROR_ENCRYPTED = 6;
    /**
     * Error code when the current channel is an unknown channel.
     */
    public static final int ERROR_UNKNOWN_CHANNEL = 7;

    private final ITvAdManager mService;
    private final int mUserId;

+24 −12
Original line number Diff line number Diff line
@@ -280,7 +280,6 @@ public abstract class TvAdService extends Service {

        /**
         * Requests the bounds of the current video.
         * @hide
         */
        @CallSuper
        public void requestCurrentVideoBounds() {
@@ -304,7 +303,6 @@ public abstract class TvAdService extends Service {

        /**
         * Requests the URI of the current channel.
         * @hide
         */
        @CallSuper
        public void requestCurrentChannelUri() {
@@ -328,7 +326,6 @@ public abstract class TvAdService extends Service {

        /**
         * Requests the list of {@link TvTrackInfo}.
         * @hide
         */
        @CallSuper
        public void requestTrackInfoList() {
@@ -354,7 +351,6 @@ public abstract class TvAdService extends Service {
         * Requests current TV input ID.
         *
         * @see android.media.tv.TvInputInfo
         * @hide
         */
        @CallSuper
        public void requestCurrentTvInputId() {
@@ -393,7 +389,6 @@ public abstract class TvAdService extends Service {
         * @param data the original bytes to be signed.
         *
         * @see #onSigningResult(String, byte[])
         * @hide
         */
        @CallSuper
        public void requestSigning(@NonNull String signingId, @NonNull String algorithm,
@@ -535,28 +530,24 @@ public abstract class TvAdService extends Service {
         * Receives current video bounds.
         *
         * @param bounds the rectangle area for rendering the current video.
         * @hide
         */
        public void onCurrentVideoBounds(@NonNull Rect bounds) {
        }

        /**
         * Receives current channel URI.
         * @hide
         */
        public void onCurrentChannelUri(@Nullable Uri channelUri) {
        }

        /**
         * Receives track list.
         * @hide
         */
        public void onTrackInfoList(@NonNull List<TvTrackInfo> tracks) {
        }

        /**
         * Receives current TV input ID.
         * @hide
         */
        public void onCurrentTvInputId(@Nullable String inputId) {
        }
@@ -569,7 +560,6 @@ public abstract class TvAdService extends Service {
         * @param result the signed result.
         *
         * @see #requestSigning(String, String, String, byte[])
         * @hide
         */
        public void onSigningResult(@NonNull String signingId, @NonNull byte[] result) {
        }
@@ -584,7 +574,6 @@ public abstract class TvAdService extends Service {
         *     "onRequestSigning" can also be added to the params.
         *
         * @see TvAdView#ERROR_KEY_METHOD_NAME
         * @hide
         */
        public void onError(@NonNull String errMsg, @NonNull Bundle params) {
        }
@@ -601,7 +590,6 @@ public abstract class TvAdService extends Service {
         *             {@link TvInputManager#TV_MESSAGE_KEY_RAW_DATA}.
         *             See {@link TvInputManager#TV_MESSAGE_KEY_SUBTYPE} for more information on
         *             how to parse this data.
         * @hide
         */
        public void onTvMessage(@TvInputManager.TvMessageType int type,
                @NonNull Bundle data) {
@@ -670,6 +658,30 @@ public abstract class TvAdService extends Service {
            });
        }

        /**
         * Notifies when the session state is changed.
         *
         * @param state the current session state.
         * @param err the error code for error state. {@link TvAdManager#ERROR_NONE} is
         *            used when the state is not {@link TvAdManager#SESSION_STATE_ERROR}.
         */
        @CallSuper
        public void notifySessionStateChanged(
                @TvAdManager.SessionState int state,
                @TvAdManager.ErrorCode int err) {
            executeOrPostRunnableOnMainThread(new Runnable() {
                @MainThread
                @Override
                public void run() {
                    if (DEBUG) {
                        Log.d(TAG, "notifySessionStateChanged (state="
                                + state + "; err=" + err + ")");
                    }
                    // TODO: handle session callback
                }
            });
        }

        /**
         * Takes care of dispatching incoming input events and tells whether the event was handled.
         */
+26 −11
Original line number Diff line number Diff line
@@ -61,10 +61,19 @@ public class TvAdView extends ViewGroup {
     * The name of the method where the error happened, if applicable. For example, if there is an
     * error during signing, the request name is "onRequestSigning".
     * @see #notifyError(String, Bundle)
     * @hide
     */
    public static final String ERROR_KEY_METHOD_NAME = "method_name";

    /**
     * The error code of an error.
     *
     * <p>It can be {@link TvAdManager#ERROR_WEAK_SIGNAL},
     * {@link TvAdManager#ERROR_RESOURCE_UNAVAILABLE}, etc.
     *
     * @see #notifyError(String, Bundle)
     */
    public static final String ERROR_KEY_ERROR_CODE = "error_code";

    private final TvAdManager mTvAdManager;

    private final Handler mHandler = new Handler();
@@ -486,7 +495,6 @@ public class TvAdView extends ViewGroup {
     * Sends current video bounds to related TV AD service.
     *
     * @param bounds the rectangle area for rendering the current video.
     * @hide
     */
    public void sendCurrentVideoBounds(@NonNull Rect bounds) {
        if (DEBUG) {
@@ -502,7 +510,6 @@ public class TvAdView extends ViewGroup {
     *
     * @param channelUri The current channel URI; {@code null} if there is no currently tuned
     *                   channel.
     * @hide
     */
    public void sendCurrentChannelUri(@Nullable Uri channelUri) {
        if (DEBUG) {
@@ -515,7 +522,6 @@ public class TvAdView extends ViewGroup {

    /**
     * Sends track info list to related TV AD service.
     * @hide
     */
    public void sendTrackInfoList(@Nullable List<TvTrackInfo> tracks) {
        if (DEBUG) {
@@ -532,7 +538,6 @@ public class TvAdView extends ViewGroup {
     * @param inputId The current TV input ID whose channel is tuned. {@code null} if no channel is
     *                tuned.
     * @see android.media.tv.TvInputInfo
     * @hide
     */
    public void sendCurrentTvInputId(@Nullable String inputId) {
        if (DEBUG) {
@@ -553,7 +558,6 @@ public class TvAdView extends ViewGroup {
     * @param signingId the ID to identify the request. It's the same as the corresponding ID in
     *        {@link TvAdService.Session#requestSigning(String, String, String, byte[])}
     * @param result the signed result.
     * @hide
     */
    public void sendSigningResult(@NonNull String signingId, @NonNull byte[] result) {
        if (DEBUG) {
@@ -574,7 +578,7 @@ public class TvAdView extends ViewGroup {
     *     can also be added to the params.
     *
     * @see #ERROR_KEY_METHOD_NAME
     * @hide
     * @see #ERROR_KEY_ERROR_CODE
     */
    public void notifyError(@NonNull String errMsg, @NonNull Bundle params) {
        if (DEBUG) {
@@ -597,7 +601,6 @@ public class TvAdView extends ViewGroup {
     *             {@link TvInputManager#TV_MESSAGE_KEY_RAW_DATA}.
     *             See {@link TvInputManager#TV_MESSAGE_KEY_SUBTYPE} for more information on
     *             how to parse this data.
     * @hide
     */
    public void notifyTvMessage(@NonNull @TvInputManager.TvMessageType int type,
            @NonNull Bundle data) {
@@ -633,7 +636,6 @@ public class TvAdView extends ViewGroup {
     * @param callback the callback to receive events. MUST NOT be {@code null}.
     *
     * @see #clearCallback()
     * @hide
     */
    public void setCallback(
            @NonNull @CallbackExecutor Executor executor,
@@ -649,7 +651,6 @@ public class TvAdView extends ViewGroup {
     * Clears the callback.
     *
     * @see #setCallback(Executor, TvAdCallback)
     * @hide
     */
    public void clearCallback() {
        synchronized (mCallbackLock) {
@@ -845,7 +846,6 @@ public class TvAdView extends ViewGroup {

    /**
     * Callback used to receive various status updates on the {@link TvAdView}.
     * @hide
     */
    public abstract static class TvAdCallback {

@@ -898,5 +898,20 @@ public class TvAdView extends ViewGroup {
        public void onRequestSigning(@NonNull String serviceId, @NonNull String signingId,
                @NonNull String algorithm, @NonNull String alias, @NonNull byte[] data) {
        }

        /**
         * This is called when the state of corresponding AD service is changed.
         *
         * @param serviceId The ID of the AD service bound to this view.
         * @param state the current state.
         * @param err the error code for error state. {@link TvAdManager#ERROR_NONE}
         *              is used when the state is not
         *              {@link TvAdManager#SESSION_STATE_ERROR}.
         */
        public void onStateChanged(
                @NonNull String serviceId,
                @TvAdManager.SessionState int state,
                @TvAdManager.ErrorCode int err) {
        }
    }
}