Exemplo n.º 1
0
 /**
  * Checks for all the permissions that need to be present to open a list
  *
  * @param pimListType CONTACT_LIST, EVENT_LIST or TODO_LIST
  * @param mode READ_ONLY, WRITE_ONLY or READ_WRITE
  * @throws IllegalArgumentException if one of the parameters is out of bounds
  * @throws SecurityException if the application does not have the required permissions
  */
 private void checkPermissions(int pimListType, int mode) {
   int[] permissions = getPermissions(pimListType, mode);
   MIDletSuite suite = Scheduler.getScheduler().getMIDletSuite();
   /*
    * Do a first pass on the permissions to make sure that none is
    * automatically denied. This is for the case when both read permission
    * and write permission are required. It is possible that, for example,
    * read permission is granted only after asking the user, but write
    * permission is automatically denied. In this case, the user should
    * not be asked a question at all.
    */
   for (int i = 0; i < permissions.length; i++) {
     String name = Permissions.getName(permissions[i]);
     int status = suite.checkPermission(name);
     if (status == 0) {
       // throw an exception
       suite.checkIfPermissionAllowed(permissions[i]);
     } else if (status == 1) {
       // don't check this permission again
       permissions[i] = -1;
     }
   }
   for (int i = 0; i < permissions.length; i++) {
     if (permissions[i] != -1) {
       try {
         suite.checkForPermission(permissions[i], null);
       } catch (InterruptedException e) {
         throw new SecurityException("Security check interrupted: " + e.getMessage());
       }
     }
   }
 }