Ejemplo n.º 1
0
  /**
   * Generate status of the features that have been activated on the device.
   *
   * @param syncmlDocument syncmlDocument object pasrsed from the syncml engine.
   * @return device statuses for the activated features
   * @throws NotificationManagementException
   */
  public List<Profile> generateDeviceOperationStatusObject(SyncmlDocument syncmlDocument)
      throws NotificationManagementException, WindowsOperationException {

    DeviceIdentifier deviceIdentifier =
        convertToDeviceIdentifierObject(syncmlDocument.getHeader().getSource().getLocURI());
    String lockUri = null;
    ResultsTag result = syncmlDocument.getBody().getResults();

    List<Profile> profiles = new ArrayList<>();
    if (result != null) {
      List<ItemTag> results = result.getItem();
      for (OperationCode.Info info : OperationCode.Info.values()) {
        if (PluginConstants.OperationCodes.PIN_CODE.equals(info.name())) {
          lockUri = info.getCode();
        }
      }
      for (ItemTag item : results) {
        for (OperationCode.Info info : OperationCode.Info.values()) {
          if (item.getSource().getLocURI().equals(info.getCode())
              && PluginConstants.OperationCodes.CAMERA_STATUS.equals(info.name())) {
            Profile cameraProfile = new Profile();
            cameraProfile.setFeatureCode(PluginConstants.OperationCodes.CAMERA);
            cameraProfile.setData(item.getData());
            if ((PluginConstants.SyncML.SYNCML_DATA_ONE.equals(item.getData()))) {
              cameraProfile.setEnable(true);
            } else {
              cameraProfile.setEnable(false);
            }
            profiles.add(cameraProfile);
          }
          if (item.getSource().getLocURI().equals(info.getCode())
              && PluginConstants.OperationCodes.ENCRYPT_STORAGE_STATUS.equals(info.name())) {
            Profile encryptStorage = new Profile();
            encryptStorage.setFeatureCode(PluginConstants.OperationCodes.ENCRYPT_STORAGE);
            encryptStorage.setData(item.getData());
            if ((PluginConstants.SyncML.SYNCML_DATA_ONE.equals(item.getData()))) {
              encryptStorage.setEnable(true);
            } else {
              encryptStorage.setEnable(false);
            }
            profiles.add(encryptStorage);
          }
          if (item.getSource().getLocURI().equals(info.getCode())
              && PluginConstants.OperationCodes.DEVICE_PASSWORD_STATUS.equals(info.name())) {
            Profile encryptStorage = new Profile();
            encryptStorage.setFeatureCode(PluginConstants.OperationCodes.PASSCODE_POLICY);
            encryptStorage.setData(item.getData());
            if ((PluginConstants.SyncML.SYNCML_DATA_ZERO.equals(item.getData()))) {
              encryptStorage.setEnable(true);
            } else {
              encryptStorage.setEnable(false);
            }
            profiles.add(encryptStorage);
          }
          if (!item.getData().isEmpty() && item.getSource().getLocURI().equals(lockUri)) {
            String pinValue = item.getData();
            NotificationManagementService nmService =
                WindowsAPIUtils.getNotificationManagementService();
            Notification notification = new Notification();
            notification.setDescription("Auto generated DevicePin : " + pinValue);
            notification.setOperationId(result.getCommandReference());
            notification.setDeviceIdentifier(deviceIdentifier);
            notification.setStatus(String.valueOf(Notification.Status.NEW));
            try {
              nmService.addNotification(notification);
            } catch (NotificationManagementException e) {
              String msg = "Failure Occurred in getting notification service.";
              log.error(msg, e);
              throw new WindowsOperationException(msg, e);
            }
            break;
          }
        }
      }
    }
    return profiles;
  }
package isola.tags.ext.menu;