예제 #1
0
 public boolean sendMessage(Message message, boolean encrypt) {
   if (!Network.hasNetwork(this.mContext)) {
     return false;
   }
   Intent intent = createServiceIntent();
   String perfData = MessageProfiling.getPrefString();
   if (!TextUtils.isEmpty(perfData)) {
     CommonPacketExtension perfExt =
         new CommonPacketExtension("pf", null, (String[]) null, (String[]) null);
     CommonPacketExtension sentPerfExt =
         new CommonPacketExtension(
             PushServiceConstants.SEND_MSG_EVENT_TYPE_SENT,
             null,
             (String[]) null,
             (String[]) null);
     sentPerfExt.setText(perfData);
     perfExt.appendChild(sentPerfExt);
     message.addExtension(perfExt);
   }
   Bundle messageBundle = message.toBundle();
   if (messageBundle == null) {
     return false;
   }
   MyLog.v("SEND:" + message.toXML());
   intent.setAction(PushConstants.ACTION_SEND_MESSAGE);
   intent.putExtra(PushConstants.EXTRA_SESSION, sSession);
   intent.putExtra(PushConstants.EXTRA_PACKET, messageBundle);
   intent.putExtra(PushConstants.EXTRA_ENCYPT, encrypt);
   this.mContext.startService(intent);
   return true;
 }
예제 #2
0
 public boolean batchSendMessage(Message[] messages, boolean encrypt) {
   if (!Network.hasNetwork(this.mContext)) {
     return false;
   }
   Intent intent = createServiceIntent();
   Bundle[] messageBundles = new Bundle[messages.length];
   for (int i = 0; i < messages.length; i++) {
     String perfData = MessageProfiling.getPrefString();
     if (!TextUtils.isEmpty(perfData)) {
       CommonPacketExtension perfExt =
           new CommonPacketExtension("pf", null, (String[]) null, (String[]) null);
       CommonPacketExtension sentPerfExt =
           new CommonPacketExtension(
               PushServiceConstants.SEND_MSG_EVENT_TYPE_SENT,
               null,
               (String[]) null,
               (String[]) null);
       sentPerfExt.setText(perfData);
       perfExt.appendChild(sentPerfExt);
       messages[i].addExtension(perfExt);
     }
     MyLog.v("SEND:" + messages[i].toXML());
     messageBundles[i] = messages[i].toBundle();
   }
   if (messageBundles.length <= 0) {
     return false;
   }
   intent.setAction(PushConstants.ACTION_BATCH_SEND_MESSAGE);
   intent.putExtra(PushConstants.EXTRA_SESSION, sSession);
   intent.putExtra(PushConstants.EXTRA_PACKETS, messageBundles);
   intent.putExtra(PushConstants.EXTRA_ENCYPT, encrypt);
   this.mContext.startService(intent);
   return true;
 }
예제 #3
0
 public boolean sendPresence(Presence presence) {
   if (!Network.hasNetwork(this.mContext)) {
     return false;
   }
   Intent intent = createServiceIntent();
   Bundle presBundle = presence.toBundle();
   if (presBundle == null) {
     return false;
   }
   MyLog.v("SEND:" + presence.toXML());
   intent.setAction(PushConstants.ACTION_SEND_PRESENCE);
   intent.putExtra(PushConstants.EXTRA_SESSION, sSession);
   intent.putExtra(PushConstants.EXTRA_PACKET, presBundle);
   this.mContext.startService(intent);
   return true;
 }
예제 #4
0
 public boolean sendIQ(IQ iq) {
   if (!Network.hasNetwork(this.mContext)) {
     return false;
   }
   Intent intent = createServiceIntent();
   Bundle iqBundle = iq.toBundle();
   if (iqBundle == null) {
     return false;
   }
   MyLog.v("SEND:" + iq.toXML());
   intent.setAction(PushConstants.ACTION_SEND_IQ);
   intent.putExtra(PushConstants.EXTRA_SESSION, sSession);
   intent.putExtra(PushConstants.EXTRA_PACKET, iqBundle);
   this.mContext.startService(intent);
   return true;
 }
예제 #5
0
 public void setConnectionStatus(int newStatus, int reason, Exception e) {
   if (newStatus != this.connectStatus) {
     MyLog.warn(
         String.format(
             "update the connection status. %1$s -> %2$s : %3$s ",
             new Object[] {
               getDesc(this.connectStatus), getDesc(newStatus), PushConstants.getErrorDesc(reason)
             }));
   }
   if (Network.hasNetwork(this.mPushService)) {
     addStatus(newStatus);
   }
   if (newStatus == 1) {
     this.mPushService.removeJobs(10);
     if (this.connectStatus != 0) {
       MyLog.warn("try set connected while not connecting.");
     }
     this.connectStatus = newStatus;
     for (ConnectionListener listener : this.connectionListeners) {
       listener.reconnectionSuccessful();
     }
   } else if (newStatus == 0) {
     this.mPushService.setConnectingTimeout();
     if (this.connectStatus != 2) {
       MyLog.warn("try set connecting while not disconnected.");
     }
     this.connectStatus = newStatus;
     for (ConnectionListener listener2 : this.connectionListeners) {
       listener2.connectionStarted();
     }
   } else if (newStatus == 2) {
     this.mPushService.removeJobs(10);
     if (this.connectStatus == 0) {
       for (ConnectionListener listener22 : this.connectionListeners) {
         listener22.reconnectionFailed(
             e == null ? new CancellationException("disconnect while connecting") : e);
       }
     } else if (this.connectStatus == 1) {
       for (ConnectionListener listener222 : this.connectionListeners) {
         listener222.connectionClosed(reason, e);
       }
     }
     this.connectStatus = newStatus;
   }
 }