Ejemplo n.º 1
0
  /**
   * Cancel the last message sent for the given messageType
   *
   * @param messageType
   * @throws NotificationServiceException
   */
  public void deleteLastMessage(NotificationMessageType messageType)
      throws NotificationServiceException {

    TransportChannelObject senderChannel = transportSenderChannels.get(messageType);
    if (senderChannel == null) {
      throw new NotificationServiceException(
          "Received an unknown message type: '"
              + messageType
              + "', can't find a transport channel to delete the notification");
    }

    // delete the last message of this messageType
    senderChannel.deleteNotification();
  } // deleteLastMessage
Ejemplo n.º 2
0
  /**
   * Called when we need to send a signal
   *
   * @param version The version of the message signature
   * @param msgId notification Id the id of the sent signal
   * @param messageType The message type of the sent message
   * @param deviceId Device id
   * @param deviceName Device name
   * @param appId App id
   * @param appName App name
   * @param attributes All the notification metadata
   * @param customAttributes The customAttributes
   * @param text Array of texts to be sent
   * @param ttl Notification message TTL
   * @throws NotificationServiceException
   */
  public void sendNotification(
      int version,
      int msgId,
      NotificationMessageType messageType,
      String deviceId,
      String deviceName,
      byte[] appId,
      String appName,
      Map<Integer, Variant> attributes,
      Map<String, String> customAttributes,
      TransportNotificationText[] text,
      int ttl)
      throws NotificationServiceException {

    GenericLogger logger = nativePlatform.getNativeLogger();

    if (stopSending) {
      logger.debug(TAG, "In stopSending mode NOT sending notification!!!");
      return;
    }

    TransportChannelObject senderChannel = transportSenderChannels.get(messageType);
    if (senderChannel == null) {
      throw new NotificationServiceException(
          "Received an unknown message type: '"
              + messageType
              + "', can't find a transport channel to send the notification");
    }

    // send this notification to the correct object based on messageType
    senderChannel.sendNotification(
        version,
        msgId,
        messageType.getTypeId(),
        deviceId,
        deviceName,
        appId,
        appName,
        attributes,
        customAttributes,
        text,
        ttl);
  } // sendNotification
Ejemplo n.º 3
0
  /** @param notifId The notification id of the notification message to be deleted */
  private void deleteNotificationById(int notifId) {

    GenericLogger logger = nativePlatform.getNativeLogger();
    logger.debug(
        TAG,
        "Trying to delete the notification by id: '"
            + notifId
            + "', searching for the relevant object");

    boolean isObjFound = false;

    for (TransportChannelObject channelObj : transportSenderChannels.values()) {

      channelObj.acquireLock(); // Lock the object to prevent changing its
      // state

      Integer chanObjNotifId = channelObj.getNotificationId();

      if (chanObjNotifId != null && chanObjNotifId == notifId) { // Found
        // the
        // object
        // to be
        // cancelled
        logger.debug(TAG, "Found the object with notifId: '" + notifId + "' to be cancelled");
        channelObj.deleteNotification();
        isObjFound = true;
        channelObj.releaseLock(); // release the lock
        break;
      } else {
        channelObj.releaseLock(); // release the lock and continue
        // iterating
      }
    }

    if (!isObjFound) {
      logger.debug(TAG, "Failed to find the Notification with Id: '" + notifId + "'");
    }
  }