@Override
 public void connectionClosedOnError(Exception e) {
   Log.d(LOGTAG, "connectionClosedOnError()...");
   if (xmppManager.getConnection() != null && xmppManager.getConnection().isConnected()) {
     xmppManager.getConnection().disconnect();
   }
   //        xmppManager.startReconnectionThread();
 }
Beispiel #2
0
  /**
   * 加载联系人
   *
   * @return roster
   */
  public List<User> loadContacts() {
    ArrayList<User> users = new ArrayList<>();
    Collection<RosterEntry> entris = XmppManager.getConnection().getRoster().getEntries();
    Roster roster = XmppManager.getConnection().getRoster();

    for (RosterEntry entry : entris) {
      User user = transEntryToUser(entry, roster);
      users.add(user);
    }
    return users;
  }
  public void processPacket(Packet packet) {
    Log.d(LOGTAG, "NotificationPacketListener.processPacket()...");
    Log.d(LOGTAG, "packet.toXML()=" + packet.toXML());

    if (packet instanceof NotificationIQ) {
      NotificationIQ notification = (NotificationIQ) packet;

      if (notification.getChildElementXML().contains("androidpn:iq:notification")) {
        Log.d(LOGTAG, "ChildElementXML=" + notification.getChildElementXML());

        String configID = notification.getConfigID();
        String devID = notification.getDeviceID();
        ArrayList<Resource> lists = notification.getResources();

        String notificationFrom = notification.getFrom();
        String packetId = notification.getPacketID();

        Intent intent = new Intent(Constants.ACTION_SHOW_NOTIFICATION);

        intent.putExtra(Constants.NOTIFICATION_CONFIGURATION, configID);
        intent.putExtra(Constants.NOTIFICATION_DEVICEID, devID);

        /*将resource list 放入bundle中,将bundle放入Intent中,进行传输*/
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList(Constants.NOTIFICATION_RESOURCES_LIST, lists);

        Log.d("NPListener", "put the lists to the bundle then to the intent~~");
        intent.putExtras(bundle);

        intent.putExtra(Constants.NOTIFICATION_FROM, notificationFrom);
        intent.putExtra(Constants.PACKET_ID, packetId);

        IQ result = NotificationIQ.createResultIQ(notification);
        xmppManager.getConnection().sendPacket(result);
        xmppManager.getContext().sendBroadcast(intent);
      }
    }
  }
  @Override
  public void processPacket(Packet packet) {
    Log.d(LOGTAG, "NotificationPacketListener.processPacket()...");
    Log.d(LOGTAG, "packet.toXML()=" + packet.toXML());

    if (packet instanceof NotificationIQ) {
      NotificationIQ notification = (NotificationIQ) packet;

      if (notification.getChildElementXML().contains("pushserver:iq:notification")) {
        String notificationId = notification.getId();
        String notificationApiKey = notification.getApiKey();
        String notificationTitle = notification.getTitle();
        String notificationMessage = notification.getMessage();
        //                String notificationTicker = notification.getTicker();
        String notificationUri = notification.getUri();

        Intent intent = new Intent(Constants.ACTION_SHOW_NOTIFICATION);
        intent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        intent.putExtra(Constants.NOTIFICATION_API_KEY, notificationApiKey);
        intent.putExtra(Constants.NOTIFICATION_TITLE, notificationTitle);
        intent.putExtra(Constants.NOTIFICATION_MESSAGE, notificationMessage);
        intent.putExtra(Constants.NOTIFICATION_URI, notificationUri);
        //                intent.setData(Uri.parse((new StringBuilder(
        //                        "notif://notification.androidpn.org/")).append(
        //                        notificationApiKey).append("/").append(
        //                        System.currentTimeMillis()).toString()));

        xmppManager.getContext().sendBroadcast(intent);

        NotificationReceivedIQ notificationReceivedIQ = new NotificationReceivedIQ();
        notificationReceivedIQ.setUuid(notificationId);
        notificationReceivedIQ.setType(IQ.Type.SET);
        xmppManager.getConnection().sendPacket(notificationReceivedIQ);
      }
    }
  }
  public static void addRosterListener() {
    XmppManager.getRoster()
        .addRosterListener(
            new RosterListener() {
              @Override
              public void entriesAdded(Collection<String> addresses) {}

              @Override
              public void entriesUpdated(Collection<String> addresses) {}

              @Override
              public void entriesDeleted(Collection<String> addresses) {}

              @Override
              public void presenceChanged(Presence prsnc) {
                System.out.println("Change: " + prsnc.getFrom() + " status :" + prsnc.getStatus());
              }
            });
  }
 public static void addRosterListener(RosterListener listener) {
   XmppManager.getRoster().addRosterListener(listener);
 }
Beispiel #7
0
  /**
   * Reads a get signer request off the wire, sends it to the WS with a new callback for returning
   * the response.
   *
   * @param request the get signer request
   * @param responseCallback the callback to send the response back
   */
  void processGetSignerRequest(final IQ request, final PacketCallback responseCallback) {
    Element items = request.getChildElement().element("items");
    Element signerRequest = items != null ? items.element("signer-request") : null;

    if (items == null
        || signerRequest == null
        || signerRequest.attributeValue("wavelet-name") == null
        || signerRequest.attributeValue("signer-id") == null
        || signerRequest.attributeValue("version") == null
        || signerRequest.attributeValue("history-hash") == null) {
      manager.sendErrorResponse(request, FederationErrors.badRequest("Malformed signer request"));
      return;
    }

    final ByteString signerId;
    try {
      signerId = Base64Util.decode(signerRequest.attributeValue("signer-id"));
    } catch (IllegalArgumentException e) {
      responseCallback.error(FederationErrors.badRequest("Malformed signer ID"));
      return;
    }

    final ProtocolHashedVersion deltaEndVersion;
    try {
      deltaEndVersion =
          parseFromUnsafe(
              signerRequest.attributeValue("version"),
              signerRequest.attributeValue("history-hash"));
    } catch (IllegalArgumentException e) {
      responseCallback.error(FederationErrors.badRequest("Invalid hashed version"));
      return;
    }

    final WaveletName waveletName;
    try {
      waveletName =
          XmppUtil.waveletNameCodec.uriToWaveletName(signerRequest.attributeValue("wavelet-name"));
    } catch (EncodingException e) {
      responseCallback.error(FederationErrors.badRequest("Malformed wavelet name"));
      return;
    }

    WaveletFederationProvider.DeltaSignerInfoResponseListener listener =
        new WaveletFederationProvider.DeltaSignerInfoResponseListener() {
          @Override
          public void onFailure(FederationError error) {
            responseCallback.error(error);
          }

          @Override
          public void onSuccess(ProtocolSignerInfo signerInfo) {
            IQ response = IQ.createResultIQ(request);

            Element pubsub = response.setChildElement("pubsub", XmppNamespace.NAMESPACE_PUBSUB);
            Element items = pubsub.addElement("items");
            XmppUtil.protocolSignerInfoToXml(signerInfo, items);

            responseCallback.run(response);
          }
        };

    waveletProvider.getDeltaSignerInfo(signerId, waveletName, deltaEndVersion, listener);
  }