Ejemplo 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());
       }
     }
   }
 }
Ejemplo n.º 2
0
  /**
   * Checks the read permission.
   *
   * @throws SecurityException if read is not allowed
   */
  private static void checkReadPermission() {
    MIDletSuite suite = Scheduler.getScheduler().getMIDletSuite();

    try {
      suite.checkForPermission(Permissions.FILE_CONNECTION_READ, null);
    } catch (InterruptedException ie) {
      throw new SecurityException("Interrupted while trying to ask the user permission");
    }
  }
Ejemplo n.º 3
0
  /**
   * Queues the last suite to run when there is not a next Suite to run. This value will be
   * persistent until it is used. Not used in MVM mode.
   *
   * @param id ID of an installed suite
   * @param midlet class name of MIDlet to invoke
   * @exception SecurityException if the caller does not have permission to manage midlets
   */
  public static void setLastSuiteToRun(int id, String midlet, String arg0, String arg1) {

    MIDletSuite midletSuite = MIDletStateHandler.getMidletStateHandler().getMIDletSuite();

    // if a MIDlet suite is not scheduled, assume the JAM is calling.
    if (midletSuite != null) {
      midletSuite.checkIfPermissionAllowed(Permissions.AMS);
    }

    lastMidletSuiteToRun = id;
    lastMidletToRun = midlet;
    arg0ForLastMidlet = arg0;
    arg1ForLastMidlet = arg1;
  }
Ejemplo n.º 4
0
  /**
   * Adds a property to the suite.
   *
   * @param key the name of the property
   * @param value the value of the property
   * @exception SecurityException if the calling suite does not have internal API permission
   */
  public void addProperty(String key, String value) {
    MIDletSuite current = Scheduler.getScheduler().getMIDletSuite();

    if (current != null) {
      current.checkIfPermissionAllowed(Permissions.MIDP);
    }

    if (bufferedJadProps != null) {
      bufferedJadProps.addProperty(key, value);
      return;
    }

    bufferedJarProps.addProperty(key, value);
  }
Ejemplo n.º 5
0
  /**
   * Install a suite.
   *
   * @param selectedSuite index into the installList
   */
  private void installSuite(int selectedSuite) {
    MIDletStateHandler midletStateHandler = MIDletStateHandler.getMidletStateHandler();
    MIDletSuite midletSuite = midletStateHandler.getMIDletSuite();
    SuiteDownloadInfo suite;
    String displayName;

    suite = (SuiteDownloadInfo) installList.elementAt(selectedSuite);

    midletSuite.setTempProperty(null, "arg-0", "I");
    midletSuite.setTempProperty(null, "arg-1", suite.url);
    midletSuite.setTempProperty(null, "arg-2", suite.label);

    displayName = Resource.getString(ResourceConstants.INSTALL_APPLICATION);
    try {
      midletStateHandler.startMIDlet("com.sun.midp.installer.GraphicalInstaller", displayName);
      /*
       * Give the create MIDlet notification 1 second to get to
       * AMS.
       */
      Thread.sleep(1000);
      notifyDestroyed();
    } catch (Exception ex) {
      StringBuffer sb = new StringBuffer();

      sb.append(displayName);
      sb.append("\n");
      sb.append(Resource.getString(ResourceConstants.ERROR));
      sb.append(": ");
      sb.append(ex.toString());

      Alert a =
          new Alert(
              Resource.getString(ResourceConstants.AMS_CANNOT_START),
              sb.toString(),
              null,
              AlertType.ERROR);
      a.setTimeout(Alert.FOREVER);
      display.setCurrent(a, urlTextBox);
    }
  }