Home | History | Annotate | Download | only in tv
      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 
     17 package android.media.tv;
     18 
     19 import android.annotation.SystemApi;
     20 import android.content.ContentResolver;
     21 import android.content.pm.ApplicationInfo;
     22 import android.net.Uri;
     23 import android.os.Parcel;
     24 import android.os.Parcelable;
     25 
     26 /**
     27  * TvContentRatingSystemInfo class provides information about a specific TV content rating system
     28  * defined either by a system app or by a third-party app.
     29  *
     30  * @hide
     31  */
     32 @SystemApi
     33 public final class TvContentRatingSystemInfo implements Parcelable {
     34     private final Uri mXmlUri;
     35 
     36     private final ApplicationInfo mApplicationInfo;
     37 
     38     /**
     39      * Creates a TvContentRatingSystemInfo object with given resource ID and receiver info.
     40      *
     41      * @param xmlResourceId The ID of an XML resource whose root element is
     42      *            <code> &lt;rating-system-definitions&gt;</code>
     43      * @param applicationInfo Information about the application that provides the TV content rating
     44      *            system definition.
     45      */
     46     public static final TvContentRatingSystemInfo createTvContentRatingSystemInfo(int xmlResourceId,
     47             ApplicationInfo applicationInfo) {
     48         Uri uri = new Uri.Builder()
     49                 .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
     50                 .authority(applicationInfo.packageName)
     51                 .appendPath(String.valueOf(xmlResourceId))
     52                 .build();
     53         return new TvContentRatingSystemInfo(uri, applicationInfo);
     54     }
     55 
     56     private TvContentRatingSystemInfo(Uri xmlUri, ApplicationInfo applicationInfo) {
     57         mXmlUri = xmlUri;
     58         mApplicationInfo = applicationInfo;
     59     }
     60 
     61     /**
     62      * Returns {@code true} if the TV content rating system is defined by a system app,
     63      * {@code false} otherwise.
     64      */
     65     public final boolean isSystemDefined() {
     66         return (mApplicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
     67     }
     68 
     69     /**
     70      * Returns the URI to the XML resource that defines the TV content rating system.
     71      *
     72      * TODO: Remove. Instead, parse the XML resource and provide an interface to directly access
     73      * parsed information.
     74      */
     75     public final Uri getXmlUri() {
     76         return mXmlUri;
     77     }
     78 
     79     /**
     80      * Used to make this class parcelable.
     81      * @hide
     82      */
     83     public static final Parcelable.Creator<TvContentRatingSystemInfo> CREATOR =
     84             new Parcelable.Creator<TvContentRatingSystemInfo>() {
     85         @Override
     86         public TvContentRatingSystemInfo createFromParcel(Parcel in) {
     87             return new TvContentRatingSystemInfo(in);
     88         }
     89 
     90         @Override
     91         public TvContentRatingSystemInfo[] newArray(int size) {
     92             return new TvContentRatingSystemInfo[size];
     93         }
     94     };
     95 
     96     private TvContentRatingSystemInfo(Parcel in) {
     97         mXmlUri = in.readParcelable(null);
     98         mApplicationInfo = in.readParcelable(null);
     99     }
    100 
    101     @Override
    102     public void writeToParcel(Parcel dest, int flags) {
    103         dest.writeParcelable(mXmlUri, flags);
    104         dest.writeParcelable(mApplicationInfo, flags);
    105     }
    106 
    107     @Override
    108     public int describeContents() {
    109         return 0;
    110     }
    111 }
    112