diff options
Diffstat (limited to 'src/com/android/tv/parental')
-rw-r--r-- | src/com/android/tv/parental/ContentRatingSystem.java | 9 | ||||
-rw-r--r-- | src/com/android/tv/parental/ContentRatingsManager.java | 19 | ||||
-rw-r--r-- | src/com/android/tv/parental/ParentalControlSettings.java | 33 |
3 files changed, 59 insertions, 2 deletions
diff --git a/src/com/android/tv/parental/ContentRatingSystem.java b/src/com/android/tv/parental/ContentRatingSystem.java index 6b5d6635..5672b793 100644 --- a/src/com/android/tv/parental/ContentRatingSystem.java +++ b/src/com/android/tv/parental/ContentRatingSystem.java @@ -110,6 +110,15 @@ public class ContentRatingSystem { return mRatings; } + public Rating getRating(String name) { + for (Rating rating : mRatings) { + if (TextUtils.equals(rating.getName(), name)) { + return rating; + } + } + return null; + } + public List<SubRating> getSubRatings(){ return mSubRatings; } diff --git a/src/com/android/tv/parental/ContentRatingsManager.java b/src/com/android/tv/parental/ContentRatingsManager.java index 57c25f48..c3bb8c0f 100644 --- a/src/com/android/tv/parental/ContentRatingsManager.java +++ b/src/com/android/tv/parental/ContentRatingsManager.java @@ -20,7 +20,10 @@ import android.content.Context; import android.media.tv.TvContentRating; import android.media.tv.TvContentRatingSystemInfo; import android.media.tv.TvInputManager; +import android.support.annotation.Nullable; +import android.text.TextUtils; +import com.android.tv.R; import com.android.tv.parental.ContentRatingSystem.Rating; import com.android.tv.parental.ContentRatingSystem.SubRating; @@ -53,6 +56,19 @@ public class ContentRatingsManager { } /** + * Returns the content rating system with the give ID. + */ + @Nullable + public ContentRatingSystem getContentRatingSystem(String contentRatingSystemId) { + for (ContentRatingSystem ratingSystem : mContentRatingSystems) { + if (TextUtils.equals(ratingSystem.getId(), contentRatingSystemId)) { + return ratingSystem; + } + } + return null; + } + + /** * Returns a new list of all content rating systems defined. */ public List<ContentRatingSystem> getContentRatingSystems() { @@ -64,6 +80,9 @@ public class ContentRatingsManager { * displayed to the user. For example, "TV-PG (L, S)". */ public String getDisplayNameForRating(TvContentRating canonicalRating) { + if (TvContentRating.UNRATED.equals(canonicalRating)) { + return mContext.getResources().getString(R.string.unrated_rating_name); + } Rating rating = getRating(canonicalRating); if (rating == null) { return null; diff --git a/src/com/android/tv/parental/ParentalControlSettings.java b/src/com/android/tv/parental/ParentalControlSettings.java index d7e1846e..2471c565 100644 --- a/src/com/android/tv/parental/ParentalControlSettings.java +++ b/src/com/android/tv/parental/ParentalControlSettings.java @@ -20,6 +20,7 @@ import android.content.Context; import android.media.tv.TvContentRating; import android.media.tv.TvInputManager; +import com.android.tv.experiments.Experiments; import com.android.tv.parental.ContentRatingSystem.Rating; import com.android.tv.parental.ContentRatingSystem.SubRating; import com.android.tv.util.TvSettings; @@ -109,6 +110,10 @@ public class ParentalControlSettings { @ContentRatingLevel int currentLevel = getContentRatingLevel(); if (currentLevel != TvSettings.CONTENT_RATING_LEVEL_CUSTOM) { mRatings = ContentRatingLevelPolicy.getRatingsForLevel(this, manager, currentLevel); + if (currentLevel != TvSettings.CONTENT_RATING_LEVEL_NONE) { + // UNRATED contents should be blocked unless the rating level is none or custom + mRatings.add(TvContentRating.UNRATED); + } storeRatings(); } } @@ -129,6 +134,11 @@ public class ParentalControlSettings { } } else { mRatings = ContentRatingLevelPolicy.getRatingsForLevel(this, manager, level); + if (level != TvSettings.CONTENT_RATING_LEVEL_NONE + && Boolean.TRUE.equals(Experiments.ENABLE_UNRATED_CONTENT_SETTINGS.get())) { + // UNRATED contents should be blocked unless the rating level is none or custom + mRatings.add(TvContentRating.UNRATED); + } } storeRatings(); } @@ -138,6 +148,23 @@ public class ParentalControlSettings { return TvSettings.getContentRatingLevel(mContext); } + /** Sets the blocked status of a unrated contents. */ + public boolean setUnratedBlocked(boolean blocked) { + boolean changed; + if (blocked) { + changed = mRatings.add(TvContentRating.UNRATED); + mTvInputManager.addBlockedRating(TvContentRating.UNRATED); + } else { + changed = mRatings.remove(TvContentRating.UNRATED); + mTvInputManager.removeBlockedRating(TvContentRating.UNRATED); + } + if (changed) { + // change to custom level if the blocked status is changed + changeToCustomLevel(); + } + return changed; + } + /** * Sets the blocked status of a given content rating. * <p> @@ -172,8 +199,10 @@ public class ParentalControlSettings { * @return The {@link TvContentRating} that is blocked. */ public TvContentRating getBlockedRating(TvContentRating[] ratings) { - if (ratings == null) { - return null; + if (ratings == null || ratings.length <= 0) { + return mTvInputManager.isRatingBlocked(TvContentRating.UNRATED) + ? TvContentRating.UNRATED + : null; } for (TvContentRating rating : ratings) { if (mTvInputManager.isRatingBlocked(rating)) { |