TvContentRating.java revision 51374011a85e7f5860766c4f56cd73ff39e77528
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.media.tv;
18
19import android.annotation.SystemApi;
20import android.text.TextUtils;
21
22import java.util.Arrays;
23import java.util.Collections;
24import java.util.List;
25import java.util.Objects;
26
27/**
28 * A class representing a TV content rating. When a TV input service inserts the content rating
29 * information on a program into the database, this class can be used to generate the formatted
30 * string for
31 * {@link TvContract.Programs#COLUMN_CONTENT_RATING TvContract.Programs.COLUMN_CONTENT_RATING}.
32 * To create a {@code TvContentRating} object, use the
33 * {@link #createRating TvContentRating.createRating} method with valid rating system string
34 * constants.
35 * <p>
36 * It is possible for an application to define its own content rating system by supplying a content
37 * rating system definition XML resource (see example below) and declaring a broadcast receiver that
38 * filters {@link TvInputManager#ACTION_QUERY_CONTENT_RATING_SYSTEMS} in its manifest.
39 * </p>
40 * <h3> Example: Rating system definition for the TV Parental Guidelines</h3>
41 * The following XML example shows how the TV Parental Guidelines in the United States can be
42 * defined:
43 * <p><pre class="prettyprint">
44 * {@literal
45 * <rating-system-definitions xmlns:android="http://schemas.android.com/apk/res/android"
46 *     android:versionCode="1">
47 *     <!-- TV content rating system for US TV -->
48 *     <rating-system-definition android:name="US_TV"
49 *         android:title="US-TV"
50 *         android:description="@string/description_ustv"
51 *         android:country="US">
52 *         <sub-rating-definition android:name="US_TV_D"
53 *             android:title="D"
54 *             android:description="@string/description_ustv_d" />
55 *         <sub-rating-definition android:name="US_TV_L"
56 *             android:title="L"
57 *             android:description="@string/description_ustv_l" />
58 *         <sub-rating-definition android:name="US_TV_S"
59 *             android:title="S"
60 *             android:description="@string/description_ustv_s" />
61 *         <sub-rating-definition android:name="US_TV_V"
62 *             android:title="V"
63 *             android:description="@string/description_ustv_v" />
64 *         <sub-rating-definition android:name="US_TV_FV"
65 *             android:title="FV"
66 *             android:description="@string/description_ustv_fv" />
67 *
68 *         <rating-definition android:name="US_TV_Y"
69 *             android:title="TV-Y"
70 *             android:description="@string/description_ustv_y"
71 *             android:ageHint="0" />
72 *         <rating-definition android:name="US_TV_Y7"
73 *             android:title="TV-Y7"
74 *             android:description="@string/description_ustv_y7"
75 *             android:ageHint="7">
76 *             <sub-rating android:name="US_TV_FV" />
77 *         </rating-definition>
78 *         <rating-definition android:name="US_TV_G"
79 *             android:title="TV-G"
80 *             android:description="@string/description_ustv_g"
81 *             android:ageHint="0" />
82 *         <rating-definition android:name="US_TV_PG"
83 *             android:title="TV-PG"
84 *             android:description="@string/description_ustv_pg"
85 *             android:ageHint="14">
86 *             <sub-rating android:name="US_TV_D" />
87 *             <sub-rating android:name="US_TV_L" />
88 *             <sub-rating android:name="US_TV_S" />
89 *             <sub-rating android:name="US_TV_V" />
90 *         </rating-definition>
91 *         <rating-definition android:name="US_TV_14"
92 *             android:title="TV-14"
93 *             android:description="@string/description_ustv_14"
94 *             android:ageHint="14">
95 *             <sub-rating android:name="US_TV_D" />
96 *             <sub-rating android:name="US_TV_L" />
97 *             <sub-rating android:name="US_TV_S" />
98 *             <sub-rating android:name="US_TV_V" />
99 *         </rating-definition>
100 *         <rating-definition android:name="US_TV_MA"
101 *             android:title="TV-MA"
102 *             android:description="@string/description_ustv_ma"
103 *             android:ageHint="17">
104 *             <sub-rating android:name="US_TV_L" />
105 *             <sub-rating android:name="US_TV_S" />
106 *             <sub-rating android:name="US_TV_V" />
107 *         </rating-definition>
108 *         <rating-order>
109 *             <rating android:name="US_TV_Y" />
110 *             <rating android:name="US_TV_Y7" />
111 *         </rating-order>
112 *         <rating-order>
113 *             <rating android:name="US_TV_G" />
114 *             <rating android:name="US_TV_PG" />
115 *             <rating android:name="US_TV_14" />
116 *             <rating android:name="US_TV_MA" />
117 *         </rating-order>
118 *     </rating-system-definition>
119 * </rating-system-definitions>}</pre></p>
120 *
121 * <h3>System defined rating strings</h3>
122 * The following strings are defined by the system to provide a standard way to create
123 * {@code TvContentRating} objects.
124 * <p>For example, to create an object that represents TV-PG rating with suggestive dialogue and
125 * coarse language from the TV Parental Guidelines in the United States, one can use the following
126 * code snippet:
127 * </p>
128 * <pre>
129 * String rating = TvContentRating.createRating(
130 *         "com.android.tv",
131 *         "US_TV",
132 *         "US_TV_PG",
133 *         "US_TV_D", "US_TV_L");
134 * </pre>
135 * <h4>System defined string for domains</h4>
136 * <table>
137 *     <tr>
138 *         <th>Constant Value</th>
139 *         <th>Description</th>
140 *     </tr>
141 *     <tr>
142 *         <td>com.android.tv</td>
143 *         <td>Used for creating system defined content ratings</td>
144 *     </tr>
145 * </table>
146 *
147 * <h4>System defined strings for rating systems</h4>
148 * <table>
149 *     <tr>
150 *         <th>Constant Value</th>
151 *         <th>Description</th>
152 *     </tr>
153 *     <tr>
154 *         <td>AM_TV_RS</td>
155 *         <td>Range specific TV content rating system strings for Armenia</td>
156 *     </tr>
157 *     <tr>
158 *         <td>AM_TV_AS</td>
159 *         <td>Age specific TV content rating system strings for Armenia</td>
160 *     </tr>
161 *     <tr>
162 *         <td>AR_TV</td>
163 *         <td>TV content rating system for Argentina</td>
164 *     </tr>
165 *     <tr>
166 *         <td>AU_TV</td>
167 *         <td>TV content rating system for Australia</td>
168 *     </tr>
169 *     <tr>
170 *         <td>BG_TV</td>
171 *         <td>TV content rating system for Bulgaria</td>
172 *     </tr>
173 *     <tr>
174 *         <td>BR_TV</td>
175 *         <td>TV content rating system for Brazil</td>
176 *     </tr>
177 *     <tr>
178 *         <td>CA_TV</td>
179 *         <td>TV content rating system for Canada</td>
180 *     </tr>
181 *     <tr>
182 *         <td>CH_TV</td>
183 *         <td>TV content rating system for Switzerland</td>
184 *     </tr>
185 *     <tr>
186 *         <td>CL_TV</td>
187 *         <td>TV content rating system for Chile</td>
188 *     </tr>
189 *     <tr>
190 *         <td>DE_TV</td>
191 *         <td>TV content rating system for Germany</td>
192 *     </tr>
193 *     <tr>
194 *         <td>DK_TV</td>
195 *         <td>TV content rating system for Denmark</td>
196 *     </tr>
197 *     <tr>
198 *         <td>ES_TV</td>
199 *         <td>TV content rating system for Spain</td>
200 *     </tr>
201 *     <tr>
202 *         <td>FI_TV</td>
203 *         <td>TV content rating system for Finland</td>
204 *     </tr>
205 *     <tr>
206 *         <td>FR_TV</td>
207 *         <td>TV content rating system for France</td>
208 *     </tr>
209 *     <tr>
210 *         <td>GR_TV</td>
211 *         <td>TV content rating system for Greece</td>
212 *     </tr>
213 *     <tr>
214 *         <td>HK_TV</td>
215 *         <td>TV content rating system for Hong Kong</td>
216 *     </tr>
217 *     <tr>
218 *         <td>HU_TV</td>
219 *         <td>TV content rating system for Hungary</td>
220 *     </tr>
221 *     <tr>
222 *         <td>ID_TV</td>
223 *         <td>TV content rating system for Indonesia</td>
224 *     </tr>
225 *     <tr>
226 *         <td>IE_TV</td>
227 *         <td>TV content rating system for Ireland</td>
228 *     </tr>
229 *     <tr>
230 *         <td>IL_TV</td>
231 *         <td>TV content rating system for Israel</td>
232 *     </tr>
233 *     <tr>
234 *         <td>IN_TV</td>
235 *         <td>TV content rating system for India</td>
236 *     </tr>
237 *     <tr>
238 *         <td>IS_TV</td>
239 *         <td>TV content rating system for Iceland</td>
240 *     </tr>
241 *     <tr>
242 *         <td>KR_TV</td>
243 *         <td>TV content rating system for South Korea</td>
244 *     </tr>
245 *     <tr>
246 *         <td>MV_TV</td>
247 *         <td>TV content rating system for Maldives</td>
248 *     </tr>
249 *     <tr>
250 *         <td>MX_TV</td>
251 *         <td>TV content rating system for Mexico</td>
252 *     </tr>
253 *     <tr>
254 *         <td>MY_TV</td>
255 *         <td>TV content rating system for Malaysia</td>
256 *     </tr>
257 *     <tr>
258 *         <td>NL_TV</td>
259 *         <td>TV content rating system for Netherlands</td>
260 *     </tr>
261 *     <tr>
262 *         <td>NZ_FTV</td>
263 *         <td>TV content rating system for free-to-air channels in New Zealand</td>
264 *     </tr>
265 *     <tr>
266 *         <td>NZ_PTV</td>
267 *         <td>TV content rating system for Pay TV channels in New Zealand</td>
268 *     </tr>
269 *     <tr>
270 *         <td>PE_TV</td>
271 *         <td>TV content rating system for some Peruvian channels in Peru</td>
272 *     </tr>
273 *     <tr>
274 *         <td>PE_ATV</td>
275 *         <td>TV content rating system for America Television in Peru that uses its own rating
276 *         system</td>
277 *     </tr>
278 *     <tr>
279 *         <td>PH_TV</td>
280 *         <td>TV content rating system for Philippines</td>
281 *     </tr>
282 *     <tr>
283 *         <td>PL_TV</td>
284 *         <td>TV content rating system for Poland</td>
285 *     </tr>
286 *     <tr>
287 *         <td>PT_TV</td>
288 *         <td>TV content rating system for Portugal</td>
289 *     </tr>
290 *     <tr>
291 *         <td>RO_TV</td>
292 *         <td>TV content rating system for Romania</td>
293 *     </tr>
294 *     <tr>
295 *         <td>RU_TV</td>
296 *         <td>TV content rating system for Russia</td>
297 *     </tr>
298 *     <tr>
299 *         <td>RS_TV</td>
300 *         <td>TV content rating system for Serbia</td>
301 *     </tr>
302 *     <tr>
303 *         <td>SG_FTV</td>
304 *         <td>TV content rating system for Singapore</td>
305 *     </tr>
306 *     <tr>
307 *         <td>SG_PTV</td>
308 *         <td>TV content rating system for Singapore</td>
309 *     </tr>
310 *     <tr>
311 *         <td>SI_TV</td>
312 *         <td>TV content rating system for Slovenia</td>
313 *     </tr>
314 *     <tr>
315 *         <td>TH_TV</td>
316 *         <td>TV content rating system for Thailand</td>
317 *     </tr>
318 *     <tr>
319 *         <td>TR_TV</td>
320 *         <td>TV content rating system for Turkey</td>
321 *     </tr>
322 *     <tr>
323 *         <td>TW_TV</td>
324 *         <td>TV content rating system for Taiwan</td>
325 *     </tr>
326 *     <tr>
327 *         <td>UA_TV</td>
328 *         <td>TV content rating system for Ukraine</td>
329 *     </tr>
330 *     <tr>
331 *         <td>US_TV</td>
332 *         <td>TV content rating system for the United States</td>
333 *     </tr>
334 *     <tr>
335 *         <td>VE_TV</td>
336 *         <td>TV content rating system for Venezuela</td>
337 *     </tr>
338 *     <tr>
339 *         <td>ZA_TV</td>
340 *         <td>TV content rating system for South Africa</td>
341 *     </tr>
342 * </table>
343 *
344 * <h4>System defined strings for ratings</h4>
345 * <table>
346 *     <tr>
347 *         <th>Rating System</th>
348 *         <th>Constant Value</th>
349 *         <th>Description</th>
350 *     </tr>
351 *     <tr>
352 *         <td valign="top" rowspan="6">AM_TV_RS</td>
353 *         <td>AM_TV_RS_Y</td>
354 *         <td>Suitable for ages 2-11</td>
355 *     </tr>
356 *     <tr>
357 *         <td>AM_TV_RS_Y7</td>
358 *         <td>Suitable for ages 7-16</td>
359 *     </tr>
360 *     <tr>
361 *         <td>AM_TV_RS_GA</td>
362 *         <td>Suitable for general audiences</td>
363 *     </tr>
364 *     <tr>
365 *         <td>AM_TV_RS_TW</td>
366 *         <td>Suitable for teens ages 9 and up</td>
367 *     </tr>
368 *     <tr>
369 *         <td>AM_TV_RS_T</td>
370 *         <td>Suitable for teens ages 12 and up</td>
371 *     </tr>
372 *     <tr>
373 *         <td>AM_TV_RS_A</td>
374 *         <td>Suitable only for adults ages 18 and up</td>
375 *     </tr>
376 *     <tr>
377 *         <td valign="top" rowspan="6">AM_TV_AS</td>
378 *         <td>AM_TV_AS_EC</td>
379 *         <td>Suitable for ages 2 and up</td>
380 *     </tr>
381 *     <tr>
382 *         <td>AM_TV_AS_E</td>
383 *         <td>Suitable for ages 5 and up</td>
384 *     </tr>
385 *     <tr>
386 *         <td>AM_TV_AS_E9</td>
387 *         <td>Suitable for ages 9 and up</td>
388 *     </tr>
389 *     <tr>
390 *         <td>AM_TV_AS_T</td>
391 *         <td>Suitable for ages 12 and up</td>
392 *     </tr>
393 *     <tr>
394 *         <td>AM_TV_AS_M</td>
395 *         <td>Suitable for ages 16 and up</td>
396 *     </tr>
397 *     <tr>
398 *         <td>AM_TV_AS_AO</td>
399 *         <td>Suitable for ages 17 and up</td>
400 *     </tr>
401 *     <tr>
402 *         <td valign="top" rowspan="4">AR_TV</td>
403 *         <td>AR_TV_ALL</td>
404 *         <td>Suitable for all audiences. Programs may contain mild violence, language and mature
405 *         situations</td>
406 *     </tr>
407 *     <tr>
408 *         <td>AR_TV_13</td>
409 *         <td>Suitable for ages 13 and up. Programs may contain mild to moderate language and mild
410 *         violence and sexual references</td>
411 *     </tr>
412 *     <tr>
413 *         <td>AR_TV_16</td>
414 *         <td>Suitable for ages 16 and up. Programs may contain more intensive violence and coarse
415 *         language, partial nudity and moderate sexual references</td>
416 *     </tr>
417 *     <tr>
418 *         <td>AR_TV_18</td>
419 *         <td>Suitable for mature audiences only. Programs contain strong violence, coarse language
420 *         and explicit sexual references</td>
421 *     </tr>
422 *     <tr>
423 *         <td valign="top" rowspan="7">AU_TV</td>
424 *         <td>AU_TV_CTC</td>
425 *         <td>This has advertising approval, but is not yet classified</td>
426 *     </tr>
427 *     <tr>
428 *         <td>AU_TV_G</td>
429 *         <td>The content is very mild in impact, and suitable for everyone</td>
430 *     </tr>
431 *     <tr>
432 *         <td>AU_TV_PG</td>
433 *         <td>The content is mild in impact, but it may contain content that children find
434 *         confusing or upsetting and may require the guidance or parents and guardians</td>
435 *     </tr>
436 *     <tr>
437 *         <td>AU_TV_M</td>
438 *         <td>The content is moderate in impact, and it is recommended for teenagers aged 15 years
439 *         and over</td>
440 *     </tr>
441 *     <tr>
442 *         <td>AU_TV_MA15</td>
443 *         <td>The content is strong in impact, and it is legally restricted to persons 15 years and
444 *         over</td>
445 *     </tr>
446 *     <tr>
447 *         <td>AU_TV_R18</td>
448 *         <td>The content is high in impact, and it is restricted to adults</td>
449 *     </tr>
450 *     <tr>
451 *         <td>AU_TV_X18</td>
452 *         <td>The content is restricted to adults. This classification is a special and legally
453 *         restricted category which contains only sexually explicit content</td>
454 *     </tr>
455 *     <tr>
456 *         <td valign="top" rowspan="5">BG_TV</td>
457 *         <td>BG_TV_A</td>
458 *         <td>Recommended to children. When the film confirms the ideals of humanism or popularizes
459 *         the national and world cultures or contributes to upbringing children</td>
460 *     </tr>
461 *     <tr>
462 *         <td>BG_TV_B</td>
463 *         <td>No restrictive recommendations from the Committee. When the film is in no way
464 *         contrary to the universal rules of morality in this country, has no restrictive
465 *         recommendations from the Committee and does not fall in rating A</td>
466 *     </tr>
467 *     <tr>
468 *         <td>BG_TV_C</td>
469 *         <td>No persons under the age of 12 are admitted unless accompanied by an adult. When the
470 *         film contains certain erotic scenes or scenes with drinking, taking drugs or stimulants
471 *         or a few scenes of violence</td>
472 *     </tr>
473 *     <tr>
474 *         <td>BG_TV_D</td>
475 *         <td>No persons under the age of 16 are admitted. When the film contains quite a number of
476 *         erotic scenes or scenes with drinking, taking drugs or stimulants or a considerable
477 *         number of scenes showing violence</td>
478 *     </tr>
479 *     <tr>
480 *         <td>BG_TV_X</td>
481 *         <td>No persons under the age of 18 are admitted. When the film is naturalistically erotic
482 *         or shows violence in an ostentatious manner</td>
483 *     </tr>
484 *     <tr>
485 *         <td valign="top" rowspan="6">BR_TV</td>
486 *         <td>BR_TV_L</td>
487 *         <td>Content is suitable for all audiences</td>
488 *     </tr>
489 *     <tr>
490 *         <td>BR_TV_10</td>
491 *         <td>Content suitable for viewers over the age of 10</td>
492 *     </tr>
493 *     <tr>
494 *         <td>BR_TV_12</td>
495 *         <td>Content suitable for viewers over the age of 12</td>
496 *     </tr>
497 *     <tr>
498 *         <td>BR_TV_14</td>
499 *         <td>Content suitable for viewers over the age of 14</td>
500 *     </tr>
501 *     <tr>
502 *         <td>BR_TV_16</td>
503 *         <td>Content suitable for viewers over the age of 16</td>
504 *     </tr>
505 *     <tr>
506 *         <td>BR_TV_18</td>
507 *         <td>Content suitable for viewers over the age of 18</td>
508 *     </tr>
509 *     <tr>
510 *         <td valign="top" rowspan="7">CA_TV</td>
511 *         <td>CA_TV_EXEMPT</td>
512 *         <td>Shows which are exempt from ratings (such as news and sports programming) will not
513 *         display an on-screen rating at all</td>
514 *     </tr>
515 *     <tr>
516 *         <td>CA_TV_C</td>
517 *         <td>Programming suitable for children ages of 2-7 years. No profanity or sexual content
518 *         of any level allowed. Contains little violence</td>
519 *     </tr>
520 *     <tr>
521 *         <td>CA_TV_C8</td>
522 *         <td>Suitable for children ages 8+. Low level violence and fantasy horror is allowed. No
523 *         foul language is allowed, but occasional "socially offensive and discriminatory" language
524 *         is allowed if in the context of the story. No sexual content of any level allowed</td>
525 *     </tr>
526 *     <tr>
527 *         <td>CA_TV_G</td>
528 *         <td>Suitable for general audiences. Programming suitable for the entire family with mild
529 *         violence, and mild profanity and/or censored language</td>
530 *     </tr>
531 *     <tr>
532 *         <td>CA_TV_PG</td>
533 *         <td>Parental guidance. Moderate violence and moderate profanity is allowed, as is brief
534 *         nudity and sexual references if important to the context of the story</td>
535 *     </tr>
536 *     <tr>
537 *         <td>CA_TV_14</td>
538 *         <td>Programming intended for viewers ages 14 and older. May contain strong violence and
539 *         strong profanity, and depictions of sexual activity as long as they are within the
540 *         context of a story</td>
541 *     </tr>
542 *     <tr>
543 *         <td>CA_TV_18</td>
544 *         <td>Programming intended for viewers ages 18 and older. May contain explicit violence and
545 *         sexual activity</td>
546 *     </tr>
547 *     <tr>
548 *         <td valign="top" rowspan="2">CH_TV</td>
549 *         <td>CH_TV_ALL</td>
550 *         <td>This program is suitable for all ages</td>
551 *     </tr>
552 *     <tr>
553 *         <td>CH_TV_RED</td>
554 *         <td>This program contains scenes that may hurt sensitive people, therefore the red symbol
555 *         will be displayed</td>
556 *     </tr>
557 *     <tr>
558 *         <td valign="top" rowspan="7">CL_TV</td>
559 *         <td>CL_TV_I</td>
560 *         <td>Programs suitable for all children</td>
561 *     </tr>
562 *     <tr>
563 *         <td>CL_TV_I7</td>
564 *         <td>Programs recommended for children ages 7 or older</td>
565 *     </tr>
566 *     <tr>
567 *         <td>CL_TV_I10</td>
568 *         <td>Programs recommended for children ages 10 or older</td>
569 *     </tr>
570 *     <tr>
571 *         <td>CL_TV_I12</td>
572 *         <td>Programs recommended for children and teens ages 12 or older</td>
573 *     </tr>
574 *     <tr>
575 *         <td>CL_TV_F</td>
576 *         <td>Programs suitable for a general audience, with content appropriate for all ages</td>
577 *     </tr>
578 *     <tr>
579 *         <td>CL_TV_R</td>
580 *         <td>Programs may content not suitable for children not accompanied by an adult</td>
581 *     </tr>
582 *     <tr>
583 *         <td>CL_TV_A</td>
584 *         <td>Programs suitable for adult audiences only (ages 18 or older), may contain coarse
585 *         language, and sexual or explicit situations</td>
586 *     </tr>
587 *     <tr>
588 *         <td valign="top" rowspan="4">DE_TV</td>
589 *         <td>DE_TV_ALL</td>
590 *         <td>The program is suitable for all ages</td>
591 *     </tr>
592 *     <tr>
593 *         <td>DE_TV_12</td>
594 *         <td>The program is not suitable for viewers under the age of 12</td>
595 *     </tr>
596 *     <tr>
597 *         <td>DE_TV_16</td>
598 *         <td>The program is not suitable for viewers under the age of 16</td>
599 *     </tr>
600 *     <tr>
601 *         <td>DE_TV_18</td>
602 *         <td>The program is not suitable for viewers under the age of 18</td>
603 *     </tr>
604 *     <tr>
605 *         <td valign="top" rowspan="4">DK_TV</td>
606 *         <td>DK_TV_G</td>
607 *         <td>programs suitable for all ages</td>
608 *     </tr>
609 *     <tr>
610 *         <td>DK_TV_Y</td>
611 *         <td>programs suitable children accompanied by an adult</td>
612 *     </tr>
613 *     <tr>
614 *         <td>DK_TV_R</td>
615 *         <td>programs containing material with more intensive content</td>
616 *     </tr>
617 *     <tr>
618 *         <td>DK_TV_B</td>
619 *         <td>programs containing explicit content and strictly for adults only</td>
620 *     </tr>
621 *     <tr>
622 *         <td valign="top" rowspan="7">ES_TV</td>
623 *         <td>ES_TV_TP</td>
624 *         <td>Recommended for all ages</td>
625 *     </tr>
626 *     <tr>
627 *         <td>ES_TV_I</td>
628 *         <td>Specially recommended for preschoolers and kids</td>
629 *     </tr>
630 *     <tr>
631 *         <td>ES_TV_7</td>
632 *         <td>Recommended for people older than 7 years old</td>
633 *     </tr>
634 *     <tr>
635 *         <td>ES_TV_7I</td>
636 *         <td>Recommended for kids older than 7 years old</td>
637 *     </tr>
638 *     <tr>
639 *         <td>ES_TV_12</td>
640 *         <td>Recommended for people older than 12 years old</td>
641 *     </tr>
642 *     <tr>
643 *         <td>ES_TV_16</td>
644 *         <td>Recommended for people older than 16 years old</td>
645 *     </tr>
646 *     <tr>
647 *         <td>ES_TV_18</td>
648 *         <td>Recommended for people older than 18 years old</td>
649 *     </tr>
650 *     <tr>
651 *         <td valign="top" rowspan="5">FI_TV</td>
652 *         <td>FI_TV_S</td>
653 *         <td>Allowed at all times</td>
654 *     </tr>
655 *     <tr>
656 *         <td>FI_TV_K7</td>
657 *         <td>Not recommended for children under 7</td>
658 *     </tr>
659 *     <tr>
660 *         <td>FI_TV_K12</td>
661 *         <td>Not recommended for children under 12</td>
662 *     </tr>
663 *     <tr>
664 *         <td>FI_TV_K16</td>
665 *         <td>Not recommended for children under 16</td>
666 *     </tr>
667 *     <tr>
668 *         <td>FI_TV_K18</td>
669 *         <td>Not recommended for children under 18</td>
670 *     </tr>
671 *     <tr>
672 *         <td valign="top" rowspan="5">FR_TV</td>
673 *         <td>FR_TV_ALL</td>
674 *         <td>Appropriate for all ages</td>
675 *     </tr>
676 *     <tr>
677 *         <td>FR_TV_10</td>
678 *         <td>Not recommended for children under 10</td>
679 *     </tr>
680 *     <tr>
681 *         <td>FR_TV_12</td>
682 *         <td>Not recommended for children under 12</td>
683 *     </tr>
684 *     <tr>
685 *         <td>FR_TV_16</td>
686 *         <td>Not recommended for children under 16</td>
687 *     </tr>
688 *     <tr>
689 *         <td>FR_TV_18</td>
690 *         <td>Not recommended for persons under 18</td>
691 *     </tr>
692 *     <tr>
693 *         <td valign="top" rowspan="5">GR_TV</td>
694 *         <td>GR_TV_ALL</td>
695 *         <td>Suitable for all ages</td>
696 *     </tr>
697 *     <tr>
698 *         <td>GR_TV_10</td>
699 *         <td>Parental consent suggested</td>
700 *     </tr>
701 *     <tr>
702 *         <td>GR_TV_12</td>
703 *         <td>Required parental consent</td>
704 *     </tr>
705 *     <tr>
706 *         <td>GR_TV_15</td>
707 *         <td>Suitable for minors over the age of 15</td>
708 *     </tr>
709 *     <tr>
710 *         <td>GR_TV_18</td>
711 *         <td>Suitable only for adults profanity before midnight is punishable by fine, except when
712 *         used in the context of the program</td>
713 *     </tr>
714 *     <tr>
715 *         <td valign="top" rowspan="3">HK_TV</td>
716 *         <td>HK_TV_G</td>
717 *         <td>For general audiences</td>
718 *     </tr>
719 *     <tr>
720 *         <td>HK_TV_PG</td>
721 *         <td>Programs are unsuitable for children, parental guidance is recommended</td>
722 *     </tr>
723 *     <tr>
724 *         <td>HK_TV_M</td>
725 *         <td>Programs are recommended only for adult viewers above the age of 18</td>
726 *     </tr>
727 *     <tr>
728 *         <td valign="top" rowspan="6">HU_TV</td>
729 *         <td>HU_TV_U</td>
730 *         <td>Programs can be viewed by any age</td>
731 *     </tr>
732 *     <tr>
733 *         <td>HU_TV_CF</td>
734 *         <td>Programs recommended for children. It is an optional rating, there is no obligation
735 *         for broadcasters to indicate it</td>
736 *     </tr>
737 *     <tr>
738 *         <td>HU_TV_6</td>
739 *         <td>Programs not recommended for children below the age of 6, may not contain any
740 *         violence or sexual content</td>
741 *     </tr>
742 *     <tr>
743 *         <td>HU_TV_12</td>
744 *         <td>Programs not recommended for children below the age of 12, may contain light sexual
745 *         content or explicit language</td>
746 *     </tr>
747 *     <tr>
748 *         <td>HU_TV_16</td>
749 *         <td>Programs not recommended for teens and children below the age of 16, may contain more
750 *         intensive violence and sexual content</td>
751 *     </tr>
752 *     <tr>
753 *         <td>HU_TV_18</td>
754 *         <td>The program is recommended only for adult viewers (for ages 18 and up), may contain
755 *         explicit violence and explicit sexual content</td>
756 *     </tr>
757 *     <tr>
758 *         <td valign="top" rowspan="8">ID_TV</td>
759 *         <td>ID_TV_P</td>
760 *         <td>Suitable for children from ages 2 through 11</td>
761 *     </tr>
762 *     <tr>
763 *         <td>ID_TV_A</td>
764 *         <td>Suitable for teens and children from ages 7 through 16</td>
765 *     </tr>
766 *     <tr>
767 *         <td>ID_TV_A_BO</td>
768 *         <td>Suitable for children ages 5 through 10, with parental guidance or permission</td>
769 *     </tr>
770 *     <tr>
771 *         <td>ID_TV_SU</td>
772 *         <td>Suitable for general audiences</td>
773 *     </tr>
774 *     <tr>
775 *         <td>ID_TV_BO</td>
776 *         <td>Parental guidance suggested for ages 5 and under</td>
777 *     </tr>
778 *     <tr>
779 *         <td>ID_TV_R</td>
780 *         <td>Suitable for teens from ages 13 through 17</td>
781 *     </tr>
782 *     <tr>
783 *         <td>ID_TV_R_BO</td>
784 *         <td>Suitable for teens with parental guidance or permission</td>
785 *     </tr>
786 *     <tr>
787 *         <td>ID_TV_D</td>
788 *         <td>Suitable for viewers over 18 and older only</td>
789 *     </tr>
790 *     <tr>
791 *         <td valign="top" rowspan="5">IE_TV</td>
792 *         <td>IE_TV_GA</td>
793 *         <td>Suitable for all ages</td>
794 *     </tr>
795 *     <tr>
796 *         <td>IE_TV_CH</td>
797 *         <td>Suitable for children ages 5 to 10, may contain comedic violence or action fantasy
798 *         violence</td>
799 *     </tr>
800 *     <tr>
801 *         <td>IE_TV_YA</td>
802 *         <td>Suitable for adolescent audiences, may contain thematic elements that would appeal to
803 *         teenagers</td>
804 *     </tr>
805 *     <tr>
806 *         <td>IE_TV_PS</td>
807 *         <td>Suitable for more mature viewers, more mature themes may be present</td>
808 *     </tr>
809 *     <tr>
810 *         <td>IE_TV_MA</td>
811 *         <td>Most restrictive classification, allowing for heavy subject matter and coarse
812 *         language</td>
813 *     </tr>
814 *     <tr>
815 *         <td valign="top" rowspan="5">IL_TV</td>
816 *         <td>IL_TV_G</td>
817 *         <td>General audience; anyone, regardless of age, can view the program, usually news and
818 *         children's programming</td>
819 *     </tr>
820 *     <tr>
821 *         <td>IL_TV_12</td>
822 *         <td>Suitable for teens and children ages 12 and over, no child under 12 are permitted to
823 *         view the program</td>
824 *     </tr>
825 *     <tr>
826 *         <td>IL_TV_15</td>
827 *         <td>Suitable for teens ages 15 and over, no child under 15 may view the programme</td>
828 *     </tr>
829 *     <tr>
830 *         <td>IL_TV_18</td>
831 *         <td>Suitable for adults only, no minors may view the programme</td>
832 *     </tr>
833 *     <tr>
834 *         <td>IL_TV_E</td>
835 *         <td>Exempt from classification</td>
836 *     </tr>
837 *     <tr>
838 *         <td valign="top" rowspan="4">IN_TV</td>
839 *         <td>IN_TV_U</td>
840 *         <td>Unrestricted public exhibition</td>
841 *     </tr>
842 *     <tr>
843 *         <td>IN_TV_U_A</td>
844 *         <td>Unrestricted public exhibition, but with a caution regarding parental guidance to
845 *         those under 12 years of age</td>
846 *     </tr>
847 *     <tr>
848 *         <td>IN_TV_A</td>
849 *         <td>Public exhibition restricted to adults 18 years of age and older only</td>
850 *     </tr>
851 *     <tr>
852 *         <td>IN_TV_S</td>
853 *         <td>Public exhibition restricted to members of any profession or any class of persons
854 *         </td>
855 *     </tr>
856 *     <tr>
857 *         <td valign="top" rowspan="7">IS_TV</td>
858 *         <td>IS_TV_L</td>
859 *         <td>Programs suitable for all ages</td>
860 *     </tr>
861 *     <tr>
862 *         <td>IS_TV_7</td>
863 *         <td>Programs suitable for ages 7 and older</td>
864 *     </tr>
865 *     <tr>
866 *         <td>IS_TV_10</td>
867 *         <td>Programs suitable for ages 10 and older</td>
868 *     </tr>
869 *     <tr>
870 *         <td>IS_TV_12</td>
871 *         <td>Programs suitable for ages 12 and older</td>
872 *     </tr>
873 *     <tr>
874 *         <td>IS_TV_14</td>
875 *         <td>Programs suitable for ages 14 and older</td>
876 *     </tr>
877 *     <tr>
878 *         <td>IS_TV_16</td>
879 *         <td>Programs suitable for ages 16 and older</td>
880 *     </tr>
881 *     <tr>
882 *         <td>IS_TV_18</td>
883 *         <td>Programs suitable for ages 18 and older</td>
884 *     </tr>
885 *     <tr>
886 *         <td valign="top" rowspan="5">KR_TV</td>
887 *         <td>KR_TV_ALL</td>
888 *         <td>Appropriate for all ages</td>
889 *     </tr>
890 *     <tr>
891 *         <td>KR_TV_7</td>
892 *         <td>May contain material inappropriate for children younger than 7, and parental
893 *         discretion should be used</td>
894 *     </tr>
895 *     <tr>
896 *         <td>KR_TV_12</td>
897 *         <td>May deemed inappropriate for those younger than 12, and parental discretion should be
898 *         used</td>
899 *     </tr>
900 *     <tr>
901 *         <td>KR_TV_15</td>
902 *         <td>May be inappropriate for children under 15, and that parental discretion should be
903 *         used</td>
904 *     </tr>
905 *     <tr>
906 *         <td>KR_TV_19</td>
907 *         <td>For adults only</td>
908 *     </tr>
909 *     <tr>
910 *         <td valign="top" rowspan="9">MV_TV</td>
911 *         <td>MV_TV_Y</td>
912 *         <td>Young children</td>
913 *     </tr>
914 *     <tr>
915 *         <td>MV_TV_G</td>
916 *         <td>General viewing for all ages</td>
917 *     </tr>
918 *     <tr>
919 *         <td>MV_TV_PG</td>
920 *         <td>Parental guidance is required unaccompanied children</td>
921 *     </tr>
922 *     <tr>
923 *         <td>MV_TV_PG_12</td>
924 *         <td>Parental guidance is required for children under the age of 12</td>
925 *     </tr>
926 *     <tr>
927 *         <td>MV_TV_12</td>
928 *         <td>Teens and children aged 12 and older may watch, otherwise restricted</td>
929 *     </tr>
930 *     <tr>
931 *         <td>MV_TV_15</td>
932 *         <td>Restricted to viewers aged 15 and above</td>
933 *     </tr>
934 *     <tr>
935 *         <td>MV_TV_18</td>
936 *         <td>Restricted to viewers aged 18 and above</td>
937 *     </tr>
938 *     <tr>
939 *         <td>MV_TV_21</td>
940 *         <td>Restricted to viewers aged 21 and above</td>
941 *     </tr>
942 *     <tr>
943 *         <td>MV_TV_X</td>
944 *         <td>Most restrictive classification, only adults ages 25 and above may view</td>
945 *     </tr>
946 *     <tr>
947 *         <td valign="top" rowspan="6">MX_TV</td>
948 *         <td>MX_TV_A</td>
949 *         <td>Appropriate for all ages, parental guidance is recommended for children under 7 years
950 *         </td>
951 *     </tr>
952 *     <tr>
953 *         <td>MX_TV_B</td>
954 *         <td>Designed for ages 12 and older, may contain some sexual situations, mild violence,
955 *         and mild language</td>
956 *     </tr>
957 *     <tr>
958 *         <td>MX_TV_B_15</td>
959 *         <td>Designed for ages 15 and up, slightly more intensive than the 'A' and 'B' ratings
960 *         </td>
961 *     </tr>
962 *     <tr>
963 *         <td>MX_TV_C</td>
964 *         <td>Designed to be viewed by adults aged 18 or older only, generally more intensive
965 *         content</td>
966 *     </tr>
967 *     <tr>
968 *         <td>MX_TV_D</td>
969 *         <td>Designed to be viewed only by mature adults (at least 21 years of age and over),
970 *         contains extreme content matter</td>
971 *     </tr>
972 *     <tr>
973 *         <td>MX_TV_RC</td>
974 *         <td>Banned from public television in Mexico</td>
975 *     </tr>
976 *     <tr>
977 *         <td valign="top" rowspan="3">MY_TV</td>
978 *         <td>MY_TV_U</td>
979 *         <td>General viewing for all ages, can be broadcast anytime</td>
980 *     </tr>
981 *     <tr>
982 *         <td>MY_TV_P13</td>
983 *         <td>For viewers ages 13 and above, children under 13 needs parental guidance, can be
984 *         broadcast anytime, but some elements may only be broadcast at night</td>
985 *     </tr>
986 *     <tr>
987 *         <td>MY_TV_18</td>
988 *         <td>For viewers ages 18 and above only</td>
989 *     </tr>
990 *     <tr>
991 *         <td valign="top" rowspan="5">NL_TV</td>
992 *         <td>NL_TV_AL</td>
993 *         <td>All Ages</td>
994 *     </tr>
995 *     <tr>
996 *         <td>NL_TV_6</td>
997 *         <td>Parental advisory for children under 6</td>
998 *     </tr>
999 *     <tr>
1000 *         <td>NL_TV_9</td>
1001 *         <td>Parental advisory for children under 9</td>
1002 *     </tr>
1003 *     <tr>
1004 *         <td>NL_TV_12</td>
1005 *         <td>Parental advisory for children under 12</td>
1006 *     </tr>
1007 *     <tr>
1008 *         <td>NL_TV_16</td>
1009 *         <td>Parental advisory for children under 16</td>
1010 *     </tr>
1011 *     <tr>
1012 *         <td valign="top" rowspan="3">NZ_FTV</td>
1013 *         <td>NZ_FTV_G</td>
1014 *         <td>These exclude material likely to harm children under 14 and can screen at any time.
1015 *         Programmes may not necessarily be designed for younger viewers, but must not contain
1016 *         material likely to cause them undue distress or discomfort</td>
1017 *     </tr>
1018 *     <tr>
1019 *         <td>NZ_FTV_PGR</td>
1020 *         <td>Programmes more suited to more mature viewers. These are not necessarily unsuitable
1021 *         for children, but viewer discretion is advised, and parents and guardians are encouraged
1022 *         to supervise younger viewers</td>
1023 *     </tr>
1024 *     <tr>
1025 *         <td>NZ_FTV_AO</td>
1026 *         <td>Contain material of an adult nature handled in such a way that it is unsuitable for
1027 *         children</td>
1028 *     </tr>
1029 *     <tr>
1030 *         <td valign="top" rowspan="5">NZ_PTV</td>
1031 *         <td>NZ_PTV_G</td>
1032 *         <td>suitable for general audiences</td>
1033 *     </tr>
1034 *     <tr>
1035 *         <td>NZ_PTV_PG</td>
1036 *         <td>Parental guidance recommended for under 10</td>
1037 *     </tr>
1038 *     <tr>
1039 *         <td>NZ_PTV_M</td>
1040 *         <td>Suitable for mature audiences 13 and up</td>
1041 *     </tr>
1042 *     <tr>
1043 *         <td>NZ_PTV_16</td>
1044 *         <td>Suitable for viewers 16 and up</td>
1045 *     </tr>
1046 *     <tr>
1047 *         <td>NZ_PTV_18</td>
1048 *         <td>Suitable for viewers 18 and up</td>
1049 *     </tr>
1050 *     <tr>
1051 *         <td valign="top" rowspan="3">PE_TV</td>
1052 *         <td>PE_TV_A</td>
1053 *         <td>Suitable for all audiences</td>
1054 *     </tr>
1055 *     <tr>
1056 *         <td>PE_TV_14</td>
1057 *         <td>Suitable for people aged 14 and above only</td>
1058 *     </tr>
1059 *     <tr>
1060 *         <td>PE_TV_18</td>
1061 *         <td>Suitable for people aged 18 and above only</td>
1062 *     </tr>
1063 *     <tr>
1064 *         <td valign="top" rowspan="4">PE_ATV</td>
1065 *         <td>PE_ATV_GP</td>
1066 *         <td>General audience</td>
1067 *     </tr>
1068 *     <tr>
1069 *         <td>PE_ATV_PG</td>
1070 *         <td>Parental guidance required for under 6</td>
1071 *     </tr>
1072 *     <tr>
1073 *         <td>PE_ATV_14</td>
1074 *         <td>Suitable for people aged 14 and above only</td>
1075 *     </tr>
1076 *     <tr>
1077 *         <td>PE_ATV_18</td>
1078 *         <td>Suitable for people aged 18 and above only</td>
1079 *     </tr>
1080 *     <tr>
1081 *         <td valign="top" rowspan="3">PH_TV</td>
1082 *         <td>PH_TV_G</td>
1083 *         <td>Suitable for all public viewers</td>
1084 *     </tr>
1085 *     <tr>
1086 *         <td>PH_TV_PG</td>
1087 *         <td>Programmes rated PG may contain scenes or other content that are unsuitable for
1088 *         children without the guidance of a parent</td>
1089 *     </tr>
1090 *     <tr>
1091 *         <td>PH_TV_SPG</td>
1092 *         <td>Contains mature themes or moderate to intense violence, which may be deemed unfit for
1093 *         children to watch without strict parental supervision</td>
1094 *     </tr>
1095 *     <tr>
1096 *         <td valign="top" rowspan="5">PL_TV</td>
1097 *         <td>PL_TV_G</td>
1098 *         <td>Positive or neutral view of the world, little to no violence, non-sexual love, and no
1099 *         sexual content</td>
1100 *     </tr>
1101 *     <tr>
1102 *         <td>PL_TV_7</td>
1103 *         <td>Age 7 and above. May additionally contain some mild language, bloodless violence, and
1104 *         a more negative view of the world</td>
1105 *     </tr>
1106 *     <tr>
1107 *         <td>PL_TV_12</td>
1108 *         <td>Age 12 and above. May contain some foul language, some violence, and some sexual
1109 *         content</td>
1110 *     </tr>
1111 *     <tr>
1112 *         <td>PL_TV_16</td>
1113 *         <td>Age 16 and above. Deviant social behaviour, world filled with violence and sexuality,
1114 *         simplified picture of adulthood, display of physical force, especially in controversial
1115 *         social context, immoral behaviour without ethic dilemma, putting the blame on the victim,
1116 *         excessive concentration on material possessions</td>
1117 *     </tr>
1118 *     <tr>
1119 *         <td>PL_TV_18</td>
1120 *         <td>Age 18 and above. One-sided display of the joys of adult life without showing
1121 *         responsibilities, social justification of violent behaviour, excessive vulgarity, use of
1122 *         racial slurs and social stereotypes, explicit sexual content, praise of aggression or
1123 *         vulgarity</td>
1124 *     </tr>
1125 *     <tr>
1126 *         <td valign="top" rowspan="4">PT_TV</td>
1127 *         <td>PT_TV_T</td>
1128 *         <td>Suitable for all</td>
1129 *     </tr>
1130 *     <tr>
1131 *         <td>PT_TV_10</td>
1132 *         <td>May not be suitable for children under 10, parental guidance advised</td>
1133 *     </tr>
1134 *     <tr>
1135 *         <td>PT_TV_12</td>
1136 *         <td>May not be suitable for children under 12, parental guidance advised</td>
1137 *     </tr>
1138 *     <tr>
1139 *         <td>PT_TV_16</td>
1140 *         <td>Not suitable for children under 16</td>
1141 *     </tr>
1142 *     <tr>
1143 *         <td valign="top" rowspan="6">RO_TV</td>
1144 *         <td>RO_TV_Y</td>
1145 *         <td>Young Ages</td>
1146 *     </tr>
1147 *     <tr>
1148 *         <td>RO_TV_G</td>
1149 *         <td>General Exhibition</td>
1150 *     </tr>
1151 *     <tr>
1152 *         <td>RO_TV_AP</td>
1153 *         <td>Parental guidance is recommended for children below the age of 12</td>
1154 *     </tr>
1155 *     <tr>
1156 *         <td>RO_TV_12</td>
1157 *         <td>Forbidden for children under 12 years of age</td>
1158 *     </tr>
1159 *     <tr>
1160 *         <td>RO_TV_15</td>
1161 *         <td>Forbidden for children under 15 years of age</td>
1162 *     </tr>
1163 *     <tr>
1164 *         <td>RO_TV_18</td>
1165 *         <td>Forbidden for children under 18 years of age</td>
1166 *     </tr>
1167 *     <tr>
1168 *         <td valign="top" rowspan="5">RU_TV</td>
1169 *         <td>RU_TV_0</td>
1170 *         <td>Can be watched by Any Age</td>
1171 *     </tr>
1172 *     <tr>
1173 *         <td>RU_TV_6</td>
1174 *         <td>Only kids the age of 6 or older can watch</td>
1175 *     </tr>
1176 *     <tr>
1177 *         <td>RU_TV_12</td>
1178 *         <td>Only kids the age of 12 or older can watch</td>
1179 *     </tr>
1180 *     <tr>
1181 *         <td>RU_TV_16</td>
1182 *         <td>Only teens the age of 16 or older can watch</td>
1183 *     </tr>
1184 *     <tr>
1185 *         <td>RU_TV_18</td>
1186 *         <td>Restricted to children ONLY people 18 or older</td>
1187 *     </tr>
1188 *     <tr>
1189 *         <td valign="top" rowspan="7">RS_TV</td>
1190 *         <td>RS_TV_G</td>
1191 *         <td>Program suitable for all ages</td>
1192 *     </tr>
1193 *     <tr>
1194 *         <td>RS_TV_12</td>
1195 *         <td>Program not suitable for children under the age of 12</td>
1196 *     </tr>
1197 *     <tr>
1198 *         <td>RS_TV_14</td>
1199 *         <td>Program not suitable for children/teens under the age of 14</td>
1200 *     </tr>
1201 *     <tr>
1202 *         <td>RS_TV_15</td>
1203 *         <td>Program not suitable for children/teens under the age of 15</td>
1204 *     </tr>
1205 *     <tr>
1206 *         <td>RS_TV_16</td>
1207 *         <td>Program not suitable for children/teens under the age of 16</td>
1208 *     </tr>
1209 *     <tr>
1210 *         <td>RS_TV_17</td>
1211 *         <td>Program not suitable for children/teens under the age of 17</td>
1212 *     </tr>
1213 *     <tr>
1214 *         <td>RS_TV_18</td>
1215 *         <td>Program not suitable for minors under the age of 18</td>
1216 *     </tr>
1217 *     <tr>
1218 *         <td valign="top" rowspan="2">SG_FTV</td>
1219 *         <td>SG_FTV_PG</td>
1220 *         <td>Suitable for most but parents should guide their young</td>
1221 *     </tr>
1222 *     <tr>
1223 *         <td>SG_FTV_PG13</td>
1224 *         <td>Parental Guidance Strongly Cautioned - Suitable for 13 And Above</td>
1225 *     </tr>
1226 *     <tr>
1227 *         <td valign="top" rowspan="2">SG_PTV</td>
1228 *         <td>SG_PTV_NC16</td>
1229 *         <td>No Children Under 16</td>
1230 *     </tr>
1231 *     <tr>
1232 *         <td>SG_PTV_M18</td>
1233 *         <td>Nobody under age 18 is admitted</td>
1234 *     </tr>
1235 *     <tr>
1236 *         <td valign="top" rowspan="4">SI_TV</td>
1237 *         <td>SI_TV_VS</td>
1238 *         <td>Parental guidance suggested (for children under 6)</td>
1239 *     </tr>
1240 *     <tr>
1241 *         <td>SI_TV_12</td>
1242 *         <td>Content suitable for teens over 12 years</td>
1243 *     </tr>
1244 *     <tr>
1245 *         <td>SI_TV_15</td>
1246 *         <td>Content suitable for teens over 15 years</td>
1247 *     </tr>
1248 *     <tr>
1249 *         <td>SI_TV_AD</td>
1250 *         <td>Content exclusively for adults</td>
1251 *     </tr>
1252 *     <tr>
1253 *         <td valign="top" rowspan="6">TH_TV</td>
1254 *         <td>TH_TV_P</td>
1255 *         <td>Content suitable for primary school aged children</td>
1256 *     </tr>
1257 *     <tr>
1258 *         <td>TH_TV_C</td>
1259 *         <td>Content suitable for children between 6-12 years old</td>
1260 *     </tr>
1261 *     <tr>
1262 *         <td>TH_TV_G</td>
1263 *         <td>Content suitable for general audiences</td>
1264 *     </tr>
1265 *     <tr>
1266 *         <td>TH_TV_PG13</td>
1267 *         <td>Content suitable for people aged 13 and above, but can be watched by those who are
1268 *         under the recommended age if parental guidance is provided</td>
1269 *     </tr>
1270 *     <tr>
1271 *         <td>TH_TV_PG18</td>
1272 *         <td>Content suitable for people aged above 18 years old; those who are younger that 18
1273 *         must be provided with parental guidance</td>
1274 *     </tr>
1275 *     <tr>
1276 *         <td>TH_TV_A</td>
1277 *         <td>Content unsuitable for children and youngsters</td>
1278 *     </tr>
1279 *     <tr>
1280 *         <td valign="top" rowspan="4">TR_TV</td>
1281 *         <td>TR_TV_G</td>
1282 *         <td>General audience. Suitable for all ages</td>
1283 *     </tr>
1284 *     <tr>
1285 *         <td>TR_TV_7</td>
1286 *         <td>Suitable for ages 7 and over</td>
1287 *     </tr>
1288 *     <tr>
1289 *         <td>TR_TV_13</td>
1290 *         <td>Suitable for ages 13 and over</td>
1291 *     </tr>
1292 *     <tr>
1293 *         <td>TR_TV_18</td>
1294 *         <td>Suitable for ages 13 and over</td>
1295 *     </tr>
1296 *     <tr>
1297 *         <td valign="top" rowspan="4">TW_TV</td>
1298 *         <td>TW_TV_G</td>
1299 *         <td>For all ages</td>
1300 *     </tr>
1301 *     <tr>
1302 *         <td>TW_TV_P</td>
1303 *         <td>Not suitable for children under 6 years old. People aged 6 but under 12 require
1304 *         guidance from accompanying adults to watch</td>
1305 *     </tr>
1306 *     <tr>
1307 *         <td>TW_TV_PG</td>
1308 *         <td>Not suitable for people under 12 years of age. Parental guidance is required for
1309 *         people aged 12 but under 18</td>
1310 *     </tr>
1311 *     <tr>
1312 *         <td>TW_TV_R</td>
1313 *         <td>For adults only and people under 18 years of age must not watch</td>
1314 *     </tr>
1315 *     <tr>
1316 *         <td valign="top" rowspan="3">UA_TV</td>
1317 *         <td>UA_TV_G</td>
1318 *         <td>This program does not have age restrictions</td>
1319 *     </tr>
1320 *     <tr>
1321 *         <td>UA_TV_Y</td>
1322 *         <td>Children must view this program with parents. In it program there are fragments,
1323 *         which unsuitable for children</td>
1324 *     </tr>
1325 *     <tr>
1326 *         <td>UA_TV_R</td>
1327 *         <td>This program is only for adult viewers. In it there are scenes with nudity, drug use,
1328 *         or violence</td>
1329 *     </tr>
1330 *     <tr>
1331 *         <td valign="top" rowspan="6">US_TV</td>
1332 *         <td>US_TV_Y</td>
1333 *         <td>This program is designed to be appropriate for all children</td>
1334 *     </tr>
1335 *     <tr>
1336 *         <td>US_TV_Y7</td>
1337 *         <td>This program is designed for children age 7 and above</td>
1338 *     </tr>
1339 *     <tr>
1340 *         <td>US_TV_G</td>
1341 *         <td>Most parents would find this program suitable for all ages</td>
1342 *     </tr>
1343 *     <tr>
1344 *         <td>US_TV_PG</td>
1345 *         <td>This program contains material that parents may find unsuitable for younger children
1346 *         </td>
1347 *     </tr>
1348 *     <tr>
1349 *         <td>US_TV_14</td>
1350 *         <td>This program contains some material that many parents would find unsuitable for
1351 *         children under 14 years of age</td>
1352 *     </tr>
1353 *     <tr>
1354 *         <td>US_TV_MA</td>
1355 *         <td>This program is specifically designed to be viewed by adults and therefore may be
1356 *         unsuitable for children under 17</td>
1357 *     </tr>
1358 *     <tr>
1359 *         <td valign="top" rowspan="3">VE_TV</td>
1360 *         <td>VE_TV_TU</td>
1361 *         <td>For all ages</td>
1362 *     </tr>
1363 *     <tr>
1364 *         <td>VE_TV_SU</td>
1365 *         <td>Parental guidance for young viewers</td>
1366 *     </tr>
1367 *     <tr>
1368 *         <td>VE_TV_A</td>
1369 *         <td>Mature viewers</td>
1370 *     </tr>
1371 *     <tr>
1372 *         <td valign="top" rowspan="6">ZA_TV</td>
1373 *         <td>ZA_TV_F</td>
1374 *         <td>This is a program/film that does not contain any obscenity, and is suitable for
1375 *         family viewing. A logo must be displayed in the corner of the screen for 30 seconds after
1376 *         each commercial break</td>
1377 *     </tr>
1378 *     <tr>
1379 *         <td>ZA_TV_PG</td>
1380 *         <td>Children under 6 may watch this program/film, but must be accompanied by an adult.
1381 *         This program contains an adult related theme, which might include very mild language,
1382 *         violence and sexual innuendo. A logo must be displayed in the corner of the screen for
1383 *         one minute after each commercial break</td>
1384 *     </tr>
1385 *     <tr>
1386 *         <td>ZA_TV_13</td>
1387 *         <td>Children under 13 are prohibited from watching this program/film. This program
1388 *         contains mild language, violence and sexual innuendo. A logo must be displayed in the
1389 *         corner of the screen for two minutes after each commercial break</td>
1390 *     </tr>
1391 *     <tr>
1392 *         <td>ZA_TV_16</td>
1393 *         <td>Children under 16 are prohibited from watching this program/film. It contains
1394 *         moderate violence, language, and some sexual situations. In the case of television, this
1395 *         program may only be broadcast after 9pm-4:30am. A logo must be displayed in the corner of
1396 *         the screen for five minutes after each commercial break. A full-screen warning must be
1397 *         issued before the start of the program. If the program is longer than an hour, a warning
1398 *         must be displayed every half an hour</td>
1399 *     </tr>
1400 *     <tr>
1401 *         <td>ZA_TV_18</td>
1402 *         <td>Children under 18 are prohibited from watching this program/film. It contains extreme
1403 *         violence, language and/or graphic sexual content. In the case of television, this program
1404 *         may only be broadcast from 10pm-4:30am. A logo must be displayed in the corner of the
1405 *         screen for the duration of the program. A full-screen warning must be issued before the
1406 *         start of the program and after each commercial break</td>
1407 *     </tr>
1408 *     <tr>
1409 *         <td>ZA_TV_R18</td>
1410 *         <td>This is reserved for films of an extreme sexual nature (pornography). R18 films may
1411 *         only be distributed in the form of video and DVD in a controlled environment (e.g. Adult
1412 *         Shops). No public viewing of this film may take place. R18 films may not be broadcast on
1413 *         television and in cinemas</td>
1414 *     </tr>
1415 * </table>
1416 *
1417 * <h4>System defined strings for sub-ratings</h4>
1418 * <table>
1419 *     <tr>
1420 *         <th>Rating System</th>
1421 *         <th>Constant Value</th>
1422 *         <th>Description</th>
1423 *     </tr>
1424 *     <tr>
1425 *         <td valign="top" rowspan="6">NL_TV</td>
1426 *         <td>NL_TV_V</td>
1427 *         <td>Violence<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12, NL_TV_16</td>
1428 *     </tr>
1429 *     <tr>
1430 *         <td>NL_TV_F</td>
1431 *         <td>Scary or Disturbing ContentViolence<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9,
1432 *         NL_TV_12, NL_TV_16</td>
1433 *     </tr>
1434 *     <tr>
1435 *         <td>NL_TV_S</td>
1436 *         <td>Sexual Content<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12, NL_TV_16</td>
1437 *     </tr>
1438 *     <tr>
1439 *         <td>NL_TV_D</td>
1440 *         <td>Discrimination<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12, NL_TV_16</td>
1441 *     </tr>
1442 *     <tr>
1443 *         <td>NL_TV_DA</td>
1444 *         <td>Drug and/or Alcohol abuse<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12,
1445 *         NL_TV_16</td>
1446 *     </tr>
1447 *     <tr>
1448 *         <td>NL_TV_L</td>
1449 *         <td>Bad Language<br/>Applicable to NL_TV_AL, NL_TV_6, NL_TV_9, NL_TV_12, NL_TV_16</td>
1450 *     </tr>
1451 *     <tr>
1452 *         <td valign="top" rowspan="4">NZ_PTV</td>
1453 *         <td>NZ_PTV_C</td>
1454 *         <td>Content may offend<br/>Applicable to NZ_PTV_PG, NZ_PTV_M, NZ_PTV_16, NZ_PTV_18</td>
1455 *     </tr>
1456 *     <tr>
1457 *         <td>NZ_PTV_V</td>
1458 *         <td>Violence<br/>Applicable to NZ_PTV_PG, NZ_PTV_M, NZ_PTV_16, NZ_PTV_18</td>
1459 *     </tr>
1460 *     <tr>
1461 *         <td>NZ_PTV_L</td>
1462 *         <td>Language<br/>Applicable to NZ_PTV_PG, NZ_PTV_M, NZ_PTV_16, NZ_PTV_18</td>
1463 *     </tr>
1464 *     <tr>
1465 *         <td>NZ_PTV_S</td>
1466 *         <td>Sexual content<br/>Applicable to NZ_PTV_PG, NZ_PTV_M, NZ_PTV_16, NZ_PTV_18</td>
1467 *     </tr>
1468 *     <tr>
1469 *         <td valign="top" rowspan="5">US_TV</td>
1470 *         <td>US_TV_D</td>
1471 *         <td>Suggestive dialogue (Usually means talks about sex)<br/>Applicable to US_TV_PG,
1472 *         US_TV_14, US_TV</td>
1473 *     </tr>
1474 *     <tr>
1475 *         <td>US_TV_L</td>
1476 *         <td>Coarse language<br/>Applicable to US_TV_PG, US_TV_14</td>
1477 *     </tr>
1478 *     <tr>
1479 *         <td>US_TV_S</td>
1480 *         <td>Sexual content<br/>Applicable to US_TV_PG, US_TV_14, US_TV_MA</td>
1481 *     </tr>
1482 *     <tr>
1483 *         <td>US_TV_V</td>
1484 *         <td>Violence<br/>Applicable to US_TV_PG, US_TV_14, US_TV_MA</td>
1485 *     </tr>
1486 *     <tr>
1487 *         <td>US_TV_FV</td>
1488 *         <td>Fantasy violence (Children's programming only)<br/>Applicable to US_TV_Y7</td>
1489 *     </tr>
1490 *     <tr>
1491 *         <td valign="top" rowspan="6">ZA_TV</td>
1492 *         <td>ZA_TV_D</td>
1493 *         <td>Drug<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18
1494 *         </td>
1495 *     </tr>
1496 *     <tr>
1497 *         <td>ZA_TV_V</td>
1498 *         <td>Violence<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18
1499 *         </td>
1500 *     </tr>
1501 *     <tr>
1502 *         <td>ZA_TV_N</td>
1503 *         <td>Nudity<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18
1504 *         </td>
1505 *     </tr>
1506 *     <tr>
1507 *         <td>ZA_TV_P</td>
1508 *         <td>Prejudice<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18,
1509 *         ZA_TV_R18</td>
1510 *     </tr>
1511 *     <tr>
1512 *         <td>ZA_TV_S</td>
1513 *         <td>Sex<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18</td>
1514 *     </tr>
1515 *     <tr>
1516 *         <td>ZA_TV_L</td>
1517 *         <td>Language<br/>Applicable to ZA_TV_F, ZA_TV_PG, ZA_TV_13, ZA_TV_16, ZA_TV_18, ZA_TV_R18
1518 *         </td>
1519 *     </tr>
1520 * </table>
1521 */
1522public final class TvContentRating {
1523    // TODO: Consider to use other DELIMITER. In some countries such as India may use this delimiter
1524    // in the main ratings.
1525    private static final String DELIMITER = "/";
1526
1527    private final String mDomain;
1528    private final String mRatingSystem;
1529    private final String mRating;
1530    private final String[] mSubRatings;
1531    private final int mHashCode;
1532
1533    /**
1534     * Creates a {@code TvContentRating} object with predefined content rating strings.
1535     *
1536     * @param domain The domain string. For example, "com.android.tv".
1537     * @param ratingSystem The rating system string. For example, "US_TV".
1538     * @param rating The content rating string. For example, "US_TV_PG".
1539     * @param subRatings The sub-rating strings. For example, "US_TV_D" and "US_TV_L".
1540     * @return A {@code TvContentRating} object.
1541     * @throws IllegalArgumentException If {@code domain}, {@code ratingSystem} or {@code rating} is
1542     *             {@code null}.
1543     */
1544    public static TvContentRating createRating(String domain, String ratingSystem,
1545            String rating, String... subRatings) {
1546        if (TextUtils.isEmpty(domain)) {
1547            throw new IllegalArgumentException("domain cannot be empty");
1548        }
1549        if (TextUtils.isEmpty(ratingSystem)) {
1550            throw new IllegalArgumentException("ratingSystem cannot be empty");
1551        }
1552        if (TextUtils.isEmpty(rating)) {
1553            throw new IllegalArgumentException("rating cannot be empty");
1554        }
1555        return new TvContentRating(domain, ratingSystem, rating, subRatings);
1556    }
1557
1558    /**
1559     * Recovers a {@code TvContentRating} object from the string that was previously created from
1560     * {@link #flattenToString}.
1561     *
1562     * @param ratingString The string returned by {@link #flattenToString}.
1563     * @return the {@code TvContentRating} object containing the domain, rating system, rating and
1564     *         sub-ratings information encoded in {@code ratingString}.
1565     * @see #flattenToString
1566     */
1567    public static TvContentRating unflattenFromString(String ratingString) {
1568        if (TextUtils.isEmpty(ratingString)) {
1569            throw new IllegalArgumentException("ratingString cannot be empty");
1570        }
1571        String[] strs = ratingString.split(DELIMITER);
1572        if (strs.length < 3) {
1573            throw new IllegalArgumentException("Invalid rating string: " + ratingString);
1574        }
1575        if (strs.length > 3) {
1576            String[] subRatings = new String[strs.length - 3];
1577            System.arraycopy(strs, 3, subRatings, 0, subRatings.length);
1578            return new TvContentRating(strs[0], strs[1], strs[2], subRatings);
1579        }
1580        return new TvContentRating(strs[0], strs[1], strs[2], null);
1581    }
1582
1583    /**
1584     * Constructs a TvContentRating object from a given rating and sub-rating constants.
1585     *
1586     * @param domain The string for domain of the content rating system such as "com.android.tv".
1587     * @param ratingSystem The rating system string such as "US_TV".
1588     * @param rating The content rating string such as "US_TV_PG".
1589     * @param subRatings The sub-rating strings such as "US_TV_D" and "US_TV_L".
1590     */
1591    private TvContentRating(
1592            String domain, String ratingSystem, String rating, String[] subRatings) {
1593        mDomain = domain;
1594        mRatingSystem = ratingSystem;
1595        mRating = rating;
1596        if (subRatings == null || subRatings.length == 0) {
1597            mSubRatings = null;
1598        } else {
1599            Arrays.sort(subRatings);
1600            mSubRatings = subRatings;
1601        }
1602        mHashCode = 31 * Objects.hash(mDomain, mRating) + Arrays.hashCode(mSubRatings);
1603    }
1604
1605    /**
1606     * Returns the domain of this {@code TvContentRating} object.
1607     */
1608    public String getDomain() {
1609        return mDomain;
1610    }
1611
1612    /**
1613     * Returns the rating system of this {@code TvContentRating} object.
1614     */
1615    public String getRatingSystem() {
1616        return mRatingSystem;
1617    }
1618
1619    /**
1620     * Returns the main rating of this {@code TvContentRating} object.
1621     */
1622    public String getMainRating() {
1623        return mRating;
1624    }
1625
1626    /**
1627     * Returns the unmodifiable sub-rating string {@link List} of this {@code TvContentRating}
1628     * object.
1629     */
1630    public List<String> getSubRatings() {
1631        if (mSubRatings == null) {
1632            return null;
1633        }
1634        return Collections.unmodifiableList(Arrays.asList(mSubRatings));
1635    }
1636
1637    /**
1638     * Returns a string that unambiguously describes the rating information contained in a
1639     * {@code TvContentRating} object. One can later recover the object from this string through
1640     * {@link #unflattenFromString}.
1641     *
1642     * @return a string containing the rating information, which can later be stored in the
1643     *         database.
1644     * @see #unflattenFromString
1645     */
1646    public String flattenToString() {
1647        StringBuilder builder = new StringBuilder();
1648        builder.append(mDomain);
1649        builder.append(DELIMITER);
1650        builder.append(mRatingSystem);
1651        builder.append(DELIMITER);
1652        builder.append(mRating);
1653        if (mSubRatings != null) {
1654            for (String subRating : mSubRatings) {
1655                builder.append(DELIMITER);
1656                builder.append(subRating);
1657            }
1658        }
1659        return builder.toString();
1660    }
1661
1662    /**
1663     * Returns {@code true} if this rating has the same main rating as the specified rating and when
1664     * this rating's sub-ratings contain the other's.
1665     * <p>
1666     * For example, a {@code TvContentRating} object that represents TV-PG with S(Sexual content)
1667     * and V(Violence) contains TV-PG, TV-PG/S, TV-PG/V and itself.
1668     * </p>
1669     *
1670     * @param rating The {@link TvContentRating} to check.
1671     * @return {@code true} if this object contains {@code rating}, {@code false} otherwise.
1672     * @hide
1673     */
1674    @SystemApi
1675    public final boolean contains(TvContentRating rating) {
1676        if (rating == null) {
1677            throw new IllegalArgumentException("rating cannot be null");
1678        }
1679        if (!rating.getMainRating().equals(mRating)) {
1680            return false;
1681        }
1682        if (!rating.getDomain().equals(mDomain) ||
1683                !rating.getRatingSystem().equals(mRatingSystem) ||
1684                !rating.getMainRating().equals(mRating)) {
1685            return false;
1686        }
1687        List<String> subRatings = getSubRatings();
1688        List<String> subRatingsOther = rating.getSubRatings();
1689        if (subRatings == null && subRatingsOther == null) {
1690            return true;
1691        } else if (subRatings == null && subRatingsOther != null) {
1692            return false;
1693        } else if (subRatings != null && subRatingsOther == null) {
1694            return true;
1695        } else {
1696            return subRatings.containsAll(subRatingsOther);
1697        }
1698    }
1699
1700    @Override
1701    public boolean equals(Object obj) {
1702        if (!(obj instanceof TvContentRating)) {
1703            return false;
1704        }
1705        TvContentRating other = (TvContentRating) obj;
1706        if (mHashCode != other.mHashCode) {
1707            return false;
1708        }
1709        if (!TextUtils.equals(mDomain, other.mDomain)) {
1710            return false;
1711        }
1712        if (!TextUtils.equals(mRatingSystem, other.mRatingSystem)) {
1713            return false;
1714        }
1715        if (!TextUtils.equals(mRating, other.mRating)) {
1716            return false;
1717        }
1718        return Arrays.equals(mSubRatings, other.mSubRatings);
1719    }
1720
1721    @Override
1722    public int hashCode() {
1723        return mHashCode;
1724    }
1725}
1726