Home | History | Annotate | Download | only in nfc
      1 package com.android.nfc;
      2 
      3 
      4 import android.content.Context;
      5 import android.os.UserHandle;
      6 
      7 public class NfcPermissions {
      8 
      9     /**
     10      * NFC ADMIN permission - only for system apps
     11      */
     12     private static final String ADMIN_PERM = android.Manifest.permission.WRITE_SECURE_SETTINGS;
     13     private static final String ADMIN_PERM_ERROR = "WRITE_SECURE_SETTINGS permission required";
     14 
     15     /**
     16      * Regular NFC permission
     17      */
     18     static final String NFC_PERMISSION = android.Manifest.permission.NFC;
     19     private static final String NFC_PERM_ERROR = "NFC permission required";
     20 
     21     public static void validateUserId(int userId) {
     22         if (userId != UserHandle.getCallingUserId()) {
     23             throw new SecurityException("userId passed in is not the calling user.");
     24         }
     25     }
     26 
     27     public static void enforceAdminPermissions(Context context) {
     28         context.enforceCallingOrSelfPermission(ADMIN_PERM, ADMIN_PERM_ERROR);
     29     }
     30 
     31 
     32     public static void enforceUserPermissions(Context context) {
     33         context.enforceCallingOrSelfPermission(NFC_PERMISSION, NFC_PERM_ERROR);
     34     }
     35 }
     36