Example #1
0
 private void rosterChanged() {
   // gracefully handle^W ignore events after a disconnect
   if (mSmackable == null) return;
   if (!mIsConnected.get() && mSmackable.isAuthenticated()) {
     // We get a roster changed update, but we are not connected,
     // that means we just got connected and need to notify the Activity.
     logInfo("rosterChanged(): we just got connected");
     // connectionEstablished();
   }
   if (mIsConnected.get() && mSmackable != null && !mSmackable.isAuthenticated()) {
     logInfo("rosterChanged(): disconnected without warning");
     connectionFailed(getString(R.string.conn_disconnected));
   }
 }
Example #2
0
  private void createAdapter() {
    System.setProperty("smack.debugEnabled", "" + mConfig.smackdebug);
    try {
      mSmackable = new SmackableImp(mConfig, getContentResolver(), this);
    } catch (NullPointerException e) {
      e.printStackTrace();
    }

    mSmackable.registerCallback(
        new XMPPServiceCallback() {

          public void newMessage(String from, String message) {
            logInfo("notification: " + from);
            notifyClient(from, mSmackable.getNameForJID(from), message, !mIsBoundTo.contains(from));
          }

          public void rosterChanged() {
            postRosterChanged();
          }

          public void disconnectOnError() {
            logInfo("Smackable disconnected on error");
            postConnectionFailed(getString(R.string.conn_disconnected));
          }

          public boolean isBoundTo(String jabberID) {
            return mIsBoundTo.contains(jabberID);
          }
        });
  }
Example #3
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);
   }
 }
Example #4
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);
 }
Example #5
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();
  }