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

Commit 31380e84 authored by Jae Seo's avatar Jae Seo Committed by Android (Google) Code Review
Browse files

Merge "TIF: Add a way to notify whether the current program content is allowed" into lmp-dev

parents c01bd116 bbcd206a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -16732,6 +16732,7 @@ package android.media.tv {
  public abstract class TvInputService.Session implements android.view.KeyEvent.Callback {
    ctor public TvInputService.Session();
    method public void dispatchChannelRetuned(android.net.Uri);
    method public void dispatchContentAllowed();
    method public void dispatchContentBlocked(android.media.tv.TvContentRating);
    method public void dispatchTrackInfoChanged(java.util.List<android.media.tv.TvTrackInfo>);
    method public void dispatchVideoAvailable();
@@ -16826,6 +16827,7 @@ package android.media.tv {
  public static abstract class TvView.TvInputListener {
    ctor public TvView.TvInputListener();
    method public void onChannelRetuned(java.lang.String, android.net.Uri);
    method public void onContentAllowed(java.lang.String);
    method public void onContentBlocked(java.lang.String, android.media.tv.TvContentRating);
    method public void onError(java.lang.String, int);
    method public void onTrackInfoChanged(java.lang.String, java.util.List<android.media.tv.TvTrackInfo>);
+1 −0
Original line number Diff line number Diff line
@@ -36,5 +36,6 @@ oneway interface ITvInputClient {
    void onTrackInfoChanged(in List<TvTrackInfo> tracks, int seq);
    void onVideoAvailable(int seq);
    void onVideoUnavailable(int reason, int seq);
    void onContentAllowed(int seq);
    void onContentBlocked(in String rating, int seq);
}
+1 −0
Original line number Diff line number Diff line
@@ -33,5 +33,6 @@ oneway interface ITvInputSessionCallback {
    void onTrackInfoChanged(in List<TvTrackInfo> tracks);
    void onVideoAvailable();
    void onVideoUnavailable(int reason);
    void onContentAllowed();
    void onContentBlocked(in String rating);
}
+32 −1
Original line number Diff line number Diff line
@@ -187,7 +187,17 @@ public final class TvInputManager {
        }

        /**
         * This is called when the current program content is blocked by parental controls.
         * This is called when the current program content turns out to be allowed to watch since
         * its content rating is not blocked by parental controls.
         *
         * @param session A {@link TvInputManager.Session} associated with this callback
         */
        public void onContentAllowed(Session session) {
        }

        /**
         * This is called when the current program content turns out to be not allowed to watch
         * since its content rating is blocked by parental controls.
         *
         * @param session A {@link TvInputManager.Session} associated with this callback
         * @param rating The content ration of the blocked program.
@@ -274,6 +284,15 @@ public final class TvInputManager {
            });
        }

        public void postContentAllowed() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mSessionCallback.onContentAllowed(mSession);
                }
            });
        }

        public void postContentBlocked(final TvContentRating rating) {
            mHandler.post(new Runnable() {
                @Override
@@ -456,6 +475,18 @@ public final class TvInputManager {
                }
            }

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

            @Override
            public void onContentBlocked(String rating, int seq) {
                synchronized (mSessionCallbackRecordMap) {
+74 −32
Original line number Diff line number Diff line
@@ -306,18 +306,49 @@ public abstract class TvInputService extends Service {
        }

        /**
         * Informs the application that the current program content is blocked by parent controls.
         * Informs the application that video is not available, so the TV input cannot continue
         * playing the TV stream.
         *
         * @param reason The reason why the TV input stopped the playback:
         * <ul>
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_UNKNOWN}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_TUNE}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_BUFFERING}
         * </ul>
         */
        public void dispatchVideoUnavailable(final int reason) {
            if (reason < TvInputManager.VIDEO_UNAVAILABLE_REASON_START
                    || reason > TvInputManager.VIDEO_UNAVAILABLE_REASON_END) {
                throw new IllegalArgumentException("Unknown reason: " + reason);
            }
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (DEBUG) Log.d(TAG, "dispatchVideoUnavailable");
                        mSessionCallback.onVideoUnavailable(reason);
                    } catch (RemoteException e) {
                        Log.w(TAG, "error in dispatchVideoUnavailable");
                    }
                }
            });
        }

        /**
         * Informs the application that the user is allowed to watch the current program content.
         * <p>
         * Each TV input service is required to query the system whether the user is allowed to
         * watch the current program before showing it to the user if the parental control is turned
         * on, which can be checked by calling {@link TvParentalControlManager#isEnabled}. Whether
         * the TV input service should block the content or not is determined by invoking
         * {@link TvParentalControlManager#isRatingBlocked} with the content rating for the current
         * program. Then the TvParentalControlManager makes a judgment based on the user blocked
         * ratings stored in the secure settings and returns the result. If the rating in question
         * turns out to be blocked, the TV input service must immediately block the content and call
         * this method with the content rating of the current program to prompt the PIN verification
         * screen.
         * watch the current program before showing it to the user if the parental control is
         * enabled (i.e. {@link TvParentalControlManager#isEnabled
         * TvParentalControlManager.isEnabled()} returns {@code true}). Whether the TV input service
         * should block the content or not is determined by invoking
         * {@link TvParentalControlManager#isRatingBlocked
         * TvParentalControlManager.isRatingBlocked(TvContentRating)} with the content rating for
         * the current program. Then the {@link TvParentalControlManager} makes a judgment based on
         * the user blocked ratings stored in the secure settings and returns the result. If the
         * rating in question turns out to be allowed by the user, the TV input service must call
         * this method to notify the application that is permitted to show the content.
         * </p><p>
         * Each TV input service also needs to continuously listen to any changes made to the
         * parental control settings by registering a
@@ -325,47 +356,58 @@ public abstract class TvInputService extends Service {
         * reevaluate the current program with the new parental control settings.
         * </p>
         *
         * @param rating The content rating for the current TV program.
         * @see #dispatchContentBlocked
         * @see TvParentalControlManager
         */
        public void dispatchContentBlocked(final TvContentRating rating) {
        public void dispatchContentAllowed() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (DEBUG) Log.d(TAG, "dispatchContentBlocked");
                        mSessionCallback.onContentBlocked(rating.flattenToString());
                        if (DEBUG) Log.d(TAG, "dispatchContentAllowed");
                        mSessionCallback.onContentAllowed();
                    } catch (RemoteException e) {
                        Log.w(TAG, "error in dispatchContentBlocked");
                        Log.w(TAG, "error in dispatchContentAllowed");
                    }
                }
            });
        }

        /**
         * Informs the application that video is not available, so the TV input cannot continue
         * playing the TV stream.
         * Informs the application that the current program content is blocked by parent controls.
         * <p>
         * Each TV input service is required to query the system whether the user is allowed to
         * watch the current program before showing it to the user if the parental control is
         * enabled (i.e. {@link TvParentalControlManager#isEnabled
         * TvParentalControlManager.isEnabled()} returns {@code true}). Whether the TV input service
         * should block the content or not is determined by invoking
         * {@link TvParentalControlManager#isRatingBlocked
         * TvParentalControlManager.isRatingBlocked(TvContentRating)} with the content rating for
         * the current program. Then the {@link TvParentalControlManager} makes a judgment based on
         * the user blocked ratings stored in the secure settings and returns the result. If the
         * rating in question turns out to be blocked, the TV input service must immediately block
         * the content and call this method with the content rating of the current program to prompt
         * the PIN verification screen.
         * </p><p>
         * Each TV input service also needs to continuously listen to any changes made to the
         * parental control settings by registering a
         * {@link TvParentalControlManager.ParentalControlCallback} to the manager and immediately
         * reevaluate the current program with the new parental control settings.
         * </p>
         *
         * @param reason The reason why the TV input stopped the playback:
         * <ul>
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_UNKNOWN}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_TUNE}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL}
         * <li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_BUFFERING}
         * </ul>
         * @param rating The content rating for the current TV program.
         * @see #dispatchContentAllowed
         * @see TvParentalControlManager
         */
        public void dispatchVideoUnavailable(final int reason) {
            if (reason < TvInputManager.VIDEO_UNAVAILABLE_REASON_START
                    || reason > TvInputManager.VIDEO_UNAVAILABLE_REASON_END) {
                throw new IllegalArgumentException("Unknown reason: " + reason);
            }
        public void dispatchContentBlocked(final TvContentRating rating) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (DEBUG) Log.d(TAG, "dispatchVideoUnavailable");
                        mSessionCallback.onVideoUnavailable(reason);
                        if (DEBUG) Log.d(TAG, "dispatchContentBlocked");
                        mSessionCallback.onContentBlocked(rating.flattenToString());
                    } catch (RemoteException e) {
                        Log.w(TAG, "error in dispatchVideoUnavailable");
                        Log.w(TAG, "error in dispatchContentBlocked");
                    }
                }
            });
Loading