Exemplo 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);
   }
 }
Exemplo 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);
 }