public void setContentRatingSystemEnabled(ContentRatingsManager manager, ContentRatingSystem contentRatingSystem, boolean enabled) { if (enabled) { TvSettings.addContentRatingSystem(mContext, contentRatingSystem.getId()); // Ensure newly added system has ratings for current level set updateRatingsForCurrentLevel(manager); } else { // Ensure no ratings are blocked for the selected rating system for (TvContentRating tvContentRating : mTvInputManager.getBlockedRatings()) { if (contentRatingSystem.ownsRating(tvContentRating)) { mTvInputManager.removeBlockedRating(tvContentRating); } } TvSettings.removeContentRatingSystem(mContext, contentRatingSystem.getId()); } }
private boolean setRatingBlockedInternal(ContentRatingSystem contentRatingSystem, Rating rating, SubRating subRating, boolean blocked) { TvContentRating tvContentRating = (subRating == null) ? toTvContentRating(contentRatingSystem, rating) : toTvContentRating(contentRatingSystem, rating, subRating); boolean changed; if (blocked) { changed = mRatings.add(tvContentRating); mTvInputManager.addBlockedRating(tvContentRating); } else { changed = mRatings.remove(tvContentRating); mTvInputManager.removeBlockedRating(tvContentRating); } if (changed) { changeToCustomLevel(); } return changed; }
/** * Returns the long name of a given content rating including descriptors (sub-ratings) that is * displayed to the user. For example, "TV-PG (L, S)". */ public String getDisplayNameForRating(TvContentRating canonicalRating) { Rating rating = getRating(canonicalRating); if (rating == null) { return null; } List<SubRating> subRatings = getSubRatings(rating, canonicalRating); if (!subRatings.isEmpty()) { StringBuilder builder = new StringBuilder(); for (SubRating subRating : subRatings) { builder.append(subRating.getTitle()); builder.append(", "); } return rating.getTitle() + " (" + builder.substring(0, builder.length() - 2) + ")"; } return rating.getTitle(); }
private Rating getRating(TvContentRating canonicalRating) { if (canonicalRating == null || mContentRatingSystems == null) { return null; } for (ContentRatingSystem system : mContentRatingSystems) { if (system.getDomain().equals(canonicalRating.getDomain()) && system.getName().equals(canonicalRating.getRatingSystem())) { for (Rating rating : system.getRatings()) { if (rating.getName().equals(canonicalRating.getMainRating())) { return rating; } } } } return null; }
private List<SubRating> getSubRatings(Rating rating, TvContentRating canonicalRating) { List<SubRating> subRatings = new ArrayList<>(); if (rating == null || rating.getSubRatings() == null || canonicalRating == null || canonicalRating.getSubRatings() == null) { return subRatings; } for (String subRatingString : canonicalRating.getSubRatings()) { for (SubRating subRating : rating.getSubRatings()) { if (subRating.getName().equals(subRatingString)) { subRatings.add(subRating); break; } } } return subRatings; }
private boolean isRatingBlocked(TvContentRating[] ratings) { if (ratings == null || ratings.length == 0 || !mTvInputManager.isParentalControlsEnabled()) { return false; } for (TvContentRating rating : ratings) { try { if (mTvInputManager.isRatingBlocked(rating)) { return true; } } catch (IllegalArgumentException e) { // Do nothing. } } return false; }
@Override public void onContentBlocked() { mTuneDurationTimer.reset(); TvContentRating rating = mTvView.getBlockedContentRating(); // When tuneTo was called while TV view was shrunken, if the channel id is the same // with the channel watched before shrunken, we allow the rating which was allowed // before. if (mWasUnderShrunkenTvView && mUnlockAllowedRatingBeforeShrunken && mChannelBeforeShrunkenTvView.equals(mChannel) && rating.equals(mAllowedRatingBeforeShrunken)) { mUnlockAllowedRatingBeforeShrunken = isUnderShrunkenTvView(); mTvView.unblockContent(rating); } mChannelBannerView.setBlockingContentRating(rating); updateChannelBannerAndShowIfNeeded(UPDATE_CHANNEL_BANNER_REASON_LOCK_OR_UNLOCK); mTvViewUiManager.fadeInTvView(); }
private void updateProgramRatings(Program program) { if (mBlockingContentRating != null) { mContentRatingsTextViews[0].setText( mContentRatingsManager.getDisplayNameForRating(mBlockingContentRating)); mContentRatingsTextViews[0].setVisibility(View.VISIBLE); for (int i = 1; i < DISPLAYED_CONTENT_RATINGS_COUNT; i++) { mContentRatingsTextViews[i].setVisibility(View.GONE); } return; } TvContentRating[] ratings = (program == null) ? null : program.getContentRatings(); for (int i = 0; i < DISPLAYED_CONTENT_RATINGS_COUNT; i++) { if (ratings == null || ratings.length <= i) { mContentRatingsTextViews[i].setVisibility(View.GONE); } else { mContentRatingsTextViews[i].setText( mContentRatingsManager.getDisplayNameForRating(ratings[i])); mContentRatingsTextViews[i].setVisibility(View.VISIBLE); } } }
private void doParentalControls() { boolean isParentalControlsEnabled = mTvInputManager.isParentalControlsEnabled(); if (isParentalControlsEnabled) { TvContentRating blockContentRating = getContentRatingOfCurrentProgramBlocked(); if (DEBUG) { if (blockContentRating != null) { Log.d(TAG, "Check parental controls: blocked by content rating - " + blockContentRating); } else { Log.d(TAG, "Check parental controls: available"); } } updateChannelBlockStatus(blockContentRating != null, blockContentRating); } else { if (DEBUG) { Log.d(TAG, "Check parental controls: available"); } updateChannelBlockStatus(false, null); } }
private TvContentRating getContentRatingOfCurrentProgramBlocked() { EitItem currentProgram = getCurrentProgram(); if (currentProgram == null) { return null; } TvContentRating[] ratings = mTvContentRatingCache .getRatings(currentProgram.getContentRating()); if (ratings == null) { return null; } for (TvContentRating rating : ratings) { if (!Objects.equals(mUnblockedContentRating, rating) && mTvInputManager .isRatingBlocked(rating)) { return rating; } } return null; }
private void updateChannelBlockStatus(boolean channelBlocked, TvContentRating contentRating) { if (mChannelBlocked == channelBlocked) { return; } mChannelBlocked = channelBlocked; if (mChannelBlocked) { mHandler.removeCallbacksAndMessages(null); stopPlayback(); resetTvTracks(); if (contentRating != null) { mSession.notifyContentBlocked(contentRating); } mHandler.sendEmptyMessageDelayed(MSG_PARENTAL_CONTROLS, PARENTAL_CONTROLS_INTERVAL_MS); } else { mHandler.removeCallbacksAndMessages(null); resetPlayback(); mSession.notifyContentAllowed(); mHandler.sendEmptyMessageDelayed(MSG_RESCHEDULE_PROGRAMS, RESCHEDULE_PROGRAMS_INITIAL_DELAY_MS); mHandler.removeMessages(MSG_CHECK_SIGNAL); mHandler.sendEmptyMessageDelayed(MSG_CHECK_SIGNAL, CHECK_NO_SIGNAL_INITIAL_DELAY_MS); } }
/** * Returns an array TvContentRatings from a string of comma separated set of rating strings * creating each from {@link TvContentRating#unflattenFromString(String)} if needed. * Returns {@code null} if the string is empty or contains no valid ratings. */ @Nullable public TvContentRating[] getRatings(String commaSeparatedRatings) { if (TextUtils.isEmpty(commaSeparatedRatings)) { return null; } TvContentRating[] tvContentRatings; if (mRatingsMultiMap.containsKey(commaSeparatedRatings)) { tvContentRatings = mRatingsMultiMap.get(commaSeparatedRatings); } else { String normalizedRatings = TextUtils .join(",", getSortedSetFromCsv(commaSeparatedRatings)); if (mRatingsMultiMap.containsKey(normalizedRatings)) { tvContentRatings = mRatingsMultiMap.get(normalizedRatings); } else { tvContentRatings = stringToContentRatings(commaSeparatedRatings); mRatingsMultiMap.put(normalizedRatings, tvContentRatings); } if (!normalizedRatings.equals(commaSeparatedRatings)) { // Add an entry so the non normalized entry points to the same result; mRatingsMultiMap.put(commaSeparatedRatings, tvContentRatings); } } return tvContentRatings; }
/** * Returns a sorted array of TvContentRatings from a comma separated string of ratings. */ @VisibleForTesting static TvContentRating[] stringToContentRatings(String commaSeparatedRatings) { if (TextUtils.isEmpty(commaSeparatedRatings)) { return null; } Set<String> ratingStrings = getSortedSetFromCsv(commaSeparatedRatings); List<TvContentRating> contentRatings = new ArrayList<>(); for (String rating : ratingStrings) { try { contentRatings.add(TvContentRating.unflattenFromString(rating)); } catch (IllegalArgumentException e) { Log.e(TAG, "Can't parse the content rating: '" + rating + "'", e); } } return contentRatings.size() == 0 ? null : contentRatings.toArray(new TvContentRating[contentRatings.size()]); }
/** * If you don't have access to an EPG or don't want to supply programs, you can simply * add several instances of this generic program object. * * Note you will have to set the start and end times manually. * @param channel The channel for which the program will be displayed * @return A very generic program object */ public Program getGenericProgram(Channel channel) { TvContentRating rating = RATING_PG; return new Program.Builder() .setTitle(channel.getName() + " Live") .setProgramId(channel.getServiceId()) // .setEpisodeNumber(1) // .setSeasonNumber(1) // .setEpisodeTitle("Streaming") .setDescription("Currently streaming") .setLongDescription(channel.getName() + " is currently streaming live.") .setCanonicalGenres(new String[]{TvContract.Programs.Genres.ENTERTAINMENT}) .setThumbnailUri(channel.getLogoUrl()) .setPosterArtUri(channel.getLogoUrl()) .setInternalProviderData(channel.getName()) .setContentRatings(new TvContentRating[] {rating}) .setVideoHeight(1080) .setVideoWidth(1920) .build(); }
public static TvContentRating[] xmlTvRatingToTvContentRating( XmlTvParser.XmlTvRating[] ratings) { List<TvContentRating> list = new ArrayList<>(); for (XmlTvParser.XmlTvRating rating : ratings) { if (ANDROID_TV_RATING.equals(rating.system)) { list.add(TvContentRating.unflattenFromString(rating.value)); } } return list.toArray(new TvContentRating[list.size()]); }
public static TvContentRating[] stringToContentRatings(String commaSeparatedRatings) { if (TextUtils.isEmpty(commaSeparatedRatings)) { return null; } String[] ratings = commaSeparatedRatings.split("\\s*,\\s*"); TvContentRating[] contentRatings = new TvContentRating[ratings.length]; for (int i = 0; i < contentRatings.length; ++i) { contentRatings[i] = TvContentRating.unflattenFromString(ratings[i]); } return contentRatings; }
public static String contentRatingsToString(TvContentRating[] contentRatings) { if (contentRatings == null || contentRatings.length == 0) { return null; } final String DELIMITER = ","; StringBuilder ratings = new StringBuilder(contentRatings[0].flattenToString()); for (int i = 1; i < contentRatings.length; ++i) { ratings.append(DELIMITER); ratings.append(contentRatings[i].flattenToString()); } return ratings.toString(); }
private void unblockContent(TvContentRating rating) { // TIS should unblock content only if unblock request is legitimate. if (rating == null || mLastBlockedRating == null || rating.equals(mLastBlockedRating)) { mLastBlockedRating = null; if (rating != null) { mUnblockedRatingSet.add(rating); } if (mPlayer == null && mCurrentProgram != null) { playProgram(mCurrentProgram); } notifyContentAllowed(); } }
/** * Checks whether any of given ratings is blocked and returns the first blocked rating. * * @param ratings The array of ratings to check * @return The {@link TvContentRating} that is blocked. */ public TvContentRating getBlockedRating(TvContentRating[] ratings) { if (ratings == null) { return null; } for (TvContentRating rating : ratings) { if (mTvInputManager.isRatingBlocked(rating)) { return rating; } } return null; }
public static Set<TvContentRating> getRatingsForLevel( ParentalControlSettings settings, ContentRatingsManager manager, @ContentRatingLevel int level) { if (level == TvSettings.CONTENT_RATING_LEVEL_NONE) { return new HashSet<>(); } else if (level == TvSettings.CONTENT_RATING_LEVEL_HIGH) { return getRatingsForAge(settings, manager, AGE_THRESHOLD_FOR_LEVEL_HIGH); } else if (level == TvSettings.CONTENT_RATING_LEVEL_MEDIUM) { return getRatingsForAge(settings, manager, AGE_THRESHOLD_FOR_LEVEL_MEDIUM); } else if (level == TvSettings.CONTENT_RATING_LEVEL_LOW) { return getRatingsForAge(settings, manager, AGE_THRESHOLD_FOR_LEVEL_LOW); } throw new IllegalArgumentException("Unexpected rating level"); }
private static Set<TvContentRating> getRatingsForAge( ParentalControlSettings settings, ContentRatingsManager manager, int age) { Set<TvContentRating> ratings = new HashSet<>(); for (ContentRatingSystem contentRatingSystem : manager.getContentRatingSystems()) { if (!settings.isContentRatingSystemEnabled(contentRatingSystem)) { continue; } int ageLimit = age; if (ageLimit == AGE_THRESHOLD_FOR_LEVEL_LOW) { ageLimit = getMaxAge(contentRatingSystem); } for (Rating rating : contentRatingSystem.getRatings()) { if (rating.getAgeHint() < ageLimit) { continue; } TvContentRating tvContentRating = TvContentRating.createRating( contentRatingSystem.getDomain(), contentRatingSystem.getName(), rating.getName()); ratings.add(tvContentRating); for (SubRating subRating : rating.getSubRatings()) { tvContentRating = TvContentRating.createRating( contentRatingSystem.getDomain(), contentRatingSystem.getName(), rating.getName(), subRating.getName()); ratings.add(tvContentRating); } } } return ratings; }
private TvContentRating getProgramBlock(Program program) { ParentalControlSettings parental = mTvInputManagerHelper.getParentalControlSettings(); if (!parental.isParentalControlsEnabled()) { return null; } return parental.getBlockedRating(program.getContentRatings()); }
private String getBlockedDescription(TvContentRating blockedRating) { String name = mTvInputManagerHelper.getContentRatingsManager() .getDisplayNameForRating(blockedRating); if (TextUtils.isEmpty(name)) { return mContext.getString(R.string.program_guide_content_locked); } else { return mContext.getString(R.string.program_guide_content_locked_format, name); } }
protected void startPlayback(RecordedProgram recordedProgram, long seekTimeMs) { if (Utils.isInBundledPackageSet(recordedProgram.getPackageName()) && !isDataUriAccessible(recordedProgram.getDataUri())) { // Since cleaning RecordedProgram from forgotten storage will take some time, // ignore playback until cleaning is finished. ToastUtils.show(getContext(), getContext().getResources().getString(R.string.dvr_toast_recording_deleted), Toast.LENGTH_SHORT); return; } ParentalControlSettings parental = TvApplication.getSingletons(getActivity()) .getTvInputManagerHelper().getParentalControlSettings(); if (!parental.isParentalControlsEnabled()) { launchPlaybackActivity(recordedProgram, seekTimeMs, false); return; } ChannelDataManager channelDataManager = TvApplication.getSingletons(getActivity()).getChannelDataManager(); Channel channel = channelDataManager.getChannel(recordedProgram.getChannelId()); if (channel != null && channel.isLocked()) { checkPinToPlay(recordedProgram, seekTimeMs); return; } String ratingString = recordedProgram.getContentRating(); if (TextUtils.isEmpty(ratingString)) { launchPlaybackActivity(recordedProgram, seekTimeMs, false); return; } String[] ratingList = ratingString.split(","); TvContentRating[] programRatings = new TvContentRating[ratingList.length]; for (int i = 0; i < ratingList.length; i++) { programRatings[i] = TvContentRating.unflattenFromString(ratingList[i]); } TvContentRating blockRatings = parental.getBlockedRating(programRatings); if (blockRatings != null) { checkPinToPlay(recordedProgram, seekTimeMs); } else { launchPlaybackActivity(recordedProgram, seekTimeMs, false); } }
public static Program fromParcel(Parcel in) { Program program = new Program(); program.mId = in.readLong(); program.mPackageName = in.readString(); program.mChannelId = in.readLong(); program.mTitle = in.readString(); program.mSeriesId = in.readString(); program.mEpisodeTitle = in.readString(); program.mSeasonNumber = in.readString(); program.mSeasonTitle = in.readString(); program.mEpisodeNumber = in.readString(); program.mStartTimeUtcMillis = in.readLong(); program.mEndTimeUtcMillis = in.readLong(); program.mDescription = in.readString(); program.mLongDescription = in.readString(); program.mVideoWidth = in.readInt(); program.mVideoHeight = in.readInt(); program.mCriticScores = in.readArrayList(Thread.currentThread().getContextClassLoader()); program.mPosterArtUri = in.readString(); program.mThumbnailUri = in.readString(); program.mCanonicalGenreIds = in.createIntArray(); int length = in.readInt(); if (length > 0) { program.mContentRatings = new TvContentRating[length]; for (int i = 0; i < length; ++i) { program.mContentRatings[i] = TvContentRating.unflattenFromString(in.readString()); } } program.mRecordingProhibited = in.readByte() != (byte) 0; return program; }
@Override public void writeToParcel(Parcel out, int paramInt) { out.writeLong(mId); out.writeString(mPackageName); out.writeLong(mChannelId); out.writeString(mTitle); out.writeString(mSeriesId); out.writeString(mEpisodeTitle); out.writeString(mSeasonNumber); out.writeString(mSeasonTitle); out.writeString(mEpisodeNumber); out.writeLong(mStartTimeUtcMillis); out.writeLong(mEndTimeUtcMillis); out.writeString(mDescription); out.writeString(mLongDescription); out.writeInt(mVideoWidth); out.writeInt(mVideoHeight); out.writeList(mCriticScores); out.writeString(mPosterArtUri); out.writeString(mThumbnailUri); out.writeIntArray(mCanonicalGenreIds); out.writeInt(mContentRatings == null ? 0 : mContentRatings.length); if (mContentRatings != null) { for (TvContentRating rating : mContentRatings) { out.writeString(rating.flattenToString()); } } out.writeByte((byte) (mRecordingProhibited ? 1 : 0)); }
private boolean isRatingBlocked(String ratings) { if (TextUtils.isEmpty(ratings) || !mTvInputManager.isParentalControlsEnabled()) { return false; } TvContentRating[] ratingArray = mTvContentRatingCache.getRatings(ratings); if (ratingArray != null) { for (TvContentRating r : ratingArray) { if (mTvInputManager.isRatingBlocked(r)) { return true; } } } return false; }
@Override public void onContentBlocked(String inputId, TvContentRating rating) { blockScreenByContentRating(rating); if (mOnTuneListener != null) { mOnTuneListener.onContentBlocked(); } }
private static String generateContentRating(List<TsDescriptor> descriptors) { List<String> contentRatings = new ArrayList<>(); for (TsDescriptor descriptor : descriptors) { if (descriptor instanceof ContentAdvisoryDescriptor) { ContentAdvisoryDescriptor contentAdvisoryDescriptor = (ContentAdvisoryDescriptor) descriptor; for (RatingRegion ratingRegion : contentAdvisoryDescriptor.getRatingRegions()) { for (RegionalRating index : ratingRegion.getRegionalRatings()) { String ratingSystem = null; String rating = null; switch (ratingRegion.getName()) { case RATING_REGION_US_TV: ratingSystem = RATING_REGION_RATING_SYSTEM_US_TV; if (index.getDimension() == 0 && index.getRating() >= 0 && index.getRating() < RATING_REGION_TABLE_US_TV.length) { rating = RATING_REGION_TABLE_US_TV[index.getRating()]; } break; case RATING_REGION_KR_TV: ratingSystem = RATING_REGION_RATING_SYSTEM_KR_TV; if (index.getDimension() == 0 && index.getRating() >= 0 && index.getRating() < RATING_REGION_TABLE_KR_TV.length) { rating = RATING_REGION_TABLE_KR_TV[index.getRating()]; } break; default: break; } if (ratingSystem != null && rating != null) { contentRatings.add(TvContentRating .createRating("com.android.tv", ratingSystem, rating) .flattenToString()); } } } } } return TextUtils.join(",", contentRatings); }
public void testStringToContentRatings_double() { TvContentRating[] results = TvContentRatingCache.stringToContentRatings( TvContentRatingConstants.STRING_US_TV_MA + "," + TvContentRatingConstants.STRING_US_TV_MA); MoreAsserts .assertEquals("ratings", asArray(TvContentRatingConstants.CONTENT_RATING_US_TV_MA), results); }
public ProgramInfo(String title, String episode, int seasonNumber, int episodeNumber, String posterArtUri, String description, long durationMs, TvContentRating[] contentRatings, String genre, String resourceUri) { this.title = title; this.episode = episode; this.seasonNumber = seasonNumber; this.episodeNumber = episodeNumber; this.posterArtUri = posterArtUri; this.description = description; this.durationMs = durationMs; this.contentRatings = contentRatings; this.genre = genre; this.resourceUri = resourceUri; }
/** * Returns a string of each flattened content rating, sorted and concatenated together * with a comma. */ public static String contentRatingsToString(TvContentRating[] contentRatings) { if (contentRatings == null || contentRatings.length == 0) { return null; } String[] ratingStrings = new String[contentRatings.length]; for (int i = 0; i < contentRatings.length; i++) { ratingStrings[i] = contentRatings[i].flattenToString(); } if (ratingStrings.length == 1) { return ratingStrings[0]; } else { return TextUtils.join(",", toSortedSet(ratingStrings)); } }
@Override public void onUnblockContent(TvContentRating unblockedRating) { super.onUnblockContent(unblockedRating); if(tvInputProvider.getApplicationContext().getResources().getBoolean(R.bool.channel_surfer_lifecycle_toasts)) Toast.makeText(tvInputProvider.getApplicationContext(), "Unblocked "+unblockedRating.flattenToString(), Toast.LENGTH_SHORT).show(); notifyContentAllowed(); }
private String contentRatingsToString(TvContentRating[] contentRatings) { if (contentRatings == null || contentRatings.length == 0) { return null; } final String DELIMITER = ","; StringBuilder ratings = new StringBuilder(contentRatings[0].flattenToString()); for (int i = 1; i < contentRatings.length; ++i) { ratings.append(DELIMITER); ratings.append(contentRatings[i].flattenToString()); } return ratings.toString(); }
@Override public void onUnblockContent(TvContentRating rating) { mLog.d("[onUnblockContent][rating: " + rating + "]"); if (mCurrentChannel != null && mContentIsBlocked) { mContentIsBlocked = false; startPlayback(); } }
/** * Converts a TV ratings from an XML file to {@link TvContentRating}. * * @param rating An XmlTvRating. * @return A TvContentRating. */ private static TvContentRating xmlTvRatingToTvContentRating( CumulusXmlParser.XmlTvRating rating) { if (ANDROID_TV_RATING.equals(rating.system)) { return TvContentRating.unflattenFromString(rating.value); } return null; }
/** * Parses a string of comma-separated ratings into an array of {@link TvContentRating}. * * @param commaSeparatedRatings String containing various ratings, separated by commas. * @return An array of TvContentRatings. * @hide */ public static TvContentRating[] stringToContentRatings(String commaSeparatedRatings) { if (TextUtils.isEmpty(commaSeparatedRatings)) { return null; } String[] ratings = commaSeparatedRatings.split("\\s*,\\s*"); TvContentRating[] contentRatings = new TvContentRating[ratings.length]; for (int i = 0; i < contentRatings.length; ++i) { contentRatings[i] = TvContentRating.unflattenFromString(ratings[i]); } return contentRatings; }
/** * Flattens an array of {@link TvContentRating} into a String to be inserted into a database. * * @param contentRatings An array of TvContentRatings. * @return A comma-separated String of ratings. * @hide */ public static String contentRatingsToString(TvContentRating[] contentRatings) { if (contentRatings == null || contentRatings.length == 0) { return null; } final String DELIMITER = ","; StringBuilder ratings = new StringBuilder(contentRatings[0].flattenToString()); for (int i = 1; i < contentRatings.length; ++i) { ratings.append(DELIMITER); ratings.append(contentRatings[i].flattenToString()); } return ratings.toString(); }