Home | History | Annotate | Download | only in util
      1 package com.android.tv.util;
      2 
      3 import android.content.Context;
      4 import android.content.pm.PackageManager;
      5 import android.os.Build;
      6 
      7 /**
      8  * Util class to handle permissions.
      9  */
     10 public class PermissionUtils {
     11     private static Boolean sHasAccessAllEpgPermission;
     12     private static Boolean sHasAccessWatchedHistoryPermission;
     13     private static Boolean sHasModifyParentalControlsPermission;
     14 
     15     public static boolean hasAccessAllEpg(Context context) {
     16         if (sHasAccessAllEpgPermission == null) {
     17             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     18                 sHasAccessAllEpgPermission = context.checkSelfPermission(
     19                         "com.android.providers.tv.permission.ACCESS_ALL_EPG_DATA")
     20                         == PackageManager.PERMISSION_GRANTED;
     21             } else {
     22                 sHasAccessAllEpgPermission = context.getPackageManager().checkPermission(
     23                         "com.android.providers.tv.permission.ACCESS_ALL_EPG_DATA",
     24                         context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
     25             }
     26         }
     27         return sHasAccessAllEpgPermission;
     28     }
     29 
     30     public static boolean hasAccessWatchedHistory(Context context) {
     31         if (sHasAccessWatchedHistoryPermission == null) {
     32             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     33                 sHasAccessWatchedHistoryPermission = context.checkSelfPermission(
     34                         "com.android.providers.tv.permission.ACCESS_WATCHED_PROGRAMS")
     35                         == PackageManager.PERMISSION_GRANTED;
     36             } else {
     37                 sHasAccessWatchedHistoryPermission = context.getPackageManager().checkPermission(
     38                         "com.android.providers.tv.permission.ACCESS_WATCHED_PROGRAMS",
     39                         context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
     40             }
     41         }
     42         return sHasAccessWatchedHistoryPermission;
     43     }
     44 
     45     public static boolean hasModifyParentalControls(Context context) {
     46         if (sHasModifyParentalControlsPermission == null) {
     47             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     48                 sHasModifyParentalControlsPermission = context.checkSelfPermission(
     49                         "android.permission.MODIFY_PARENTAL_CONTROLS")
     50                         == PackageManager.PERMISSION_GRANTED;
     51             } else {
     52                 sHasModifyParentalControlsPermission = context.getPackageManager().checkPermission(
     53                         "android.permission.MODIFY_PARENTAL_CONTROLS",
     54                         context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
     55             }
     56         }
     57         return sHasModifyParentalControlsPermission;
     58     }
     59 
     60     public static boolean hasReadTvListings(Context context) {
     61         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     62             return context.checkSelfPermission("android.permission.READ_TV_LISTINGS")
     63                     == PackageManager.PERMISSION_GRANTED;
     64         } else {
     65             return context.getPackageManager().checkPermission(
     66                     "android.permission.MODIFY_PARENTAL_CONTROLS",
     67                     context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
     68         }
     69     }
     70 }
     71