1 package com.android.tv.util; 2 3 import android.content.Context; 4 import android.content.pm.PackageManager; 5 6 /** 7 * Util class to handle permissions. 8 */ 9 public class PermissionUtils { 10 /** 11 * Permission to read the TV listings. 12 */ 13 public static final String PERMISSION_READ_TV_LISTINGS = "android.permission.READ_TV_LISTINGS"; 14 15 private static Boolean sHasAccessAllEpgPermission; 16 private static Boolean sHasAccessWatchedHistoryPermission; 17 private static Boolean sHasModifyParentalControlsPermission; 18 hasAccessAllEpg(Context context)19 public static boolean hasAccessAllEpg(Context context) { 20 if (sHasAccessAllEpgPermission == null) { 21 sHasAccessAllEpgPermission = context.checkSelfPermission( 22 "com.android.providers.tv.permission.ACCESS_ALL_EPG_DATA") 23 == PackageManager.PERMISSION_GRANTED; 24 } 25 return sHasAccessAllEpgPermission; 26 } 27 hasAccessWatchedHistory(Context context)28 public static boolean hasAccessWatchedHistory(Context context) { 29 if (sHasAccessWatchedHistoryPermission == null) { 30 sHasAccessWatchedHistoryPermission = context.checkSelfPermission( 31 "com.android.providers.tv.permission.ACCESS_WATCHED_PROGRAMS") 32 == PackageManager.PERMISSION_GRANTED; 33 } 34 return sHasAccessWatchedHistoryPermission; 35 } 36 hasModifyParentalControls(Context context)37 public static boolean hasModifyParentalControls(Context context) { 38 if (sHasModifyParentalControlsPermission == null) { 39 sHasModifyParentalControlsPermission = context.checkSelfPermission( 40 "android.permission.MODIFY_PARENTAL_CONTROLS") 41 == PackageManager.PERMISSION_GRANTED; 42 } 43 return sHasModifyParentalControlsPermission; 44 } 45 hasReadTvListings(Context context)46 public static boolean hasReadTvListings(Context context) { 47 return context.checkSelfPermission(PERMISSION_READ_TV_LISTINGS) 48 == PackageManager.PERMISSION_GRANTED; 49 } 50 hasInternet(Context context)51 public static boolean hasInternet(Context context) { 52 return context.checkSelfPermission("android.permission.INTERNET") 53 == PackageManager.PERMISSION_GRANTED; 54 } 55 } 56