Ejemplo n.º 1
0
 private void connectionFailed(String reason) {
   logInfo("connectionFailed: " + reason);
   mLastConnectionError = reason;
   mIsConnected.set(false);
   broadcastConnectionStatus(false, mConnectionDemanded.get());
   if (!networkConnected()) {
     mLastConnectionError = null;
     mReconnectInfo = "";
     updateServiceNotification();
     if (mSmackable != null) {
       mSmackable.unRegisterCallback();
       mSmackable = null;
     }
   } else if (mConnectionDemanded.get()) {
     mReconnectInfo = getString(R.string.conn_reconnect, mReconnectTimeout);
     updateServiceNotification();
     logInfo("connectionFailed(): registering reconnect in " + mReconnectTimeout + "s");
     ((AlarmManager) getSystemService(Context.ALARM_SERVICE))
         .set(
             AlarmManager.RTC_WAKEUP,
             System.currentTimeMillis() + mReconnectTimeout * 1000,
             mPAlarmIntent);
     mReconnectTimeout = mReconnectTimeout * 2;
     if (mReconnectTimeout > RECONNECT_MAXIMUM) mReconnectTimeout = RECONNECT_MAXIMUM;
   } else {
     mReconnectInfo = "";
     mServiceNotification.hideNotification(this, SERVICE_NOTIFICATION);
   }
 }
Ejemplo n.º 2
0
 public void performDisconnect() {
   if (mConnectingThread != null) {
     synchronized (mConnectingThread) {
       try {
         mConnectingThread.interrupt();
         mConnectingThread.join(50);
       } catch (InterruptedException e) {
         logError("doDisconnect: failed catching connecting thread");
       } finally {
         mConnectingThread = null;
       }
     }
   }
   if (mSmackable != null) {
     mSmackable.unRegisterCallback();
     mSmackable = null;
   }
   connectionFailed(getString(R.string.conn_offline));
   mServiceNotification.hideNotification(this, SERVICE_NOTIFICATION);
 }
Ejemplo n.º 3
0
  private void doConnect() {
    if (mConnectingThread != null) {
      // a connection is still goign on!
      return;
    }

    mLastConnectionError = getString(R.string.conn_connecting);
    updateServiceNotification();
    if (mSmackable != null) {
      mSmackable.unRegisterCallback();
    }

    mConnectingThread =
        new Thread() {

          public void run() {
            try {
              createAdapter();
              if (!mSmackable.doConnect(create_account)) {
                postConnectionFailed("Inconsistency in Smackable.doConnect()");
              }
              postConnectionEstablished();
            } catch (YaximXMPPException e) {
              String message = e.getLocalizedMessage();
              if (e.getCause() != null) message += "\n" + e.getCause().getLocalizedMessage();
              postConnectionFailed(message);
              logError("YaximXMPPException in doConnect():");
              e.printStackTrace();
            } finally {
              if (mConnectingThread != null)
                synchronized (mConnectingThread) {
                  mConnectingThread = null;
                }
              create_account = false;
            }
          }
        };
    mConnectingThread.start();
  }